c85b6a182169183587cb64f23d2deaeaaeccac74
[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
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 m = Map("network", translate("interfaces"), translate("a_n_ifaces1"))
15
16 arg = arg or {}
17
18 s = m:section(TypedSection, "interface", translate("interfaces"))
19 function s.create(self, section)
20         local stat = TypedSection.create(self, section)
21         if stat then
22                 arg = {section or stat}
23         end
24         return stat
25 end
26
27 function s.filter(self, section)
28         return section ~= "loopback" and
29          (not arg or not arg[1] or arg[1] == section)
30 end
31
32 if not arg or not arg[1] then
33         s.addremove = true
34 end
35 s:depends("proto", "static")
36 s:depends("proto", "dhcp")
37
38 p = s:option(ListValue, "proto", translate("protocol"))
39 p:value("static", translate("static"))
40 p:value("dhcp", "DHCP")
41 p.default = "static"
42
43 br = s:option(Flag, "type", translate("a_n_i_bridge"), translate("a_n_i_bridge1"))
44 br.enabled = "bridge"
45 br.rmempty = true
46
47 ifname = s:option(Value, "ifname", translate("interface"))
48 ifname.rmempty = true
49 for i,d in ipairs(luci.sys.net.devices()) do
50         if d ~= "lo" then
51                 ifname:value(d)
52         end
53 end
54
55
56 ipaddr = s:option(Value, "ipaddr", translate("ipaddress"))
57 ipaddr.rmempty = true
58 ipaddr:depends("proto", "static")
59
60 nm = s:option(Value, "netmask", translate("netmask"))
61 nm.rmempty = true
62 nm:depends("proto", "static")
63 nm:value("255.255.255.0")
64 nm:value("255.255.0.0")
65 nm:value("255.0.0.0")
66
67 gw = s:option(Value, "gateway", translate("gateway"))
68 gw:depends("proto", "static")
69 gw.rmempty = true
70
71 bcast = s:option(Value, "bcast", translate("broadcast"))
72 bcast:depends("proto", "static")
73 bcast.optional = true
74
75 ip6addr = s:option(Value, "ip6addr", translate("ip6address"), translate("cidr6"))
76 ip6addr.optional = true
77 ip6addr:depends("proto", "static")
78
79 ip6gw = s:option(Value, "ip6gw", translate("gateway6"))
80 ip6gw:depends("proto", "static")
81 ip6gw.optional = true
82
83 dns = s:option(Value, "dns", translate("dnsserver"))
84 dns:depends("proto", "static")
85 dns.optional = true
86
87 mtu = s:option(Value, "mtu", "MTU")
88 mtu.optional = true
89 mtu.isinteger = true
90
91 mac = s:option(Value, "macaddr", translate("macaddress"))
92 mac.optional = true
93
94
95
96
97 s2 = m:section(TypedSection, "alias", translate("aliases"))
98 s2.addremove = true
99
100 if arg and arg[1] then
101         s2:depends("interface", arg[1])
102         s2.defaults.interface = arg[1]
103 else
104         parent = s2:option(ListValue, "interface", translate("interface"))
105         luci.model.uci.foreach("network", "interface",
106                 function (section)
107                         if section[".name"] ~= "loopback" then
108                                 parent:value(section[".name"])
109                         end
110                 end
111         )
112 end
113
114
115 s2.defaults.proto = "static"
116
117 ipaddr = s2:option(Value, "ipaddr", translate("ipaddress"))
118 ipaddr.rmempty = true
119
120 nm = s2:option(Value, "netmask", translate("netmask"))
121 nm.rmempty = true
122 nm:value("255.255.255.0")
123 nm:value("255.255.0.0")
124 nm:value("255.0.0.0")
125
126 gw = s2:option(Value, "gateway", translate("gateway"))
127 gw.rmempty = true
128
129 bcast = s2:option(Value, "bcast", translate("broadcast"))
130 bcast.optional = true
131
132 ip6addr = s2:option(Value, "ip6addr", translate("ip6address"), translate("cidr6"))
133 ip6addr.optional = true
134
135 ip6gw = s2:option(Value, "ip6gw", translate("gateway6"))
136 ip6gw.optional = true
137
138 dns = s2:option(Value, "dns", translate("dnsserver"))
139 dns.optional = true
140
141 return m