]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Fix #1427 - webui: Added reverse proxy support.
authorAdam Sutton <dev@adamsutton.me.uk>
Thu, 20 Dec 2012 21:38:20 +0000 (21:38 +0000)
committerAdam Sutton <dev@adamsutton.me.uk>
Thu, 20 Dec 2012 21:38:20 +0000 (21:38 +0000)
This includes a next webroot command line argument (using -W) and
some minor mods to the core HTTP/WebUI code to support this. Most
of the mods are pretty trivial and hopefully nothing will break
too badly.

src/http.c
src/main.c
src/tvheadend.h
src/webui/static/app/tvheadend.js
src/webui/webui.c

index 07c88fc64502895d73ab64ae82b66439e3662540..7610adf1d48eb39cede7a862f0a1b10071114308 100644 (file)
@@ -608,8 +608,18 @@ http_path_add(const char *path, void *opaque, http_callback_t *callback,
 {
   http_path_t *hp = malloc(sizeof(http_path_t));
 
-  hp->hp_len      = strlen(path);
-  hp->hp_path     = strdup(path);
+  if (tvheadend_webroot) {
+    char *tmp; const char *pre = "";
+    size_t len = strlen(tvheadend_webroot) + strlen(path) + 1;
+    if (*tvheadend_webroot != '/') {
+      len++;
+      pre = "/";
+    }
+    hp->hp_path     = tmp = malloc(len);
+    sprintf(tmp, "%s%s%s", pre, tvheadend_webroot, path);
+  } else
+    hp->hp_path     = strdup(path);
+  hp->hp_len      = strlen(hp->hp_path);
   hp->hp_opaque   = opaque;
   hp->hp_callback = callback;
   hp->hp_accessmask = accessmask;
index 564e592cbd6f12576c1e947f74a914502847a4d7..baae957c1c9c04fc3f15bbdfd7e504de35716fb6 100644 (file)
@@ -77,6 +77,7 @@ int webui_port;
 int htsp_port;
 int htsp_port_extra;
 char *tvheadend_cwd;
+const char *tvheadend_webroot;
 
 const char *tvheadend_capabilities[] = {
 #if ENABLE_CWC
@@ -202,6 +203,7 @@ usage(const char *argv0)
   printf(" -s              Log debug to syslog\n");
   printf(" -w <portnumber> WebUI access port [default 9981]\n");
   printf(" -e <portnumber> HTSP access port [default 9982]\n");
+  printf(" -W <path>       WebUI context path [default /]\n");
   printf("\n");
   printf("Development options\n");
   printf("\n");
@@ -297,7 +299,7 @@ main(int argc, char **argv)
   // make sure the timezone is set
   tzset();
 
-  while((c = getopt(argc, argv, "Aa:fp:u:g:c:Chdr:j:sw:e:E:R:")) != -1) {
+  while((c = getopt(argc, argv, "Aa:fp:u:g:c:Chdr:j:sw:e:E:R:W:")) != -1) {
     switch(c) {
     case 'a':
       adapter_mask = 0x0;
@@ -366,6 +368,9 @@ main(int argc, char **argv)
     case 'j':
       join_transport = optarg;
       break;
+    case 'W':
+      tvheadend_webroot = optarg;
+      break;
     default:
       usage(argv[0]);
     }
index eb317b9cc3e2e4153f0c1433e1dad5a8969d4305..8ad66cd04db2c360418a9f3ab1abc2fc817fba63 100644 (file)
@@ -37,6 +37,7 @@
 extern const char *tvheadend_version;
 extern char *tvheadend_cwd;
 extern const char *tvheadend_capabilities[];
+extern const char *tvheadend_webroot;
 
 #define PTS_UNSET INT64_C(0x8000000000000000)
 
index 2a1af2b7e313439af5e99bb98f8bba9fd11f783c..d1754f498f73b645e59e8ef85c2457c678e7ef45 100644 (file)
@@ -34,7 +34,7 @@ tvheadend.help = function(title, pagename) {
  * General capabilities
  */
 Ext.Ajax.request({
-  url: '/capabilities',
+  url: 'capabilities',
   success: function(d)
   {
     if (d && d.responseText)
index 170127cf86f6c2f793d744a3237ee7b9e50be651..fbd0416f2fa47d895b86c2ae2f5de4939bbf1249 100644 (file)
@@ -74,13 +74,24 @@ static int
 page_root(http_connection_t *hc, const char *remain, void *opaque)
 {
   if(is_client_simple(hc)) {
-    http_redirect(hc, "/simple.html");
+    http_redirect(hc, "simple.html");
   } else {
-    http_redirect(hc, "/extjs.html");
+    http_redirect(hc, "extjs.html");
   }
   return 0;
 }
 
+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);
+  free(tmp);
+  return 0;
+}
+
 /**
  * Static download of a file from the filesystem
  */
@@ -922,6 +933,7 @@ int page_statedump(http_connection_t *hc, const char *remain, void *opaque);
 void
 webui_init(void)
 {
+  http_path_add("", NULL, page_root2, ACCESS_WEB_INTERFACE);
   http_path_add("/", NULL, page_root, ACCESS_WEB_INTERFACE);
 
   http_path_add("/dvrfile", NULL, page_dvrfile, ACCESS_WEB_INTERFACE);