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 local network = luci.model.uci.cursor_state():get_all("network")
20 local netstat = luci.sys.net.deviceinfo()
23 for k, v in pairs(network) do
24 if v[".type"] == "interface" and k ~= "loopback" then
25 table.insert(ifaces, v)
29 m = Map("network", translate("network"))
30 s = m:section(Table, ifaces, translate("status"))
31 s.parse = function() end
33 s:option(DummyValue, ".name", translate("network"))
35 hwaddr = s:option(DummyValue, "_hwaddr",
36 translate("network_interface_hwaddr"), translate("network_interface_hwaddr_desc"))
37 function hwaddr.cfgvalue(self, section)
38 local ix = self.map:get(section, "ifname") or ""
39 return luci.fs.readfile("/sys/class/net/" .. ix .. "/address") or "n/a"
43 s:option(DummyValue, "ipaddr", translate("ipaddress"))
45 s:option(DummyValue, "netmask", translate("netmask"))
48 txrx = s:option(DummyValue, "_txrx",
49 translate("network_interface_txrx"), translate("network_interface_txrx_desc"))
51 function txrx.cfgvalue(self, section)
52 local ix = self.map:get(section, "ifname")
54 local rx = netstat and netstat[ix] and netstat[ix][1]
55 rx = rx and luci.tools.webadmin.byte_format(tonumber(rx)) or "-"
57 local tx = netstat and netstat[ix] and netstat[ix][9]
58 tx = tx and luci.tools.webadmin.byte_format(tonumber(tx)) or "-"
60 return string.format("%s / %s", tx, rx)
63 errors = s:option(DummyValue, "_err",
64 translate("network_interface_err"), translate("network_interface_err_desc"))
66 function errors.cfgvalue(self, section)
67 local ix = self.map:get(section, "ifname")
69 local rx = netstat and netstat[ix] and netstat[ix][3]
70 local tx = netstat and netstat[ix] and netstat[ix][11]
72 rx = rx and tostring(rx) or "-"
73 tx = tx and tostring(tx) or "-"
75 return string.format("%s / %s", tx, rx)
80 s = m:section(NamedSection, "lan", "interface", translate("m_n_local"))
82 s:option(Value, "ipaddr", translate("ipaddress"))
84 nm = s:option(Value, "netmask", translate("netmask"))
85 nm:value("255.255.255.0")
86 nm:value("255.255.0.0")
89 gw = s:option(Value, "gateway", translate("gateway") .. translate("cbi_optional"))
91 dns = s:option(Value, "dns", translate("dnsserver") .. translate("cbi_optional"))
95 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")