* CBI: improvements, bug fixes
authorSteven Barth <steven@midlink.org>
Fri, 28 Mar 2008 22:55:27 +0000 (22:55 +0000)
committerSteven Barth <steven@midlink.org>
Fri, 28 Mar 2008 22:55:27 +0000 (22:55 +0000)
* admin: Introduced wifi, olsr, password pages

20 files changed:
contrib/media/cascade.css
src/ffluci/cbi.lua
src/ffluci/controller/admin/index.lua
src/ffluci/controller/admin/mesh.lua [new file with mode: 0644]
src/ffluci/controller/admin/network.lua
src/ffluci/controller/admin/system.lua [new file with mode: 0644]
src/ffluci/controller/admin/uci.lua
src/ffluci/controller/admin/wifi.lua [new file with mode: 0644]
src/ffluci/dispatcher.lua
src/ffluci/http.lua
src/ffluci/model/cbi/admin_network/ifaces.lua
src/ffluci/model/cbi/admin_wifi/devices.lua [new file with mode: 0644]
src/ffluci/model/cbi/admin_wifi/networks.lua [new file with mode: 0644]
src/ffluci/sys.lua
src/ffluci/view/admin_system/index.htm [new file with mode: 0644]
src/ffluci/view/admin_system/passwd.htm [new file with mode: 0644]
src/ffluci/view/admin_wifi/index.htm [new file with mode: 0644]
src/ffluci/view/cbi/dvalue.htm [new file with mode: 0644]
src/ffluci/view/cbi/tsection.htm
src/ffluci/view/cbi/value.htm

