diff --git a/webui/extjs.c b/webui/extjs.c index b1484169..b0ab8390 100644 --- a/webui/extjs.c +++ b/webui/extjs.c @@ -40,14 +40,6 @@ extern const char *htsversion; -#include "obj/tvheadend.jsh" -#include "obj/extensions.jsh" -#include "obj/acleditor.jsh" -#include "obj/cwceditor.jsh" -#include "obj/dvb.jsh" -#include "obj/ext.cssh" - - static void extjs_load(htsbuf_queue_t *hq, const char *script) { @@ -89,7 +81,7 @@ extjs_root(http_connection_t *hc, http_reply_t *hr, htsbuf_qprintf(hq, "\n" "\n" - "\n" + "\n" "\n" "\n"); @@ -99,8 +91,7 @@ extjs_root(http_connection_t *hc, http_reply_t *hr, /** * Load extjs extensions */ - extjs_load(hq, "app/extensions.js"); - extjs_load(hq, "app/tabclosemenu.js"); + extjs_load(hq, "static/app/extensions.js"); /** * Create a namespace for our app @@ -110,14 +101,14 @@ extjs_root(http_connection_t *hc, http_reply_t *hr, /** * Load all components */ - extjs_load(hq, "app/acleditor.js"); - extjs_load(hq, "app/cwceditor.js"); - extjs_load(hq, "app/dvb.js"); + extjs_load(hq, "static/app/acleditor.js"); + extjs_load(hq, "static/app/cwceditor.js"); + extjs_load(hq, "static/app/dvb.js"); /** * Finally, the app itself */ - extjs_load(hq, "app/tvheadend.js"); + extjs_load(hq, "static/app/tvheadend.js"); extjs_exec(hq, "Ext.onReady(tvheadend.app.init, tvheadend.app);"); @@ -401,16 +392,4 @@ extjs_start(void) http_path_add("/dvbtree", NULL, extjs_dvbtree, ACCESS_WEB_INTERFACE); http_path_add("/dvbadapter", NULL, extjs_dvbadapter, ACCESS_WEB_INTERFACE); http_path_add("/dvbnetworks", NULL, extjs_dvbnetworks, ACCESS_WEB_INTERFACE); - -#define ADD_JS_RESOURCE(path, name) \ - http_resource_add(path, name, sizeof(name), "text/javascript", "gzip") - - ADD_JS_RESOURCE("/app/extensions.js", embedded_extensions); - ADD_JS_RESOURCE("/app/extensions.css", embedded_ext); - - ADD_JS_RESOURCE("/app/tvheadend.js", embedded_tvheadend); - - ADD_JS_RESOURCE("/app/acleditor.js", embedded_acleditor); - ADD_JS_RESOURCE("/app/cwceditor.js", embedded_cwceditor); - ADD_JS_RESOURCE("/app/dvb.js", embedded_dvb); } diff --git a/webui/acleditor.js b/webui/static/app/acleditor.js similarity index 100% rename from webui/acleditor.js rename to webui/static/app/acleditor.js diff --git a/webui/cwceditor.js b/webui/static/app/cwceditor.js similarity index 100% rename from webui/cwceditor.js rename to webui/static/app/cwceditor.js diff --git a/webui/dvb.js b/webui/static/app/dvb.js similarity index 100% rename from webui/dvb.js rename to webui/static/app/dvb.js diff --git a/webui/ext.css b/webui/static/app/ext.css similarity index 100% rename from webui/ext.css rename to webui/static/app/ext.css diff --git a/webui/extensions.js b/webui/static/app/extensions.js similarity index 100% rename from webui/extensions.js rename to webui/static/app/extensions.js diff --git a/webui/tvheadend.js b/webui/static/app/tvheadend.js similarity index 100% rename from webui/tvheadend.js rename to webui/static/app/tvheadend.js diff --git a/webui/webui.c b/webui/webui.c index e6ba79e5..13ad173c 100644 --- a/webui/webui.c +++ b/webui/webui.c @@ -23,6 +23,9 @@ #include #include +#include +#include + #include "tvhead.h" #include "access.h" #include "http.h" @@ -62,6 +65,58 @@ page_root(http_connection_t *hc, http_reply_t *hr, return 0; } +/** + * Root page, we direct the client to different pages depending + * on if it is a full blown browser or just some mobile app + */ +static int +page_static(http_connection_t *hc, http_reply_t *hr, + const char *remain, void *opaque) +{ + int fd, r; + const char *rootpath = HTS_BUILD_ROOT "/tvheadend/webui/static"; + char path[500]; + struct stat st; + void *buf; + htsbuf_queue_t *hq = &hr->hr_q; + const char *content = NULL, *postfix; + + if(strstr(remain, "..")) + return HTTP_STATUS_BAD_REQUEST; + + snprintf(path, sizeof(path), "%s/%s", rootpath, remain); + + if((fd = open(path, O_RDONLY)) < 0) + return 404; + + if(fstat(fd, &st) < 0) { + close(fd); + return 404; + } + + buf = malloc(st.st_size); + r = read(fd, buf, st.st_size); + close(fd); + + if(r != st.st_size) { + free(buf); + return 404; + } + + postfix = strrchr(remain, '.'); + if(postfix != NULL) { + postfix++; + + if(!strcmp(postfix, "js")) + content = "text/javascript; charset=UTF-8"; + } + + htsbuf_append_prealloc(hq, buf, st.st_size); + http_output(hc, hr, content, NULL, 0); + return 0; +} + + /** * WEB user interface */ @@ -70,7 +125,10 @@ webui_start(void) { http_path_add("/", NULL, page_root, ACCESS_WEB_INTERFACE); + http_path_add("/static", NULL, page_static, ACCESS_WEB_INTERFACE); + simpleui_start(); extjs_start(); comet_init(); + }