From 429473aed896a8f038d8934c8711a29366a894c5 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Wed, 16 Jul 2008 10:08:28 +0000 Subject: [PATCH] applications/luci-fw: Added support for luci-mini modules/admin-mini: Added portforwarding page, and UCI changes, apply and revert pages --- .../luci-fw/luasrc/controller/luci_fw/luci_fw.lua | 12 ++- applications/luci-fw/luasrc/i18n/luci-fw.de.lua | 4 +- applications/luci-fw/luasrc/i18n/luci-fw.en.lua | 4 +- .../luasrc/model/cbi/luci_fw/miniportfw.lua | 37 ++++++++ applications/luci-fw/root/etc/init.d/luci_fw | 2 + .../admin-mini/luasrc/controller/mini/index.lua | 2 +- .../admin-mini/luasrc/controller/mini/network.lua | 2 +- modules/admin-mini/luasrc/controller/mini/uci.lua | 100 +++++++++++++++++++++ modules/admin-mini/luasrc/view/mini/uci_apply.htm | 20 +++++ .../admin-mini/luasrc/view/mini/uci_changes.htm | 26 ++++++ modules/admin-mini/luasrc/view/mini/uci_revert.htm | 19 ++++ 11 files changed, 219 insertions(+), 9 deletions(-) create mode 100644 applications/luci-fw/luasrc/model/cbi/luci_fw/miniportfw.lua create mode 100644 modules/admin-mini/luasrc/controller/mini/uci.lua create mode 100644 modules/admin-mini/luasrc/view/mini/uci_apply.htm create mode 100644 modules/admin-mini/luasrc/view/mini/uci_changes.htm create mode 100644 modules/admin-mini/luasrc/view/mini/uci_revert.htm diff --git a/applications/luci-fw/luasrc/controller/luci_fw/luci_fw.lua b/applications/luci-fw/luasrc/controller/luci_fw/luci_fw.lua index 4efddb6e7..b8c104601 100644 --- a/applications/luci-fw/luasrc/controller/luci_fw/luci_fw.lua +++ b/applications/luci-fw/luasrc/controller/luci_fw/luci_fw.lua @@ -4,7 +4,13 @@ function index() require("luci.i18n").loadc("luci-fw") local i18n = luci.i18n.translate - entry({"admin", "network", "portfw"}, cbi("luci_fw/portfw"), i18n("fw_portfw", "Portweiterleitung"), 70).i18n = "luci-fw" - entry({"admin", "network", "routing"}, cbi("luci_fw/routing"), i18n("fw_routing", "Routing"), 73).i18n = "luci-fw" - entry({"admin", "network", "firewall"}, cbi("luci_fw/firewall"), i18n("fw_fw", "Firewall"), 76).i18n = "luci-fw" + if registered("admin") then + entry({"admin", "network", "portfw"}, cbi("luci_fw/portfw"), i18n("fw_portfw", "Portweiterleitung"), 70).i18n = "luci-fw" + entry({"admin", "network", "routing"}, cbi("luci_fw/routing"), i18n("fw_routing", "Routing"), 73).i18n = "luci-fw" + entry({"admin", "network", "firewall"}, cbi("luci_fw/firewall"), i18n("fw_fw", "Firewall"), 76).i18n = "luci-fw" + end + + if registered("mini") then + entry({"mini", "network", "portfw"}, cbi("luci_fw/miniportfw"), i18n("fw_portfw", "Portweiterleitung"), 70).i18n = "luci-fw" + end end \ No newline at end of file diff --git a/applications/luci-fw/luasrc/i18n/luci-fw.de.lua b/applications/luci-fw/luasrc/i18n/luci-fw.de.lua index ae336da9f..d7adf3600 100644 --- a/applications/luci-fw/luasrc/i18n/luci-fw.de.lua +++ b/applications/luci-fw/luasrc/i18n/luci-fw.de.lua @@ -27,9 +27,9 @@ fw_portfw1 = [[Portweiterleitungen ermöglichen es interne Netzwerkdienste von einem anderen externen Netzwerk aus erreichbar zu machen.]] lucifw_portfw_iface_desc = "Externe Schnittstelle" lucifw_portfw_dport = "Externer Port" -lucifw_portfw_dport_desc = "Port[:Endport]" +lucifw_portfw_dport_desc = "Einzelner Port oder Erster Port-Letzter Port" lucifw_portfw_to = "Interne Adresse" -lucifw_portfw_to_desc = "IP-Adresse[:Zielport[-Zielendport]]" +lucifw_portfw_to_desc = "IP, IP:Port oder IP:Erster Port-Letzter Port" fw_routing1 = [[An dieser Stelle wird festlegt, welcher Netzverkehr zwischen einzelnen Schnittstellen erlaubt werden soll. Es werden jeweils nur neue Verbindungen diff --git a/applications/luci-fw/luasrc/i18n/luci-fw.en.lua b/applications/luci-fw/luasrc/i18n/luci-fw.en.lua index b822c8171..7d3a3a032 100644 --- a/applications/luci-fw/luasrc/i18n/luci-fw.en.lua +++ b/applications/luci-fw/luasrc/i18n/luci-fw.en.lua @@ -26,9 +26,9 @@ fw_portfw1 = [[Port forwarding allows to provide network services in the internal network to an external network.]] lucifw_portfw_iface_desc = "External interface" lucifw_portfw_dport = "External port" -lucifw_portfw_dport_desc = "Port[:last port]" +lucifw_portfw_dport_desc = "single port or first port-last port" lucifw_portfw_to = "Internal address" -lucifw_portfw_to_desc = "IP-address[:target port[-last port]]" +lucifw_portfw_to_desc = "IP, IP:port or IP:first port-last port" fw_routing1 = [[Here you can specify which network traffic is allowed to flow between network interfaces. Only new connections will be matched. Packets belonging to already open connections are automatically allowed diff --git a/applications/luci-fw/luasrc/model/cbi/luci_fw/miniportfw.lua b/applications/luci-fw/luasrc/model/cbi/luci_fw/miniportfw.lua new file mode 100644 index 000000000..39eefa659 --- /dev/null +++ b/applications/luci-fw/luasrc/model/cbi/luci_fw/miniportfw.lua @@ -0,0 +1,37 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Steven Barth + +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$ +]]-- +require("luci.sys") +m = Map("luci_fw", translate("fw_portfw"), translate("fw_portfw1")) + + +s = m:section(TypedSection, "portfw", "") +s:depends("iface", "wan") +s.defaults.iface = "wan" + +s.template = "cbi/tblsection" +s.addremove = true +s.anonymous = true + +name = s:option(Value, "_name", translate("name") .. translate("cbi_optional")) + +proto = s:option(ListValue, "proto", translate("protocol")) +proto:value("tcp", "TCP") +proto:value("udp", "UDP") +proto:value("tcpudp", "TCP + UDP") + +dport = s:option(Value, "dport") + +to = s:option(Value, "to") + +return m diff --git a/applications/luci-fw/root/etc/init.d/luci_fw b/applications/luci-fw/root/etc/init.d/luci_fw index 5f09b5277..86d8a56a3 100755 --- a/applications/luci-fw/root/etc/init.d/luci_fw +++ b/applications/luci-fw/root/etc/init.d/luci_fw @@ -15,6 +15,8 @@ apply_portfw() { [ -n "$ifname" ] || return 0 [ -n "$to" ] || return 0 + dport=$(echo $dport | sed -e 's/-/:/') + ports=$(echo $to | cut -sd: -f2) if [ -n "$ports" ]; then ports="--dport $(echo $ports | sed -e 's/-/:/')" 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 +Copyright 2008 Jo-Philipp Wich + +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 diff --git a/modules/admin-mini/luasrc/view/mini/uci_apply.htm b/modules/admin-mini/luasrc/view/mini/uci_apply.htm new file mode 100644 index 000000000..e28094728 --- /dev/null +++ b/modules/admin-mini/luasrc/view/mini/uci_apply.htm @@ -0,0 +1,20 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2008 Steven Barth +Copyright 2008 Jo-Philipp Wich + +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$ + +-%> +<%+header%> +

<%:config%>

+

<%:uci_applied%>:

+<%=(changes or "-")%> +<%=output%> +<%+footer%> \ No newline at end of file diff --git a/modules/admin-mini/luasrc/view/mini/uci_changes.htm b/modules/admin-mini/luasrc/view/mini/uci_changes.htm new file mode 100644 index 000000000..09d8d3e7e --- /dev/null +++ b/modules/admin-mini/luasrc/view/mini/uci_changes.htm @@ -0,0 +1,26 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2008 Steven Barth +Copyright 2008 Jo-Philipp Wich + +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$ + +-%> +<%+header%> +

<%:config%>

+

<%:changes%>

+<%=changes%> +

+
+ +
+
+ +
+<%+footer%> diff --git a/modules/admin-mini/luasrc/view/mini/uci_revert.htm b/modules/admin-mini/luasrc/view/mini/uci_revert.htm new file mode 100644 index 000000000..7f98a0435 --- /dev/null +++ b/modules/admin-mini/luasrc/view/mini/uci_revert.htm @@ -0,0 +1,19 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2008 Steven Barth +Copyright 2008 Jo-Philipp Wich + +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$ + +-%> +<%+header%> +

<%:config%>

+

<%:uci_reverted%>:

+<%=(changes or "-")%> +<%+footer%> \ No newline at end of file -- 2.11.0