diff options
author | Steven Barth <steven@midlink.org> | 2008-06-05 19:16:38 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2008-06-05 19:16:38 +0000 |
commit | dd9606825da5d73883b8313f5af905ea1b2a4d7d (patch) | |
tree | 1f853ae56dd8e3051698ac6d0a38d61bf6d6997f /applications | |
parent | 75f3dbaa6136a1288fbe92d80fc127f5228f5d64 (diff) |
* Merged Luci to use native UCI-library
Diffstat (limited to 'applications')
13 files changed, 245 insertions, 244 deletions
diff --git a/applications/luci-ffwizard-leipzig/luasrc/controller/luci_ffwizard_leipzig/wizard.lua b/applications/luci-ffwizard-leipzig/luasrc/controller/luci_ffwizard_leipzig/wizard.lua index 2fabfb11d..216230fe1 100644 --- a/applications/luci-ffwizard-leipzig/luasrc/controller/luci_ffwizard_leipzig/wizard.lua +++ b/applications/luci-ffwizard-leipzig/luasrc/controller/luci_ffwizard_leipzig/wizard.lua @@ -11,233 +11,220 @@ function action_wizard() end local ifaces = {} - local wldevs = luci.model.uci.sections("wireless") - - if wldevs then - for k, v in pairs(wldevs) do - if v[".type"] == "wifi-device" then - table.insert(ifaces, k) - end - end - end + luci.model.uci.foreach("wireless", "wifi-device", + function(section) + table.insert(ifaces, section[".name"]) + end) luci.template.render("freifunk/wizard", {ifaces=ifaces}) end function configure_freifunk() local ip = luci.http.formvalue("ip") - local uci = luci.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") - uci:t_load("luci_fw") + local uci = luci.model.uci + local cfg = uci.config -- Configure FF-Interface - uci:t_del("network", "ff") - uci:t_del("network", "ffdhcp") + uci.delete("network", "ff") + uci.delete("network", "ffdhcp") - 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")) + cfg.network.ff = "interface" + cfg.network.ff.type = "bridge" + cfg.network.ff.proto = "static" + cfg.network.ff.ipaddr = ip + cfg.network.ff.netmask = cfg.freifunk.community.mask + cfg.network.ff.dns = cfg.freifunk.community.dns -- Reset Routing - local routing = uci:t_sections("luci_fw") - if routing then - for k, v in pairs(routing) do - if v[".type"] == "routing" and (v.iface == "ff" or v.oface == "ff") then - uci:t_del("luci_fw", k) + uci.foreach("luci_fw", "routing", + function (section) + if section.iface == "ff" or section.oface == "ff" then + uci.delete("luci_fw", section[".name"]) end - end + end) - local int = uci:t_add("luci_fw", "routing") - uci:t_set("luci_fw", int, "iface", "ff") - uci:t_set("luci_fw", int, "oface", "ff") - uci:t_set("luci_fw", int, "fwd", "1") + if cfg.luci_fw then + cfg.luci_fw[""] = "routing" + cfg.luci_fw[""].iface = "ff" + cfg.luci_fw[""].oface = "ff" + cfg.luci_fw[""].fwd = "1" end -- Routing from Internal local iface = luci.http.formvalue("frominternal") if iface and iface ~= "" then - local routing = uci:t_sections("luci_fw") - if routing then - for k, v in pairs(routing) do - if v[".type"] == "routing" and (v.iface == iface and v.oface == "ff") then - uci:t_del("luci_fw", k) + uci.foreach("luci_fw", "routing", + function (section) + if section.iface == iface and section.oface == "ff" then + uci.delete("luci_fw", section[".name"]) end - end + end) - local int = uci:t_add("luci_fw", "routing") - uci:t_set("luci_fw", int, "iface", iface) - uci:t_set("luci_fw", int, "oface", "ff") - uci:t_set("luci_fw", int, "fwd", "1") - uci:t_set("luci_fw", int, "nat", "1") - end + if cfg.luci_fw then + cfg.luci_fw[""] = "routing" + cfg.luci_fw[""].iface = iface + cfg.luci_fw[""].oface = "ff" + cfg.luci_fw[""].fwd = "1" + cfg.luci_fw[""].nat = "1" + end end -- Routing to External local iface = luci.http.formvalue("toexternal") if iface and iface ~= "" then - local routing = uci:t_sections("luci_fw") - if routing then - for k, v in pairs(routing) do - if v[".type"] == "routing" and (v.oface == iface and v.iface == "ff") then - uci:t_del("luci_fw", k) + uci.foreach("luci_fw", "routing", + function (section) + if section.oface == iface and section.iface == "ff" then + uci.delete("luci_fw", section[".name"]) end - end + end) - local int = uci:t_add("luci_fw", "routing") - uci:t_set("luci_fw", int, "iface", "ff") - uci:t_set("luci_fw", int, "oface", iface) - uci:t_set("luci_fw", int, "fwd", "1") - uci:t_set("luci_fw", int, "nat", "1") - end + if cfg.luci_fw then + cfg.luci_fw[""] = "routing" + cfg.luci_fw[""].oface = iface + cfg.luci_fw[""].iface = "ff" + cfg.luci_fw[""].fwd = "1" + cfg.luci_fw[""].nat = "1" + end end -- Configure DHCP if luci.http.formvalue("dhcp") then - local dhcpnet = uci:t_get("freifunk", "community", "dhcp"):match("^([0-9]+)") + local dhcpnet = cfg.freifunk.community.dhcp:match("^([0-9]+)") local dhcpip = ip:gsub("^[0-9]+", dhcpnet) - 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")) + cfg.network.ffdhcp = "interface" + cfg.network.ffdhcp.proto = "static" + cfg.network.ffdhcp.ifname = "br-ff:dhcp" + cfg.network.ffdhcp.ipaddr = dhcpip + cfg.network.ffdhcp.netmask = cfg.freifunk.community.dhcpmask - 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:t_del("dhcp", k) + uci.foreach("dhcp", "dhcp", + function (section) + if section.interface == "ffdhcp" then + uci.delete("dhcp", section[".name"]) end - end - - local dhcpbeg = 48 + tonumber(ip:match("[0-9]+$")) * 4 + end) - 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 dhcpbeg = 48 + tonumber(ip:match("[0-9]+$")) * 4 + + cfg.dhcp[""] = "dhcp" + cfg.dhcp[""].interface = "ffdhcp" + cfg.dhcp[""].start = dhcpbeg + cfg.dhcp[""].limit = (dhcpbeg < 252) and 3 or 2 + cfg.dhcp[""].leasetime = "30m" - local splash = uci:t_sections("luci_splash") - if splash then - for k, v in pairs(splash) do - if v[".type"] == "iface" then - uci:t_del("luci_splash", k) + + uci.foreach("luci_splash", "iface", + function (section) + if section.network == "ffdhcp" then + uci.delete("luci_splash", section[".name"]) end - end + end) - local sk = uci:t_add("luci_splash", "iface") - uci:t_set("luci_splash", sk, "network", "ffdhcp") - end + if cfg.luci_splash then + cfg.luci_splash[""] = "iface" + cfg.luci_splash[""].network = "ffdhcp" + end + - local routing = uci:t_sections("luci_fw") - if routing then - for k, v in pairs(routing) do - if v[".type"] == "routing" and (v.iface == "ffdhcp" or v.oface == "ffdhcp") then - uci:t_del("luci_fw", k) + uci.foreach("luci_fw", "routing", + function (section) + if section.iface == "ffdhcp" or section.oface == "ffdhcp" then + uci.delete("luci_fw", section[".name"]) end - end - - local int = uci:t_add("luci_fw", "routing") - uci:t_set("luci_fw", int, "iface", "ffdhcp") - uci:t_set("luci_fw", int, "oface", "ff") - uci:t_set("luci_fw", int, "nat", "1") + end) + + if cfg.luci_fw then + cfg.luci_fw[""] = "routing" + cfg.luci_fw[""].iface = "ffdhcp" + cfg.luci_fw[""].oface = "ff" + cfg.luci_fw[""].nat = "1" local iface = luci.http.formvalue("toexternal") if iface and iface ~= "" then - local int = uci:t_add("luci_fw", "routing") - uci:t_set("luci_fw", int, "iface", "ffdhcp") - uci:t_set("luci_fw", int, "oface", iface) - uci:t_set("luci_fw", int, "nat", "1") + cfg.luci_fw[""] = "routing" + cfg.luci_fw[""].iface = "ffdhcp" + cfg.luci_fw[""].oface = iface + cfg.luci_fw[""].nat = "1" end end end -- Configure OLSR - if luci.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:t_del("olsr", k) - end - end + if luci.http.formvalue("olsr") and cfg.olsr then + uci.foreach("olsr", "Interface", + function (section) + uci.delete("olsr", section[".name"]) + end) + + uci.foreach("olsr", "LoadPlugin", + function (section) + uci.delete("olsr", section[".name"]) + end) if luci.http.formvalue("shareinet") then - uci:t_set("olsr", "dyn_gw", nil, "LoadPlugin") - uci:t_set("olsr", "dyn_gw", "Library", "olsrd_dyn_gw.so.0.4") + cfg.olsr.dyn_gw = "LoadPlugin" + cfg.olsr.dyn_gw.Library = "olsrd_dyn_gw.so.0.4" end - 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") + cfg.olsr.nameservice = "LoadPlugin" + cfg.olsr.nameservice.Library = "olsrd_nameservice.so.0.3" + cfg.olsr.nameservice.name = ip:gsub("%.", "-") + cfg.olsr.nameservice.hosts_file = "/var/etc/hosts" + cfg.olsr.nameservice.suffix = ".olsr" + cfg.olsr.nameservice.latlon_infile = "/tmp/latlon.txt" - 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") + cfg.olsr.txtinfo = "LoadPlugin" + cfg.olsr.txtinfo.Library = "olsrd_txtinfo.so.0.1" + cfg.olsr.txtinfo.Accept = "127.0.0.1" - 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") + cfg.olsr[""] = "Interface" + cfg.olsr[""].Interface = "ff" + cfg.olsr[""].HelloInterval = "6.0" + cfg.olsr[""].HelloValidityTime = "108.0" + cfg.olsr[""].TcInterval = "4.0" + cfg.olsr[""].TcValidityTime = "324.0" + cfg.olsr[""].MidInterval = "18.0" + cfg.olsr[""].MidValidityTime = "324.0" + cfg.olsr[""].HnaInterval = "18.0" + cfg.olsr[""].HnaValidityTime = "108.0" end -- Configure Wifi - local wcfg = uci:t_sections("wireless") - if wcfg then - for iface, v in pairs(wcfg) do - if v[".type"] == "wifi-device" and luci.http.formvalue("wifi."..iface) then - -- Cleanup - for k, j in pairs(wcfg) do - if j[".type"] == "wifi-iface" and j.device == iface then - uci:t_del("wireless", k) - end + if cfg.wireless then + uci.foreach("wireless", "wifi-device", + function (section) + local device = section[".name"] + + if luci.http.formvalue("wifi."..iface) then + uci.foreach("wireless", "wifi-iface", + function (section) + if section.device == device then + uci.delete("wireless", section[".name"]) + end + end) end - 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")) + cfg.wireless[device].disabled = "0" + cfg.wireless[device].mode = "11g" + cfg.wireless[device].txantenna = "1" + cfg.wireless[device].rxantenna = "1" + cfg.wireless[device].channel = cfg.freifunk.community.channel - 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 + cfg.wireless[""] = "wifi-iface" + cfg.wireless[""].device = iface + cfg.wireless[""].network = "ff" + cfg.wireless[""].mode = "adhoc" + cfg.wireless[""].ssid = cfg.freifunk.community.essid + cfg.wireless[""].bssid = cfg.freifunk.community.bssid + cfg.wireless[""].txpower = 13 + 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") - uci:t_save("luci_fw") + uci.save() luci.http.redirect(luci.dispatcher.build_url("admin", "uci", "changes")) end
\ No newline at end of file diff --git a/applications/luci-ffwizard-leipzig/luasrc/view/freifunk/wizard.htm b/applications/luci-ffwizard-leipzig/luasrc/view/freifunk/wizard.htm index e3d6cb4c0..ab1c3438f 100644 --- a/applications/luci-ffwizard-leipzig/luasrc/view/freifunk/wizard.htm +++ b/applications/luci-ffwizard-leipzig/luasrc/view/freifunk/wizard.htm @@ -26,7 +26,7 @@ <div class="cbi-value-title"><%:cfginternal Erlaube Zugriff von internem Netzwerk%>:</div> <div class="cbi-value-field"><select name="frominternal"> <option value=""></option> -<% for k, v in pairs(luci.model.uci.sections("network")) do +<% for k, v in pairs(luci.model.uci.get_all("network")) do if v[".type"] == "interface" and k ~= "loopback" then %> <option value="<%=k%>"<% if k == "lan" then %> selected="selected"<% end %>><%=k%></option> <% end @@ -37,7 +37,7 @@ end %> <div class="cbi-value-title"><%:cfgexternal Erlaube Zugriff auf externes Netzwerk%>:</div> <div class="cbi-value-field"><select name="toexternal"> <option value=""></option> -<% for k, v in pairs(luci.model.uci.sections("network")) do +<% for k, v in pairs(luci.model.uci.get_all("network")) do if v[".type"] == "interface" and k ~= "loopback" then %> <option value="<%=k%>"<% if k == "wan" then %> selected="selected"<% end %>><%=k%></option> <% end diff --git a/applications/luci-fw/luasrc/model/cbi/luci_fw/firewall.lua b/applications/luci-fw/luasrc/model/cbi/luci_fw/firewall.lua index f58f74c2b..c22c37000 100644 --- a/applications/luci-fw/luasrc/model/cbi/luci_fw/firewall.lua +++ b/applications/luci-fw/luasrc/model/cbi/luci_fw/firewall.lua @@ -19,12 +19,13 @@ iface.optional = true oface = s:option(ListValue, "oface", "Ausgangsschnittstelle") oface.optional = true -for k, v in pairs(luci.model.uci.sections("network")) do - if v[".type"] == "interface" and k ~= "loopback" then - iface:value(k) - oface:value(k) - end -end +luci.model.uci.foreach("network", "interface", + function (section) + if section[".name"] ~= "loopback" then + iface:value(section[".name"]) + oface:value(section[".name"]) + end + end) proto = s:option(ListValue, "proto", "Protokoll") proto.optional = true diff --git a/applications/luci-fw/luasrc/model/cbi/luci_fw/portfw.lua b/applications/luci-fw/luasrc/model/cbi/luci_fw/portfw.lua index e4f4fa2ac..79868af17 100644 --- a/applications/luci-fw/luasrc/model/cbi/luci_fw/portfw.lua +++ b/applications/luci-fw/luasrc/model/cbi/luci_fw/portfw.lua @@ -10,11 +10,12 @@ s.anonymous = true iface = s:option(ListValue, "iface", "Schnittstelle", "Externe Schnittstelle") iface.default = "wan" -for k, v in pairs(luci.model.uci.sections("network")) do - if v[".type"] == "interface" and k ~= "loopback" then - iface:value(k) - end -end +luci.model.uci.foreach("network", "interface", + function (section) + if section[".name"] ~= "loopback" then + iface:value(section[".name"]) + end + end) proto = s:option(ListValue, "proto", "Protokoll") proto:value("tcp", "TCP") diff --git a/applications/luci-fw/luasrc/model/cbi/luci_fw/routing.lua b/applications/luci-fw/luasrc/model/cbi/luci_fw/routing.lua index 364e69f62..615e7c874 100644 --- a/applications/luci-fw/luasrc/model/cbi/luci_fw/routing.lua +++ b/applications/luci-fw/luasrc/model/cbi/luci_fw/routing.lua @@ -14,12 +14,13 @@ s.anonymous = true iface = s:option(ListValue, "iface", "Eingang", "Eingangsschnittstelle") oface = s:option(ListValue, "oface", "Ausgang", "Ausgangsschnittstelle") -for k, v in pairs(luci.model.uci.sections("network")) do - if v[".type"] == "interface" and k ~= "loopback" then - iface:value(k) - oface:value(k) - end -end +luci.model.uci.foreach("network", "interface", + function (section) + if section[".name"] ~= "loopback" then + iface:value(section[".name"]) + oface:value(section[".name"]) + end + end) s:option(Flag, "fwd", "FWD", "weiterleiten").rmempty = true s:option(Flag, "nat", "NAT", "übersetzen").rmempty = true diff --git a/applications/luci-splash/luasrc/model/cbi/splash/splash.lua b/applications/luci-splash/luasrc/model/cbi/splash/splash.lua index 6050ac8a0..a14a38c1d 100644 --- a/applications/luci-splash/luasrc/model/cbi/splash/splash.lua +++ b/applications/luci-splash/luasrc/model/cbi/splash/splash.lua @@ -11,11 +11,12 @@ s.addremove = true s.anonymous = true iface = s:option(ListValue, "network", "Schnittstelle") -for k, v in pairs(luci.model.uci.sections("network")) do - if v[".type"] == "interface" and k ~= "loopback" then - iface:value(k) - end -end +luci.model.uci.foreach("network", "interface", + function (section) + if section[".name"] ~= "loopback" then + iface:value(section[".name"]) + end + end) s = m:section(TypedSection, "whitelist", "Automatische Freigabe") s.addremove = true diff --git a/applications/luci-splash/luasrc/view/splash/splash.htm b/applications/luci-splash/luasrc/view/splash/splash.htm index 363c39072..c2a2f889a 100644 --- a/applications/luci-splash/luasrc/view/splash/splash.htm +++ b/applications/luci-splash/luasrc/view/splash/splash.htm @@ -1,4 +1,4 @@ -<% local c = luci.model.uci.sections("freifunk").community %> +<% local c = luci.model.uci.get_all("freifunk", "community") %> <h1><%:welcome Willkommen%>!</h1> <p> diff --git a/applications/luci-splash/root/usr/lib/luci-splash/htdocs/cgi-bin/index.cgi b/applications/luci-splash/root/usr/lib/luci-splash/htdocs/cgi-bin/index.cgi index 545233d8d..22cab67cc 100644 --- a/applications/luci-splash/root/usr/lib/luci-splash/htdocs/cgi-bin/index.cgi +++ b/applications/luci-splash/root/usr/lib/luci-splash/htdocs/cgi-bin/index.cgi @@ -1,31 +1,33 @@ #!/usr/bin/haserl --shell=luac -package.path = "/usr/lib/lua/?.lua;/usr/lib/lua/?/init.lua;" .. package.path -package.cpath = "/usr/lib/lua/?.so;" .. package.cpath require("luci.http") require("luci.sys") require("luci.model.uci") +luci.model.uci.set_savedir(luci.model.uci.savedir_state) + local srv local net local ip = luci.http.env.REMOTE_ADDR -for k, v in pairs(luci.model.uci.sections("network")) do - if v[".type"] == "interface" and v.ipaddr then - local p = luci.sys.net.mask4prefix(v.netmask) - if luci.sys.net.belongs(ip, v.ipaddr, p) then - net = k - srv = v.ipaddr - break +luci.model.uci.foreach("network", "interface", + function (section) + if section.ipaddr then + local p = luci.sys.net.mask4prefix(section.netmask) + if luci.sys.net.belongs(ip, section.ipaddr, p) then + net = section[".name"] + srv = section.ipaddr + return + end end - end -end + end) local stat = false -for k, v in pairs(luci.model.uci.sections("luci_splash")) do - if v[".type"] == "iface" and v.network == net then - stat = true - end -end +luci.model.uci.foreach("luci_splash", "iface", + function (section) + if section.network == net then + stat = true + end + end) if not srv then luci.http.prepare_content("text/plain") diff --git a/applications/luci-splash/root/usr/sbin/luci-splash b/applications/luci-splash/root/usr/sbin/luci-splash index f62d45c45..347bdcc65 100644 --- a/applications/luci-splash/root/usr/sbin/luci-splash +++ b/applications/luci-splash/root/usr/sbin/luci-splash @@ -1,13 +1,13 @@ #!/usr/bin/lua -package.path = "/usr/lib/lua/?.lua;/usr/lib/lua/?/init.lua;" .. package.path -package.cpath = "/usr/lib/lua/?.so;" .. package.cpath require("luci.http") require("luci.sys") require("luci.model.uci") -- Init state session -uci = luci.model.uci.StateSession() +luci.model.uci.set_savedir(luci.model.uci.savedir_state) +local uci = luci.model.uci +local cfg = uci.config function main(argv) @@ -61,10 +61,12 @@ end -- Add a lease to state and invoke add_rule function add_lease(mac) - local key = uci:add("luci_splash", "lease") - uci:set("luci_splash", key, "mac", mac) - uci:set("luci_splash", key, "start", os.time()) + cfg.luci_splash[""] = "lease" + cfg.luci_splash[""].mac = mac + cfg.luci_splash[""].start = os.time() add_rule(mac) + + uci.save() end @@ -72,12 +74,15 @@ end function remove_lease(mac) mac = mac:lower() - for k, v in pairs(uci:sections("luci_splash")) do - if v[".type"] == "lease" and v.mac:lower() == mac then - remove_rule(mac) - uci:del("luci_splash", k) - end - end + uci.foreach("luci_splash", "lease", + function (section) + if section.mac:lower() == mac then + remove_rule(mac) + uci.delete("luci_splash", section[".name"]) + end + end) + + uci.save() end @@ -96,14 +101,17 @@ end -- Check whether a MAC-Address is listed in the lease state list function haslease(mac) mac = mac:lower() + local stat = false - for k, v in pairs(uci:sections("luci_splash")) do - if v[".type"] == "lease" and v.mac and v.mac:lower() == mac then - return true - end - end + uci.foreach("luci_splash", "lease", + function (section) + if section.mac:lower() == mac then + stat = true + return + end + end) - return false + return stat end @@ -111,11 +119,13 @@ end function iswhitelisted(mac) mac = mac:lower() - for k, v in pairs(uci:sections("luci_splash")) do - if v[".type"] == "whitelist" and v.mac and v.mac:lower() == mac then - return true - end - end + uci.foreach("luci_splash", "whitelist", + function (section) + if section.mac:lower() == mac then + stat = true + return + end + end) return false end @@ -134,16 +144,14 @@ function sync() local written = {} local time = os.time() - uci:t_load("luci_splash") - -- Current leases in state files - local leases = uci:t_sections("luci_splash") + local leases = uci.get_all("luci_splash") -- Convert leasetime to seconds - local leasetime = tonumber(uci:t_get("luci_splash", "general", "leasetime")) * 3600 + local leasetime = tonumber(cfg.luci_splash.general.leasetime) * 3600 -- Clean state file - uci:t_revert("luci_splash") + uci.revert("luci_splash") -- For all leases @@ -154,9 +162,9 @@ function sync() remove_rule(v.mac) else -- Rewrite state - local n = uci:t_add("luci_splash", "lease") - uci:t_set("luci_splash", n, "mac", v.mac) - uci:t_set("luci_splash", n, "start", v.start) + cfg.luci_splash[""] = "lease" + cfg.luci_splash[""].mac = v.mac + cfg.luci_splash[""].start = v.start written[v.mac:lower()] = 1 end end @@ -170,7 +178,7 @@ function sync() end end - uci:t_save("luci_splash") + uci.save("luci_splash") end main(arg)
\ No newline at end of file diff --git a/applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua b/applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua index ad3e05427..2f6807153 100644 --- a/applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua +++ b/applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua @@ -146,9 +146,9 @@ function statistics_render() local vars = luci.http.formvalues() local req = luci.dispatcher.request local path = luci.dispatcher.dispatched.path - local uci = luci.model.uci.Session() - local spans = luci.util.split( uci:get( "luci_statistics", "collectd_rrdtool", "RRATimespans" ), "%s+", nil, true ) - local span = vars.timespan or uci:get( "luci_statistics", "rrdtool", "default_timespan" ) or spans[1] + local uci = luci.model.uci + local spans = luci.util.split( uci.get( "luci_statistics", "collectd_rrdtool", "RRATimespans" ), "%s+", nil, true ) + local span = vars.timespan or uci.get( "luci_statistics", "rrdtool", "default_timespan" ) or spans[1] local graph = luci.statistics.rrdtool.Graph( luci.util.parse_units( span ) ) local plugin, instances diff --git a/applications/luci-statistics/luasrc/statistics/datatree.lua b/applications/luci-statistics/luasrc/statistics/datatree.lua index 03608b10b..5d3d63f99 100644 --- a/applications/luci-statistics/luasrc/statistics/datatree.lua +++ b/applications/luci-statistics/luasrc/statistics/datatree.lua @@ -18,8 +18,8 @@ module("luci.statistics.datatree", package.seeall) local util = require("luci.util") local sys = require("luci.sys") local fs = require("luci.fs") -local uci = require("luci.model.uci").Session() -local sections = uci:sections( "luci_statistics" ) +local uci = require("luci.model.uci") +local sections = uci.get_all( "luci_statistics" ) Instance = util.class() diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool.lua b/applications/luci-statistics/luasrc/statistics/rrdtool.lua index 35f5c8727..69fb5cff6 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool.lua @@ -31,8 +31,8 @@ function Graph.__init__( self, timespan, opts ) opts = opts or { } - local uci = luci.model.uci.Session() - local sections = uci:sections( "luci_statistics" ) + local uci = luci.model.uci + local sections = uci.get_all( "luci_statistics" ) -- helper classes self.colors = luci.statistics.rrdtool.colors.Instance() diff --git a/applications/luci-statistics/root/usr/bin/stat-genconfig b/applications/luci-statistics/root/usr/bin/stat-genconfig index c106ed39d..609fd61b9 100755 --- a/applications/luci-statistics/root/usr/bin/stat-genconfig +++ b/applications/luci-statistics/root/usr/bin/stat-genconfig @@ -21,8 +21,8 @@ require("luci.sys.iptparser") require("luci.util") local ipt = luci.sys.iptparser.IptParser() -local uci = luci.model.uci.Session() -local sections = uci:sections( "luci_statistics" ) +local uci = luci.model.uci +local sections = uci.get_all( "luci_statistics" ) function section( plugin ) |