From: Hannu Nyman Date: Sat, 28 Apr 2018 05:48:09 +0000 (+0300) Subject: Merge pull request #1767 from SvenRoederer/patch-2 X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci.git;a=commitdiff_plain;h=8656ab726d4aba08164f8ed7a242830c12239be3;hp=c4460f09a580425efebb9f3ee7c9c3372d5f085b Merge pull request #1767 from SvenRoederer/patch-2 luci-mod-freifunk: align spacing --- diff --git a/modules/luci-base/htdocs/luci-static/resources/xhr.js b/modules/luci-base/htdocs/luci-static/resources/xhr.js index 3385f8f23..91dcf3fef 100644 --- a/modules/luci-base/htdocs/luci-static/resources/xhr.js +++ b/modules/luci-base/htdocs/luci-static/resources/xhr.js @@ -39,7 +39,7 @@ XHR = function() this._xmlHttp.abort(); } - this.get = function(url,data,callback) + this.get = function(url,data,callback,timeout) { this.reinit(); @@ -54,6 +54,9 @@ XHR = function() else url += '?' + code; + if (!isNaN(timeout)) + xhr.timeout = timeout; + xhr.open('GET', url, true); xhr.onreadystatechange = function() @@ -76,7 +79,7 @@ XHR = function() xhr.send(null); } - this.post = function(url,data,callback) + this.post = function(url,data,callback,timeout) { this.reinit(); @@ -89,6 +92,9 @@ XHR = function() callback(xhr); } + if (!isNaN(timeout)) + xhr.timeout = timeout; + xhr.open('POST', url, true); xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); xhr.send(code); @@ -168,7 +174,7 @@ XHR.get = function(url, data, callback) (new XHR()).get(url, data, callback); } -XHR.poll = function(interval, url, data, callback) +XHR.poll = function(interval, url, data, callback, post) { if (isNaN(interval) || interval < 1) interval = 5; @@ -181,22 +187,38 @@ XHR.poll = function(interval, url, data, callback) for (var i = 0, e = XHR._q[0]; i < XHR._q.length; e = XHR._q[++i]) { if (!(XHR._t % e.interval) && !e.xhr.busy()) - e.xhr.get(e.url, e.data, e.callback); + e.xhr[post ? 'post' : 'get'](e.url, e.data, e.callback, e.interval * 1000 - 5); } XHR._t++; }; } - XHR._q.push({ + var e = { interval: interval, callback: callback, url: url, data: data, xhr: new XHR() - }); + }; + XHR._q.push(e); XHR.run(); + + return e; +} + +XHR.stop = function(e) +{ + for (var i = 0; XHR._q && XHR._q[i]; i++) { + if (XHR._q[i] === e) { + e.xhr.cancel(); + XHR._q.splice(i, 1); + return true; + } + } + + return false; } XHR.halt = function() diff --git a/modules/luci-base/luasrc/dispatcher.lua b/modules/luci-base/luasrc/dispatcher.lua index 5fc2b80e7..1984fc4ad 100644 --- a/modules/luci-base/luasrc/dispatcher.lua +++ b/modules/luci-base/luasrc/dispatcher.lua @@ -442,6 +442,13 @@ function dispatch(request) ctx.authuser = sdat.username end + if track.cors and http.getenv("REQUEST_METHOD") == "OPTIONS" then + luci.http.status(200, "OK") + luci.http.header("Access-Control-Allow-Origin", http.getenv("HTTP_ORIGIN") or "*") + luci.http.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS") + return + end + if c and require_post_security(c.target) then if not test_post_security(c) then return diff --git a/modules/luci-base/luasrc/http.lua b/modules/luci-base/luasrc/http.lua index be5577ee0..16fb04c54 100644 --- a/modules/luci-base/luasrc/http.lua +++ b/modules/luci-base/luasrc/http.lua @@ -486,26 +486,22 @@ end -- handled then the whole message body will be stored unaltered as "content" -- property within the given message object. function parse_message_body(src, msg, filecb) - local ctype = lhttp.header_attribute(msg.env.CONTENT_TYPE, nil) + if msg.env.CONTENT_LENGTH or msg.env.REQUEST_METHOD == "POST" then + local ctype = lhttp.header_attribute(msg.env.CONTENT_TYPE, nil) - -- Is it multipart/mime ? - if msg.env.REQUEST_METHOD == "POST" and - ctype == "multipart/form-data" - then - return mimedecode_message_body(src, msg, filecb) + -- Is it multipart/mime ? + if ctype == "multipart/form-data" then + return mimedecode_message_body(src, msg, filecb) - -- Is it application/x-www-form-urlencoded ? - elseif msg.env.REQUEST_METHOD == "POST" and - ctype == "application/x-www-form-urlencoded" - then - return urldecode_message_body(src, msg) + -- Is it application/x-www-form-urlencoded ? + elseif ctype == "application/x-www-form-urlencoded" then + return urldecode_message_body(src, msg) + end - -- Unhandled encoding - -- If a file callback is given then feed it chunk by chunk, else - -- store whole buffer in message.content - else - + -- Unhandled encoding + -- If a file callback is given then feed it chunk by chunk, else + -- store whole buffer in message.content local sink -- If we have a file callback then feed it @@ -553,4 +549,6 @@ function parse_message_body(src, msg, filecb) return true end + + return false end diff --git a/themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap/header.htm b/themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap/header.htm index 0441c9583..4881535ac 100644 --- a/themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap/header.htm +++ b/themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap/header.htm @@ -145,7 +145,7 @@ end if ucichanges > 0 then - write('%s: %d' %{ + write('%s: %d' %{ url(category, 'uci/changes'), http.urlencode(http.formvalue('redir') or table.concat(disp.context.request, "/")), translate('Unsaved Changes'), diff --git a/themes/luci-theme-freifunk-generic/luasrc/view/themes/freifunk-generic/header.htm b/themes/luci-theme-freifunk-generic/luasrc/view/themes/freifunk-generic/header.htm index 818565528..16ffc992a 100644 --- a/themes/luci-theme-freifunk-generic/luasrc/view/themes/freifunk-generic/header.htm +++ b/themes/luci-theme-freifunk-generic/luasrc/view/themes/freifunk-generic/header.htm @@ -205,7 +205,7 @@ if tree.nodes[category] and tree.nodes[category].ucidata then -%>
<% if ucic > 0 then %> - "><%:Unsaved Changes%>: <%=ucic%> + "><%:Unsaved Changes%>: <%=ucic%> <% end -%>
<% end %> diff --git a/themes/luci-theme-material/luasrc/view/themes/material/header.htm b/themes/luci-theme-material/luasrc/view/themes/material/header.htm index be7b9ffb8..0aca882c0 100644 --- a/themes/luci-theme-material/luasrc/view/themes/material/header.htm +++ b/themes/luci-theme-material/luasrc/view/themes/material/header.htm @@ -170,7 +170,7 @@ end if ucichanges > 0 then - write('%s: %d' %{ + write('%s: %d' %{ url(category, 'uci/changes'), http.urlencode(http.formvalue('redir') or table.concat(disp.context.request, "/")), translate('Unsaved Changes'), diff --git a/themes/luci-theme-openwrt/luasrc/view/themes/openwrt.org/header.htm b/themes/luci-theme-openwrt/luasrc/view/themes/openwrt.org/header.htm index d6db8e885..a560014d3 100644 --- a/themes/luci-theme-openwrt/luasrc/view/themes/openwrt.org/header.htm +++ b/themes/luci-theme-openwrt/luasrc/view/themes/openwrt.org/header.htm @@ -99,22 +99,14 @@ end end - write('
') - if ucic > 0 then - write('%s: %d' %{ + write('' %{ url(category, 'uci/changes'), http.urlencode(http.formvalue('redir') or table.concat(disp.context.request, "/")), translate('Unsaved Changes'), ucic }) - else - write('%s: 0' %{ - translate('Unsaved Changes') - }) end - - write('
') end end -%>