summaryrefslogtreecommitdiffhomepage
path: root/module
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-05-06 14:28:51 +0000
committerSteven Barth <steven@midlink.org>2008-05-06 14:28:51 +0000
commit6a1fee5115cdf047a29812dcf81b03edeefccb15 (patch)
treeef1a698180652fb236610850c514e1abcf110f4d /module
parent522c6c928e36db9b5243681fb16f751451ad473a (diff)
* Rewrote and optimized ffluci.model.uci
* Use optimized UCI code for ffluci.cbi and ffluci.controller.admin.index if possible
Diffstat (limited to 'module')
-rw-r--r--module/admin-core/src/controller/admin/index.lua150
-rw-r--r--module/admin-core/src/controller/admin/uci.lua5
2 files changed, 85 insertions, 70 deletions
diff --git a/module/admin-core/src/controller/admin/index.lua b/module/admin-core/src/controller/admin/index.lua
index 09d5aa1f5..edca5721e 100644
--- a/module/admin-core/src/controller/admin/index.lua
+++ b/module/admin-core/src/controller/admin/index.lua
@@ -23,133 +23,149 @@ function configure_freifunk()
local ip = ffluci.http.formvalue("ip")
local uci = ffluci.model.uci.Session()
+ -- Load UCI
+ uci:t_load("network")
+ uci:t_load("dhcp")
+ uci:t_load("freifunk")
+ uci:t_load("luci_splash")
+ uci:t_load("olsr")
+ uci:t_load("wireless")
+
+
-- Configure FF-Interface
- uci:del("network", "ff")
- uci:del("network", "ffdhcp")
+ uci:t_del("network", "ff")
+ uci:t_del("network", "ffdhcp")
- uci:set("network", "ff", nil, "interface")
- uci:set("network", "ff", "type", "bridge")
- uci:set("network", "ff", "proto", "static")
- uci:set("network", "ff", "ipaddr", ip)
- uci:set("network", "ff", "netmask", uci:get("freifunk", "community", "mask"))
- uci:set("network", "ff", "dns", uci:get("freifunk", "community", "dns"))
+ uci:t_set("network", "ff", nil, "interface")
+ uci:t_set("network", "ff", "type", "bridge")
+ uci:t_set("network", "ff", "proto", "static")
+ uci:t_set("network", "ff", "ipaddr", ip)
+ uci:t_set("network", "ff", "netmask", uci:t_get("freifunk", "community", "mask"))
+ uci:t_set("network", "ff", "dns", uci:t_get("freifunk", "community", "dns"))
-- Enable internal routing
- uci:set("freifunk", "routing", "internal", "1")
+ uci:t_set("freifunk", "routing", "internal", "1")
-- Enable internet routing
if ffluci.http.formvalue("shareinet") then
- uci:set("freifunk", "routing", "internet", "1")
+ uci:t_set("freifunk", "routing", "internet", "1")
else
- uci:set("freifunk", "routing", "internet", "0")
+ uci:t_set("freifunk", "routing", "internet", "0")
end
-- Configure DHCP
if ffluci.http.formvalue("dhcp") then
- local dhcpnet = uci:get("freifunk", "community", "dhcp"):match("^([0-9]+)")
+ local dhcpnet = uci:t_get("freifunk", "community", "dhcp"):match("^([0-9]+)")
local dhcpip = ip:gsub("^[0-9]+", dhcpnet)
- uci:set("network", "ffdhcp", nil, "interface")
- uci:set("network", "ffdhcp", "proto", "static")
- uci:set("network", "ffdhcp", "ifname", "br-ff:dhcp")
- uci:set("network", "ffdhcp", "ipaddr", dhcpip)
- uci:set("network", "ffdhcp", "netmask", uci:get("freifunk", "community", "dhcpmask"))
+ uci:t_set("network", "ffdhcp", nil, "interface")
+ uci:t_set("network", "ffdhcp", "proto", "static")
+ uci:t_set("network", "ffdhcp", "ifname", "br-ff:dhcp")
+ uci:t_set("network", "ffdhcp", "ipaddr", dhcpip)
+ uci:t_set("network", "ffdhcp", "netmask", uci:t_get("freifunk", "community", "dhcpmask"))
- local dhcp = uci:sections("dhcp")
+ local dhcp = uci:t_sections("dhcp")
if dhcp then
for k, v in pairs(dhcp) do
if v[".type"] == "dhcp" and v.interface == "ffdhcp" then
- uci:del("dhcp", k)
+ uci:t_del("dhcp", k)
end
end
local dhcpbeg = 48 + tonumber(ip:match("[0-9]+$")) * 4
- local sk = uci:add("dhcp", "dhcp")
- uci:set("dhcp", sk, "interface", "ffdhcp")
- uci:set("dhcp", sk, "start", dhcpbeg)
- uci:set("dhcp", sk, "limit", (dhcpbeg < 252) and 3 or 2)
- uci:set("dhcp", sk, "leasetime", "30m")
+ local sk = uci:t_add("dhcp", "dhcp")
+ uci:t_set("dhcp", sk, "interface", "ffdhcp")
+ uci:t_set("dhcp", sk, "start", dhcpbeg)
+ uci:t_set("dhcp", sk, "limit", (dhcpbeg < 252) and 3 or 2)
+ uci:t_set("dhcp", sk, "leasetime", "30m")
end
- local splash = uci:sections("luci_splash")
+ local splash = uci:t_sections("luci_splash")
if splash then
for k, v in pairs(splash) do
if v[".type"] == "iface" then
- uci:del("luci_splash", k)
+ uci:t_del("luci_splash", k)
end
end
- local sk = uci:add("luci_splash", "iface")
- uci:set("luci_splash", sk, "network", "ffdhcp")
+ local sk = uci:t_add("luci_splash", "iface")
+ uci:t_set("luci_splash", sk, "network", "ffdhcp")
end
end
-- Configure OLSR
- if ffluci.http.formvalue("olsr") and uci:sections("olsr") then
- for k, v in pairs(uci:sections("olsr")) do
+ if ffluci.http.formvalue("olsr") and uci:t_sections("olsr") then
+ for k, v in pairs(uci:t_sections("olsr")) do
if v[".type"] == "Interface" or v[".type"] == "LoadPlugin" then
- uci:del("olsr", k)
+ uci:t_del("olsr", k)
end
end
if ffluci.http.formvalue("shareinet") then
- uci:set("olsr", "dyn_gw", nil, "LoadPlugin")
- uci:set("olsr", "dyn_gw", "Library", "olsrd_dyn_gw.so.0.4")
+ uci:t_set("olsr", "dyn_gw", nil, "LoadPlugin")
+ uci:t_set("olsr", "dyn_gw", "Library", "olsrd_dyn_gw.so.0.4")
end
- uci:set("olsr", "nameservice", nil, "LoadPlugin")
- uci:set("olsr", "nameservice", "Library", "olsrd_nameservice.so.0.3")
- uci:set("olsr", "nameservice", "name", ip:gsub("%.", "-"))
- uci:set("olsr", "nameservice", "hosts_file", "/var/etc/hosts")
- uci:set("olsr", "nameservice", "suffix", ".olsr")
- uci:set("olsr", "nameservice", "latlon_infile", "/tmp/latlon.txt")
+ uci:t_set("olsr", "nameservice", nil, "LoadPlugin")
+ uci:t_set("olsr", "nameservice", "Library", "olsrd_nameservice.so.0.3")
+ uci:t_set("olsr", "nameservice", "name", ip:gsub("%.", "-"))
+ uci:t_set("olsr", "nameservice", "hosts_file", "/var/etc/hosts")
+ uci:t_set("olsr", "nameservice", "suffix", ".olsr")
+ uci:t_set("olsr", "nameservice", "latlon_infile", "/tmp/latlon.txt")
- uci:set("olsr", "txtinfo", nil, "LoadPlugin")
- uci:set("olsr", "txtinfo", "Library", "olsrd_txtinfo.so.0.1")
- uci:set("olsr", "txtinfo", "Accept", "127.0.0.1")
+ uci:t_set("olsr", "txtinfo", nil, "LoadPlugin")
+ uci:t_set("olsr", "txtinfo", "Library", "olsrd_txtinfo.so.0.1")
+ uci:t_set("olsr", "txtinfo", "Accept", "127.0.0.1")
- local oif = uci:add("olsr", "Interface")
- uci:set("olsr", oif, "Interface", "ff")
- uci:set("olsr", oif, "HelloInterval", "6.0")
- uci:set("olsr", oif, "HelloValidityTime", "108.0")
- uci:set("olsr", oif, "TcInterval", "4.0")
- uci:set("olsr", oif, "TcValidityTime", "324.0")
- uci:set("olsr", oif, "MidInterval", "18.0")
- uci:set("olsr", oif, "MidValidityTime", "324.0")
- uci:set("olsr", oif, "HnaInterval", "18.0")
- uci:set("olsr", oif, "HnaValidityTime", "108.0")
+ local oif = uci:t_add("olsr", "Interface")
+ uci:t_set("olsr", oif, "Interface", "ff")
+ uci:t_set("olsr", oif, "HelloInterval", "6.0")
+ uci:t_set("olsr", oif, "HelloValidityTime", "108.0")
+ uci:t_set("olsr", oif, "TcInterval", "4.0")
+ uci:t_set("olsr", oif, "TcValidityTime", "324.0")
+ uci:t_set("olsr", oif, "MidInterval", "18.0")
+ uci:t_set("olsr", oif, "MidValidityTime", "324.0")
+ uci:t_set("olsr", oif, "HnaInterval", "18.0")
+ uci:t_set("olsr", oif, "HnaValidityTime", "108.0")
end
-- Configure Wifi
- local wcfg = uci:sections("wireless")
+ local wcfg = uci:t_sections("wireless")
if wcfg then
for iface, v in pairs(wcfg) do
if v[".type"] == "wifi-device" and ffluci.http.formvalue("wifi."..iface) then
-- Cleanup
for k, j in pairs(wcfg) do
if j[".type"] == "wifi-iface" and j.device == iface then
- uci:del("wireless", k)
+ uci:t_del("wireless", k)
end
end
- uci:set("wireless", iface, "disabled", "0")
- uci:set("wireless", iface, "mode", "11g")
- uci:set("wireless", iface, "txantenna", 1)
- uci:set("wireless", iface, "rxantenna", 1)
- uci:set("wireless", iface, "channel", uci:get("freifunk", "community", "channel"))
+ uci:t_set("wireless", iface, "disabled", "0")
+ uci:t_set("wireless", iface, "mode", "11g")
+ uci:t_set("wireless", iface, "txantenna", 1)
+ uci:t_set("wireless", iface, "rxantenna", 1)
+ uci:t_set("wireless", iface, "channel", uci:t_get("freifunk", "community", "channel"))
- local wif = uci:add("wireless", "wifi-iface")
- uci:set("wireless", wif, "device", iface)
- uci:set("wireless", wif, "network", "ff")
- uci:set("wireless", wif, "mode", "adhoc")
- uci:set("wireless", wif, "ssid", uci:get("freifunk", "community", "essid"))
- uci:set("wireless", wif, "bssid", uci:get("freifunk", "community", "bssid"))
- uci:set("wireless", wif, "txpower", 13)
+ local wif = uci:t_add("wireless", "wifi-iface")
+ uci:t_set("wireless", wif, "device", iface)
+ uci:t_set("wireless", wif, "network", "ff")
+ uci:t_set("wireless", wif, "mode", "adhoc")
+ uci:t_set("wireless", wif, "ssid", uci:t_get("freifunk", "community", "essid"))
+ uci:t_set("wireless", wif, "bssid", uci:t_get("freifunk", "community", "bssid"))
+ uci:t_set("wireless", wif, "txpower", 13)
end
end
end
-
+
+ -- Save UCI
+ uci:t_save("network")
+ uci:t_save("dhcp")
+ uci:t_save("freifunk")
+ uci:t_save("luci_splash")
+ uci:t_save("olsr")
+ uci:t_save("wireless")
ffluci.http.redirect(ffluci.dispatcher.build_url("admin", "uci", "changes"))
end \ No newline at end of file
diff --git a/module/admin-core/src/controller/admin/uci.lua b/module/admin-core/src/controller/admin/uci.lua
index 251107dfe..5c34e56d3 100644
--- a/module/admin-core/src/controller/admin/uci.lua
+++ b/module/admin-core/src/controller/admin/uci.lua
@@ -10,16 +10,15 @@ function action_apply()
if changes then
local apply = {}
- -- Collect files to be applied
+ -- Collect files to be applied and commit changes
for i, line in ipairs(ffluci.util.split(changes)) do
local r = line:match("^-?([^.]+)")
if r and not ffluci.util.contains(apply, ffluci.config.uci_oncommit[r]) then
table.insert(apply, ffluci.config.uci_oncommit[r])
+ ffluci.model.uci.commit(r)
end
end
- -- Commit changes
- ffluci.model.uci.commit()
-- Search for post-commit commands
if ffluci.config.uci_oncommit then