2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
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
11 http://www.apache.org/licenses/LICENSE-2.0
15 require("luci.tools.webadmin")
18 luci.model.uci.load_state("network")
19 local wireless = luci.model.uci.get_all("network")
20 luci.model.uci.unload("network")
22 local netstat = luci.sys.net.deviceinfo()
25 for k, v in pairs(wireless) do
26 if v[".type"] == "interface" and k ~= "loopback" then
27 table.insert(ifaces, v)
31 m = Map("network", translate("network"))
32 s = m:section(Table, ifaces, translate("status"))
33 s.parse = function() end
35 s:option(DummyValue, ".name", translate("network"))
37 hwaddr = s:option(DummyValue, "_hwaddr",
38 translate("network_interface_hwaddr"), translate("network_interface_hwaddr_desc"))
39 function hwaddr.cfgvalue(self, section)
40 local ix = self.map:get(section, "ifname") or ""
41 return luci.fs.readfile("/sys/class/net/" .. ix .. "/address") or "n/a"
45 s:option(DummyValue, "ipaddr", translate("ipaddress"))
47 s:option(DummyValue, "netmask", translate("netmask"))
50 txrx = s:option(DummyValue, "_txrx",
51 translate("network_interface_txrx"), translate("network_interface_txrx_desc"))
53 function txrx.cfgvalue(self, section)
54 local ix = self.map:get(section, "ifname")
56 local rx = netstat and netstat[ix] and netstat[ix][1]
57 rx = rx and luci.tools.webadmin.byte_format(tonumber(rx)) or "-"
59 local tx = netstat and netstat[ix] and netstat[ix][9]
60 tx = tx and luci.tools.webadmin.byte_format(tonumber(tx)) or "-"
62 return string.format("%s / %s", tx, rx)
65 errors = s:option(DummyValue, "_err",
66 translate("network_interface_err"), translate("network_interface_err_desc"))
68 function errors.cfgvalue(self, section)
69 local ix = self.map:get(section, "ifname")
71 local rx = netstat and netstat[ix] and netstat[ix][3]
72 local tx = netstat and netstat[ix] and netstat[ix][11]
74 rx = rx and tostring(rx) or "-"
75 tx = tx and tostring(tx) or "-"
77 return string.format("%s / %s", tx, rx)
82 s = m:section(NamedSection, "lan", "interface", translate("m_n_local"))
83 s:option(Value, "ipaddr", translate("ipaddress"))
85 nm = s:option(Value, "netmask", translate("netmask"))
86 nm:value("255.255.255.0")
87 nm:value("255.255.0.0")
90 gw = s:option(Value, "gateway", translate("gateway") .. translate("cbi_optional"))
92 dns = s:option(Value, "dns", translate("dnsserver") .. translate("cbi_optional"))
96 s = m:section(NamedSection, "wan", "interface", translate("m_n_inet"))
97 p = s:option(ListValue, "proto", translate("protocol"))
98 p:value("none", "disabled")
99 p:value("static", translate("manual", "manual"))
100 p:value("dhcp", translate("automatic", "automatic"))
101 p:value("pppoe", "PPPoE")
102 p:value("pptp", "PPTP")
104 ip = s:option(Value, "ipaddr", translate("ipaddress"))
105 ip:depends("proto", "static")
107 nm = s:option(Value, "netmask", translate("netmask"))
108 nm:depends("proto", "static")
110 gw = s:option(Value, "gateway", translate("gateway"))
111 gw:depends("proto", "static")
114 dns = s:option(Value, "dns", translate("dnsserver"))
115 dns:depends("proto", "static")
118 usr = s:option(Value, "username", translate("username"))
119 usr:depends("proto", "pppoe")
120 usr:depends("proto", "pptp")
122 pwd = s:option(Value, "password", translate("password"))
123 pwd:depends("proto", "pppoe")
124 pwd:depends("proto", "pptp")
126 kea = s:option(Flag, "keepalive", translate("m_n_keepalive"))
127 kea:depends("proto", "pppoe")
128 kea:depends("proto", "pptp")
133 cod = s:option(Value, "demand", translate("m_n_dialondemand"), "s")
134 cod:depends("proto", "pppoe")
135 cod:depends("proto", "pptp")
138 srv = s:option(Value, "server", translate("m_n_pptp_server"))
139 srv:depends("proto", "pptp")