]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
webui: fix --http_root issues, fixes #3035
authorJaroslav Kysela <perex@perex.cz>
Thu, 6 Aug 2015 13:41:33 +0000 (15:41 +0200)
committerJaroslav Kysela <perex@perex.cz>
Thu, 6 Aug 2015 13:42:31 +0000 (15:42 +0200)
src/http.c
src/http.h
src/webui/simpleui.c
src/webui/webui.c

index 205a992de28d0c42f9fa1b0a0a377e0854f7661a..2a418bbb02607773dbad61c3d1a9471d1e34afd8 100644 (file)
@@ -407,7 +407,8 @@ http_error(http_connection_t *hc, int error)
                    error, errtxt, error, errtxt);
 
     if (error == HTTP_STATUS_UNAUTHORIZED)
-      htsbuf_qprintf(&hc->hc_reply, "<P><A HREF=\"/\">Default Login</A></P>");
+      htsbuf_qprintf(&hc->hc_reply, "<P><A HREF=\"%s/\">Default Login</A></P>",
+                     tvheadend_webroot ? tvheadend_webroot : "");
 
     htsbuf_qprintf(&hc->hc_reply, "</BODY></HTML>\r\n");
 
@@ -444,7 +445,7 @@ http_output_content(http_connection_t *hc, const char *content)
  */
 void
 http_redirect(http_connection_t *hc, const char *location,
-              http_arg_list_t *req_args)
+              http_arg_list_t *req_args, int external)
 {
   const char *loc = location;
   htsbuf_queue_flush(&hc->hc_reply);
@@ -454,6 +455,8 @@ http_redirect(http_connection_t *hc, const char *location,
     htsbuf_queue_t hq;
     int first = 1;
     htsbuf_queue_init(&hq, 0);
+    if (!external && tvheadend_webroot && location[0] == '/')
+      htsbuf_append(&hq, tvheadend_webroot, strlen(tvheadend_webroot));
     htsbuf_append(&hq, location, strlen(location));
     htsbuf_append(&hq, "?", 1);
     TAILQ_FOREACH(ra, req_args, link) {
@@ -466,6 +469,10 @@ http_redirect(http_connection_t *hc, const char *location,
     }
     loc = htsbuf_to_string(&hq);
     htsbuf_queue_flush(&hq);
+  } else if (!external && tvheadend_webroot && location[0] == '/') {
+    loc = malloc(strlen(location) + strlen(tvheadend_webroot) + 1);
+    strcpy((char *)loc, tvheadend_webroot);
+    strcat((char *)loc, location);
   }
 
   htsbuf_qprintf(&hc->hc_reply,
index 8df736e8b2abb56539151a0a6517816daf6db22e..2326618d8f3ed3659a07d06459ebb5aa5db53c8c 100644 (file)
@@ -191,7 +191,7 @@ void http_output_html(http_connection_t *hc);
 void http_output_content(http_connection_t *hc, const char *content);
 
 void http_redirect(http_connection_t *hc, const char *location,
-                   struct http_arg_list *req_args);
+                   struct http_arg_list *req_args, int external);
 
 void http_send_header(http_connection_t *hc, int rc, const char *content, 
                      int64_t contentlen, const char *encoding,
index ad4f7c136ba0f2af637e48c48dd5e867f51b08f2..4a71f664fcb85f24359d5d137dcf26e7bfe13562 100644 (file)
@@ -409,7 +409,7 @@ page_pvrinfo(http_connection_t *hc, const char *remain, void *opaque)
 
   if(de == NULL) {
     pthread_mutex_unlock(&global_lock);
-    http_redirect(hc, "/simple.html", &hc->hc_req_args);
+    http_redirect(hc, "/simple.html", &hc->hc_req_args, 0);
     return 0;
   }
 
index c144c1a36b77b0e6b8a3620194ce2e6c60db3a4a..3407496319a4d0b7bd26be89896fc72933100c8d 100644 (file)
@@ -92,9 +92,9 @@ static int
 page_root(http_connection_t *hc, const char *remain, void *opaque)
 {
   if(is_client_simple(hc)) {
-    http_redirect(hc, "simple.html", &hc->hc_req_args);
+    http_redirect(hc, "simple.html", &hc->hc_req_args, 0);
   } else {
-    http_redirect(hc, "extjs.html", &hc->hc_req_args);
+    http_redirect(hc, "extjs.html", &hc->hc_req_args, 0);
   }
   return 0;
 }
@@ -103,10 +103,7 @@ static int
 page_root2(http_connection_t *hc, const char *remain, void *opaque)
 {
   if (!tvheadend_webroot) return 1;
-  char *tmp = malloc(strlen(tvheadend_webroot) + 2);
-  sprintf(tmp, "%s/", tvheadend_webroot);
-  http_redirect(hc, tmp, &hc->hc_req_args);
-  free(tmp);
+  http_redirect(hc, "/", &hc->hc_req_args, 0);
   return 0;
 }
 
@@ -116,7 +113,7 @@ page_login(http_connection_t *hc, const char *remain, void *opaque)
   if (hc->hc_access != NULL &&
       hc->hc_access->aa_username != NULL &&
       hc->hc_access->aa_username != '\0') {
-    http_redirect(hc, "/", &hc->hc_req_args);
+    http_redirect(hc, "/", &hc->hc_req_args, 0);
     return 0;
   } else {
     return HTTP_STATUS_UNAUTHORIZED;
@@ -130,7 +127,7 @@ page_logout(http_connection_t *hc, const char *remain, void *opaque)
       hc->hc_access->aa_username == NULL ||
       hc->hc_access->aa_username == '\0') {
 redirect:
-    http_redirect(hc, "/", &hc->hc_req_args);
+    http_redirect(hc, "/", &hc->hc_req_args, 0);
     return 0;
   } else {
     const char *s = http_arg_get(&hc->hc_args, "Cookie");
@@ -1406,7 +1403,7 @@ webui_static_content(const char *http_path, const char *source)
 static int
 favicon(http_connection_t *hc, const char *remain, void *opaque)
 {
-  http_redirect(hc, "static/htslogo.png", NULL);
+  http_redirect(hc, "static/htslogo.png", NULL, 0);
   return 0;
 }