From 2176dae3a0a648805f7de447e4af7ead8b7655dd Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Mon, 16 Nov 2009 16:58:48 +0000 Subject: NIU: +PortFw +QoS Reorganize Network --- .../niu/luasrc/model/cbi/niu/network/routes.lua | 17 ----- .../niu/luasrc/model/cbi/niu/network/routes1.lua | 57 -------------- .../niu/luasrc/model/cbi/niu/traffic/portfw.lua | 20 +++++ .../niu/luasrc/model/cbi/niu/traffic/portfw1.lua | 65 ++++++++++++++++ modules/niu/luasrc/model/cbi/niu/traffic/qos.lua | 36 +++++++++ modules/niu/luasrc/model/cbi/niu/traffic/qos1.lua | 89 ++++++++++++++++++++++ .../niu/luasrc/model/cbi/niu/traffic/routes.lua | 17 +++++ .../niu/luasrc/model/cbi/niu/traffic/routes1.lua | 57 ++++++++++++++ 8 files changed, 284 insertions(+), 74 deletions(-) delete mode 100644 modules/niu/luasrc/model/cbi/niu/network/routes.lua delete mode 100644 modules/niu/luasrc/model/cbi/niu/network/routes1.lua create mode 100644 modules/niu/luasrc/model/cbi/niu/traffic/portfw.lua create mode 100644 modules/niu/luasrc/model/cbi/niu/traffic/portfw1.lua create mode 100644 modules/niu/luasrc/model/cbi/niu/traffic/qos.lua create mode 100644 modules/niu/luasrc/model/cbi/niu/traffic/qos1.lua create mode 100644 modules/niu/luasrc/model/cbi/niu/traffic/routes.lua create mode 100644 modules/niu/luasrc/model/cbi/niu/traffic/routes1.lua (limited to 'modules/niu/luasrc/model') diff --git a/modules/niu/luasrc/model/cbi/niu/network/routes.lua b/modules/niu/luasrc/model/cbi/niu/network/routes.lua deleted file mode 100644 index 64a587c813..0000000000 --- a/modules/niu/luasrc/model/cbi/niu/network/routes.lua +++ /dev/null @@ -1,17 +0,0 @@ -local cursor = require "luci.model.uci".cursor() -local d = Delegator() -d.allow_finish = true -d.allow_back = true -d.allow_cancel = true - -d:add("routes1", load("niu/network/routes1")) - -function d.on_cancel() - cursor:revert("network") -end - -function d.on_done() - cursor:commit("network") -end - -return d \ No newline at end of file diff --git a/modules/niu/luasrc/model/cbi/niu/network/routes1.lua b/modules/niu/luasrc/model/cbi/niu/network/routes1.lua deleted file mode 100644 index 094831e72f..0000000000 --- a/modules/niu/luasrc/model/cbi/niu/network/routes1.lua +++ /dev/null @@ -1,57 +0,0 @@ ---[[ -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$ -]]-- - -m = Map("network", translate("Display and Customize Routing"), -translate("With additional static routes you allow computers on your network to reach unannounced remote hosts or networks.")) - -local routes6 = luci.sys.net.routes6() -local bit = require "bit" - -m:append(Template("niu/network/rtable")) - -s = m:section(TypedSection, "route", "Static IPv4 Routes") -s.addremove = true -s.anonymous = true - -s.template = "cbi/tblsection" - -iface1 = s:option(ListValue, "interface", translate("Interface")) - -s:option(Value, "target", translate("Target"), translate("Host-IP or Network")) -s:option(Value, "netmask", translate("IPv4-Netmask"), translate("if target is a network")).rmemepty = true -s:option(Value, "gateway", translate("IPv4-Gateway")) - -if routes6 then - s = m:section(TypedSection, "route6", "Static IPv6 Routes") - s.addremove = true - s.anonymous = true - - s.template = "cbi/tblsection" - - iface2 = s:option(ListValue, "interface", translate("Interface")) - - s:option(Value, "target", translate("Target"), translate("IPv6-Address or Network (CIDR)")) - s:option(Value, "gateway", translate("IPv6-Gateway")).rmempty = true -end - -m.uci:foreach("network", "interface", function(s) - if s[".name"] ~= "loopback" then - iface:value(s[".name"]) - if iface2 then - iface2:value(s[".name"]) - end - end -end) - -return m diff --git a/modules/niu/luasrc/model/cbi/niu/traffic/portfw.lua b/modules/niu/luasrc/model/cbi/niu/traffic/portfw.lua new file mode 100644 index 0000000000..bf4e132df1 --- /dev/null +++ b/modules/niu/luasrc/model/cbi/niu/traffic/portfw.lua @@ -0,0 +1,20 @@ +local uci = require "luci.model.uci" +local cursor = uci.cursor() +local d = Delegator() +d.allow_finish = true +d.allow_back = true +d.allow_cancel = true + +d:add("portfw1", load("niu/traffic/portfw1")) + +function d.on_cancel() + cursor:revert("firewall") + cursor:revert("upnpd") +end + +function d.on_done() + cursor:commit("firewall") + cursor:commit("upnpd") +end + +return d \ No newline at end of file diff --git a/modules/niu/luasrc/model/cbi/niu/traffic/portfw1.lua b/modules/niu/luasrc/model/cbi/niu/traffic/portfw1.lua new file mode 100644 index 0000000000..11ed4aa92d --- /dev/null +++ b/modules/niu/luasrc/model/cbi/niu/traffic/portfw1.lua @@ -0,0 +1,65 @@ +--[[ +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$ +]]-- +local fs = require "nixio.fs" +local sys = require "luci.sys" + +m = Map("firewall", translate("Manage Port Forwarding")) + +s = m:section(TypedSection, "redirect", translate("Manual Port Forwarding"), +translate([[To manually define a forwarding rule you have to specify at least +the internal IP-address and port of the service that should be forwarded. +If you ommit the external port it will be the same as the internal port. +You also can forward a range of ports by using the syntax first-last Port +(e.g. 1024-1030) in the port field.]])) +s.template = "cbi/tblsection" +s.addremove = true +s.anonymous = true + +name = s:option(Value, "_name", translate("Name"), translate("optional")) +name.size = 10 + +iface = s:option(ListValue, "src", translate("Zone")) +iface:value("wan", "Internet") +iface.default = "wan" + +proto = s:option(ListValue, "proto", translate("Protocol")) +proto:value("tcp", "TCP") +proto:value("udp", "UDP") +proto:value("tcpudp", "TCP+UDP") + +dport = s:option(Value, "src_dport", translate("Internal Port")) +dport.size = 5 + +to = s:option(Value, "dest_ip", translate("Internal Address"), translate("Device running the service")) +for i, dataset in ipairs(sys.net.arptable()) do + to:value(dataset["IP address"]) +end + +toport = s:option(Value, "dest_port", translate("External Port"), translate("optional")); +toport.size = 5 + +local m2 +if fs.access("/etc/config/upnpd") then + m2 = Map("upnpd") + s = m2:section(NamedSection, "config", "upnpd", translate("Automatic Port Forwarding (UPnP IGD)"), + translate([[Allows UPnP-capable applications to automatically forward ports on the router to their IP-Address. + Be aware that this is a potential security risk as applications are not authenticated.]])) + s.addremove = false + + on = s:option(ListValue, "external_iface", translate("Port Forwarding Restrictions")) + on:value("none", translate("Manual Forwarding Only")) + on:value("wan", translate("Automatic and Manual Forwarding")) +end + +return m, m2 diff --git a/modules/niu/luasrc/model/cbi/niu/traffic/qos.lua b/modules/niu/luasrc/model/cbi/niu/traffic/qos.lua new file mode 100644 index 0000000000..aa1f3f89e4 --- /dev/null +++ b/modules/niu/luasrc/model/cbi/niu/traffic/qos.lua @@ -0,0 +1,36 @@ +local uci = require "luci.model.uci" +local cursor = uci.cursor() + +if not cursor:get("qos", "wan", "_niuinit") then + -- Load some more sensible default classifications + cursor:delete_all("qos", "classify") + cursor:section("qos", "classify", "dns", + {target = "Priority", ports = "53", _name = "DNS"} + ) + cursor:section("qos", "classify", "inet1", + {target = "Normal", ports = "20,21,22,80,443", _name = "WWW, SSH, FTP"} + ) + cursor:section("qos", "classify", "inet2", + {target = "Normal", ports = "25,110,119,143", _name = "E-Mail, News"} + ) + + cursor:set("qos", "wan", "_niuinit", "1") + cursor:save("qos") +end + +local d = Delegator() +d.allow_finish = true +d.allow_back = true +d.allow_cancel = true + +d:add("qos1", load("niu/traffic/qos1")) + +function d.on_cancel() + cursor:revert("qos") +end + +function d.on_done() + cursor:commit("qos") +end + +return d \ No newline at end of file diff --git a/modules/niu/luasrc/model/cbi/niu/traffic/qos1.lua b/modules/niu/luasrc/model/cbi/niu/traffic/qos1.lua new file mode 100644 index 0000000000..6171dfaa71 --- /dev/null +++ b/modules/niu/luasrc/model/cbi/niu/traffic/qos1.lua @@ -0,0 +1,89 @@ +--[[ +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$ +]]-- + +local sys = require "luci.sys" +local fs = require "nixio.fs" + +m = Map("qos", translate("Manage Prioritization (QoS)"), translate([[Different +kinds of network traffic usually have different transmission requirements. +For example the important factor for a large HTTP-download is bandwith whereas +VoIP has a large focus on low packet latency. Prioritization takes these quality +of service factors into account and optimizes priorities to allow reasonable +performance for time critical services.]])) + +s = m:section(NamedSection, "wan", "interface", translate("General Settings"), +translate([[For QoS to work correctly you need to provide the upload and +download speed of your internet connection. Values are in kilobits per second. +For comparison a standard consumer ADSL connection has between 1000 and 25000 +kbps as donwload speed and between 128 and 1000 kbps upload speed.]])) +s.addremove = false + +local en = s:option(ListValue, "enabled", translate("Prioritization")) +en:value("1", "Enable Quality of Service") +en:value("0", "Disable") + +local dl = s:option(Value, "download", translate("Maximum Download Speed"), "kbps") +dl:depends("enabled", "1") + +local ul = s:option(Value, "upload", translate("Maximum Upload Speed"), "kbps") +ul:depends("enabled", "1") + +s = m:section(TypedSection, "classify", translate("Finetuning"), translate([[ +The QoS application provides different useful default prioritization rules not +listed here that cover many common use-cases. You however can add custom rules +to finetune the prioritization process.]])) +s.template = "cbi/tblsection" + +s.anonymous = true +s.addremove = true + +n = s:option(Value, "_name", translate("Name"), translate("optional")) + +srch = s:option(Value, "srchost", translate("Local IP-Address")) +srch.rmempty = true +srch:value("", translate("all")) +for i, dataset in ipairs(sys.net.arptable()) do + srch:value(dataset["IP address"]) +end + +p = s:option(ListValue, "proto", translate("Protocol")) +p:value("", translate("all")) +p:value("tcp", "TCP") +p:value("udp", "UDP") +p.rmempty = true + +ports = s:option(Value, "ports", translate("Ports")) +ports.rmempty = true +ports:value("", translate("any")) + +if fs.access("/etc/l7-protocols") then + l7 = s:option(ListValue, "layer7", translate("Service")) + l7.rmempty = true + l7:value("", translate("all")) + for f in fs.glob("/etc/l7-protocols/*.pat") do + l7:value(f:sub(19, #f-4)) + end +end + +s:option(Value, "connbytes", translate("Bytes sent"), translate("from[-to]")) + +t = s:option(ListValue, "target", translate("Priority")) +t:value("Priority", translate("Highest")) +t:value("Express", translate("High")) +t:value("Normal", translate("Normal")) +t:value("Bulk", translate("Low")) +t.default = "Normal" + +return m diff --git a/modules/niu/luasrc/model/cbi/niu/traffic/routes.lua b/modules/niu/luasrc/model/cbi/niu/traffic/routes.lua new file mode 100644 index 0000000000..f8e8a8af98 --- /dev/null +++ b/modules/niu/luasrc/model/cbi/niu/traffic/routes.lua @@ -0,0 +1,17 @@ +local cursor = require "luci.model.uci".cursor() +local d = Delegator() +d.allow_finish = true +d.allow_back = true +d.allow_cancel = true + +d:add("routes1", load("niu/traffic/routes1")) + +function d.on_cancel() + cursor:revert("network") +end + +function d.on_done() + cursor:commit("network") +end + +return d \ No newline at end of file diff --git a/modules/niu/luasrc/model/cbi/niu/traffic/routes1.lua b/modules/niu/luasrc/model/cbi/niu/traffic/routes1.lua new file mode 100644 index 0000000000..094831e72f --- /dev/null +++ b/modules/niu/luasrc/model/cbi/niu/traffic/routes1.lua @@ -0,0 +1,57 @@ +--[[ +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$ +]]-- + +m = Map("network", translate("Display and Customize Routing"), +translate("With additional static routes you allow computers on your network to reach unannounced remote hosts or networks.")) + +local routes6 = luci.sys.net.routes6() +local bit = require "bit" + +m:append(Template("niu/network/rtable")) + +s = m:section(TypedSection, "route", "Static IPv4 Routes") +s.addremove = true +s.anonymous = true + +s.template = "cbi/tblsection" + +iface1 = s:option(ListValue, "interface", translate("Interface")) + +s:option(Value, "target", translate("Target"), translate("Host-IP or Network")) +s:option(Value, "netmask", translate("IPv4-Netmask"), translate("if target is a network")).rmemepty = true +s:option(Value, "gateway", translate("IPv4-Gateway")) + +if routes6 then + s = m:section(TypedSection, "route6", "Static IPv6 Routes") + s.addremove = true + s.anonymous = true + + s.template = "cbi/tblsection" + + iface2 = s:option(ListValue, "interface", translate("Interface")) + + s:option(Value, "target", translate("Target"), translate("IPv6-Address or Network (CIDR)")) + s:option(Value, "gateway", translate("IPv6-Gateway")).rmempty = true +end + +m.uci:foreach("network", "interface", function(s) + if s[".name"] ~= "loopback" then + iface:value(s[".name"]) + if iface2 then + iface2:value(s[".name"]) + end + end +end) + +return m -- cgit v1.2.3