luci-base: remove hardcoded cgi-bin path
authorAnsuel Smith <ansuelsmth@gmail.com>
Wed, 15 Jan 2020 23:30:30 +0000 (00:30 +0100)
committerJo-Philipp Wich <jo@mein.io>
Wed, 4 Mar 2020 07:50:21 +0000 (08:50 +0100)
Currently LuCI can be loaded only when placed in the root of the server as the cgi-bin path are hardcoded. Change the index.html to load the cgi-bin path from the current level.
Also add a new entry in the env Object to make the cgi_base path easily accessible.
This variable will be based on the position of /cgi-bin/luci.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
(cherry picked from commit 5e6ec8562fe828934ef835490cee405653b06d3a)

modules/luci-base/htdocs/luci-static/resources/fs.js
modules/luci-base/htdocs/luci-static/resources/luci.js
modules/luci-base/htdocs/luci-static/resources/ui.js
modules/luci-base/root/www/index.html
modules/luci-mod-system/htdocs/luci-static/resources/view/system/flash.js

index e1bf4f874afbbace912857ea6f7882342afe0525..d32b20f2f1cc73bbe8699545eca1fab29cd1b545 100644 (file)
@@ -342,7 +342,7 @@ var FileSystem = L.Class.extend(/** @lends LuCI.fs.prototype */ {
                var postdata = 'sessionid=%s&path=%s'
                        .format(encodeURIComponent(L.env.sessionid), encodeURIComponent(path));
 
-               return L.Request.post('/cgi-bin/cgi-download', postdata, {
+               return L.Request.post(L.env.cgi_base + '/cgi-download', postdata, {
                        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
                }).then(handleCgiIoReply);
        },
@@ -385,7 +385,7 @@ var FileSystem = L.Class.extend(/** @lends LuCI.fs.prototype */ {
                var postdata = 'sessionid=%s&command=%s'
                        .format(encodeURIComponent(L.env.sessionid), encodeURIComponent(cmdstr));
 
-               return L.Request.post('/cgi-bin/cgi-exec', postdata, {
+               return L.Request.post(L.env.cgi_base + '/cgi-exec', postdata, {
                        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
                }).then(handleCgiIoReply);
        }
index dbe2510527a9a2c1c473be21e802a9516797416a..5a8f31cf5790ba7363726691a5209239fa698ae8 100644 (file)
                        if (env.base_url == null)
                                this.error('InternalError', 'Cannot find url of luci.js');
 
+                       env.cgi_base = env.scriptname.replace(/\/[^\/]+$/, '');
+
                        Object.assign(this.env, env);
 
                        document.addEventListener('poll-start', function(ev) {
index a12cbdb30d646b60fa0d36b11cec376ac901c566..618b3941e9520f812a53e6a6230512979825290c 100644 (file)
@@ -1736,7 +1736,7 @@ var UIFileUpload = UIElement.extend({
                data.append('filename', path + '/' + filename);
                data.append('filedata', fileinput.files[0]);
 
-               return L.Request.post('/cgi-bin/cgi-upload', data, {
+               return L.Request.post(L.env.cgi_base + '/cgi-upload', data, {
                        progress: L.bind(function(btn, ev) {
                                btn.firstChild.data = '%.2f%%'.format((ev.loaded / ev.total) * 100);
                        }, this, ev.target)
@@ -2433,7 +2433,7 @@ return L.Class.extend({
 
                                                                var filename = input.files[0].name;
 
-                                                               L.Request.post('/cgi-bin/cgi-upload', data, {
+                                                               L.Request.post(L.env.cgi_base + '/cgi-upload', data, {
                                                                        timeout: 0,
                                                                        progress: function(pev) {
                                                                                var percent = (pev.loaded / pev.total) * 100;
index 6899820a44007876976865dd7682162d8f828b85..35c0ea0d32e3c208f838e5b9d962ac6542aa6de0 100644 (file)
@@ -3,9 +3,9 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
-<meta http-equiv="refresh" content="0; URL=/cgi-bin/luci/" />
+<meta http-equiv="refresh" content="0; URL=cgi-bin/luci/" />
 </head>
 <body style="background-color: white">
-<a style="color: black; font-family: arial, helvetica, sans-serif;" href="/cgi-bin/luci/">LuCI - Lua Configuration Interface</a>
+<a style="color: black; font-family: arial, helvetica, sans-serif;" href="cgi-bin/luci/">LuCI - Lua Configuration Interface</a>
 </body>
 </html>
index 05e1434f15a1f4eae0f797fe1d4e28d05e6a110f..b1cc4d1a6f83a6e2421e01f7e42e7572cbcc7551 100644 (file)
@@ -76,7 +76,7 @@ return L.view.extend({
        handleBackup: function(ev) {
                var form = E('form', {
                        method: 'post',
-                       action: '/cgi-bin/cgi-backup',
+                       action: L.env.cgi_base + '/cgi-backup',
                        enctype: 'application/x-www-form-urlencoded'
                }, E('input', { type: 'hidden', name: 'sessionid', value: rpc.getSessionID() }));
 
@@ -169,7 +169,7 @@ return L.view.extend({
                var mtdblock = L.dom.parent(ev.target, '.cbi-section').querySelector('[data-name="mtdselect"] select').value;
                var form = E('form', {
                        'method': 'post',
-                       'action': '/cgi-bin/cgi-download',
+                       'action': L.env.cgi_base + '/cgi-download',
                        'enctype': 'application/x-www-form-urlencoded'
                }, [
                        E('input', { 'type': 'hidden', 'name': 'sessionid', 'value': rpc.getSessionID() }),