luci-mod-admin-full: canonicalize configured static lease MAC
[project/luci.git] / modules / luci-mod-admin-full / luasrc / model / cbi / admin_network / network.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
3 -- Licensed to the public under the Apache License 2.0.
4
5 local fs = require "nixio.fs"
6 local json = require "luci.jsonc"
7
8 m = Map("network", translate("Interfaces"))
9 m.pageaction = false
10 m:section(SimpleSection).template = "admin_network/iface_overview"
11
12 if fs.access("/etc/init.d/dsl_control") then
13         local ok, boarddata = pcall(json.parse, fs.readfile("/etc/board.json"))
14         local modemtype = (ok == true)
15                 and (type(boarddata) == "table")
16                 and (type(boarddata.dsl) == "table")
17                 and (type(boarddata.dsl.modem) == "table")
18                 and boarddata.dsl.modem.type
19
20         dsl = m:section(TypedSection, "dsl", translate("DSL"))
21         dsl.anonymous = true
22
23         annex = dsl:option(ListValue, "annex", translate("Annex"))
24         annex:value("a", translate("Annex A + L + M (all)"))
25         annex:value("b", translate("Annex B (all)"))
26         annex:value("j", translate("Annex J (all)"))
27         annex:value("m", translate("Annex M (all)"))
28         annex:value("bdmt", translate("Annex B G.992.1"))
29         annex:value("b2", translate("Annex B G.992.3"))
30         annex:value("b2p", translate("Annex B G.992.5"))
31         annex:value("at1", translate("ANSI T1.413"))
32         annex:value("admt", translate("Annex A G.992.1"))
33         annex:value("alite", translate("Annex A G.992.2"))
34         annex:value("a2", translate("Annex A G.992.3"))
35         annex:value("a2p", translate("Annex A G.992.5"))
36         annex:value("l", translate("Annex L G.992.3 POTS 1"))
37         annex:value("m2", translate("Annex M G.992.3"))
38         annex:value("m2p", translate("Annex M G.992.5"))
39
40         tone = dsl:option(ListValue, "tone", translate("Tone"))
41         tone:value("", translate("auto"))
42         tone:value("a", translate("A43C + J43 + A43"))
43         tone:value("av", translate("A43C + J43 + A43 + V43"))
44         tone:value("b", translate("B43 + B43C"))
45         tone:value("bv", translate("B43 + B43C + V43"))
46
47         if modemtype == "vdsl" then
48                 xfer_mode = dsl:option(ListValue, "xfer_mode", translate("Encapsulation mode"))
49                 xfer_mode:value("", translate("auto"))
50                 xfer_mode:value("atm", translate("ATM (Asynchronous Transfer Mode)"))
51                 xfer_mode:value("ptm", translate("PTM/EFM (Packet Transfer Mode)"))
52
53                 line_mode = dsl:option(ListValue, "line_mode", translate("DSL line mode"))
54                 line_mode:value("", translate("auto"))
55                 line_mode:value("adsl", translate("ADSL"))
56                 line_mode:value("vdsl", translate("VDSL"))
57
58                 ds_snr = dsl:option(ListValue, "ds_snr_offset", translate("Downstream SNR offset"))
59                 ds_snr.default = "0"
60                 for i = -100, 100, 5 do
61                         ds_snr:value(i, translatef("%.1f dB", i / 10))
62                 end
63         end
64
65         firmware = dsl:option(Value, "firmware", translate("Firmware File"))
66
67         m.pageaction = true
68 end
69
70 -- Show ATM bridge section if we have the capabilities
71 if fs.access("/usr/sbin/br2684ctl") then
72         atm = m:section(TypedSection, "atm-bridge", translate("ATM Bridges"),
73                 translate("ATM bridges expose encapsulated ethernet in AAL5 " ..
74                         "connections as virtual Linux network interfaces which can " ..
75                         "be used in conjunction with DHCP or PPP to dial into the " ..
76                         "provider network."))
77
78         atm.addremove = true
79         atm.anonymous = true
80
81         atm.create = function(self, section)
82                 local sid = TypedSection.create(self, section)
83                 local max_unit = -1
84
85                 m.uci:foreach("network", "atm-bridge",
86                         function(s)
87                                 local u = tonumber(s.unit)
88                                 if u ~= nil and u > max_unit then
89                                         max_unit = u
90                                 end
91                         end)
92
93                 m.uci:set("network", sid, "unit", max_unit + 1)
94                 m.uci:set("network", sid, "atmdev", 0)
95                 m.uci:set("network", sid, "encaps", "llc")
96                 m.uci:set("network", sid, "payload", "bridged")
97                 m.uci:set("network", sid, "vci", 35)
98                 m.uci:set("network", sid, "vpi", 8)
99
100                 return sid
101         end
102
103         atm:tab("general", translate("General Setup"))
104         atm:tab("advanced", translate("Advanced Settings"))
105
106         vci    = atm:taboption("general", Value, "vci", translate("ATM Virtual Channel Identifier (VCI)"))
107         vpi    = atm:taboption("general", Value, "vpi", translate("ATM Virtual Path Identifier (VPI)"))
108         encaps = atm:taboption("general", ListValue, "encaps", translate("Encapsulation mode"))
109         encaps:value("llc", translate("LLC"))
110         encaps:value("vc", translate("VC-Mux"))
111
112         atmdev  = atm:taboption("advanced", Value, "atmdev", translate("ATM device number"))
113         unit    = atm:taboption("advanced", Value, "unit", translate("Bridge unit number"))
114         payload = atm:taboption("advanced", ListValue, "payload", translate("Forwarding mode"))
115         payload:value("bridged", translate("bridged"))
116         payload:value("routed", translate("routed"))
117         m.pageaction = true
118 end
119
120 local network = require "luci.model.network"
121 if network:has_ipv6() then
122         local s = m:section(NamedSection, "globals", "globals", translate("Global network options"))
123         local o = s:option(Value, "ula_prefix", translate("IPv6 ULA-Prefix"))
124         o.datatype = "ip6addr"
125         o.rmempty = true
126         m.pageaction = true
127 end
128
129
130 return m