* CBI: improvements, bug fixes

* admin: Introduced wifi, olsr, password pages
This commit is contained in:
Steven Barth 2008-03-28 22:55:27 +00:00
parent fb2a9a328d
commit bd32a8aac5
20 changed files with 260 additions and 22 deletions

View 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 {

View 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

View file

@ -1,4 +1,4 @@
module(..., package.seeall)
module("ffluci.controller.admin.index", package.seeall)
menu = {
descr = "Übersicht",

View file

@ -0,0 +1,9 @@
module("ffluci.controller.admin.mesh", package.seeall)
menu = {
descr = "Mesh",
order = 50,
entries = {
{action = "olsrd", descr = "OLSR"},
}
}

View 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"},
}

View file

@ -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

View 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

View file

@ -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"},
}
}

View 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()

View 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

View 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

View file

@ -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

View file

@ -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

View 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

View file

@ -0,0 +1,2 @@
<%+header%>
<%+footer%>

View file

@ -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%>

View file

@ -0,0 +1,2 @@
<%+header%>
<%+footer%>

View file

@ -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%>

View file

@ -12,9 +12,10 @@
<% 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 %>

View 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%>