summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-03-28 22:55:27 +0000
committerSteven Barth <steven@midlink.org>2008-03-28 22:55:27 +0000
commitbd32a8aac5de9beb321b3cdfe180a8798c5a3379 (patch)
treea0b5e2926066e23c7356122a8afeb0ed0ef0e505 /src
parentfb2a9a328d619ecf329e64cb500ff1385e3f8290 (diff)
* CBI: improvements, bug fixes
* admin: Introduced wifi, olsr, password pages
Diffstat (limited to 'src')
-rw-r--r--src/ffluci/cbi.lua38
-rw-r--r--src/ffluci/controller/admin/index.lua2
-rw-r--r--src/ffluci/controller/admin/mesh.lua9
-rw-r--r--src/ffluci/controller/admin/network.lua4
-rw-r--r--src/ffluci/controller/admin/system.lua26
-rw-r--r--src/ffluci/controller/admin/uci.lua2
-rw-r--r--src/ffluci/controller/admin/wifi.lua10
-rw-r--r--src/ffluci/dispatcher.lua9
-rw-r--r--src/ffluci/http.lua2
-rw-r--r--src/ffluci/model/cbi/admin_network/ifaces.lua7
-rw-r--r--src/ffluci/model/cbi/admin_wifi/devices.lua52
-rw-r--r--src/ffluci/model/cbi/admin_wifi/networks.lua67
-rw-r--r--src/ffluci/sys.lua13
-rw-r--r--src/ffluci/view/admin_system/index.htm2
-rw-r--r--src/ffluci/view/admin_system/passwd.htm15
-rw-r--r--src/ffluci/view/admin_wifi/index.htm2
-rw-r--r--src/ffluci/view/cbi/dvalue.htm12
-rw-r--r--src/ffluci/view/cbi/tsection.htm7
-rw-r--r--src/ffluci/view/cbi/value.htm2
19 files changed, 259 insertions, 22 deletions
diff --git a/src/ffluci/cbi.lua b/src/ffluci/cbi.lua
index 844f6c0bb..296a77b49 100644
--- a/src/ffluci/cbi.lua
+++ b/src/ffluci/cbi.lua
@@ -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
diff --git a/src/ffluci/controller/admin/index.lua b/src/ffluci/controller/admin/index.lua
index 3ee564f64..d57e3fd9f 100644
--- a/src/ffluci/controller/admin/index.lua
+++ b/src/ffluci/controller/admin/index.lua
@@ -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
index 000000000..fcdcdabb0
--- /dev/null
+++ b/src/ffluci/controller/admin/mesh.lua
@@ -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
diff --git a/src/ffluci/controller/admin/network.lua b/src/ffluci/controller/admin/network.lua
index 2774dfdb0..534193b4d 100644
--- a/src/ffluci/controller/admin/network.lua
+++ b/src/ffluci/controller/admin/network.lua
@@ -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
index 000000000..df2d981e4
--- /dev/null
+++ b/src/ffluci/controller/admin/system.lua
@@ -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
diff --git a/src/ffluci/controller/admin/uci.lua b/src/ffluci/controller/admin/uci.lua
index a1eb0d7d7..9f8c12499 100644
--- a/src/ffluci/controller/admin/uci.lua
+++ b/src/ffluci/controller/admin/uci.lua
@@ -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
index 000000000..54b6bfb20
--- /dev/null
+++ b/src/ffluci/controller/admin/wifi.lua
@@ -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
diff --git a/src/ffluci/dispatcher.lua b/src/ffluci/dispatcher.lua
index ee836043d..139b0e308 100644
--- a/src/ffluci/dispatcher.lua
+++ b/src/ffluci/dispatcher.lua
@@ -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()
diff --git a/src/ffluci/http.lua b/src/ffluci/http.lua
index bf9410573..81076233b 100644
--- a/src/ffluci/http.lua
+++ b/src/ffluci/http.lua
@@ -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
diff --git a/src/ffluci/model/cbi/admin_network/ifaces.lua b/src/ffluci/model/cbi/admin_network/ifaces.lua
index aaabe653e..193f83f51 100644
--- a/src/ffluci/model/cbi/admin_network/ifaces.lua
+++ b/src/ffluci/model/cbi/admin_network/ifaces.lua
@@ -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
index 000000000..7ef794c7e
--- /dev/null
+++ b/src/ffluci/model/cbi/admin_wifi/devices.lua
@@ -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
index 000000000..ebc25715e
--- /dev/null
+++ b/src/ffluci/model/cbi/admin_wifi/networks.lua
@@ -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
diff --git a/src/ffluci/sys.lua b/src/ffluci/sys.lua
index 048f6d375..4ed2262c8 100644
--- a/src/ffluci/sys.lua
+++ b/src/ffluci/sys.lua
@@ -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
index 000000000..75aa02658
--- /dev/null
+++ b/src/ffluci/view/admin_system/index.htm
@@ -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
index 000000000..3458fef92
--- /dev/null
+++ b/src/ffluci/view/admin_system/passwd.htm
@@ -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
index 000000000..75aa02658
--- /dev/null
+++ b/src/ffluci/view/admin_wifi/index.htm
@@ -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
index 000000000..178f2e16a
--- /dev/null
+++ b/src/ffluci/view/cbi/dvalue.htm
@@ -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%>
diff --git a/src/ffluci/view/cbi/tsection.htm b/src/ffluci/view/cbi/tsection.htm
index 012ae063a..8da0b4a1d 100644
--- a/src/ffluci/view/cbi/tsection.htm
+++ b/src/ffluci/view/cbi/tsection.htm
@@ -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 %>
diff --git a/src/ffluci/view/cbi/value.htm b/src/ffluci/view/cbi/value.htm
index b994790d2..61033a0f5 100644
--- a/src/ffluci/view/cbi/value.htm
+++ b/src/ffluci/view/cbi/value.htm
@@ -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%>