NIU: Minor fixes
[project/luci.git] / modules / niu / luasrc / model / cbi / niu / traffic / portfw1.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14 local fs = require "nixio.fs"
15 local sys = require "luci.sys"
16
17 m = Map("firewall", translate("Manage Port Forwarding"))
18
19 s = m:section(TypedSection, "redirect", translate("Manual Port Forwarding"), 
20 translate([[To manually define a forwarding rule you have to specify at least
21 the internal IP-address and port of the service that should be forwarded.
22 If you ommit the external port it will be the same as the internal port.
23 You also can forward a range of ports by using the syntax first-last Port
24 (e.g. 1024-1030) in the port field.]]))
25 s.template  = "cbi/tblsection"
26 s.addremove = true
27 s.anonymous = true
28
29 name = s:option(Value, "_name", translate("Name"), translate("optional"))
30 name.size = 10
31
32 iface = s:option(ListValue, "src", translate("Zone"))
33 iface:value("wan", "Internet")
34 iface.default = "wan"
35
36 proto = s:option(ListValue, "proto", translate("Protocol"))
37 proto:value("tcp", "TCP")
38 proto:value("udp", "UDP")
39 proto:value("tcpudp", "TCP+UDP")
40
41 dport = s:option(Value, "src_dport", translate("Internal Port"))
42 dport.size = 5
43
44 to = s:option(Value, "dest_ip", translate("Internal Address"), translate("Device running the service"))
45 for i, dataset in ipairs(sys.net.arptable()) do
46         to:value(dataset["IP address"])
47 end
48
49 toport = s:option(Value, "dest_port", translate("External Port"), translate("optional"));
50 toport.size = 5
51
52 local m2
53 if fs.access("/etc/config/upnpd") then
54         m2 = Map("upnpd")
55         s = m2:section(NamedSection, "config", "upnpd", translate("Automatic Port Forwarding (UPnP IGD)"),
56         translate([[Allows UPnP-capable applications to automatically forward ports on the router to their IP-Address.
57         Be aware that this is a potential security risk as applications are not authenticated.]]))
58         s.addremove = false
59         
60         on = s:option(ListValue, "external_iface", translate("Port Forwarding Restrictions"))
61         on:value("none", translate("Manual Forwarding Only")) 
62         on:value("wan", translate("Automatic and Manual Forwarding"))
63 end
64
65 return m, m2