applications/luci-fw: Added support for luci-mini
authorSteven Barth <steven@midlink.org>
Wed, 16 Jul 2008 10:08:28 +0000 (10:08 +0000)
committerSteven Barth <steven@midlink.org>
Wed, 16 Jul 2008 10:08:28 +0000 (10:08 +0000)
modules/admin-mini: Added portforwarding page, and UCI changes, apply and revert pages

applications/luci-fw/luasrc/controller/luci_fw/luci_fw.lua
applications/luci-fw/luasrc/i18n/luci-fw.de.lua
applications/luci-fw/luasrc/i18n/luci-fw.en.lua
applications/luci-fw/luasrc/model/cbi/luci_fw/miniportfw.lua [new file with mode: 0644]
applications/luci-fw/root/etc/init.d/luci_fw
modules/admin-mini/luasrc/controller/mini/index.lua
modules/admin-mini/luasrc/controller/mini/network.lua
modules/admin-mini/luasrc/controller/mini/uci.lua [new file with mode: 0644]
modules/admin-mini/luasrc/view/mini/uci_apply.htm [new file with mode: 0644]
modules/admin-mini/luasrc/view/mini/uci_changes.htm [new file with mode: 0644]
modules/admin-mini/luasrc/view/mini/uci_revert.htm [new file with mode: 0644]

index 4efddb6..b8c1046 100644 (file)
@@ -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
index ae336da..d7adf36 100644 (file)
@@ -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
index b822c81..7d3a3a0 100644 (file)
@@ -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 (file)
index 0000000..39eefa6
--- /dev/null
@@ -0,0 +1,37 @@
+--[[
+LuCI - Lua Configuration Interface
+
+Copyright 2008 Steven Barth <steven@midlink.org>
+
+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
index 5f09b52..86d8a56 100755 (executable)
@@ -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/-/:/')"
index bde9649..08587ac 100644 (file)
@@ -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
index 4f9c415..177afc9 100644 (file)
@@ -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 (file)
index 0000000..eabc895
--- /dev/null
@@ -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
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 (file)
index 0000000..e280947
--- /dev/null
@@ -0,0 +1,20 @@
+<%#
+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$
+
+-%>
+<%+header%>
+<h1><%:config%></h1>
+<p><%:uci_applied%>:</p>
+<code><%=(changes or "-")%>
+<%=output%></code>
+<%+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 (file)
index 0000000..09d8d3e
--- /dev/null
@@ -0,0 +1,26 @@
+<%#
+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$
+
+-%>
+<%+header%>
+<h1><%:config%></h1>
+<h2><%:changes%></h2>
+<code><%=changes%></code>
+<br /><br />
+<form class="inline" method="get" action="<%=controller%>/admin/uci/apply">
+       <input type="submit" value="<%:apply%>" />
+</form>
+<form class="inline" method="get" action="<%=controller%>/admin/uci/revert">
+       <input type="submit" value="<%:revert%>" />
+</form>
+<%+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 (file)
index 0000000..7f98a04
--- /dev/null
@@ -0,0 +1,19 @@
+<%#
+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$
+
+-%>
+<%+header%>
+<h1><%:config%></h1>
+<p><%:uci_reverted%>:</p>
+<code><%=(changes or "-")%></code>
+<%+footer%>
\ No newline at end of file