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 m0 = Map("network", translate("network"))
20 local netstat = luci.sys.net.deviceinfo()
22 m0.parse = function() end
24 s = m0:section(TypedSection, "interface", translate("status"))
25 s.template = "cbi/tblsection"
28 function s.filter(self, section)
29 return section ~= "loopback" and section
32 hwaddr = s:option(DummyValue, "_hwaddr")
33 function hwaddr.cfgvalue(self, section)
34 local ix = self.map:get(section, "ifname") or ""
35 return luci.fs.readfile("/sys/class/net/" .. ix .. "/address") or "n/a"
39 s:option(DummyValue, "ipaddr", translate("ipaddress"))
41 s:option(DummyValue, "netmask", translate("netmask"))
44 txrx = s:option(DummyValue, "_txrx")
46 function txrx.cfgvalue(self, section)
47 local ix = self.map:get(section, "ifname")
49 local rx = netstat and netstat[ix] and netstat[ix][1]
50 rx = rx and luci.tools.webadmin.byte_format(tonumber(rx)) or "-"
52 local tx = netstat and netstat[ix] and netstat[ix][9]
53 tx = tx and luci.tools.webadmin.byte_format(tonumber(tx)) or "-"
55 return string.format("%s / %s", tx, rx)
58 errors = s:option(DummyValue, "_err")
60 function errors.cfgvalue(self, section)
61 local ix = self.map:get(section, "ifname")
63 local rx = netstat and netstat[ix] and netstat[ix][3]
64 local tx = netstat and netstat[ix] and netstat[ix][11]
66 rx = rx and tostring(rx) or "-"
67 tx = tx and tostring(tx) or "-"
69 return string.format("%s / %s", tx, rx)
75 m = Map("network", "")
77 s = m:section(NamedSection, "lan", "interface", translate("m_n_local"))
78 s:option(Value, "ipaddr", translate("ipaddress"))
80 nm = s:option(Value, "netmask", translate("netmask"))
81 nm:value("255.255.255.0")
82 nm:value("255.255.0.0")
85 gw = s:option(Value, "gateway", translate("gateway") .. translate("cbi_optional"))
87 dns = s:option(Value, "dns", translate("dnsserver") .. translate("cbi_optional"))
91 s = m:section(NamedSection, "wan", "interface", translate("m_n_inet"))
92 p = s:option(ListValue, "proto", translate("protocol"))
93 p:value("none", "disabled")
94 p:value("static", translate("manual", "manual"))
95 p:value("dhcp", translate("automatic", "automatic"))
96 p:value("pppoe", "PPPoE")
97 p:value("pptp", "PPTP")
99 ip = s:option(Value, "ipaddr", translate("ipaddress"))
100 ip:depends("proto", "static")
102 nm = s:option(Value, "netmask", translate("netmask"))
103 nm:depends("proto", "static")
105 gw = s:option(Value, "gateway", translate("gateway"))
106 gw:depends("proto", "static")
109 dns = s:option(Value, "dns", translate("dnsserver"))
110 dns:depends("proto", "static")
113 usr = s:option(Value, "username", translate("username"))
114 usr:depends("proto", "pppoe")
115 usr:depends("proto", "pptp")
117 pwd = s:option(Value, "password", translate("password"))
118 pwd:depends("proto", "pppoe")
119 pwd:depends("proto", "pptp")
121 kea = s:option(Flag, "keepalive", translate("m_n_keepalive"))
122 kea:depends("proto", "pppoe")
123 kea:depends("proto", "pptp")
128 cod = s:option(Value, "demand", translate("m_n_dialondemand"), "s")
129 cod:depends("proto", "pppoe")
130 cod:depends("proto", "pptp")
133 srv = s:option(Value, "server", translate("m_n_pptp_server"))
134 srv:depends("proto", "pptp")