From 07fdaa87dbac0582960cded4e9aa981d4a141782 Mon Sep 17 00:00:00 2001 From: Steven Barth <steven@midlink.org> Date: Wed, 13 Aug 2008 01:24:44 +0000 Subject: modules/admin-full: Network interface configuration optimization part #1 --- .../luasrc/model/cbi/admin_network/ifaces.lua | 67 +++++++++--------- .../luasrc/model/cbi/admin_network/network.lua | 79 ++++++++++++++++++++++ .../luasrc/model/cbi/admin_network/ptp.lua | 48 ------------- 3 files changed, 112 insertions(+), 82 deletions(-) create mode 100644 modules/admin-full/luasrc/model/cbi/admin_network/network.lua delete mode 100644 modules/admin-full/luasrc/model/cbi/admin_network/ptp.lua (limited to 'modules/admin-full/luasrc/model/cbi') diff --git a/modules/admin-full/luasrc/model/cbi/admin_network/ifaces.lua b/modules/admin-full/luasrc/model/cbi/admin_network/ifaces.lua index c85b6a1821..9065636836 100644 --- a/modules/admin-full/luasrc/model/cbi/admin_network/ifaces.lua +++ b/modules/admin-full/luasrc/model/cbi/admin_network/ifaces.lua @@ -2,6 +2,7 @@ LuCI - Lua Configuration Interface Copyright 2008 Steven Barth <steven@midlink.org> +Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -11,33 +12,18 @@ You may obtain a copy of the License at $Id$ ]]-- -m = Map("network", translate("interfaces"), translate("a_n_ifaces1")) - -arg = arg or {} +arg[1] = arg[1] or "" -s = m:section(TypedSection, "interface", translate("interfaces")) -function s.create(self, section) - local stat = TypedSection.create(self, section) - if stat then - arg = {section or stat} - end - return stat -end - -function s.filter(self, section) - return section ~= "loopback" and - (not arg or not arg[1] or arg[1] == section) -end +m = Map("network", translate("interfaces"), translate("a_n_ifaces1")) -if not arg or not arg[1] then - s.addremove = true -end -s:depends("proto", "static") -s:depends("proto", "dhcp") +s = m:section(NamedSection, arg[1], "interface", translate("interfaces")) +s.addremove = true p = s:option(ListValue, "proto", translate("protocol")) p:value("static", translate("static")) p:value("dhcp", "DHCP") +p:value("pppoe", "PPPoE") +p:value("pptp", "PPTP") p.default = "static" br = s:option(Flag, "type", translate("a_n_i_bridge"), translate("a_n_i_bridge1")) @@ -91,25 +77,38 @@ mtu.isinteger = true mac = s:option(Value, "macaddr", translate("macaddress")) mac.optional = true +user = s:option(Value, "username", translate("username")) +user.rmempty = true +user:depends("proto", "pptp") +user:depends("proto", "ppoe") + +pass = s:option(Value, "password", translate("password")) +pass.rmempty = true +pass:depends("proto", "pptp") +pass:depends("proto", "ppoe") + +ka = s:option(Value, "keepalive") +ka.rmempty = true +ka:depends("proto", "pptp") +ka:depends("proto", "ppoe") + +demand = s:option(Value, "demand") +demand.rmempty = true +demand:depends("proto", "pptp") +demand:depends("proto", "ppoe") + +srv = s:option(Value, "server") +srv:depends("proto", "pptp") +srv.rmempty = true + s2 = m:section(TypedSection, "alias", translate("aliases")) s2.addremove = true -if arg and arg[1] then - s2:depends("interface", arg[1]) - s2.defaults.interface = arg[1] -else - parent = s2:option(ListValue, "interface", translate("interface")) - luci.model.uci.foreach("network", "interface", - function (section) - if section[".name"] ~= "loopback" then - parent:value(section[".name"]) - end - end - ) -end +s2:depends("interface", arg[1]) +s2.defaults.interface = arg[1] s2.defaults.proto = "static" diff --git a/modules/admin-full/luasrc/model/cbi/admin_network/network.lua b/modules/admin-full/luasrc/model/cbi/admin_network/network.lua new file mode 100644 index 0000000000..c79dc8359d --- /dev/null +++ b/modules/admin-full/luasrc/model/cbi/admin_network/network.lua @@ -0,0 +1,79 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Steven Barth <steven@midlink.org> +Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ +]]-- +require("luci.sys") + + +m = Map("network", translate("interfaces"), translate("a_n_ifaces1")) + +local created +local netstat = luci.sys.net.deviceinfo() + +s = m:section(TypedSection, "interface", translate("interfaces")) +s.addremove = true +s.extedit = luci.http.getenv("REQUEST_URI") .. "/%s" +s.template = "cbi/tblsection" + +function s.filter(self, section) + return section ~= "loopback" and section +end + +function s.create(self, section) + if TypedSection.create(self, section) then + created = section + end +end + +function s.parse(self, ...) + TypedSection.parse(self, ...) + if created then + luci.http.redirect(luci.http.getenv("REQUEST_URI") .. "/" .. created) + end +end + +up = s:option(Flag, "up") +up.stateful = true +function up.write(self, section, value) + local call = value == "1" and "ifdown" or "ifup" + os.execute(call .. " " .. section) +end + +ipaddr = s:option(DummyValue, "ipaddr", translate("ipaddress")) +ipaddr.stateful = true + +function ipaddr.cfgvalue(self, section) + local ip = self.map:stateget(section, "ipaddr") + local nm = self.map:stateget(section, "netmask") + + local parsed = ip and luci.ip.IPv4(ip, nm) + return parsed and parsed:string() or "" +end + +rx = s:option(DummyValue, "_rx") + +function rx.cfgvalue(self, section) + local ix = self.map:stateget(section, "ifname") + local bt = netstat and netstat[ix] and netstat[ix][1] + return bt and string.format("%.2f MB", tonumber(bt) / 1024 / 1024) +end + +tx = s:option(DummyValue, "_tx") + +function tx.cfgvalue(self, section) + local ix = self.map:stateget(section, "ifname") + local bt = netstat and netstat[ix] and netstat[ix][9] + return bt and string.format("%.2f MB", tonumber(bt) / 1024 / 1024) +end + +return m \ No newline at end of file diff --git a/modules/admin-full/luasrc/model/cbi/admin_network/ptp.lua b/modules/admin-full/luasrc/model/cbi/admin_network/ptp.lua deleted file mode 100644 index 7fd7135ffd..0000000000 --- a/modules/admin-full/luasrc/model/cbi/admin_network/ptp.lua +++ /dev/null @@ -1,48 +0,0 @@ ---[[ -LuCI - Lua Configuration Interface - -Copyright 2008 Steven Barth <steven@midlink.org> - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -$Id$ -]]-- -m = Map("network", translate("a_n_ptp"), translate("a_n_ptp1")) - -s = m:section(TypedSection, "interface", "") -s.addremove = true -s:depends("proto", "pppoe") -s:depends("proto", "pptp") - -p = s:option(ListValue, "proto", translate("protocol")) -p:value("pppoe", "PPPoE") -p:value("pptp", "PPTP") -p.default = "pppoe" - -ifname = s:option(Value, "ifname", translate("interface")) -for i,d in ipairs(luci.sys.net.devices()) do - if d ~= "lo" then - ifname:value(d) - end -end - -s:option(Value, "username", translate("username")) -s:option(Value, "password", translate("password")) - -s:option(Value, "keepalive").optional = true - -s:option(Value, "demand").optional = true - -srv = s:option(Value, "server") -srv:depends("proto", "pptp") -srv.rmempty = true - -mtu = s:option(Value, "mtu", "MTU") -mtu.optional = true -mtu.isinteger = true - -return m \ No newline at end of file -- cgit v1.2.3