From 110470cb85d0bd9791d45532da48fbfccc6c1aff Mon Sep 17 00:00:00 2001 From: Ycarus Date: Tue, 31 Jul 2018 17:18:00 +0200 Subject: [PATCH] Update to 18.06 --- luci-base/Makefile | 3 +- luci-base/htdocs/luci-static/resources/cbi.js | 24 ++- luci-base/htdocs/luci-static/resources/xhr.js | 19 +- luci-base/luasrc/dispatcher.lua | 15 +- luci-base/luasrc/model/uci.lua | 92 +++++++--- luci-base/luasrc/util.lua | 16 +- luci-base/luasrc/view/cbi/apply_widget.htm | 10 +- .../luasrc/view/cbi/cell_valueheader.htm | 6 +- luci-base/luasrc/view/cbi/map.htm | 15 -- luci-base/luasrc/view/cbi/ucisection.htm | 8 +- luci-base/luasrc/view/cbi/value.htm | 10 +- luci-base/luasrc/view/footer.htm | 25 ++- luci-base/po/ca/base.po | 3 - luci-base/po/cs/base.po | 3 - luci-base/po/de/base.po | 3 - luci-base/po/el/base.po | 3 - luci-base/po/en/base.po | 3 - luci-base/po/es/base.po | 3 - luci-base/po/fr/base.po | 3 - luci-base/po/he/base.po | 3 - luci-base/po/hu/base.po | 3 - luci-base/po/it/base.po | 3 - luci-base/po/ja/base.po | 3 - luci-base/po/ko/base.po | 3 - luci-base/po/ms/base.po | 3 - luci-base/po/no/base.po | 3 - luci-base/po/pl/base.po | 53 +++--- luci-base/po/pt-br/base.po | 3 - luci-base/po/pt/base.po | 3 - luci-base/po/ro/base.po | 3 - luci-base/po/ru/base.po | 3 - luci-base/po/sk/base.po | 3 - luci-base/po/sv/base.po | 3 - luci-base/po/templates/base.pot | 3 - luci-base/po/tr/base.po | 3 - luci-base/po/uk/base.po | 3 - luci-base/po/vi/base.po | 3 - luci-base/po/zh-cn/base.po | 171 +++++++++--------- luci-base/po/zh-tw/base.po | 3 - luci-base/src/po2lmo | Bin 0 -> 18576 bytes luci-base/src/po2lmo.o | Bin 0 -> 6376 bytes luci-base/src/template_lmo.o | Bin 0 -> 7200 bytes .../luasrc/controller/admin/uci.lua | 26 ++- .../model/cbi/admin_network/wifi_overview.lua | 6 +- .../admin_network/iface_overview_status.htm | 4 +- .../view/admin_network/iface_status.htm | 2 +- .../luasrc/view/admin_status/index.htm | 97 +++------- .../luasrc/view/admin_system/packages.htm | 4 +- .../luasrc/view/admin_uci/changes.htm | 10 +- .../luasrc/view/admin_uci/revert.htm | 11 +- 50 files changed, 335 insertions(+), 367 deletions(-) create mode 100755 luci-base/src/po2lmo create mode 100644 luci-base/src/po2lmo.o create mode 100644 luci-base/src/template_lmo.o diff --git a/luci-base/Makefile b/luci-base/Makefile index fc8a31d2a..9ce3b39f5 100644 --- a/luci-base/Makefile +++ b/luci-base/Makefile @@ -37,13 +37,14 @@ endef define Host/Compile $(MAKE) -C src/ clean po2lmo - $(MAKE) -C $(HOST_BUILD_DIR) bin/luasrcdiet endef define Host/Install $(INSTALL_DIR) $(1)/bin + $(INSTALL_DIR) $(1)/lib/lua/5.1 $(INSTALL_BIN) src/po2lmo $(1)/bin/po2lmo $(INSTALL_BIN) $(HOST_BUILD_DIR)/bin/luasrcdiet $(1)/bin/luasrcdiet + $(CP) $(HOST_BUILD_DIR)/luasrcdiet $(1)/lib/lua/5.1/ endef $(eval $(call HostBuild)) diff --git a/luci-base/htdocs/luci-static/resources/cbi.js b/luci-base/htdocs/luci-static/resources/cbi.js index 89dfac9e4..fcfc50694 100644 --- a/luci-base/htdocs/luci-static/resources/cbi.js +++ b/luci-base/htdocs/luci-static/resources/cbi.js @@ -627,6 +627,18 @@ function cbi_init() { s.parentNode.classList.add('cbi-tooltip-container'); }); + document.querySelectorAll('.cbi-section-remove > input[name^="cbi.rts"]').forEach(function(i) { + var handler = function(ev) { + var bits = this.name.split(/\./), + section = document.getElementById('cbi-' + bits[2] + '-' + bits[3]); + + section.style.opacity = (ev.type === 'mouseover') ? 0.5 : ''; + }; + + i.addEventListener('mouseover', handler); + i.addEventListener('mouseout', handler); + }); + cbi_d_update(); } @@ -818,9 +830,9 @@ function cbi_dynlist_init(parent, datatype, optional, choices) t.placeholder = holder; } - var b = document.createElement('img'); - b.src = cbi_strings.path.resource + ((i+1) < values.length ? '/cbi/remove.gif' : '/cbi/add.gif'); - b.className = 'cbi-image-button'; + var b = E('div', { + class: 'cbi-button cbi-button-' + ((i+1) < values.length ? 'remove' : 'add') + }, (i+1) < values.length ? '×' : '+'); parent.appendChild(t); parent.appendChild(b); @@ -986,8 +998,7 @@ function cbi_dynlist_init(parent, datatype, optional, choices) input = input.previousSibling; } - if (se.src.indexOf('remove') > -1) - { + if (se.classList.contains('cbi-button-remove')) { input.value = ''; cbi_dynlist_keydown({ @@ -995,8 +1006,7 @@ function cbi_dynlist_init(parent, datatype, optional, choices) keyCode: 8 }); } - else - { + else { cbi_dynlist_keydown({ target: input, keyCode: 13 diff --git a/luci-base/htdocs/luci-static/resources/xhr.js b/luci-base/htdocs/luci-static/resources/xhr.js index 62b525ebb..25a90e725 100644 --- a/luci-base/htdocs/luci-static/resources/xhr.js +++ b/luci-base/htdocs/luci-static/resources/xhr.js @@ -65,12 +65,8 @@ XHR = function() if (xhr.readyState == 4) { var json = null; if (xhr.getResponseHeader("Content-Type") == "application/json") { - try { - json = JSON.parse(xhr.responseText); - } - catch(e) { - json = null; - } + try { json = JSON.parse(xhr.responseText); } + catch(e) { json = null; } } callback(xhr, json, Date.now() - ts); @@ -90,8 +86,15 @@ XHR = function() xhr.onreadystatechange = function() { - if (xhr.readyState == 4) - callback(xhr, null, Date.now() - ts); + if (xhr.readyState == 4) { + var json = null; + if (xhr.getResponseHeader("Content-Type") == "application/json") { + try { json = JSON.parse(xhr.responseText); } + catch(e) { json = null; } + } + + callback(xhr, json, Date.now() - ts); + } } xhr.open('POST', url, true); diff --git a/luci-base/luasrc/dispatcher.lua b/luci-base/luasrc/dispatcher.lua index 6d5a8f4d3..6cf2712eb 100644 --- a/luci-base/luasrc/dispatcher.lua +++ b/luci-base/luasrc/dispatcher.lua @@ -893,8 +893,6 @@ local function _cbi(self, ...) local pageaction = true local parsechain = { } - local is_rollback, time_remaining = uci:rollback_pending() - for i, res in ipairs(maps) do if res.apply_needed and res.parsechain then local c @@ -921,8 +919,6 @@ local function _cbi(self, ...) for i, res in ipairs(maps) do res:render({ firstmap = (i == 1), - applymap = applymap, - confirmmap = (is_rollback and time_remaining or nil), redirect = redirect, messages = messages, pageaction = pageaction, @@ -932,11 +928,12 @@ local function _cbi(self, ...) if not config.nofooter then tpl.render("cbi/footer", { - flow = config, - pageaction = pageaction, - redirect = redirect, - state = state, - autoapply = config.autoapply + flow = config, + pageaction = pageaction, + redirect = redirect, + state = state, + autoapply = config.autoapply, + trigger_apply = applymap }) end end diff --git a/luci-base/luasrc/model/uci.lua b/luci-base/luasrc/model/uci.lua index 92c0d8f69..b2c1e463b 100644 --- a/luci-base/luasrc/model/uci.lua +++ b/luci-base/luasrc/model/uci.lua @@ -147,19 +147,31 @@ function apply(self, rollback) local _, err if rollback then + local sys = require "luci.sys" local conf = require "luci.config" - local timeout = tonumber(conf and conf.apply and conf.apply.rollback or "") or 0 + local timeout = tonumber(conf and conf.apply and conf.apply.rollback or 30) or 0 _, err = call("apply", { - timeout = (timeout > 30) and timeout or 30, + timeout = (timeout > 30) and timeout or 30, rollback = true }) if not err then + local now = os.time() + local token = sys.uniqueid(16) + util.ubus("session", "set", { - ubus_rpc_session = session_id, - values = { rollback = os.time() + timeout } + ubus_rpc_session = "00000000000000000000000000000000", + values = { + rollback = { + token = token, + session = session_id, + timeout = now + timeout + } + } }) + + return token end else _, err = call("changes", {}) @@ -184,40 +196,72 @@ function apply(self, rollback) return (err == nil), ERRSTR[err] end -function confirm(self) - local _, err = call("confirm", {}) - if not err then - util.ubus("session", "set", { - ubus_rpc_session = session_id, - values = { rollback = 0 } +function confirm(self, token) + local is_pending, time_remaining, rollback_sid, rollback_token = self:rollback_pending() + + if is_pending then + if token ~= rollback_token then + return false, "Permission denied" + end + + local _, err = util.ubus("uci", "confirm", { + ubus_rpc_session = rollback_sid }) + + if not err then + util.ubus("session", "set", { + ubus_rpc_session = "00000000000000000000000000000000", + values = { rollback = {} } + }) + end + + return (err == nil), ERRSTR[err] end - return (err == nil), ERRSTR[err] + + return false, "No data" end function rollback(self) - local _, err = call("rollback", {}) - if not err then - util.ubus("session", "set", { - ubus_rpc_session = session_id, - values = { rollback = 0 } + local is_pending, time_remaining, rollback_sid = self:rollback_pending() + + if is_pending then + local _, err = util.ubus("uci", "rollback", { + ubus_rpc_session = rollback_sid }) + + if not err then + util.ubus("session", "set", { + ubus_rpc_session = "00000000000000000000000000000000", + values = { rollback = {} } + }) + end + + return (err == nil), ERRSTR[err] end - return (err == nil), ERRSTR[err] + + return false, "No data" end function rollback_pending(self) - local deadline, err = util.ubus("session", "get", { - ubus_rpc_session = session_id, + local rv, err = util.ubus("session", "get", { + ubus_rpc_session = "00000000000000000000000000000000", keys = { "rollback" } }) - if type(deadline) == "table" and - type(deadline.values) == "table" and - type(deadline.values.rollback) == "number" and - deadline.values.rollback > os.time() + local now = os.time() + + if type(rv) == "table" and + type(rv.values) == "table" and + type(rv.values.rollback) == "table" and + type(rv.values.rollback.token) == "string" and + type(rv.values.rollback.session) == "string" and + type(rv.values.rollback.timeout) == "number" and + rv.values.rollback.timeout > now then - return true, deadline.values.rollback - os.time() + return true, + rv.values.rollback.timeout - now, + rv.values.rollback.session, + rv.values.rollback.token end return false, ERRSTR[err] diff --git a/luci-base/luasrc/util.lua b/luci-base/luasrc/util.lua index 10428b0b3..f16b3afb2 100644 --- a/luci-base/luasrc/util.lua +++ b/luci-base/luasrc/util.lua @@ -16,7 +16,7 @@ local _ubus = require "ubus" local _ubus_connection = nil local getmetatable, setmetatable = getmetatable, setmetatable -local rawget, rawset, unpack = rawget, rawset, unpack +local rawget, rawset, unpack, select = rawget, rawset, unpack, select local tostring, type, assert, error = tostring, type, assert, error local ipairs, pairs, next, loadstring = ipairs, pairs, next, loadstring local require, pcall, xpcall = require, pcall, xpcall @@ -647,6 +647,17 @@ local ubus_codes = { "CONNECTION_FAILED" } +local function ubus_return(...) + if select('#', ...) == 2 then + local rv, err = select(1, ...), select(2, ...) + if rv == nil and type(err) == "number" then + return nil, err, ubus_codes[err] + end + end + + return ... +end + function ubus(object, method, data) if not _ubus_connection then _ubus_connection = _ubus.connect() @@ -657,8 +668,7 @@ function ubus(object, method, data) if type(data) ~= "table" then data = { } end - local rv, err = _ubus_connection:call(object, method, data) - return rv, err, ubus_codes[err] + return ubus_return(_ubus_connection:call(object, method, data)) elseif object then return _ubus_connection:signatures(object) else diff --git a/luci-base/luasrc/view/cbi/apply_widget.htm b/luci-base/luasrc/view/cbi/apply_widget.htm index f76846ee8..4d7e9c56e 100644 --- a/luci-base/luasrc/view/cbi/apply_widget.htm +++ b/luci-base/luasrc/view/cbi/apply_widget.htm @@ -1,4 +1,4 @@ -<% export("cbi_apply_widget", function(redirect_ok) -%> +<% export("cbi_apply_widget", function(redirect_ok, rollback_token) -%>