From 69bc4e646dff6ed98cabc5b0f425e4dbf6fcc135 Mon Sep 17 00:00:00 2001 From: Sudhanshu Gautam Date: Wed, 21 Aug 2019 20:08:58 +0530 Subject: [PATCH] replaces attendedsysupgrade with sysupgrade Utilises the JSON schema generated after build as suggested in: https://github.com/openwrt/openwrt/pull/2192#discussion_r315166182 Ability to apply fresh images (default packages only, from openwrt) or to apply image with installed packages (from attendedsysupgrade server) Signed-off-by: Sudhanshu Gautam --- .../luasrc/controller/attendedsysupgrade.lua | 5 - .../luasrc/view/attendedsysupgrade.htm | 123 ----- .../po/templates/attendedsysupgrade.pot | 7 - .../resources/attendedsysupgrade.js | 427 ------------------ .../Makefile | 2 +- .../luasrc/controller/sysupgrade.lua | 5 + .../luasrc/view/sysupgrade.htm | 51 +++ .../po/es/sysupgrade.po} | 6 +- .../po/templates/sysupgrade.pot | 7 + .../root/etc/uci-defaults/40_luci-sysupgrade} | 0 .../usr/share/rpcd/acl.d/sysupgrade.json} | 6 +- .../www/luci-static/resources/sysupgrade.js | 362 +++++++++++++++ 12 files changed, 432 insertions(+), 569 deletions(-) delete mode 100644 applications/luci-app-attendedsysupgrade/luasrc/controller/attendedsysupgrade.lua delete mode 100644 applications/luci-app-attendedsysupgrade/luasrc/view/attendedsysupgrade.htm delete mode 100644 applications/luci-app-attendedsysupgrade/po/templates/attendedsysupgrade.pot delete mode 100644 applications/luci-app-attendedsysupgrade/root/www/luci-static/resources/attendedsysupgrade.js rename applications/{luci-app-attendedsysupgrade => luci-app-sysupgrade}/Makefile (85%) create mode 100644 applications/luci-app-sysupgrade/luasrc/controller/sysupgrade.lua create mode 100644 applications/luci-app-sysupgrade/luasrc/view/sysupgrade.htm rename applications/{luci-app-attendedsysupgrade/po/es/attendedsysupgrade.po => luci-app-sysupgrade/po/es/sysupgrade.po} (69%) create mode 100644 applications/luci-app-sysupgrade/po/templates/sysupgrade.pot rename applications/{luci-app-attendedsysupgrade/root/etc/uci-defaults/40_luci-attendedsysupgrade => luci-app-sysupgrade/root/etc/uci-defaults/40_luci-sysupgrade} (100%) rename applications/{luci-app-attendedsysupgrade/root/usr/share/rpcd/acl.d/attendedsysupgrade.json => luci-app-sysupgrade/root/usr/share/rpcd/acl.d/sysupgrade.json} (74%) create mode 100644 applications/luci-app-sysupgrade/root/www/luci-static/resources/sysupgrade.js diff --git a/applications/luci-app-attendedsysupgrade/luasrc/controller/attendedsysupgrade.lua b/applications/luci-app-attendedsysupgrade/luasrc/controller/attendedsysupgrade.lua deleted file mode 100644 index 1bd050af6691..000000000000 --- a/applications/luci-app-attendedsysupgrade/luasrc/controller/attendedsysupgrade.lua +++ /dev/null @@ -1,5 +0,0 @@ -module("luci.controller.attendedsysupgrade", package.seeall) - -function index() - entry({"admin", "system", "attended_sysupgrade"}, template("attendedsysupgrade"), _("Attended Sysupgrade"), 1) -end diff --git a/applications/luci-app-attendedsysupgrade/luasrc/view/attendedsysupgrade.htm b/applications/luci-app-attendedsysupgrade/luasrc/view/attendedsysupgrade.htm deleted file mode 100644 index c9259559be09..000000000000 --- a/applications/luci-app-attendedsysupgrade/luasrc/view/attendedsysupgrade.htm +++ /dev/null @@ -1,123 +0,0 @@ -<% --- all lua code provided by https://github.com/jow-/ --- thank you very much! - - function apply_acls(filename, session) - local json = require "luci.jsonc" - local util = require "luci.util" - local fs = require "nixio.fs" - - local grants = { } - - local acl = json.parse(fs.readfile(filename)) - if type(acl) ~= "table" then - return - end - - local group, perms - for group, perms in pairs(acl) do - local perm, scopes - for perm, scopes in pairs(perms) do - if type(scopes) == "table" then - local scope, objects - for scope, objects in pairs(scopes) do - if type(objects) == "table" then - if not grants[scope] then - grants[scope] = { } - end - - if next(objects) == 1 then - local _, object - for _, object in ipairs(objects) do - if not grants[scope][object] then - grants[scope][object] = { } - end - table.insert(grants[scope][object], perm) - end - else - local object, funcs - for object, funcs in pairs(objects) do - if type(funcs) == "table" then - local _, func - for _, func in ipairs(funcs) do - if not grants[scope][object] then - grants[scope][object] = { } - end - table.insert(grants[scope][object], func) - end - end - end - end - end - end - end - end - end - - local _, scope, object, func - for scope, _ in pairs(grants) do - local objects = { } - for object, _ in pairs(_) do - for _, func in ipairs(_) do - table.insert(objects, { object, func }) - end - end - - util.ubus("session", "grant", { - ubus_rpc_session = session, - scope = scope, objects = objects - }) - end - end - - apply_acls("/usr/share/rpcd/acl.d/attendedsysupgrade.json", luci.dispatcher.context.authsession) -%> -<%+header%> -

