ae5f2aeab8aadcde66af940631474df495838d63
[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 p = s:option(ListValue, "proto", translate("protocol"))
23 p:value("static", translate("static"))
24 p:value("dhcp", "DHCP")
25 p:value("pppoe", "PPPoE")
26 p:value("pptp", "PPTP")
27 p.default = "static"
28
29 br = s:option(Flag, "type", translate("a_n_i_bridge"), translate("a_n_i_bridge1"))
30 br.enabled = "bridge"
31 br.rmempty = true
32
33 ifname = s:option(Value, "ifname", translate("interface"))
34 ifname.rmempty = true
35 for i,d in ipairs(luci.sys.net.devices()) do
36         if d ~= "lo" then
37                 ifname:value(d)
38         end
39 end
40
41 local zones = luci.tools.webadmin.network_get_zones(arg[1])
42 if zones and #zones == 0 then
43         m:chain("firewall")
44         
45         fwzone = s:option(Value, "_fwzone", 
46                 translate("network_interface_fwzone"),
47                 translate("network_interface_fwzone_desc"))
48         fwzone.rmempty = true
49         fwzone:value("", "- " .. translate("none") .. " -")
50         fwzone:value(arg[1])
51         luci.model.uci.foreach("firewall", "zone",
52                 function (section)
53                         fwzone:value(section.name)
54                 end
55         )
56         
57         function fwzone.write(self, section, value)     
58                 local zone = luci.tools.webadmin.firewall_find_zone(value)
59                 local stat
60                 
61                 if not zone then
62                         stat = luci.model.uci.section("firewall", "zone", nil, {
63                                 name = value,
64                                 network = section
65                         })
66                 else
67                         local net = luci.model.uci.get("firewall", zone, "network")
68                         net = (net or value) .. " " .. section
69                         stat = luci.model.uci.set("firewall", zone, "network", net)
70                 end
71                 
72                 if stat then
73                         self.render = function() end
74                 end
75         end
76 end
77
78 ipaddr = s:option(Value, "ipaddr", translate("ipaddress"))
79 ipaddr.rmempty = true
80 ipaddr:depends("proto", "static")
81
82 nm = s:option(Value, "netmask", translate("netmask"))
83 nm.rmempty = true
84 nm:depends("proto", "static")
85 nm:value("255.255.255.0")
86 nm:value("255.255.0.0")
87 nm:value("255.0.0.0")
88
89 gw = s:option(Value, "gateway", translate("gateway"))
90 gw:depends("proto", "static")
91 gw.rmempty = true
92
93 bcast = s:option(Value, "bcast", translate("broadcast"))
94 bcast:depends("proto", "static")
95 bcast.optional = true
96
97 ip6addr = s:option(Value, "ip6addr", translate("ip6address"), translate("cidr6"))
98 ip6addr.optional = true
99 ip6addr:depends("proto", "static")
100
101 ip6gw = s:option(Value, "ip6gw", translate("gateway6"))
102 ip6gw:depends("proto", "static")
103 ip6gw.optional = true
104
105 dns = s:option(Value, "dns", translate("dnsserver"))
106 dns:depends("proto", "static")
107 dns.optional = true
108
109 mtu = s:option(Value, "mtu", "MTU")
110 mtu.optional = true
111 mtu.isinteger = true
112
113 mac = s:option(Value, "macaddr", translate("macaddress"))
114 mac.optional = true
115
116 user = s:option(Value, "username", translate("username"))
117 user.rmempty = true
118 user:depends("proto", "pptp")
119 user:depends("proto", "pppoe")
120
121 pass = s:option(Value, "password", translate("password"))
122 pass.rmempty = true
123 pass:depends("proto", "pptp")
124 pass:depends("proto", "pppoe")
125
126 ka = s:option(Value, "keepalive",
127  translate("network_interface_keepalive"),
128  translate("network_interface_keepalive_desc")
129 )
130 ka.rmempty = true
131 ka:depends("proto", "pptp")
132 ka:depends("proto", "pppoe")
133
134 demand = s:option(Value, "demand", 
135  translate("network_interface_demand"),
136  translate("network_interface_demand_desc")
137 )
138 demand.rmempty = true
139 demand:depends("proto", "pptp")
140 demand:depends("proto", "pppoe")
141
142 srv = s:option(Value, "server", translate("network_interface_server"))
143 srv:depends("proto", "pptp")
144 srv.rmempty = true
145
146
147
148
149 s2 = m:section(TypedSection, "alias", translate("aliases"))
150 s2.addremove = true
151
152 s2:depends("interface", arg[1])
153 s2.defaults.interface = arg[1]
154
155
156 s2.defaults.proto = "static"
157
158 ipaddr = s2:option(Value, "ipaddr", translate("ipaddress"))
159 ipaddr.rmempty = true
160
161 nm = s2:option(Value, "netmask", translate("netmask"))
162 nm.rmempty = true
163 nm:value("255.255.255.0")
164 nm:value("255.255.0.0")
165 nm:value("255.0.0.0")
166
167 gw = s2:option(Value, "gateway", translate("gateway"))
168 gw.rmempty = true
169
170 bcast = s2:option(Value, "bcast", translate("broadcast"))
171 bcast.optional = true
172
173 ip6addr = s2:option(Value, "ip6addr", translate("ip6address"), translate("cidr6"))
174 ip6addr.optional = true
175
176 ip6gw = s2:option(Value, "ip6gw", translate("gateway6"))
177 ip6gw.optional = true
178
179 dns = s2:option(Value, "dns", translate("dnsserver"))
180 dns.optional = true
181
182 return m