From 8933910f9846bac630bf0dab06a4b7cd6b2b5ce3 Mon Sep 17 00:00:00 2001 From: Christian Pointner <equinox@helsinki.at> Date: Sat, 2 Apr 2016 18:10:36 +0200 Subject: added http static dir for static files diff --git a/html/upload-form.html b/html/upload-form.html deleted file mode 100644 index 1718b1b..0000000 --- a/html/upload-form.html +++ /dev/null @@ -1,25 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - <head> - <title>rhimportd File Upload</title> - </head> - <body> - <div class="container"> - <h1>rhimportd File Upload</h1> - <form class="form-upload" method="post" enctype="multipart/form-data"> - <fieldset> - <label for="LOGIN_NAME">Username:</label> - <input type="text" name="LOGIN_NAME"> - </br> - <label for="LOGIN_NAME">Password:</label> - <input type="password" name="PASSWORD"> - </br> - <label for="FILENAME">File:</label> - <input type="file" name="FILENAME"> - </br> - <input type="submit" name="submit" value="Submit"> - </fieldset> - </form> - </div> - </body> -</html> diff --git a/src/rhimportd/ctrlWeb.go b/src/rhimportd/ctrlWeb.go index 6bee325..2b52ef0 100644 --- a/src/rhimportd/ctrlWeb.go +++ b/src/rhimportd/ctrlWeb.go @@ -44,9 +44,10 @@ func (self webHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { self.H(self.Config, self.DBChan, self.SessionStoreChan, self.trusted, w, r) } -func StartControlWeb(addr string, uploadMaxAge time.Duration, conf *rhimport.Config, db *rddb.DBChan, sessions *rhimport.SessionStoreChan) { - // http.Handle("/trusted/simple", webHandler{conf, db, sessions, true, webSimpleHandler}) +func StartControlWeb(addr, staticDir string, uploadMaxAge time.Duration, conf *rhimport.Config, db *rddb.DBChan, sessions *rhimport.SessionStoreChan) { + http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir)))) + // http.Handle("/trusted/simple", webHandler{conf, db, sessions, true, webSimpleHandler}) http.Handle("/public/simple", webHandler{conf, db, sessions, false, webSimpleHandler}) http.Handle("/public/socket", webHandler{conf, db, sessions, false, webSocketHandler}) http.Handle("/public/upload", webHandler{conf, db, sessions, false, webUploadHandler}) diff --git a/src/rhimportd/main.go b/src/rhimportd/main.go index 68b0177..97a12ec 100644 --- a/src/rhimportd/main.go +++ b/src/rhimportd/main.go @@ -92,6 +92,8 @@ func (d *envDurationValue) String() string { return fmt.Sprintf("%v", *d) } func main() { webAddr := newEnvStringValue("RHIMPORTD_WEB_ADDR", "localhost:4080") flag.Var(webAddr, "web-addr", "addr:port to listen on (environment: RHIMPORTD_WEB_ADDR)") + webStaticDir := newEnvStringValue("RHIMPORTD_WEB_STATIC_DIR", "/usr/share/rhimportd/web-static/") + flag.Var(webStaticDir, "web-static-dir", "path to static html files (environment: RHIMPORTD_WEB_STATIC_DIR)") telnetAddr := newEnvStringValue("RHIMPORTD_TELNET_ADDR", "localhost:4023") flag.Var(telnetAddr, "telnet-addr", "addr:port to listen on (environment: RHIMPORTD_TELNET_ADDR)") watchDir := newEnvStringValue("RHIMPORTD_WATCH_DIR", "") @@ -143,7 +145,7 @@ func main() { go func() { defer wg.Done() rhl.Println("starting web-ctrl") - StartControlWeb(webAddr.Get().(string), uploadMaxAge.Get().(time.Duration), conf, db.GetInterface(), sessions.GetInterface()) + StartControlWeb(webAddr.Get().(string), webStaticDir.Get().(string), uploadMaxAge.Get().(time.Duration), conf, db.GetInterface(), sessions.GetInterface()) rhl.Println("web-ctrl finished") }() } diff --git a/src/rhimportd/uploadWeb.go b/src/rhimportd/uploadWeb.go index 3a4e7bc..4dc0368 100644 --- a/src/rhimportd/uploadWeb.go +++ b/src/rhimportd/uploadWeb.go @@ -64,7 +64,7 @@ const ( func webUploadHandler(conf *rhimport.Config, db *rddb.DBChan, sessions *rhimport.SessionStoreChan, trusted bool, w http.ResponseWriter, r *http.Request) { if r.Method == "GET" { - http.ServeFile(w, r, "./html/upload-form.html") // TODO: hardcoded html-dir... should we print the html directly? + http.Redirect(w, r, "/static/upload-form.html", http.StatusTemporaryRedirect) return } diff --git a/web-static/upload-form.html b/web-static/upload-form.html new file mode 100644 index 0000000..bbb397c --- /dev/null +++ b/web-static/upload-form.html @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <title>rhimportd File Upload</title> + </head> + <body> + <div class="container"> + <h1>rhimportd File Upload</h1> + <form class="form-upload" method="post" action="/public/upload" enctype="multipart/form-data"> + <fieldset> + <label for="LOGIN_NAME">Username:</label> + <input type="text" name="LOGIN_NAME"> + </br> + <label for="LOGIN_NAME">Password:</label> + <input type="password" name="PASSWORD"> + </br> + <label for="FILENAME">File:</label> + <input type="file" name="FILENAME"> + </br> + <input type="submit" name="submit" value="Submit"> + </fieldset> + </form> + </div> + </body> +</html> -- cgit v0.10.2