diff options
author | Steven Barth <steven@midlink.org> | 2008-08-13 01:24:44 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2008-08-13 01:24:44 +0000 |
commit | 07fdaa87dbac0582960cded4e9aa981d4a141782 (patch) | |
tree | 158e9c66902494de736ea282b216a374ba01f516 | |
parent | 0e3fda59e094a272bafc43b67e6393dc6f2b279e (diff) |
modules/admin-full: Network interface configuration optimization part #1
-rw-r--r-- | i18n/english/luasrc/i18n/default.en.lua | 1 | ||||
-rw-r--r-- | i18n/german/luasrc/i18n/default.de.lua | 1 | ||||
-rw-r--r-- | libs/cbi/htdocs/luci-static/resources/cbi/edit.gif | bin | 0 -> 280 bytes | |||
-rw-r--r-- | libs/cbi/htdocs/luci-static/resources/cbi/remove.gif | bin | 0 -> 385 bytes | |||
-rw-r--r-- | libs/cbi/luasrc/view/cbi/editlink.htm | 18 | ||||
-rw-r--r-- | libs/cbi/luasrc/view/cbi/tblsection.htm | 38 | ||||
-rw-r--r-- | libs/sys/luasrc/sys.lua | 15 | ||||
-rw-r--r-- | modules/admin-full/luasrc/controller/admin/network.lua | 23 | ||||
-rw-r--r-- | modules/admin-full/luasrc/model/cbi/admin_network/ifaces.lua | 67 | ||||
-rw-r--r-- | modules/admin-full/luasrc/model/cbi/admin_network/network.lua | 79 | ||||
-rw-r--r-- | modules/admin-full/luasrc/model/cbi/admin_network/ptp.lua | 48 | ||||
-rw-r--r-- | themes/fledermaus/htdocs/luci-static/fledermaus/cascade.css | 6 | ||||
-rw-r--r-- | themes/openwrt-light/htdocs/luci-static/openwrt-light/cascade.css | 6 | ||||
-rw-r--r-- | themes/openwrt.org/htdocs/luci-static/openwrt.org/cascade.css | 6 |
14 files changed, 184 insertions, 124 deletions
diff --git a/i18n/english/luasrc/i18n/default.en.lua b/i18n/english/luasrc/i18n/default.en.lua index 89b7c6321..a3d1d601f 100644 --- a/i18n/english/luasrc/i18n/default.en.lua +++ b/i18n/english/luasrc/i18n/default.en.lua @@ -25,6 +25,7 @@ disable = "disable" distance = "Distance" dnsserver = "DNS-Server" +edit = "Edit" enable = "enable" encryption = "Encryption" error = "Error" diff --git a/i18n/german/luasrc/i18n/default.de.lua b/i18n/german/luasrc/i18n/default.de.lua index 08ef89e69..5ef48de60 100644 --- a/i18n/german/luasrc/i18n/default.de.lua +++ b/i18n/german/luasrc/i18n/default.de.lua @@ -25,6 +25,7 @@ disable = "deaktivieren" distance = "Distanz" dnsserver = "DNS-Server" +edit = "Bearbeiten" enable = "aktivieren" encryption = "Verschlüsselung" error = "Fehler" diff --git a/libs/cbi/htdocs/luci-static/resources/cbi/edit.gif b/libs/cbi/htdocs/luci-static/resources/cbi/edit.gif Binary files differnew file mode 100644 index 000000000..7b02b6e72 --- /dev/null +++ b/libs/cbi/htdocs/luci-static/resources/cbi/edit.gif diff --git a/libs/cbi/htdocs/luci-static/resources/cbi/remove.gif b/libs/cbi/htdocs/luci-static/resources/cbi/remove.gif Binary files differnew file mode 100644 index 000000000..bf43a0a0b --- /dev/null +++ b/libs/cbi/htdocs/luci-static/resources/cbi/remove.gif diff --git a/libs/cbi/luasrc/view/cbi/editlink.htm b/libs/cbi/luasrc/view/cbi/editlink.htm deleted file mode 100644 index 83260e437..000000000 --- a/libs/cbi/luasrc/view/cbi/editlink.htm +++ /dev/null @@ -1,18 +0,0 @@ -<%# -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$ - --%> - -<%+cbi/valueheader%> -<a href="<%=REQUEST_URI%>/<%=section%>"><%:edit%></a> -<%+cbi/valuefooter%> diff --git a/libs/cbi/luasrc/view/cbi/tblsection.htm b/libs/cbi/luasrc/view/cbi/tblsection.htm index acaf6693e..46f7e5115 100644 --- a/libs/cbi/luasrc/view/cbi/tblsection.htm +++ b/libs/cbi/luasrc/view/cbi/tblsection.htm @@ -21,36 +21,52 @@ $Id$ <%- local count = 0 -%> <table class="cbi-section-table"> <tr class="cbi-section-table-titles"> + <%- if not self.anonymous then -%> + <th> </th> + <%- end -%> <%- for i, k in pairs(self.children) do -%> <th class="cbi-section-table-cell"><%=k.title%></th> + <%- count = count + 1; end; if self.extedit then -%> + <th class="cbi-section-table-cell"> </th> <%- count = count + 1; end; if self.addremove then -%> <th class="cbi-section-table-cell"> </th> <%- count = count + 1; end -%> </tr> <tr class="cbi-section-table-descr"> + <%- if not self.anonymous then -%> + <th> </th> + <%- end -%> <%- for i, k in pairs(self.children) do -%> <th class="cbi-section-table-cell"><%=k.description%></th> + <%- end; if self.extedit then -%> + <th class="cbi-section-table-cell"> </th> <%- end; if self.addremove then -%> <th class="cbi-section-table-cell"> </th> <%- end -%> </tr> <%- local isempty = true for i, k in ipairs(self:cfgsections()) do - if not self.anonymous then - -%> - <tr class="cbi-section-table-title"> - <th colspan="<%=count%>"><h3><%=k%></h3></th> - </tr> - <%- end section = k isempty = false scope = { valueheader = "cbi/cell_valueheader", valuefooter = "cbi/cell_valuefooter" } -%> <tr class="cbi-section-table-row" id="cbi-<%=self.config%>-<%=section%>"> + <% if not self.anonymous then -%> + <th><h3><%=k%></h3></th> + <%- end %> <%-+cbi/ucisection-%> + <%- if self.extedit or self.addremove then -%> + <td class="cbi-section-table-cell"> + <%- if self.extedit then -%> + <a href="<%=self.extedit:format(section)%>"><img style="border: none" src="<%=resource%>/cbi/edit.gif" alt="<%:edit%>" /></a> + <%- end; if self.addremove then %> + <button class="clean" type="submit" value="1" name="cbi.rts.<%=self.config%>.<%=k%>" title="<%:delete%>"><img src="<%=resource%>/cbi/remove.gif" alt="<%:delete%>" /></button> + <%- end -%> + </td> + <%- end -%> <%- if self.addremove then -%> <td class="cbi-section-table-cell"> - <input type="submit" name="cbi.rts.<%=self.config%>.<%=k%>" value="X" title="<%:delete%>" /> + </td> <%- end -%> </tr> @@ -61,9 +77,10 @@ $Id$ <td colspan="<%=count%>"><em><br /><%:cbi_sectempty%></em></td> </tr> <%- end -%> - + </table> <%- if self.addremove then -%> - <tr class="cbi-section-table-row"> + <br /> + <div class="cbi-section-table-row"> <td colspan="<%=count%>" class="cbi-section-table-optionals"> <div class="cbi-section-create"> <% if self.anonymous then %> @@ -78,9 +95,8 @@ $Id$ <% end %> </div> </td> - </tr> + </div> <%- end -%> - </table> </div> </div> <!-- /tblsection --> diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua index 56beafe94..c8d7a5477 100644 --- a/libs/sys/luasrc/sys.lua +++ b/libs/sys/luasrc/sys.lua @@ -212,6 +212,21 @@ function net.devices() return devices end + +--- Return information about available network interfaces. +-- @return Table containing all current interface names and their information +function net.deviceinfo() + local devices = {} + for line in io.lines("/proc/net/dev") do + local name, data = line:match("^ *(.-): *(.*)$") + if name and data then + devices[name] = luci.util.split(data, " +", nil, true) + end + end + return devices +end + + -- Determine the MAC address belonging to the given IP address. -- @param ip IPv4 address -- @return String containing the MAC address or nil if it cannot be found diff --git a/modules/admin-full/luasrc/controller/admin/network.lua b/modules/admin-full/luasrc/controller/admin/network.lua index 1d44bda77..fa7a8c719 100644 --- a/modules/admin-full/luasrc/controller/admin/network.lua +++ b/modules/admin-full/luasrc/controller/admin/network.lua @@ -28,35 +28,32 @@ function index() page.title = i18n("a_n_switch", "Switch") page.order = 10 - local page = node("admin", "network", "ifaces") - page.target = cbi("admin_network/ifaces") + local page = node("admin", "network", "network") + page.target = cbi("admin_network/network") page.title = i18n("interfaces", "Schnittstellen") page.order = 20 - page.leaf = true - luci.model.uci.foreach("network", "interface", function (section) local ifc = section[".name"] if ifc ~= "loopback" then - entry({"admin", "network", "ifaces", ifc}, - page.target, ifc:upper()) + entry({"admin", "network", "network", ifc}, + alias("admin", "network", "ifaces", ifc), + ifc:upper()) end end ) - + + local page = node("admin", "network", "ifaces") + page.target = cbi("admin_network/ifaces") + page.leaf = true local page = node("admin", "network", "dhcp") page.target = cbi("admin_network/dhcp") page.title = "DHCP" page.order = 30 - local page = node("admin", "network", "ptp") - page.target = cbi("admin_network/ptp") - page.title = "PPPoE / PPTP" - page.order = 40 - local page = node("admin", "network", "routes") page.target = cbi("admin_network/routes") page.title = i18n("a_n_routes", "Routen") - page.order = 50 + page.order = 40 end
\ No newline at end of file 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 c85b6a182..906563683 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 000000000..c79dc8359 --- /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 7fd7135ff..000000000 --- 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 diff --git a/themes/fledermaus/htdocs/luci-static/fledermaus/cascade.css b/themes/fledermaus/htdocs/luci-static/fledermaus/cascade.css index d9ec173d8..a6dbcf833 100644 --- a/themes/fledermaus/htdocs/luci-static/fledermaus/cascade.css +++ b/themes/fledermaus/htdocs/luci-static/fledermaus/cascade.css @@ -252,6 +252,12 @@ td input[type=password] { width: 99%; } +button.clean { + cursor: pointer; + border: none; + background-color: inherit; +} + textarea { margin-left: -1px; margin-bottom: 0.5em; diff --git a/themes/openwrt-light/htdocs/luci-static/openwrt-light/cascade.css b/themes/openwrt-light/htdocs/luci-static/openwrt-light/cascade.css index a4203a6f4..42b9b33a5 100644 --- a/themes/openwrt-light/htdocs/luci-static/openwrt-light/cascade.css +++ b/themes/openwrt-light/htdocs/luci-static/openwrt-light/cascade.css @@ -237,6 +237,12 @@ td input[type=password] { width: 99%; } +button.clean { + cursor: pointer; + border: none; + background-color: inherit; +} + textarea { margin-left: -1px; margin-bottom: 0.5em; diff --git a/themes/openwrt.org/htdocs/luci-static/openwrt.org/cascade.css b/themes/openwrt.org/htdocs/luci-static/openwrt.org/cascade.css index 8144a10d9..218d7674d 100644 --- a/themes/openwrt.org/htdocs/luci-static/openwrt.org/cascade.css +++ b/themes/openwrt.org/htdocs/luci-static/openwrt.org/cascade.css @@ -245,6 +245,12 @@ td input[type=password] { width: 99%; } +button.clean { + cursor: pointer; + border: none; + background-color: inherit; +} + textarea { margin-left: -1px; margin-bottom: 0.5em; |