diff options
author | Steven Barth <steven@midlink.org> | 2008-07-16 10:08:28 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2008-07-16 10:08:28 +0000 |
commit | 429473aed896a8f038d8934c8711a29366a894c5 (patch) | |
tree | 958d0b7459f644ee5ffd996acc7f14528292749f /modules/admin-mini/luasrc/controller/mini | |
parent | 9b1ef9e2b1a9e318a2840ee4b846f7ca8d82d3bb (diff) |
applications/luci-fw: Added support for luci-mini
modules/admin-mini: Added portforwarding page, and UCI changes, apply and revert pages
Diffstat (limited to 'modules/admin-mini/luasrc/controller/mini')
-rw-r--r-- | modules/admin-mini/luasrc/controller/mini/index.lua | 2 | ||||
-rw-r--r-- | modules/admin-mini/luasrc/controller/mini/network.lua | 2 | ||||
-rw-r--r-- | modules/admin-mini/luasrc/controller/mini/uci.lua | 100 |
3 files changed, 102 insertions, 2 deletions
diff --git a/modules/admin-mini/luasrc/controller/mini/index.lua b/modules/admin-mini/luasrc/controller/mini/index.lua index bde96493e..08587acb8 100644 --- a/modules/admin-mini/luasrc/controller/mini/index.lua +++ b/modules/admin-mini/luasrc/controller/mini/index.lua @@ -26,7 +26,7 @@ function index() entry({"about"}, template("about")).i18n = "admin-core" - local page = entry({"mini"}, alias("mini", "index"), i18n("mini", "Mini"), 10) + local page = entry({"mini"}, alias("mini", "index"), i18n("essentials", "Essentials"), 10) page.i18n = "admin-core" page.sysauth = "root" page.ucidata = true diff --git a/modules/admin-mini/luasrc/controller/mini/network.lua b/modules/admin-mini/luasrc/controller/mini/network.lua index 4f9c4152d..177afc978 100644 --- a/modules/admin-mini/luasrc/controller/mini/network.lua +++ b/modules/admin-mini/luasrc/controller/mini/network.lua @@ -20,5 +20,5 @@ function index() local i18n = luci.i18n.translate entry({"mini", "network"}, cbi("mini-network/basic"), i18n("network")) - entry({"mini", "network", "dhcp"}, cbi("mini-network/dhcp"), "DHCP") + entry({"mini", "network", "dhcp"}, cbi("mini-network/dhcp"), "DHCP", 10) end
\ No newline at end of file diff --git a/modules/admin-mini/luasrc/controller/mini/uci.lua b/modules/admin-mini/luasrc/controller/mini/uci.lua new file mode 100644 index 000000000..eabc89540 --- /dev/null +++ b/modules/admin-mini/luasrc/controller/mini/uci.lua @@ -0,0 +1,100 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Steven Barth <steven@midlink.org> +Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ +]]-- +module("luci.controller.mini.uci", package.seeall) + +function index() + local i18n = luci.i18n.translate + + entry({"mini", "uci"}, nil, i18n("config")) + entry({"mini", "uci", "changes"}, call("action_changes"), i18n("changes")) + entry({"mini", "uci", "revert"}, call("action_revert"), i18n("revert")) + entry({"mini", "uci", "apply"}, call("action_apply"), i18n("apply")) +end + +function convert_changes(changes) + local ret = {} + for r, tbl in pairs(changes) do + for s, os in pairs(tbl) do + for o, v in pairs(os) do + local val, str + if (v == "") then + str = "-" + val = "" + else + str = "" + val = "="..v + end + str = r.."."..s + if o ~= ".type" then + str = str.."."..o + end + table.insert(ret, str..val) + end + end + end + return table.concat(ret, "\n") +end + +function action_changes() + local changes = convert_changes(luci.model.uci.changes()) + luci.template.render("mini/uci_changes", {changes=changes}) +end + +function action_apply() + local changes = luci.model.uci.changes() + local output = "" + + if changes then + local com = {} + local run = {} + + -- Collect files to be applied and commit changes + for r, tbl in pairs(changes) do + if r then + luci.model.uci.load(r) + luci.model.uci.commit(r) + luci.model.uci.unload(r) + if luci.config.uci_oncommit and luci.config.uci_oncommit[r] then + run[luci.config.uci_oncommit[r]] = true + end + end + end + + -- Search for post-commit commands + for cmd, i in pairs(run) do + output = output .. cmd .. ":" .. luci.sys.exec(cmd) .. "\n" + end + end + + + luci.template.render("mini/uci_apply", {changes=convert_changes(changes), output=output}) +end + + +function action_revert() + local changes = luci.model.uci.changes() + if changes then + local revert = {} + + -- Collect files to be reverted + for r, tbl in pairs(changes) do + luci.model.uci.load(r) + luci.model.uci.revert(r) + luci.model.uci.unload(r) + end + end + + luci.template.render("mini/uci_revert", {changes=convert_changes(changes)}) +end |