Added several backreference to Overview pages
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_network / ifaces.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11         http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15 require("luci.tools.webadmin")
16 arg[1] = arg[1] or ""
17 m = Map("network", translate("interfaces"), translate("a_n_ifaces1"))
18
19 s = m:section(NamedSection, arg[1], "interface")
20 s.addremove = true
21
22 back = s:option(DummyValue, translate("overview"))
23 back.value = ""
24 back.titleref = luci.dispatcher.build_url("admin", "network", "network")
25
26 p = s:option(ListValue, "proto", translate("protocol"))
27 p:value("static", translate("static"))
28 p:value("dhcp", "DHCP")
29 p:value("pppoe", "PPPoE")
30 p:value("pptp", "PPTP")
31 p.default = "static"
32
33 br = s:option(Flag, "type", translate("a_n_i_bridge"), translate("a_n_i_bridge1"))
34 br.enabled = "bridge"
35 br.rmempty = true
36
37 ifname = s:option(Value, "ifname", translate("interface"))
38 ifname.rmempty = true
39 for i,d in ipairs(luci.sys.net.devices()) do
40         if d ~= "lo" then
41                 ifname:value(d)
42         end
43 end
44
45 local zones = luci.tools.webadmin.network_get_zones(arg[1])
46 if zones then 
47         if #zones == 0 then
48                 m:chain("firewall")
49                 
50                 fwzone = s:option(Value, "_fwzone", 
51                         translate("network_interface_fwzone"),
52                         translate("network_interface_fwzone_desc"))
53                 fwzone.rmempty = true
54                 fwzone:value("", "- " .. translate("none") .. " -")
55                 fwzone:value(arg[1])
56                 m.uci:load("firewall")
57                 m.uci:foreach("firewall", "zone",
58                         function (section)
59                                 fwzone:value(section.name)
60                         end
61                 )
62                 
63                 function fwzone.write(self, section, value)     
64                         local zone = luci.tools.webadmin.firewall_find_zone(value)
65                         local stat
66                         
67                         if not zone then
68                                 stat = m.uci:section("firewall", "zone", nil, {
69                                         name = value,
70                                         network = section
71                                 })
72                         else
73                                 local net = m.uci:get("firewall", zone, "network")
74                                 net = (net or value) .. " " .. section
75                                 stat = m.uci:set("firewall", zone, "network", net)
76                         end
77                         
78                         if stat then
79                                 self.render = function() end
80                         end
81                 end
82         else
83                 fwzone = s:option(DummyValue, "_fwzone", translate("zone"))
84                 fwzone.value = table.concat(zones, ", ")
85         end
86         fwzone.titleref = luci.dispatcher.build_url("admin", "network", "firewall", "zones")
87         m.uci:unload("firewall")
88 end
89
90 ipaddr = s:option(Value, "ipaddr", translate("ipaddress"))
91 ipaddr.rmempty = true
92 ipaddr:depends("proto", "static")
93
94 nm = s:option(Value, "netmask", translate("netmask"))
95 nm.rmempty = true
96 nm:depends("proto", "static")
97 nm:value("255.255.255.0")
98 nm:value("255.255.0.0")
99 nm:value("255.0.0.0")
100
101 gw = s:option(Value, "gateway", translate("gateway"))
102 gw:depends("proto", "static")
103 gw.rmempty = true
104
105 bcast = s:option(Value, "bcast", translate("broadcast"))
106 bcast:depends("proto", "static")
107 bcast.optional = true
108
109 ip6addr = s:option(Value, "ip6addr", translate("ip6address"), translate("cidr6"))
110 ip6addr.optional = true
111 ip6addr:depends("proto", "static")
112
113 ip6gw = s:option(Value, "ip6gw", translate("gateway6"))
114 ip6gw:depends("proto", "static")
115 ip6gw.optional = true
116
117 dns = s:option(Value, "dns", translate("dnsserver"))
118 dns:depends("proto", "static")
119 dns.optional = true
120
121 mtu = s:option(Value, "mtu", "MTU")
122 mtu.optional = true
123 mtu.isinteger = true
124
125 mac = s:option(Value, "macaddr", translate("macaddress"))
126 mac.optional = true
127
128
129 srv = s:option(Value, "server", translate("network_interface_server"))
130 srv:depends("proto", "pptp")
131 srv.rmempty = true
132
133 user = s:option(Value, "username", translate("username"))
134 user.rmempty = true
135 user:depends("proto", "pptp")
136 user:depends("proto", "pppoe")
137
138 pass = s:option(Value, "password", translate("password"))
139 pass.rmempty = true
140 pass:depends("proto", "pptp")
141 pass:depends("proto", "pppoe")
142
143 ka = s:option(Value, "keepalive",
144  translate("network_interface_keepalive"),
145  translate("network_interface_keepalive_desc")
146 )
147 ka.rmempty = true
148 ka:depends("proto", "pptp")
149 ka:depends("proto", "pppoe")
150
151 demand = s:option(Value, "demand", 
152  translate("network_interface_demand"),
153  translate("network_interface_demand_desc")
154 )
155 demand.rmempty = true
156 demand:depends("proto", "pptp")
157 demand:depends("proto", "pppoe")
158
159
160
161
162 s2 = m:section(TypedSection, "alias", translate("aliases"))
163 s2.addremove = true
164
165 s2:depends("interface", arg[1])
166 s2.defaults.interface = arg[1]
167
168
169 s2.defaults.proto = "static"
170
171 ipaddr = s2:option(Value, "ipaddr", translate("ipaddress"))
172 ipaddr.rmempty = true
173
174 nm = s2:option(Value, "netmask", translate("netmask"))
175 nm.rmempty = true
176 nm:value("255.255.255.0")
177 nm:value("255.255.0.0")
178 nm:value("255.0.0.0")
179
180 gw = s2:option(Value, "gateway", translate("gateway"))
181 gw.rmempty = true
182
183 bcast = s2:option(Value, "bcast", translate("broadcast"))
184 bcast.optional = true
185
186 ip6addr = s2:option(Value, "ip6addr", translate("ip6address"), translate("cidr6"))
187 ip6addr.optional = true
188
189 ip6gw = s2:option(Value, "ip6gw", translate("gateway6"))
190 ip6gw.optional = true
191
192 dns = s2:option(Value, "dns", translate("dnsserver"))
193 dns.optional = true
194
195 return m