index 55d6f76bd11e49d8e2a7290705fd203b2c067602..8555e3f829140018e888ab1d052695c478c2944e 100644 (file)
@@ -198,6 +198,7 @@ code {
 .cbi-optionals select, .cbi-optionals input,
 .cbi-section-remove input, .cbi-section-create input  {
        font-size: 0.8em;
+       margin: 0%;
 }
 
 .cbi-value-description {
index 844f6c0bb333430cdd037c4508cf50c8bbc768a5..296a77b493562ff221679693ece07b845d5cb67b 100644 (file)
@@ -43,10 +43,11 @@ function load(cbimap)
        local func, err = loadfile(cbidir..cbimap..".lua")
        
        if not func then
-               error(err)
                return nil
        end
        
+       ffluci.i18n.loadc("cbi")
+       
        ffluci.util.resfenv(func)
        ffluci.util.updfenv(func, ffluci.cbi)
        ffluci.util.extfenv(func, "translate", ffluci.i18n.translate)
@@ -58,8 +59,6 @@ function load(cbimap)
                return nil
        end
        
-       ffluci.i18n.loadc("cbi")
-       
        return map
 end
 
@@ -131,7 +130,8 @@ end
 function Map.add(self, sectiontype)
        local name = self.uci:add(self.config, sectiontype)
        if name then
-               self.ucidata[name] = self.uci:show(self.config, name)
+               self.ucidata[name] = {}
+               self.ucidata[name][".type"] = sectiontype
        end
        return name
 end
@@ -317,7 +317,9 @@ function NamedSection.parse(self)
        
        if active then
                AbstractSection.parse_dynamic(self, s)
-               Node.parse(self, s)
+               if ffluci.http.formvalue("cbi.submit") then
+                       Node.parse(self, s)
+               end
                AbstractSection.parse_optionals(self, s)
        end     
 end
@@ -337,7 +339,7 @@ function TypedSection.__init__(self, ...)
        self.deps = {}
        self.excludes = {}
        
-       self.anonymous   = false
+       self.anonymous = false
 end
 
 -- Return all matching UCI sections for this TypedSection
@@ -420,7 +422,9 @@ function TypedSection.parse(self)
        
        for k, v in pairs(self:cfgsections()) do
                AbstractSection.parse_dynamic(self, k)
-               Node.parse(self, k)
+               if ffluci.http.formvalue("cbi.submit") then
+                       Node.parse(self, k)
+               end
                AbstractSection.parse_optionals(self, k)
        end
 end
@@ -518,7 +522,7 @@ function AbstractValue.parse(self, section)
                if fvalue and not (fvalue == self:cfgvalue(section)) then
                        self:write(section, fvalue)
                end 
-       elseif ffluci.http.formvalue("cbi.submit") then -- Unset the UCI or error
+       else                                                    -- Unset the UCI or error
                if self.rmempty or self.optional then
                        self:remove(section)
                end
@@ -583,6 +587,23 @@ function Value.validate(self, val)
 end
 
 
+-- DummyValue - This does nothing except being there
+DummyValue = class(AbstractValue)
+
+function DummyValue.__init__(self, map, ...)
+       AbstractValue.__init__(self, map, ...)
+       self.template = "cbi/dvalue"
+       self.value = nil
+end
+
+function DummyValue.parse(self)
+       
+end
+
+function DummyValue.render(self, s)
+       ffluci.template.render(self.template, {self=self, section=s})
+end
+
 
 --[[
 Flag - A flag being enabled or disabled
@@ -599,7 +620,6 @@ end
 
 -- A flag can only have two states: set or unset
 function Flag.parse(self, section)
-       self.default = self.enabled
        local fvalue = self:formvalue(section)
        
        if fvalue then
index 3ee564f640f23c4c4779c9e0af0a2375da5d88ff..d57e3fd9f44bfcd5374e271e396f8a3587259b24 100644 (file)
@@ -1,4 +1,4 @@
-module(..., package.seeall)
+module("ffluci.controller.admin.index", package.seeall)
 
 menu = {
        descr   = "Übersicht",
diff --git a/src/ffluci/controller/admin/mesh.lua b/src/ffluci/controller/admin/mesh.lua
new file mode 100644 (file)
index 0000000..fcdcdab
--- /dev/null
@@ -0,0 +1,9 @@
+module("ffluci.controller.admin.mesh", package.seeall)
+
+menu = {
+       descr   = "Mesh",
+       order   = 50,
+       entries = {
+               {action = "olsrd", descr = "OLSR"},
+       }
+}
\ No newline at end of file
index 2774dfdb02276d5894ebac2d3202b5bf02b16c86..534193b4db77f0254527ab0166674a282480ae6a 100644 (file)
@@ -2,9 +2,9 @@ module(..., package.seeall)
 
 menu = {
        descr   = "Netzwerk",
-       order   = 20,
+       order   = 30,
        entries = {
-               {action = "vlan", descr = "VLAN"},
+               {action = "vlan", descr = "Switch"},
                {action = "ifaces", descr = "Schnittstellen"},
                {action = "ptp", descr = "PPPoE / PPTP"},
        }
diff --git a/src/ffluci/controller/admin/system.lua b/src/ffluci/controller/admin/system.lua
new file mode 100644 (file)
index 0000000..df2d981
--- /dev/null
@@ -0,0 +1,26 @@
+module("ffluci.controller.admin.system", package.seeall)
+
+require("ffluci.util")
+require("ffluci.http")
+
+menu = {
+       descr   = "System",
+       order   = 20,
+       entries = {
+               {action = "passwd", descr = "Passwort"},
+       }
+}
+
+function action_passwd()
+       local p1 = ffluci.http.formvalue("pwd1")
+       local p2 = ffluci.http.formvalue("pwd2")
+       local msg = nil
+       local cm
+       
+       if p1 or p2 then
+               cm = "(echo '"..p1.."';sleep 1;echo '"..p2.."') | passwd root 2>&1"
+               msg = ffluci.util.exec(cm)
+       end
+       
+       ffluci.template.render("admin_system/passwd", {msg=msg})
+end
\ No newline at end of file
index a1eb0d7d72c6c5fd5d1c9562bb22f40fd40a246e..9f8c1249964b33954ea305e15bd38b22f4c610fd 100644 (file)
@@ -24,7 +24,7 @@ function action_apply()
                        for k, v in pairs(apply) do
                                local cmd = ffluci.config.uci_oncommit[k]
                                if cmd then
-                                       output = output .. ffluci.util.exec(cmd)
+                                       output = output .. cmd .. ":" .. ffluci.util.exec(cmd)
                                end
                        end
                end
diff --git a/src/ffluci/controller/admin/wifi.lua b/src/ffluci/controller/admin/wifi.lua
new file mode 100644 (file)
index 0000000..54b6bfb
--- /dev/null
@@ -0,0 +1,10 @@
+module("ffluci.controller.admin.wifi", package.seeall)
+
+menu = {
+       descr   = "Drahtlos",
+       order   = 40,
+       entries = {
+               {action = "devices", descr = "Geräte"},
+               {action = "networks", descr = "Netze"},
+       }
+}
\ No newline at end of file
index ee836043d2678bce05eaf053e310d46e5f59890f..139b0e308314853982fc65e0f36671239b941577 100644 (file)
@@ -172,7 +172,7 @@ function cbi(request)
        i18n.loadc(request.module)
        
        local stat, map = pcall(cbi.load, path)
-       if stat then
+       if stat and map then
                local stat, err = pcall(map.parse, map)
                if not stat then
                        disp.error500(err)
@@ -181,6 +181,8 @@ function cbi(request)
                tmpl.render("cbi/header")
                map:render()
                tmpl.render("cbi/footer")
+       elseif not stat then
+               disp.error500(map)
        else
                disp.error404()
        end
@@ -208,7 +210,7 @@ function dynamic(request)
        end
        
        local stat, map = pcall(cbi.load, path)
-       if stat then
+       if stat and map then
                local stat, err = pcall(map.parse, map)
                if not stat then
                        disp.error500(err)
@@ -218,6 +220,9 @@ function dynamic(request)
                map:render()
                tmpl.render("cbi/footer")
                return
+       elseif not stat then
+               disp.error500(map)
+               return
        end     
        
        disp.error404()
index bf94105734e1be14bde4f160f433b6197bffacde..81076233b9967044dc45c4d4b22c74e16d40ed37 100644 (file)
@@ -59,7 +59,7 @@ end
 function formvalue(key, default)
        local c = formvalues()
        
-       for match in key:gmatch("%w+") do
+       for match in key:gmatch("[%w-_]+") do
                c = c[match]
                if c == nil then
                        return default
index aaabe653e4b592c6f24be459f16066527c3ac4f2..193f83f514e4c7861a6d0b1ce5075c2aaf13bf45 100644 (file)
@@ -12,6 +12,10 @@ p:value("static", "statisch")
 p:value("dhcp", "DHCP")
 p.default = "static"
 
+br = s:option(Flag, "type", "Netzwerkbrücke", "überbrückt angegebene Schnittstelle(n)")
+br.enabled = "bridge"
+br.rmempty = true
+
 s:option(Value, "ifname", "Schnittstelle")
 
 s:option(Value, "ipaddr", "IP-Adresse")
@@ -30,4 +34,7 @@ mtu = s:option(Value, "mtu", "MTU")
 mtu.optional = true
 mtu.isinteger = true
 
+mac = s:option(Value, "macaddr", "MAC-Adresse")
+mac.optional = true
+
 return m
\ No newline at end of file
diff --git a/src/ffluci/model/cbi/admin_wifi/devices.lua b/src/ffluci/model/cbi/admin_wifi/devices.lua
new file mode 100644 (file)
index 0000000..7ef794c
--- /dev/null
@@ -0,0 +1,52 @@
+-- ToDo: Translate, Add descriptions and help texts
+require("ffluci.util")
+
+m = Map("wireless", "Geräte")
+
+s = m:section(TypedSection, "wifi-device")
+--s.addremove = true
+
+en = s:option(Flag, "disabled", "Aktivieren")
+en.enabled = "0"
+en.disabled = "1"
+
+t = s:option(ListValue, "type", "Typ")
+t:value("broadcom")
+t:value("atheros")
+t:value("mac80211")
+t:value("prism2")
+--[[
+local c = ". /etc/functions.sh;for i in /lib/wifi/*;do . $i;done;echo $DRIVERS"
+for driver in ffluci.util.execl(c)[1]:gmatch("[^ ]+") do
+       t:value(driver)
+end
+]]--
+
+mode = s:option(ListValue, "mode", "Modus")
+mode:value("", "standard")
+mode:value("11b", "802.11b")
+mode:value("11g", "802.11g")
+mode:value("11a", "802.11a")
+mode:value("11bg", "802.11b+g")
+mode.rmempty = true
+
+s:option(Value, "channel", "Funkkanal")
+
+s:option(Value, "txantenna", "Sendeantenne").rmempty = true
+
+s:option(Value, "rxantenna", "Empfangsantenne").rmempty = true
+
+s:option(Value, "distance", "Distanz",
+       "Distanz zum am weitesten entfernten Funkpartner (m)").rmempty = true
+
+s:option(Value, "diversity", "Diversität"):depends("type", "atheros")
+       
+country = s:option(Value, "country", "Ländercode")
+country.optional = true
+country:depends("type", "broadcom")
+
+maxassoc = s:option(Value, "maxassoc", "Verbindungslimit")
+maxassoc:depends("type", "broadcom")
+maxassoc.optional = true
+
+return m
\ No newline at end of file
diff --git a/src/ffluci/model/cbi/admin_wifi/networks.lua b/src/ffluci/model/cbi/admin_wifi/networks.lua
new file mode 100644 (file)
index 0000000..ebc2571
--- /dev/null
@@ -0,0 +1,67 @@
+-- ToDo: Translate, Add descriptions and help texts
+m = Map("wireless", "Netze")
+
+s = m:section(TypedSection, "wifi-iface")
+s.addremove = true
+s.anonymous = true
+
+s:option(Value, "ssid", "Netzkennung (ESSID)").maxlength = 32
+
+device = s:option(ListValue, "device", "Gerät")
+for k, v in pairs(ffluci.model.uci.show("wireless").wireless) do
+       if v[".type"] == "wifi-device" then
+               device:value(k)
+       end
+end
+
+network = s:option(ListValue, "network", "Netzwerk")
+network:value("")
+for k, v in pairs(ffluci.model.uci.show("network").network) do
+       if v[".type"] == "interface" then
+               network:value(k)
+       end
+end
+
+mode = s:option(ListValue, "mode", "Modus")
+mode:value("ap", "Access Point")
+mode:value("adhoc", "Ad-Hoc")
+mode:value("sta", "Client")
+mode:value("wds", "WDS")
+
+s:option(Value, "bssid", "BSSID").optional = true
+
+s:option(Value, "txpower", "Sendeleistung", "dbm").rmempty = true
+
+encr = s:option(ListValue, "encryption", "Verschlüsselung")
+encr:value("none", "keine")
+encr:value("wep", "WEP")
+encr:value("psk", "WPA-PSK")
+encr:value("wpa", "WPA-Radius")
+encr:value("psk2", "WPA2-PSK")
+encr:value("wpa2", "WPA2-Radius")
+
+key = s:option(Value, "key", "Schlüssel")
+key:depends("encryption", "wep")
+key:depends("encryption", "psk")
+key:depends("encryption", "wpa")
+key:depends("encryption", "psk2")
+key:depends("encryption", "wpa2")
+key.rmempty = true
+
+server = s:option(Value, "server", "Radius-Server")
+server:depends("encryption", "wpa")
+server:depends("encryption", "wpa2")
+server.rmempty = true
+
+port = s:option(Value, "port", "Radius-Port")
+port:depends("encryption", "wpa")
+port:depends("encryption", "wpa2")
+port.rmempty = true
+
+s:option(Flag, "isolate", "AP-Isolation", "Unterbindet Client-Client-Verkehr").optional = true
+
+s:option(Flag, "hidden", "ESSID verstecken").optional = true
+
+
+
+return m
\ No newline at end of file
index 048f6d375179d0573a02f7ba2878e197170207e3..4ed2262c8b2a1d244a7ecf05d4416b5bd3773fab 100644 (file)
@@ -29,11 +29,20 @@ require("ffluci.fs")
 
 -- Returns the hostname
 function hostname()
-       return ffluci.fs.readfilel("/proc/sys/kernel/hostname")[1]
+       return io.lines("/proc/sys/kernel/hostname")()
 end
 
 -- Returns the load average
 function loadavg()
-       local loadavg = ffluci.fs.readfilel("/proc/loadavg")[1]
+       local loadavg = io.lines("/proc/loadavg")()
        return loadavg:match("^(.-) (.-) (.-) (.-) (.-)$")
+end
+
+-- Returns all available network interfaces
+function net_devices()
+       local devices = {}
+       for line in io.lines("/proc/net/dev") do
+               table.insert(devices, line:match(" *(.-):"))
+       end
+       return devices
 end
\ No newline at end of file
diff --git a/src/ffluci/view/admin_system/index.htm b/src/ffluci/view/admin_system/index.htm
new file mode 100644 (file)
index 0000000..75aa026
--- /dev/null
@@ -0,0 +1,2 @@
+<%+header%>
+<%+footer%>
\ No newline at end of file
diff --git a/src/ffluci/view/admin_system/passwd.htm b/src/ffluci/view/admin_system/passwd.htm
new file mode 100644 (file)
index 0000000..3458fef
--- /dev/null
@@ -0,0 +1,15 @@
+<%+header%>
+<h1><%:system System%></h1>
+<h2><%:changepw Passwort ändern%></h2>
+<div><br />
+<% if msg then %>
+       <code><%=msg%></code>
+<% else %>
+       <form method="post" action="<%=controller%>/admin/system/passwd">
+               <input type="password" name="pwd1" /> <%:password Passwort%><br />
+               <input type="password" name="pwd2" /> <%:confirmation Bestätigung%><br />
+               <input type="submit" value="<%:save Speichern%>" />
+       </form>
+<% end %>
+</div>
+<%+footer%>
\ No newline at end of file
diff --git a/src/ffluci/view/admin_wifi/index.htm b/src/ffluci/view/admin_wifi/index.htm
new file mode 100644 (file)
index 0000000..75aa026
--- /dev/null
@@ -0,0 +1,2 @@
+<%+header%>
+<%+footer%>
\ No newline at end of file
diff --git a/src/ffluci/view/cbi/dvalue.htm b/src/ffluci/view/cbi/dvalue.htm
new file mode 100644 (file)
index 0000000..178f2e1
--- /dev/null
@@ -0,0 +1,12 @@
+<%+cbi/valueheader%>
+<% if self.value then
+       if type(self.value) == "function" then %>
+       <%=self:value(section)%>
+<% else %>
+       <%=self.value%>
+<%     end
+else %>
+       <%=(self:cfgvalue(section) or "")%>
+<% end %>
+&nbsp;
+<%+cbi/valuefooter%>
index 012ae063a8052479f4b6a565aba0149e5c27ee56..8da0b4a1da0b44aac0157878811aeb5436ba65c6 100644 (file)
 <% if self.addremove then %>
                                        <div class="cbi-section-create">
                                                <% if self.anonymous then %>
-                                               <input type="submit" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" value="<%:cbi_add Eintrag hinzufügen%>" />
-                                               <% else %><input type="text" class="cbi-section-create-name" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" />
-                                               <input type="submit" value="<%:cbi_add Eintrag hinzufügen%>" />
+                                                       <input type="submit" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" value="<%:cbi_add Eintrag hinzufügen%>" />
+                                               <% else %>
+                                                       <input type="text" class="cbi-section-create-name" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" />
+                                                       <input type="submit" value="<%:cbi_add Eintrag hinzufügen%>" />
                                                <% end %><% if self.err_invalid then %><div class="cbi-error"><%:cbi_invalid Fehler: Ungültige Eingabe%></div><% end %>
                                        </div>
 <% end %>
index b994790d2753498bf676fe166c989630a62ef3db..61033a0f50d7450da6cd03164b0fc6b2b93bcb6b 100644 (file)
@@ -1,3 +1,3 @@
 <%+cbi/valueheader%>
-                                                               <input type="text" onchange="cbi_d_update(this.id)" <% if self.size then %>size="<%=self.size%>" <% end %><% if self.maxlength then %>maxlength="<%=self.maxlength%>" <% end %>name="cbid.<%=self.config.."."..section.."."..self.option%>" value="<%=(self:cfgvalue(section) or "")%>" />
+                                                               <input type="text" onchange="cbi_d_update(this.id)" <% if self.size then %>size="<%=self.size%>" <% end %><% if self.maxlength then %>maxlength="<%=self.maxlength%>" <% end %>name="cbid.<%=self.config.."."..section.."."..self.option%>" id="cbid.<%=self.config.."."..section.."."..self.option%>" value="<%=(self:cfgvalue(section) or "")%>" />
 <%+cbi/valuefooter%>