<%:Attended Sysupgrade%>

-
- Easily search and install new releases and package upgrades. Sysupgrade firmware are created on demand based on locally installed packages. -
- - -

- -

-
-
-
- - - -
-
- -
-
-
-
-
- - -<%+footer%> diff --git a/applications/luci-app-attendedsysupgrade/po/templates/attendedsysupgrade.pot b/applications/luci-app-attendedsysupgrade/po/templates/attendedsysupgrade.pot deleted file mode 100644 index f5f87dd3172a..000000000000 --- a/applications/luci-app-attendedsysupgrade/po/templates/attendedsysupgrade.pot +++ /dev/null @@ -1,7 +0,0 @@ -msgid "" -msgstr "Content-Type: text/plain; charset=UTF-8" - -#: applications/luci-app-attendedsysupgrade/luasrc/controller/attendedsysupgrade.lua:4 -#: applications/luci-app-attendedsysupgrade/luasrc/view/attendedsysupgrade.htm:76 -msgid "Attended Sysupgrade" -msgstr "" diff --git a/applications/luci-app-attendedsysupgrade/root/www/luci-static/resources/attendedsysupgrade.js b/applications/luci-app-attendedsysupgrade/root/www/luci-static/resources/attendedsysupgrade.js deleted file mode 100644 index 2cf5cc6e1b47..000000000000 --- a/applications/luci-app-attendedsysupgrade/root/www/luci-static/resources/attendedsysupgrade.js +++ /dev/null @@ -1,427 +0,0 @@ -function $(s) { - return document.getElementById(s.substring(1)); -} - -function show(s) { - $(s).style.display = 'block'; -} - -function hide(s) { - $(s).style.display = 'none'; -} - -function set_server() { - hide("#status_box"); - data.url = $("#server").value; - ubus_call("uci", "set", { - "config": "attendedsysupgrade", - "section": "server", - values: { - "url": data.url - } - }) - ubus_call("uci", "commit", { - "config": "attendedsysupgrade" - }) - var server_button = $("#server") - server_button.type = 'button'; - server_button.className = 'cbi-button cbi-button-edit'; - server_button.parentElement.removeChild($("#button_set")); - server_button.onclick = edit_server; -} - -function edit_server() { - $("#server").type = 'text'; - $("#server").onkeydown = function(event) { - if (event.key === 'Enter') { - set_server(); - return false; - } - } - $("#server").className = ''; - $("#server").onclick = null; - - var button_set = document.createElement("input"); - button_set.type = "button"; - button_set.value = "Save"; - button_set.name = "button_set"; - button_set.id = "button_set"; - button_set.className = 'cbi-button cbi-button-save'; - button_set.onclick = set_server - $("#server").parentElement.appendChild(button_set); -} - -function edit_packages() { - data.edit_packages = true - hide("#edit_button"); - $("#edit_packages").value = data.packages.join("\n"); - show("#edit_packages"); -} - -// requests to the upgrade server -function server_request(path, callback) { - var request = new XMLHttpRequest(); - request.open("POST", data.url + "/" + path, true); - request.setRequestHeader("Content-type", "application/json"); - request.send(JSON.stringify(request_dict)); - request.onerror = function(e) { - set_status("danger", "upgrade server down") - show("#server_div"); - } - request.addEventListener('load', function(event) { - callback(request) - }); -} - -// initial setup, get system information -function setup() { - ubus_call("rpc-sys", "packagelist", {}, "packages"); - ubus_call("system", "board", {}, "release"); - ubus_call("system", "board", {}, "board_name"); - ubus_call("system", "board", {}, "model"); - ubus_call("system", "info", {}, "memory"); - uci_get({ - "config": "attendedsysupgrade", - "section": "server", - "option": "url" - }) - uci_get({ - "config": "attendedsysupgrade", - "section": "client", - "option": "upgrade_packages" - }) - uci_get({ - "config": "attendedsysupgrade", - "section": "client", - "option": "advanced_mode" - }) - uci_get({ - "config": "attendedsysupgrade", - "section": "client", - "option": "auto_search" - }) - setup_ready(); -} - -function setup_ready() { - // checks if a async ubus calls have finished - if (ubus_counter != ubus_closed) { - setTimeout(setup_ready, 300) - } else { - if (data.auto_search == 1) { - upgrade_check(); - } else { - show("#upgrade_button"); - show("#server_div"); - $("#server").value = data.url; - } - } -} - -function uci_get(option) { - // simple wrapper to get a uci value store in data.