UCI API changes
This commit is contained in:
parent
43b3217e55
commit
91ba7c42f5
43 changed files with 255 additions and 374 deletions
|
@ -24,7 +24,7 @@ iface.rmempty = true
|
|||
oface = s:option(ListValue, "dest")
|
||||
oface.optional = true
|
||||
|
||||
luci.model.uci.foreach("firewall", "zone",
|
||||
luci.model.uci.cursor():foreach("firewall", "zone",
|
||||
function (section)
|
||||
iface:value(section.name)
|
||||
oface:value(section.name)
|
||||
|
|
|
@ -25,7 +25,7 @@ name.size = 10
|
|||
|
||||
iface = s:option(ListValue, "src", translate("fw_zone"))
|
||||
iface.default = "wan"
|
||||
luci.model.uci.foreach("firewall", "zone",
|
||||
luci.model.uci.cursor():foreach("firewall", "zone",
|
||||
function (section)
|
||||
iface:value(section.name)
|
||||
end)
|
||||
|
|
|
@ -21,7 +21,7 @@ s.anonymous = true
|
|||
iface = s:option(ListValue, "src")
|
||||
oface = s:option(ListValue, "dest")
|
||||
|
||||
luci.model.uci.foreach("firewall", "zone",
|
||||
luci.model.uci.cursor():foreach("firewall", "zone",
|
||||
function (section)
|
||||
iface:value(section.name)
|
||||
oface:value(section.name)
|
||||
|
|
|
@ -22,7 +22,7 @@ function action_activate()
|
|||
local mac = luci.sys.net.ip4mac(luci.http.getenv("REMOTE_ADDR"))
|
||||
if mac and luci.http.formvalue("accept") then
|
||||
os.execute("luci-splash add "..mac.." >/dev/null 2>&1")
|
||||
luci.http.redirect(luci.model.uci.get("freifunk", "community", "homepage"))
|
||||
luci.http.redirect(luci.model.uci.cursor():get("freifunk", "community", "homepage"))
|
||||
else
|
||||
luci.http.redirect(luci.dispatcher.build_url())
|
||||
end
|
||||
|
|
|
@ -11,21 +11,23 @@ s.template = "cbi/tblsection"
|
|||
s.addremove = true
|
||||
s.anonymous = true
|
||||
|
||||
local uci = luci.model.uci.cursor()
|
||||
|
||||
zone = s:option(ListValue, "zone", "Firewallzone")
|
||||
luci.model.uci.foreach("firewall", "zone",
|
||||
uci:foreach("firewall", "zone",
|
||||
function (section)
|
||||
zone:value(section.name)
|
||||
end)
|
||||
|
||||
iface = s:option(ListValue, "network", "Netzwerk")
|
||||
luci.model.uci.foreach("network", "interface",
|
||||
uci:foreach("network", "interface",
|
||||
function (section)
|
||||
if section[".name"] ~= "loopback" then
|
||||
iface:value(section[".name"])
|
||||
end
|
||||
end)
|
||||
|
||||
luci.model.uci.foreach("network", "alias",
|
||||
uci:foreach("network", "alias",
|
||||
function (section)
|
||||
iface:value(section[".name"])
|
||||
end)
|
||||
|
|
|
@ -12,7 +12,7 @@ You may obtain a copy of the License at
|
|||
$Id$
|
||||
|
||||
-%>
|
||||
<% local c = luci.model.uci.get_all("freifunk", "community") %>
|
||||
<% local c = luci.model.uci.cursor():get_all("freifunk", "community") %>
|
||||
|
||||
<h1>Willkommen!</h1>
|
||||
<p>
|
||||
|
|
|
@ -4,7 +4,8 @@ require("socket")
|
|||
require("luci.ip")
|
||||
require("luci.model.uci")
|
||||
|
||||
luci.model.uci.load_state("network")
|
||||
local uci = luci.model.uci.cursor_state()
|
||||
uci:load("network")
|
||||
|
||||
local server = socket.bind("0.0.0.0", arg[1] or 8082)
|
||||
server:settimeout(0, "t")
|
||||
|
@ -16,7 +17,7 @@ while true do
|
|||
client:settimeout(1)
|
||||
local srv
|
||||
local ip = luci.ip.IPv4(client:getpeername())
|
||||
luci.model.uci.foreach("network", "interface",
|
||||
uci:foreach("network", "interface",
|
||||
function (section)
|
||||
if section.ipaddr then
|
||||
local net = luci.ip.IPv4(section.ipaddr, section.netmask)
|
||||
|
|
|
@ -5,8 +5,7 @@ require("luci.util")
|
|||
require("luci.model.uci")
|
||||
|
||||
-- Init state session
|
||||
luci.model.uci.load_state("luci_splash")
|
||||
local uci = luci.model.uci
|
||||
local uci = luci.model.uci.cursor_state()
|
||||
|
||||
|
||||
function main(argv)
|
||||
|
@ -60,13 +59,13 @@ end
|
|||
|
||||
-- Add a lease to state and invoke add_rule
|
||||
function add_lease(mac)
|
||||
uci.section("luci_splash", "lease", nil, {
|
||||
uci:section("luci_splash", "lease", nil, {
|
||||
mac = mac,
|
||||
start = os.time()
|
||||
})
|
||||
add_rule(mac)
|
||||
|
||||
uci.save_state("luci_splash")
|
||||
uci:save("luci_splash")
|
||||
end
|
||||
|
||||
|
||||
|
@ -75,7 +74,7 @@ function remove_lease(mac)
|
|||
mac = mac:lower()
|
||||
local del = {}
|
||||
|
||||
uci.foreach("luci_splash", "lease",
|
||||
uci:foreach("luci_splash", "lease",
|
||||
function (section)
|
||||
if section.mac:lower() == mac then
|
||||
table.insert(del, section[".name"])
|
||||
|
@ -84,10 +83,10 @@ function remove_lease(mac)
|
|||
|
||||
for i,j in ipairs(del) do
|
||||
remove_rule(j)
|
||||
uci.delete("luci_splash", j)
|
||||
uci:delete("luci_splash", j)
|
||||
end
|
||||
|
||||
uci.save_state("luci_splash")
|
||||
uci:save("luci_splash")
|
||||
end
|
||||
|
||||
|
||||
|
@ -108,7 +107,7 @@ function haslease(mac)
|
|||
mac = mac:lower()
|
||||
local stat = false
|
||||
|
||||
uci.foreach("luci_splash", "lease",
|
||||
uci:foreach("luci_splash", "lease",
|
||||
function (section)
|
||||
if section.mac:lower() == mac then
|
||||
stat = true
|
||||
|
@ -124,7 +123,7 @@ end
|
|||
function iswhitelisted(mac)
|
||||
mac = mac:lower()
|
||||
|
||||
uci.foreach("luci_splash", "whitelist",
|
||||
uci:foreach("luci_splash", "whitelist",
|
||||
function (section)
|
||||
if section.mac:lower() == mac then
|
||||
stat = true
|
||||
|
@ -150,14 +149,14 @@ function sync()
|
|||
local time = os.time()
|
||||
|
||||
-- Current leases in state files
|
||||
local leases = uci.get_all("luci_splash")
|
||||
local leases = uci:get_all("luci_splash")
|
||||
|
||||
-- Convert leasetime to seconds
|
||||
local leasetime = tonumber(uci.get("luci_splash", "general", "leasetime")) * 3600
|
||||
local leasetime = tonumber(uci:get("luci_splash", "general", "leasetime")) * 3600
|
||||
|
||||
-- Clean state file
|
||||
uci.load_state("luci_splash")
|
||||
uci.revert("luci_splash")
|
||||
uci:load("luci_splash")
|
||||
uci:revert("luci_splash")
|
||||
|
||||
|
||||
-- For all leases
|
||||
|
@ -168,7 +167,7 @@ function sync()
|
|||
remove_rule(v.mac)
|
||||
else
|
||||
-- Rewrite state
|
||||
uci.section("luci_splash", "lease", nil, {
|
||||
uci:section("luci_splash", "lease", nil, {
|
||||
mac = v.mac,
|
||||
start = v.start
|
||||
})
|
||||
|
@ -185,7 +184,7 @@ function sync()
|
|||
end
|
||||
end
|
||||
|
||||
uci.save_state("luci_splash")
|
||||
uci:save("luci_splash")
|
||||
end
|
||||
|
||||
main(arg)
|
|
@ -151,9 +151,9 @@ function statistics_render()
|
|||
local vars = luci.http.formvalue()
|
||||
local req = luci.dispatcher.context.request
|
||||
local path = luci.dispatcher.context.dispatched.path
|
||||
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 uci = luci.model.uci.cursor()
|
||||
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
|
||||
|
|
|
@ -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")
|
||||
local sections = uci.get_all( "luci_statistics" )
|
||||
local uci = require("luci.model.uci").cursor()
|
||||
local sections = uci:get_all( "luci_statistics" )
|
||||
|
||||
|
||||
Instance = util.class()
|
||||
|
|
|
@ -31,8 +31,8 @@ function Graph.__init__( self, timespan, opts )
|
|||
|
||||
opts = opts or { }
|
||||
|
||||
local uci = luci.model.uci
|
||||
local sections = uci.get_all( "luci_statistics" )
|
||||
local uci = luci.model.uci.cursor()
|
||||
local sections = uci:get_all( "luci_statistics" )
|
||||
|
||||
-- helper classes
|
||||
self.colors = luci.statistics.rrdtool.colors.Instance()
|
||||
|
|
|
@ -21,8 +21,8 @@ require("luci.sys.iptparser")
|
|||
require("luci.util")
|
||||
|
||||
local ipt = luci.sys.iptparser.IptParser()
|
||||
local uci = luci.model.uci
|
||||
local sections = uci.get_all( "luci_statistics" )
|
||||
local uci = luci.model.uci.cursor()
|
||||
local sections = uci:get_all( "luci_statistics" )
|
||||
|
||||
|
||||
function section( plugin )
|
||||
|
|
|
@ -148,12 +148,14 @@ endef
|
|||
|
||||
define Package/luci-uci
|
||||
$(call Package/luci/libtemplate)
|
||||
DEPENDS+=+libuci-lua
|
||||
DEPENDS+=+libuci
|
||||
TITLE:=High-Level UCI API
|
||||
endef
|
||||
|
||||
define Package/luci-uci/install
|
||||
$(call Package/luci/install/template,$(1),libs/uci)
|
||||
$(INSTALL_DIR) $(1)/usr/lib/lua
|
||||
$(CP) $(PKG_BUILD_DIR)/contrib/uci/dist/usr/lib/lua/uci.so $(1)/usr/lib/lua
|
||||
endef
|
||||
|
||||
|
||||
|
@ -632,7 +634,7 @@ ifneq ($(CONFIG_PACKAGE_luci-json),)
|
|||
PKG_SELECTED_MODULES+=libs/json
|
||||
endif
|
||||
ifneq ($(CONFIG_PACKAGE_luci-uci),)
|
||||
PKG_SELECTED_MODULES+=libs/uci
|
||||
PKG_SELECTED_MODULES+=libs/uci contrib/uci
|
||||
endif
|
||||
ifneq ($(CONFIG_PACKAGE_luci-sys),)
|
||||
PKG_SELECTED_MODULES+=libs/sys
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
Index: uci.git/list.c
|
||||
===================================================================
|
||||
--- uci.git.orig/list.c 2008-08-26 12:31:34.000000000 +0200
|
||||
+++ uci.git/list.c 2008-08-26 21:09:10.000000000 +0200
|
||||
@@ -398,7 +398,7 @@
|
||||
e = uci_lookup_list(&ptr->p->sections, ptr->section);
|
||||
|
||||
if (!e)
|
||||
- goto abort;
|
||||
+ goto notfound;
|
||||
|
||||
ptr->last = e;
|
||||
ptr->s = uci_to_section(e);
|
||||
@@ -406,7 +406,7 @@
|
||||
if (ptr->option) {
|
||||
e = uci_lookup_list(&ptr->s->options, ptr->option);
|
||||
if (!e)
|
||||
- goto abort;
|
||||
+ goto notfound;
|
||||
|
||||
ptr->o = uci_to_option(e);
|
||||
ptr->last = e;
|
|
@ -1,7 +1,7 @@
|
|||
Index: uci.git/lua/uci.c
|
||||
===================================================================
|
||||
--- uci.git.orig/lua/uci.c 2008-08-26 12:31:34.000000000 +0200
|
||||
+++ uci.git/lua/uci.c 2008-08-26 21:09:10.000000000 +0200
|
||||
+++ uci.git/lua/uci.c 2008-08-27 00:30:46.000000000 +0200
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <uci.h>
|
||||
|
||||
|
@ -244,7 +244,19 @@ Index: uci.git/lua/uci.c
|
|||
goto error;
|
||||
|
||||
uci_lookup_ptr(ctx, &ptr, NULL, false);
|
||||
@@ -323,7 +372,7 @@
|
||||
@@ -297,6 +346,11 @@
|
||||
goto error;
|
||||
}
|
||||
|
||||
+ if (!(ptr.flags & UCI_LOOKUP_COMPLETE)) {
|
||||
+ err = UCI_ERR_NOTFOUND;
|
||||
+ goto error;
|
||||
+ }
|
||||
+
|
||||
err = UCI_OK;
|
||||
e = ptr.last;
|
||||
switch(e->type) {
|
||||
@@ -323,7 +377,7 @@
|
||||
switch(err) {
|
||||
default:
|
||||
ctx->err = err;
|
||||
|
@ -253,7 +265,7 @@ Index: uci.git/lua/uci.c
|
|||
/* fall through */
|
||||
case UCI_ERR_NOTFOUND:
|
||||
lua_pushnil(L);
|
||||
@@ -348,6 +397,7 @@
|
||||
@@ -348,6 +402,7 @@
|
||||
static int
|
||||
uci_lua_add(lua_State *L)
|
||||
{
|
||||
|
@ -261,7 +273,7 @@ Index: uci.git/lua/uci.c
|
|||
struct uci_section *s = NULL;
|
||||
struct uci_package *p;
|
||||
const char *package;
|
||||
@@ -355,9 +405,9 @@
|
||||
@@ -355,9 +410,9 @@
|
||||
const char *name = NULL;
|
||||
|
||||
do {
|
||||
|
@ -274,7 +286,7 @@ Index: uci.git/lua/uci.c
|
|||
if (!p)
|
||||
break;
|
||||
|
||||
@@ -374,11 +424,12 @@
|
||||
@@ -374,11 +429,12 @@
|
||||
static int
|
||||
uci_lua_delete(lua_State *L)
|
||||
{
|
||||
|
@ -288,7 +300,7 @@ Index: uci.git/lua/uci.c
|
|||
goto error;
|
||||
|
||||
err = uci_delete(ctx, &ptr);
|
||||
@@ -387,7 +438,7 @@
|
||||
@@ -387,7 +443,7 @@
|
||||
if (s)
|
||||
free(s);
|
||||
if (err)
|
||||
|
@ -297,7 +309,7 @@ Index: uci.git/lua/uci.c
|
|||
lua_pushboolean(L, (err == 0));
|
||||
return 1;
|
||||
}
|
||||
@@ -395,6 +446,7 @@
|
||||
@@ -395,6 +451,7 @@
|
||||
static int
|
||||
uci_lua_set(lua_State *L)
|
||||
{
|
||||
|
@ -305,7 +317,7 @@ Index: uci.git/lua/uci.c
|
|||
bool istable = false;
|
||||
struct uci_ptr ptr;
|
||||
int err = UCI_ERR_MEM;
|
||||
@@ -402,14 +454,14 @@
|
||||
@@ -402,14 +459,14 @@
|
||||
int i, nargs;
|
||||
|
||||
nargs = lua_gettop(L);
|
||||
|
@ -323,7 +335,7 @@ Index: uci.git/lua/uci.c
|
|||
/* Format: uci.set("p", "s", "o", "v") */
|
||||
if (lua_istable(L, nargs)) {
|
||||
if (lua_objlen(L, nargs) < 1)
|
||||
@@ -422,7 +474,7 @@
|
||||
@@ -422,7 +479,7 @@
|
||||
ptr.value = luaL_checkstring(L, nargs);
|
||||
}
|
||||
break;
|
||||
|
@ -332,7 +344,7 @@ Index: uci.git/lua/uci.c
|
|||
/* Format: uci.set("p", "s", "v") */
|
||||
ptr.value = ptr.option;
|
||||
ptr.option = NULL;
|
||||
@@ -433,17 +485,23 @@
|
||||
@@ -433,17 +490,23 @@
|
||||
}
|
||||
|
||||
err = uci_lookup_ptr(ctx, &ptr, NULL, false);
|
||||
|
@ -359,7 +371,7 @@ Index: uci.git/lua/uci.c
|
|||
|
||||
if (istable) {
|
||||
for (i = 2; i <= lua_objlen(L, nargs); i++) {
|
||||
@@ -458,7 +516,7 @@
|
||||
@@ -458,7 +521,7 @@
|
||||
|
||||
error:
|
||||
if (err)
|
||||
|
@ -368,7 +380,7 @@ Index: uci.git/lua/uci.c
|
|||
lua_pushboolean(L, (err == 0));
|
||||
return 1;
|
||||
}
|
||||
@@ -472,6 +530,7 @@
|
||||
@@ -472,6 +535,7 @@
|
||||
static int
|
||||
uci_lua_package_cmd(lua_State *L, enum pkg_cmd cmd)
|
||||
{
|
||||
|
@ -376,7 +388,7 @@ Index: uci.git/lua/uci.c
|
|||
struct uci_element *e, *tmp;
|
||||
struct uci_ptr ptr;
|
||||
char *s = NULL;
|
||||
@@ -479,10 +538,10 @@
|
||||
@@ -479,10 +543,10 @@
|
||||
int nargs;
|
||||
|
||||
nargs = lua_gettop(L);
|
||||
|
@ -389,7 +401,7 @@ Index: uci.git/lua/uci.c
|
|||
goto err;
|
||||
|
||||
uci_lookup_ptr(ctx, &ptr, NULL, false);
|
||||
@@ -562,16 +621,16 @@
|
||||
@@ -562,16 +626,16 @@
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -409,7 +421,7 @@ Index: uci.git/lua/uci.c
|
|||
if (!p)
|
||||
return;
|
||||
}
|
||||
@@ -596,6 +655,7 @@
|
||||
@@ -596,6 +660,7 @@
|
||||
static int
|
||||
uci_lua_changes(lua_State *L)
|
||||
{
|
||||
|
@ -417,7 +429,7 @@ Index: uci.git/lua/uci.c
|
|||
const char *package = NULL;
|
||||
char **config = NULL;
|
||||
int nargs;
|
||||
@@ -603,9 +663,9 @@
|
||||
@@ -603,9 +668,9 @@
|
||||
|
||||
nargs = lua_gettop(L);
|
||||
switch(nargs) {
|
||||
|
@ -429,7 +441,7 @@ Index: uci.git/lua/uci.c
|
|||
break;
|
||||
default:
|
||||
luaL_error(L, "invalid argument count");
|
||||
@@ -613,13 +673,13 @@
|
||||
@@ -613,13 +678,13 @@
|
||||
|
||||
lua_newtable(L);
|
||||
if (package) {
|
||||
|
@ -445,7 +457,7 @@ Index: uci.git/lua/uci.c
|
|||
}
|
||||
}
|
||||
|
||||
@@ -628,29 +688,53 @@
|
||||
@@ -628,29 +693,53 @@
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -502,7 +514,7 @@ Index: uci.git/lua/uci.c
|
|||
{ "load", uci_lua_load },
|
||||
{ "unload", uci_lua_unload },
|
||||
{ "get", uci_lua_get },
|
||||
@@ -663,25 +747,33 @@
|
||||
@@ -663,25 +752,33 @@
|
||||
{ "revert", uci_lua_revert },
|
||||
{ "changes", uci_lua_changes },
|
||||
{ "foreach", uci_lua_foreach },
|
||||
|
|
|
@ -175,7 +175,8 @@ function Map.__init__(self, config, ...)
|
|||
self.config = config
|
||||
self.parsechain = {self.config}
|
||||
self.template = "cbi/map"
|
||||
if not uci.load_config(self.config) then
|
||||
self.uci = uci.cursor()
|
||||
if not self.uci:load(self.config) then
|
||||
error("Unable to read UCI data: " .. self.config)
|
||||
end
|
||||
|
||||
|
@ -192,15 +193,6 @@ function Map.get_scheme(self, sectiontype, option)
|
|||
end
|
||||
end
|
||||
|
||||
function Map.render(self, ...)
|
||||
if self.stateful then
|
||||
uci.load_state(self.config)
|
||||
else
|
||||
uci.load_config(self.config)
|
||||
end
|
||||
Node.render(self, ...)
|
||||
end
|
||||
|
||||
|
||||
-- Chain foreign config
|
||||
function Map.chain(self, config)
|
||||
|
@ -209,26 +201,18 @@ end
|
|||
|
||||
-- Use optimized UCI writing
|
||||
function Map.parse(self, ...)
|
||||
if self.stateful then
|
||||
uci.load_state(self.config)
|
||||
else
|
||||
uci.load_config(self.config)
|
||||
end
|
||||
|
||||
Node.parse(self, ...)
|
||||
|
||||
for i, config in ipairs(self.parsechain) do
|
||||
uci.save_config(config)
|
||||
self.uci:save(config)
|
||||
end
|
||||
if luci.http.formvalue("cbi.apply") then
|
||||
for i, config in ipairs(self.parsechain) do
|
||||
uci.commit(config)
|
||||
if luci.config.uci_oncommit and luci.config.uci_oncommit[config] then
|
||||
luci.util.exec(luci.config.uci_oncommit[config])
|
||||
end
|
||||
self.uci:commit(config)
|
||||
self.uci:apply(config)
|
||||
|
||||
-- Refresh data because commit changes section names
|
||||
uci.load_config(config)
|
||||
self.uci:load(config)
|
||||
end
|
||||
|
||||
-- Reparse sections
|
||||
|
@ -236,7 +220,7 @@ function Map.parse(self, ...)
|
|||
|
||||
end
|
||||
for i, config in ipairs(self.parsechain) do
|
||||
uci.unload(config)
|
||||
self.uci:unload(config)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -253,35 +237,35 @@ end
|
|||
|
||||
-- UCI add
|
||||
function Map.add(self, sectiontype)
|
||||
return uci.add(self.config, sectiontype)
|
||||
return self.uci:add(self.config, sectiontype)
|
||||
end
|
||||
|
||||
-- UCI set
|
||||
function Map.set(self, section, option, value)
|
||||
if option then
|
||||
return uci.set(self.config, section, option, value)
|
||||
return self.uci:set(self.config, section, option, value)
|
||||
else
|
||||
return uci.set(self.config, section, value)
|
||||
return self.uci:set(self.config, section, value)
|
||||
end
|
||||
end
|
||||
|
||||
-- UCI del
|
||||
function Map.del(self, section, option)
|
||||
if option then
|
||||
return uci.delete(self.config, section, option)
|
||||
return self.uci:delete(self.config, section, option)
|
||||
else
|
||||
return uci.delete(self.config, section)
|
||||
return self.uci:delete(self.config, section)
|
||||
end
|
||||
end
|
||||
|
||||
-- UCI get
|
||||
function Map.get(self, section, option)
|
||||
if not section then
|
||||
return uci.get_all(self.config)
|
||||
return self.uci:get_all(self.config)
|
||||
elseif option then
|
||||
return uci.get(self.config, section, option)
|
||||
return self.uci:get(self.config, section, option)
|
||||
else
|
||||
return uci.get_all(self.config, section)
|
||||
return self.uci:get_all(self.config, section)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -669,7 +653,7 @@ end
|
|||
-- Return all matching UCI sections for this TypedSection
|
||||
function TypedSection.cfgsections(self)
|
||||
local sections = {}
|
||||
uci.foreach(self.map.config, self.sectiontype,
|
||||
self.map.uci:foreach(self.map.config, self.sectiontype,
|
||||
function (section)
|
||||
if self:checkscope(section[".name"]) then
|
||||
table.insert(sections, section[".name"])
|
||||
|
@ -706,7 +690,7 @@ function TypedSection.parse(self)
|
|||
self.err_invalid = true
|
||||
end
|
||||
|
||||
if name and name:len() > 0 then
|
||||
if name and #name > 0 then
|
||||
self:create(name)
|
||||
end
|
||||
end
|
||||
|
@ -716,9 +700,6 @@ function TypedSection.parse(self)
|
|||
crval = REMOVE_PREFIX .. self.config
|
||||
name = luci.http.formvaluetable(crval)
|
||||
for k,v in pairs(name) do
|
||||
luci.util.perror(k)
|
||||
luci.util.perror(self:cfgvalue(k))
|
||||
luci.util.perror(self:checkscope(k))
|
||||
if self:cfgvalue(k) and self:checkscope(k) then
|
||||
self:remove(k)
|
||||
end
|
||||
|
|
|
@ -18,9 +18,9 @@ vhost = luci.httpd.server.VHost()
|
|||
server:set_default_vhost(vhost)
|
||||
|
||||
if pcall(require, "uci") and pcall(require, "luci.model.uci") then
|
||||
luci.model.uci.confdir_default = SYSROOT .. luci.model.uci.confdir_default
|
||||
luci.model.uci.savedir_state = SYSROOT .. luci.model.uci.savedir_state
|
||||
luci.model.uci.set_confdir(luci.model.uci.confdir_default)
|
||||
luci.model.uci.cursor = function(config, ...)
|
||||
return uci.cursor(config or SYSROOT .. "/etc/config", ...)
|
||||
end
|
||||
end
|
||||
|
||||
require("luci.sys")
|
||||
|
|
|
@ -24,9 +24,9 @@ function init(path)
|
|||
|
||||
if (root ~= '/') then
|
||||
-- Entering dummy mode
|
||||
luci.model.uci.confdir_default = root .. '/etc/config'
|
||||
luci.model.uci.savedir_state = root .. '/var/state'
|
||||
uci.set_confdir(luci.model.uci.confdir_default)
|
||||
luci.model.uci.cursor = function(config, ...)
|
||||
return uci.cursor(config or root .. "/etc/config", ...)
|
||||
end
|
||||
|
||||
luci.sys.hostname = function() return "" end
|
||||
luci.sys.loadavg = function() return 0,0,0,0,0 end
|
||||
|
|
|
@ -29,20 +29,26 @@ local table = require "table"
|
|||
|
||||
local setmetatable, rawget, rawset = setmetatable, rawget, rawset
|
||||
local error, pairs, ipairs, tostring = error, pairs, ipairs, tostring
|
||||
local require = require
|
||||
local require, getmetatable = require, getmetatable
|
||||
|
||||
--- LuCI UCI model library.
|
||||
module("luci.model.uci", function(m) setmetatable(m, {__index = uci}) end)
|
||||
module("luci.model.uci")
|
||||
|
||||
savedir_default = "/tmp/.uci"
|
||||
confdir_default = "/etc/config"
|
||||
cursor = uci.cursor
|
||||
APIVERSION = uci.APIVERSION
|
||||
|
||||
savedir_state = "/var/state"
|
||||
--- Creates a new statevalue cursor
|
||||
-- @return UCI cursor
|
||||
function cursor_state()
|
||||
return cursor(nil, "/var/state")
|
||||
end
|
||||
|
||||
--- UCI-Cursor
|
||||
local Cursor = getmetatable(cursor())
|
||||
|
||||
--- Applies the new config
|
||||
-- @param config UCI config
|
||||
function apply(config)
|
||||
function Cursor.apply(self, config)
|
||||
local conf = require "luci.config"
|
||||
return conf.uci_oncommit[config] and os.execute(conf.uci_oncommit[config])
|
||||
end
|
||||
|
@ -52,18 +58,18 @@ end
|
|||
-- @param type UCI section type
|
||||
-- @param comparator Function that will be called for each section and
|
||||
-- returns a boolean whether to delete the current section (optional)
|
||||
function delete_all(config, type, comparator)
|
||||
function Cursor.delete_all(self, config, type, comparator)
|
||||
local del = {}
|
||||
local function helper (section)
|
||||
if not comparator or comparator(section) then
|
||||
table.insert(del, section[".name"])
|
||||
end
|
||||
if not comparator or comparator(section) then
|
||||
table.insert(del, section[".name"])
|
||||
end
|
||||
end
|
||||
|
||||
foreach(config, type, helper)
|
||||
self:foreach(config, type, helper)
|
||||
|
||||
for i, j in ipairs(del) do
|
||||
delete(config, j)
|
||||
self:delete(config, j)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -73,73 +79,31 @@ end
|
|||
-- @param name UCI section name (optional)
|
||||
-- @param values Table of key - value pairs to initialize the section with
|
||||
-- @return Name of created section
|
||||
function section(config, type, name, values)
|
||||
function Cursor.section(self, config, type, name, values)
|
||||
local stat = true
|
||||
if name then
|
||||
stat = set(config, name, type)
|
||||
stat = self:set(config, name, type)
|
||||
else
|
||||
name = add(config, type)
|
||||
name = self:add(config, type)
|
||||
stat = name and true
|
||||
end
|
||||
|
||||
if stat and values then
|
||||
stat = tset(config, name, values)
|
||||
stat = self:tset(config, name, values)
|
||||
end
|
||||
|
||||
return stat and name
|
||||
end
|
||||
|
||||
--- Savely load the configuration.
|
||||
-- @param config Configuration to load
|
||||
-- @return Sucess status
|
||||
-- @see load_state
|
||||
-- @see load
|
||||
function load_config(...)
|
||||
set_confdir(confdir_default)
|
||||
set_savedir(savedir_default)
|
||||
return load(...)
|
||||
end
|
||||
|
||||
--- Savely load state values.
|
||||
-- @param config Configuration to load
|
||||
-- @return Sucess status
|
||||
-- @see load_config
|
||||
-- @see load
|
||||
function load_state(config)
|
||||
set_confdir(confdir_default)
|
||||
set_savedir(savedir_state)
|
||||
return load(config)
|
||||
end
|
||||
|
||||
--- Save changes to config values.
|
||||
-- @param config Configuration to save
|
||||
-- @return Sucess status
|
||||
-- @see save_state
|
||||
-- @see save
|
||||
function save_config(config)
|
||||
set_savedir(savedir_default)
|
||||
return save(config)
|
||||
end
|
||||
|
||||
--- Save changes to state values.
|
||||
-- @param config Configuration to save
|
||||
-- @return Sucess status
|
||||
-- @see save_config
|
||||
-- @see save
|
||||
function save_state(config)
|
||||
set_savedir(savedir_state)
|
||||
return save(config)
|
||||
end
|
||||
|
||||
--- Updated the data of a section using data from a table.
|
||||
-- @param config UCI config
|
||||
-- @param section UCI section name (optional)
|
||||
-- @param values Table of key - value pairs to update the section with
|
||||
function tset(config, section, values)
|
||||
function Cursor.tset(self, config, section, values)
|
||||
local stat = true
|
||||
for k, v in pairs(values) do
|
||||
if k:sub(1, 1) ~= "." then
|
||||
stat = stat and set(config, section, k, v)
|
||||
stat = stat and self:set(config, section, k, v)
|
||||
end
|
||||
end
|
||||
return stat
|
||||
|
@ -150,9 +114,9 @@ end
|
|||
-- @param section UCI section name
|
||||
-- @param option UCI option
|
||||
-- @return UCI value
|
||||
function get_list(config, section, option)
|
||||
function Cursor.get_list(self, config, section, option)
|
||||
if config and section and option then
|
||||
local val = get(config, section, option)
|
||||
local val = self:get(config, section, option)
|
||||
return ( type(val) == "table" and val or { val } )
|
||||
end
|
||||
return nil
|
||||
|
@ -164,9 +128,9 @@ end
|
|||
-- @param option UCI option
|
||||
-- @param value UCI value
|
||||
-- @return Boolean whether operation succeeded
|
||||
function set_list(config, section, option, value)
|
||||
function Cursor.set_list(self, config, section, option, value)
|
||||
if config and section and option then
|
||||
return set(
|
||||
return self:set(
|
||||
config, section, option,
|
||||
( type(value) == "table" and value or { value } )
|
||||
)
|
||||
|
@ -177,27 +141,27 @@ end
|
|||
|
||||
--- Add an anonymous section.
|
||||
-- @class function
|
||||
-- @name add
|
||||
-- @name Cursor.add
|
||||
-- @param config UCI config
|
||||
-- @param type UCI section type
|
||||
-- @return Name of created section
|
||||
|
||||
--- Get a table of unsaved changes.
|
||||
-- @class function
|
||||
-- @name changes
|
||||
-- @name Cursor.changes
|
||||
-- @param config UCI config
|
||||
-- @return Table of changes
|
||||
|
||||
--- Commit unsaved changes.
|
||||
-- @class function
|
||||
-- @name commit
|
||||
-- @name Cursor.commit
|
||||
-- @param config UCI config
|
||||
-- @return Boolean whether operation succeeded
|
||||
-- @see revert
|
||||
|
||||
--- Deletes a section or an option.
|
||||
-- @class function
|
||||
-- @name delete
|
||||
-- @name Cursor.delete
|
||||
-- @param config UCI config
|
||||
-- @param section UCI section name
|
||||
-- @param option UCI option (optional)
|
||||
|
@ -205,7 +169,7 @@ end
|
|||
|
||||
--- Call a function for every section of a certain type.
|
||||
-- @class function
|
||||
-- @name foreach
|
||||
-- @name Cursor.foreach
|
||||
-- @param config UCI config
|
||||
-- @param type UCI section type
|
||||
-- @param callback Function to be called
|
||||
|
@ -213,7 +177,7 @@ end
|
|||
|
||||
--- Get a section type or an option
|
||||
-- @class function
|
||||
-- @name get
|
||||
-- @name Cursor.get
|
||||
-- @param config UCI config
|
||||
-- @param section UCI section name
|
||||
-- @param option UCI option (optional)
|
||||
|
@ -221,7 +185,7 @@ end
|
|||
|
||||
--- Get all sections of a config or all values of a section.
|
||||
-- @class function
|
||||
-- @name get_all
|
||||
-- @name Cursor.get_all
|
||||
-- @param config UCI config
|
||||
-- @param section UCI section name (optional)
|
||||
-- @return Table of UCI sections or table of UCI values
|
||||
|
@ -229,7 +193,7 @@ end
|
|||
--- Manually load a config.
|
||||
-- Warning: This function is unsave! You should use load_config or load_state if possible.
|
||||
-- @class function
|
||||
-- @name load
|
||||
-- @name Cursor.load
|
||||
-- @param config UCI config
|
||||
-- @return Boolean whether operation succeeded
|
||||
-- @see load_config
|
||||
|
@ -239,14 +203,14 @@ end
|
|||
|
||||
--- Revert unsaved changes.
|
||||
-- @class function
|
||||
-- @name revert
|
||||
-- @name Cursor.revert
|
||||
-- @param config UCI config
|
||||
-- @return Boolean whether operation succeeded
|
||||
-- @see commit
|
||||
|
||||
--- Saves changes made to a config to make them committable.
|
||||
-- @class function
|
||||
-- @name save
|
||||
-- @name Cursor.save
|
||||
-- @param config UCI config
|
||||
-- @return Boolean whether operation succeeded
|
||||
-- @see load
|
||||
|
@ -254,28 +218,38 @@ end
|
|||
|
||||
--- Set a value or create a named section.
|
||||
-- @class function
|
||||
-- @name set
|
||||
-- @name Cursor.set
|
||||
-- @param config UCI config
|
||||
-- @param section UCI section name
|
||||
-- @param option UCI option or UCI section type
|
||||
-- @param value UCI value or nil if you want to create a section
|
||||
-- @return Boolean whether operation succeeded
|
||||
|
||||
--- Get the configuration directory.
|
||||
-- @class function
|
||||
-- @name Cursor.get_confdir
|
||||
-- @return Configuration directory
|
||||
|
||||
--- Get the directory for uncomitted changes.
|
||||
-- @class function
|
||||
-- @name Cursor.get_savedir
|
||||
-- @return Save directory
|
||||
|
||||
--- Set the configuration directory.
|
||||
-- @class function
|
||||
-- @name set_confdir
|
||||
-- @name Cursor.set_confdir
|
||||
-- @param directory UCI configuration directory
|
||||
-- @return Boolean whether operation succeeded
|
||||
|
||||
--- Set the directory for uncommited changes.
|
||||
-- @class function
|
||||
-- @name set_savedir
|
||||
-- @name Cursor.set_savedir
|
||||
-- @param directory UCI changes directory
|
||||
-- @return Boolean whether operation succeeded
|
||||
|
||||
--- Discard changes made to a config.
|
||||
-- @class function
|
||||
-- @name unload
|
||||
-- @name Cursor.unload
|
||||
-- @param config UCI config
|
||||
-- @return Boolean whether operation succeeded
|
||||
-- @see load
|
||||
|
|
|
@ -28,6 +28,6 @@ limitations under the License.
|
|||
module("luci.config",
|
||||
function(m)
|
||||
if pcall(require, "luci.model.uci") then
|
||||
setmetatable(m, {__index = luci.model.uci.get_all("luci")})
|
||||
setmetatable(m, {__index = luci.model.uci.cursor():get_all("luci")})
|
||||
end
|
||||
end)
|
|
@ -14,7 +14,7 @@ $Id$
|
|||
]]--
|
||||
|
||||
module("luci.tools.webadmin", package.seeall)
|
||||
require("luci.model.uci")
|
||||
local uci = require("luci.model.uci")
|
||||
require("luci.sys")
|
||||
require("luci.ip")
|
||||
|
||||
|
@ -59,11 +59,12 @@ function date_format(secs)
|
|||
end
|
||||
|
||||
function network_get_addresses(net)
|
||||
luci.model.uci.load_state("network")
|
||||
local state = uci.cursor_state()
|
||||
state:load("network")
|
||||
local addr = {}
|
||||
local ipv4 = luci.model.uci.get("network", net, "ipaddr")
|
||||
local mav4 = luci.model.uci.get("network", net, "netmask")
|
||||
local ipv6 = luci.model.uci.get("network", net, "ip6addr")
|
||||
local ipv4 = state:get("network", net, "ipaddr")
|
||||
local mav4 = state:get("network", net, "netmask")
|
||||
local ipv6 = state:get("network", net, "ip6addr")
|
||||
|
||||
if ipv4 and mav4 then
|
||||
ipv4 = luci.ip.IPv4(ipv4, mav4)
|
||||
|
@ -77,7 +78,7 @@ function network_get_addresses(net)
|
|||
table.insert(addr, ipv6)
|
||||
end
|
||||
|
||||
luci.model.uci.foreach("network", "alias",
|
||||
state:foreach("network", "alias",
|
||||
function (section)
|
||||
if section.interface == net then
|
||||
if section.ipaddr and section.netmask then
|
||||
|
@ -99,7 +100,7 @@ function network_get_addresses(net)
|
|||
end
|
||||
|
||||
function cbi_add_networks(field)
|
||||
luci.model.uci.foreach("network", "interface",
|
||||
uci.cursor():foreach("network", "interface",
|
||||
function (section)
|
||||
if section[".name"] ~= "loopback" then
|
||||
field:value(section[".name"])
|
||||
|
@ -116,13 +117,14 @@ function cbi_add_knownips(field)
|
|||
end
|
||||
|
||||
function network_get_zones(net)
|
||||
if not luci.model.uci.load_state("firewall") then
|
||||
local state = uci.cursor_state()
|
||||
if not state:load("firewall") then
|
||||
return nil
|
||||
end
|
||||
|
||||
local zones = {}
|
||||
|
||||
luci.model.uci.foreach("firewall", "zone",
|
||||
state:foreach("firewall", "zone",
|
||||
function (section)
|
||||
local znet = section.network or section.name
|
||||
if luci.util.contains(luci.util.split(znet, " "), net) then
|
||||
|
@ -137,7 +139,7 @@ end
|
|||
function firewall_find_zone(name)
|
||||
local find
|
||||
|
||||
luci.model.uci.foreach("firewall", "zone",
|
||||
luci.model.uci.cursor():foreach("firewall", "zone",
|
||||
function (section)
|
||||
if section.name == name then
|
||||
find = section[".name"]
|
||||
|
@ -149,12 +151,13 @@ function firewall_find_zone(name)
|
|||
end
|
||||
|
||||
function iface_get_network(iface)
|
||||
luci.model.uci.load_state("network")
|
||||
local state = uci.cursor_state()
|
||||
state:load("network")
|
||||
local net
|
||||
|
||||
luci.model.uci.foreach("network", "interface",
|
||||
state:foreach("network", "interface",
|
||||
function (section)
|
||||
local ifname = luci.model.uci.get(
|
||||
local ifname = state:get(
|
||||
"network", section[".name"], "ifname"
|
||||
)
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ module("luci.controller.admin.network", package.seeall)
|
|||
|
||||
function index()
|
||||
require("luci.i18n")
|
||||
require("luci.model.uci")
|
||||
local uci = require("luci.model.uci").cursor()
|
||||
local i18n = luci.i18n.translate
|
||||
|
||||
local page = node("admin", "network")
|
||||
|
@ -32,7 +32,7 @@ function index()
|
|||
page.target = form("admin_network/wireless")
|
||||
page.title = i18n("wifi")
|
||||
page.order = 15
|
||||
luci.model.uci.foreach("wireless", "wifi-device",
|
||||
uci:foreach("wireless", "wifi-device",
|
||||
function (section)
|
||||
local ifc = section[".name"]
|
||||
entry({"admin", "network", "wireless", ifc},
|
||||
|
@ -49,7 +49,7 @@ function index()
|
|||
page.target = cbi("admin_network/network")
|
||||
page.title = i18n("interfaces", "Schnittstellen")
|
||||
page.order = 10
|
||||
luci.model.uci.foreach("network", "interface",
|
||||
uci:foreach("network", "interface",
|
||||
function (section)
|
||||
local ifc = section[".name"]
|
||||
if ifc ~= "loopback" then
|
||||
|
|
|
@ -216,7 +216,7 @@ end
|
|||
|
||||
function _keep_pattern()
|
||||
local kpattern = ""
|
||||
local files = luci.model.uci.get_all("luci", "flash_keep")
|
||||
local files = luci.model.uci.cursor():get_all("luci", "flash_keep")
|
||||
if files then
|
||||
kpattern = ""
|
||||
for k,v in pairs(files) do
|
||||
|
|
|
@ -48,7 +48,7 @@ function convert_changes(changes)
|
|||
end
|
||||
|
||||
function action_changes()
|
||||
local changes = convert_changes(luci.model.uci.changes())
|
||||
local changes = convert_changes(luci.model.uci.cursor():changes())
|
||||
luci.template.render("admin_uci/changes", {changes=changes})
|
||||
end
|
||||
|
||||
|
@ -56,6 +56,7 @@ function action_apply()
|
|||
local path = luci.dispatcher.context.path
|
||||
local changes = luci.model.uci.changes()
|
||||
local output = ""
|
||||
local uci = luci.model.uci.cursor()
|
||||
|
||||
if changes then
|
||||
local com = {}
|
||||
|
@ -65,9 +66,9 @@ function action_apply()
|
|||
for r, tbl in pairs(changes) do
|
||||
if r then
|
||||
if path[#path] ~= "apply" then
|
||||
luci.model.uci.load_config(r)
|
||||
luci.model.uci.commit(r)
|
||||
luci.model.uci.unload(r)
|
||||
uci:load(r)
|
||||
uci:commit(r)
|
||||
uci:unload(r)
|
||||
end
|
||||
if luci.config.uci_oncommit and luci.config.uci_oncommit[r] then
|
||||
run[luci.config.uci_oncommit[r]] = true
|
||||
|
@ -87,15 +88,16 @@ end
|
|||
|
||||
|
||||
function action_revert()
|
||||
local changes = luci.model.uci.changes()
|
||||
local uci = luci.model.uci.cursor()
|
||||
local changes = uci:changes()
|
||||
if changes then
|
||||
local revert = {}
|
||||
|
||||
-- Collect files to be reverted
|
||||
for r, tbl in pairs(changes) do
|
||||
luci.model.uci.load_config(r)
|
||||
luci.model.uci.revert(r)
|
||||
luci.model.uci.unload(r)
|
||||
uci:load(r)
|
||||
uci:revert(r)
|
||||
uci:unload(r)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -24,7 +24,8 @@ s.anonymous = true
|
|||
iface = s:option(ListValue, "interface", translate("interface"))
|
||||
luci.tools.webadmin.cbi_add_networks(iface)
|
||||
|
||||
luci.model.uci.foreach("network", "interface",
|
||||
local uci = luci.model.uci.cursor()
|
||||
uci:foreach("network", "interface",
|
||||
function (section)
|
||||
if section[".name"] ~= "loopback" then
|
||||
iface.default = iface.default or section[".name"]
|
||||
|
@ -32,7 +33,7 @@ luci.model.uci.foreach("network", "interface",
|
|||
end
|
||||
end)
|
||||
|
||||
luci.model.uci.foreach("network", "alias",
|
||||
uci:foreach("network", "alias",
|
||||
function (section)
|
||||
iface:value(section[".name"])
|
||||
s:depends("interface", section[".name"])
|
||||
|
|
|
@ -16,7 +16,7 @@ require("luci.tools.webadmin")
|
|||
m2 = Map("luci_ethers", translate("dhcp_leases"))
|
||||
|
||||
local leasefn, leasefp, leases
|
||||
luci.model.uci.foreach("dhcp", "dnsmasq",
|
||||
luci.model.uci.cursor():foreach("dhcp", "dnsmasq",
|
||||
function(section)
|
||||
leasefn = section.leasefile
|
||||
end
|
||||
|
|
|
@ -49,8 +49,8 @@ if zones then
|
|||
fwzone.rmempty = true
|
||||
fwzone:value("", "- " .. translate("none") .. " -")
|
||||
fwzone:value(arg[1])
|
||||
luci.model.uci.load_config("firewall")
|
||||
luci.model.uci.foreach("firewall", "zone",
|
||||
m.uci:load("firewall")
|
||||
m.uci:foreach("firewall", "zone",
|
||||
function (section)
|
||||
fwzone:value(section.name)
|
||||
end
|
||||
|
@ -61,14 +61,14 @@ if zones then
|
|||
local stat
|
||||
|
||||
if not zone then
|
||||
stat = luci.model.uci.section("firewall", "zone", nil, {
|
||||
stat = m.uci:section("firewall", "zone", nil, {
|
||||
name = value,
|
||||
network = section
|
||||
})
|
||||
else
|
||||
local net = luci.model.uci.get("firewall", zone, "network")
|
||||
local net = m.uci:get("firewall", zone, "network")
|
||||
net = (net or value) .. " " .. section
|
||||
stat = luci.model.uci.set("firewall", zone, "network", net)
|
||||
stat = m.uci:set("firewall", zone, "network", net)
|
||||
end
|
||||
|
||||
if stat then
|
||||
|
@ -80,7 +80,7 @@ if zones then
|
|||
fwzone.value = table.concat(zones, ", ")
|
||||
end
|
||||
fwzone.titleref = luci.dispatcher.build_url("admin", "network", "firewall", "zones")
|
||||
luci.model.uci.unload("firewall")
|
||||
m.uci:unload("firewall")
|
||||
end
|
||||
|
||||
ipaddr = s:option(Value, "ipaddr", translate("ipaddress"))
|
||||
|
|
|
@ -15,11 +15,7 @@ $Id$
|
|||
require("luci.sys")
|
||||
require("luci.tools.webadmin")
|
||||
|
||||
luci.model.uci.load_state("network")
|
||||
local netstate = luci.model.uci.get_all("network")
|
||||
luci.model.uci.unload("network")
|
||||
|
||||
|
||||
local netstate = luci.model.uci.cursor_state():get_all("network")
|
||||
m = Map("network", translate("interfaces"))
|
||||
|
||||
local created
|
||||
|
@ -70,7 +66,8 @@ end
|
|||
|
||||
ifname.titleref = luci.dispatcher.build_url("admin", "network", "vlan")
|
||||
|
||||
if luci.model.uci.load("firewall") then
|
||||
|
||||
if luci.model.uci.cursor():load("firewall") then
|
||||
zone = s:option(DummyValue, "_zone", translate("zone"))
|
||||
zone.titleref = luci.dispatcher.build_url("admin", "network", "firewall", "zones")
|
||||
|
||||
|
|
|
@ -48,11 +48,6 @@ s = m:section(TypedSection, "route", translate("a_n_routes_static"))
|
|||
s.addremove = true
|
||||
s.anonymous = true
|
||||
|
||||
function s.render(...)
|
||||
luci.model.uci.load_config("network")
|
||||
TypedSection.render(...)
|
||||
end
|
||||
|
||||
s.template = "cbi/tblsection"
|
||||
|
||||
iface = s:option(ListValue, "interface", translate("interface"))
|
||||
|
|
|
@ -86,12 +86,12 @@ network.combobox_manual = translate("a_w_netmanual")
|
|||
luci.tools.webadmin.cbi_add_networks(network)
|
||||
|
||||
function network.write(self, section, value)
|
||||
if not luci.model.uci.get("network", value) then
|
||||
if not m:uci.get("network", value) then
|
||||
m:chain("network")
|
||||
luci.model.uci.set("network", value, "interface")
|
||||
m.uci:set("network", value, "interface")
|
||||
Value.write(self, section, value)
|
||||
else
|
||||
if luci.model.uci.get("network", value) == "interface" then
|
||||
if m.uci:get("network", value) == "interface" then
|
||||
Value.write(self, section, value)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,10 +15,7 @@ $Id$
|
|||
require("luci.sys")
|
||||
require("luci.tools.webadmin")
|
||||
|
||||
luci.model.uci.load_state("wireless")
|
||||
local wireless = luci.model.uci.get_all("wireless")
|
||||
luci.model.uci.unload("wireless")
|
||||
|
||||
local wireless = luci.model.uci.cursor_state():get_all("wireless")
|
||||
local wifidata = luci.sys.wifi.getiwconfig()
|
||||
local ifaces = {}
|
||||
|
||||
|
@ -123,9 +120,10 @@ for k, v in pairs(wireless) do
|
|||
end
|
||||
|
||||
function create.write(self, section, value)
|
||||
luci.model.uci.load_config("wireless")
|
||||
luci.model.uci.section("wireless", "wifi-iface", nil, {device=value})
|
||||
luci.model.uci.save_config("wireless")
|
||||
local uci = luci.model.uci.cursor()
|
||||
uci:load("wireless")
|
||||
uci:section("wireless", "wifi-iface", nil, {device=value})
|
||||
uci:save("wireless")
|
||||
luci.http.redirect(luci.http.getenv("REQUEST_URI") .. "/" .. value)
|
||||
end
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ end
|
|||
|
||||
function _keep_pattern()
|
||||
local kpattern = ""
|
||||
local files = luci.model.uci.get_all("luci", "flash_keep")
|
||||
local files = luci.model.uci.cursor():get_all("luci", "flash_keep")
|
||||
if files then
|
||||
kpattern = ""
|
||||
for k,v in pairs(files) do
|
||||
|
|
|
@ -48,12 +48,13 @@ function convert_changes(changes)
|
|||
end
|
||||
|
||||
function action_changes()
|
||||
local changes = convert_changes(luci.model.uci.changes())
|
||||
local changes = convert_changes(luci.model.uci.cursor():changes())
|
||||
luci.template.render("mini/uci_changes", {changes=changes})
|
||||
end
|
||||
|
||||
function action_apply()
|
||||
local changes = luci.model.uci.changes()
|
||||
local uci = luci.model.uci.cursor()
|
||||
local changes = uci:changes()
|
||||
local output = ""
|
||||
|
||||
if changes then
|
||||
|
@ -63,9 +64,9 @@ function action_apply()
|
|||
-- Collect files to be applied and commit changes
|
||||
for r, tbl in pairs(changes) do
|
||||
if r then
|
||||
luci.model.uci.load_config(r)
|
||||
luci.model.uci.commit(r)
|
||||
luci.model.uci.unload(r)
|
||||
uci:load(r)
|
||||
uci:commit(r)
|
||||
uci:unload(r)
|
||||
if luci.config.uci_oncommit and luci.config.uci_oncommit[r] then
|
||||
run[luci.config.uci_oncommit[r]] = true
|
||||
end
|
||||
|
@ -84,15 +85,16 @@ end
|
|||
|
||||
|
||||
function action_revert()
|
||||
local changes = luci.model.uci.changes()
|
||||
local uci = luci.model.uci.cursor()
|
||||
local changes = uci:changes()
|
||||
if changes then
|
||||
local revert = {}
|
||||
|
||||
-- Collect files to be reverted
|
||||
for r, tbl in pairs(changes) do
|
||||
luci.model.uci.load_config(r)
|
||||
luci.model.uci.revert(r)
|
||||
luci.model.uci.unload(r)
|
||||
uci:load(r)
|
||||
uci:revert(r)
|
||||
uci:unload(r)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ time.rmempty = true
|
|||
m2 = Map("luci_ethers", translate("dhcp_leases"))
|
||||
|
||||
local leasefn, leasefp, leases
|
||||
luci.model.uci.foreach("dhcp", "dnsmasq",
|
||||
luci.model.uci.cursor():foreach("dhcp", "dnsmasq",
|
||||
function(section)
|
||||
leasefn = section.leasefile
|
||||
end
|
||||
|
|
|
@ -15,9 +15,7 @@ $Id$
|
|||
require("luci.tools.webadmin")
|
||||
require("luci.sys")
|
||||
|
||||
luci.model.uci.load_state("network")
|
||||
local network = luci.model.uci.get_all("network")
|
||||
luci.model.uci.unload("network")
|
||||
local network = luci.model.uci.cursor_state():get_all("network")
|
||||
|
||||
local netstat = luci.sys.net.deviceinfo()
|
||||
local ifaces = {}
|
||||
|
|
|
@ -15,10 +15,7 @@ $Id$
|
|||
|
||||
-- Data init --
|
||||
|
||||
luci.model.uci.load_state("wireless")
|
||||
local wireless = luci.model.uci.get_all("wireless")
|
||||
luci.model.uci.unload("wireless")
|
||||
|
||||
local wireless = luci.model.uci.cursor_state():get_all("wireless")
|
||||
local wifidata = luci.sys.wifi.getiwconfig()
|
||||
local ifaces = {}
|
||||
|
||||
|
@ -148,7 +145,7 @@ s.anonymous = true
|
|||
s:option(Value, "ssid", translate("a_w_netid")).maxlength = 32
|
||||
|
||||
local devs = {}
|
||||
luci.model.uci.foreach("wireless", "wifi-device",
|
||||
luci.model.uci.cursor():foreach("wireless", "wifi-device",
|
||||
function (section)
|
||||
table.insert(devs, section[".name"])
|
||||
end)
|
||||
|
@ -167,21 +164,21 @@ mode:value("sta", translate("m_w_client"))
|
|||
function mode.write(self, section, value)
|
||||
if value == "sta" then
|
||||
-- ToDo: Move this away
|
||||
if not luci.model.uci.get("network", "wan") then
|
||||
luci.model.uci.set("network", "wan", "proto", "none")
|
||||
luci.model.uci.set("network", "wan", "ifname", " ")
|
||||
if not m.uci:get("network", "wan") then
|
||||
m.uci:set("network", "wan", "proto", "none")
|
||||
m.uci:set("network", "wan", "ifname", " ")
|
||||
end
|
||||
|
||||
local oldif = luci.model.uci.get("network", "wan", "ifname")
|
||||
local oldif = m.uci:get("network", "wan", "ifname")
|
||||
if oldif and oldif ~= " " then
|
||||
luci.model.uci.set("network", "wan", "_ifname", oldif)
|
||||
m.uci:set("network", "wan", "_ifname", oldif)
|
||||
end
|
||||
luci.model.uci.set("network", "wan", "ifname", " ")
|
||||
m.uci:set("network", "wan", "ifname", " ")
|
||||
|
||||
self.map:set(section, "network", "wan")
|
||||
else
|
||||
if luci.model.uci.get("network", "wan", "_ifname") then
|
||||
luci.model.uci.set("network", "wan", "ifname", luci.model.uci.get("network", "wan", "_ifname"))
|
||||
if m.uci:get("network", "wan", "_ifname") then
|
||||
m.uci:set("network", "wan", "ifname", m.uci:get("network", "wan", "_ifname"))
|
||||
end
|
||||
self.map:set(section, "network", "lan")
|
||||
end
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
--[[
|
||||
LuCI - Lua Configuration Interface
|
||||
|
||||
Copyright 2008 Steven Barth <steven@midlink.org>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
$Id$
|
||||
]]--
|
||||
module("luci.controller.freifunk.luciinfo", package.seeall)
|
||||
|
||||
function index()
|
||||
node("freifunk", "luciinfo").target = call("action_index")
|
||||
end
|
||||
|
||||
function action_index()
|
||||
local uci = luci.model.uci
|
||||
luci.http.prepare_content("text/plain")
|
||||
|
||||
-- General
|
||||
luci.http.write("luciinfo.api=1\n")
|
||||
luci.http.write("luciinfo.version=" .. tostring(require("luci").__version__) .. "\n")
|
||||
|
||||
-- Sysinfo
|
||||
local s, m, r = luci.sys.sysinfo()
|
||||
local dr = luci.sys.net.defaultroute()
|
||||
dr = dr and luci.ip.Hex(dr.Gateway, 32, luci.ip.FAMILY_INET4):string()
|
||||
local l1, l5, l15 = luci.sys.loadavg()
|
||||
|
||||
luci.http.write("sysinfo.system=" .. sanitize(s) .. "\n")
|
||||
luci.http.write("sysinfo.cpu=" .. sanitize(m) .. "\n")
|
||||
luci.http.write("sysinfo.ram=" .. sanitize(r) .. "\n")
|
||||
luci.http.write("sysinfo.hostname=" .. sanitize(luci.sys.hostname()) .. "\n")
|
||||
luci.http.write("sysinfo.load1=" .. tostring(l1) .. "\n")
|
||||
luci.http.write("sysinfo.load5=" .. tostring(l5) .. "\n")
|
||||
luci.http.write("sysinfo.load15=" .. tostring(l15) .. "\n")
|
||||
luci.http.write("sysinfo.defaultgw=" .. dr or "" .. "\n")
|
||||
|
||||
|
||||
-- Freifunk
|
||||
local ff = uci.get_all("freifunk") or {}
|
||||
for k, v in pairs(ff) do
|
||||
for i, j in pairs(v) do
|
||||
if i:sub(1, 1) ~= "." then
|
||||
luci.http.write("freifunk." .. k .. "." .. i .. "=" .. j .. "\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function sanitize(val)
|
||||
return val:gsub("\n", "\t")
|
||||
end
|
|
@ -13,7 +13,7 @@ $Id$
|
|||
|
||||
-%>
|
||||
<%+header%>
|
||||
<% local contact = luci.model.uci.get_all("freifunk", "contact") %>
|
||||
<% local contact = luci.model.uci.cursor():get_all("freifunk", "contact") %>
|
||||
<h1><%:contact%></h1>
|
||||
<table cellspacing="0" cellpadding="6">
|
||||
<tr><th><%:nickname%>:</th><td><%=contact.nickname%></td></tr>
|
||||
|
|
|
@ -13,7 +13,7 @@ $Id$
|
|||
|
||||
-%>
|
||||
<%+header%>
|
||||
<% local ff = luci.model.uci.get_all("freifunk") %>
|
||||
<% local ff = luci.model.uci.cursor():get_all("freifunk") %>
|
||||
<h1><%:hellonet%> <%=ff.community.name%>!</h1>
|
||||
<p><%:public1%><br />
|
||||
<%:public2%><%=luci.sys.hostname()%>. <%:public3%>
|
||||
|
|
|
@ -13,7 +13,8 @@ http://www.apache.org/licenses/LICENSE-2.0
|
|||
$Id$
|
||||
]]--
|
||||
|
||||
local uci = require "luci.model.uci"
|
||||
local uci = require "luci.model.uci".cursor()
|
||||
local ucis = require "luci.model.uci".cursor_state()
|
||||
local table = require "table"
|
||||
|
||||
|
||||
|
@ -21,73 +22,73 @@ module "luci.controller.rpc.uci"
|
|||
_M, _PACKAGE, _NAME = nil, nil, nil
|
||||
|
||||
function add(config, ...)
|
||||
uci.load_config(config)
|
||||
local stat = uci.add(config, ...)
|
||||
return uci.save_config(config) and stat
|
||||
uci:load(config)
|
||||
local stat = uci:add(config, ...)
|
||||
return uci:save(config) and stat
|
||||
end
|
||||
|
||||
function apply(config)
|
||||
return uci.apply(config)
|
||||
return uci:apply(config)
|
||||
end
|
||||
|
||||
function changes(...)
|
||||
return uci.changes(...)
|
||||
return uci:changes(...)
|
||||
end
|
||||
|
||||
function commit(config)
|
||||
return uci.load(config) and uci.commit(config)
|
||||
return uci:load(config) and uci:commit(config)
|
||||
end
|
||||
|
||||
function delete(config, ...)
|
||||
uci.load(config)
|
||||
return uci.delete(config, ...) and uci.save(config)
|
||||
uci:load(config)
|
||||
return uci:delete(config, ...) and uci:save(config)
|
||||
end
|
||||
|
||||
function delete_all(config, ...)
|
||||
uci.load(config)
|
||||
return uci.delete_all(config, ...) and uci.save(config)
|
||||
uci:load(config)
|
||||
return uci:delete_all(config, ...) and uci:save(config)
|
||||
end
|
||||
|
||||
function foreach(config, stype)
|
||||
uci.load_config(config)
|
||||
uci:load(config)
|
||||
local sections = {}
|
||||
|
||||
return uci.foreach(config, stype, function(section)
|
||||
return uci:foreach(config, stype, function(section)
|
||||
table.insert(sections, section)
|
||||
end) and sections
|
||||
end
|
||||
|
||||
function get(config, ...)
|
||||
uci.load_config(config)
|
||||
return uci.get(config, ...)
|
||||
uci:load(config)
|
||||
return uci:get(config, ...)
|
||||
end
|
||||
|
||||
function get_all(config, ...)
|
||||
uci.load_config(config)
|
||||
return uci.get_all(config, ...)
|
||||
uci:load(config)
|
||||
return uci:get_all(config, ...)
|
||||
end
|
||||
|
||||
function get_state(config, ...)
|
||||
uci.load_state(config)
|
||||
return uci.get(config, ...)
|
||||
ucis:load(config)
|
||||
return ucis:get(config, ...)
|
||||
end
|
||||
|
||||
function revert(config)
|
||||
return uci.load(config) and uci.revert(config)
|
||||
return uci:load(config) and uci:revert(config)
|
||||
end
|
||||
|
||||
function section(config, ...)
|
||||
uci.load_config(config)
|
||||
return uci.section(config, ...) and uci.save_config(config)
|
||||
uci:load(config)
|
||||
return uci:section(config, ...) and uci:save(config)
|
||||
end
|
||||
|
||||
function set(config, ...)
|
||||
uci.load_config(config)
|
||||
return uci.set(config, ...) and uci.save_config(config)
|
||||
uci:load(config)
|
||||
return uci:set(config, ...) and uci:save(config)
|
||||
end
|
||||
|
||||
function tset(config, ...)
|
||||
uci.load_config(config)
|
||||
return uci.tset(config, ...) and uci.save_config(config)
|
||||
uci:load(config)
|
||||
return uci:tset(config, ...) and uci:save(config)
|
||||
end
|
||||
|
||||
|
|
|
@ -154,9 +154,8 @@ end
|
|||
<%
|
||||
if tree.nodes[category] and tree.nodes[category].ucidata then
|
||||
local ucic = 0
|
||||
require("luci.model.uci")
|
||||
luci.model.uci.set_savedir(luci.model.uci.savedir_default)
|
||||
for i, j in pairs(luci.model.uci.changes()) do
|
||||
|
||||
for i, j in pairs(require("luci.model.uci").cursor():changes()) do
|
||||
for k, l in pairs(j) do
|
||||
for m, n in pairs(l) do
|
||||
ucic = ucic + 1;
|
||||
|
|
|
@ -161,9 +161,7 @@ end
|
|||
<%
|
||||
if tree.nodes[category] and tree.nodes[category].ucidata then
|
||||
local ucic = 0
|
||||
require("luci.model.uci")
|
||||
luci.model.uci.set_savedir(luci.model.uci.savedir_default)
|
||||
for i, j in pairs(luci.model.uci.changes()) do
|
||||
for i, j in pairs(require("luci.model.uci").cursor():changes()) do
|
||||
for k, l in pairs(j) do
|
||||
for m, n in pairs(l) do
|
||||
ucic = ucic + 1;
|
||||
|
|
|
@ -162,9 +162,7 @@ end
|
|||
<%
|
||||
if tree.nodes[category] and tree.nodes[category].ucidata then
|
||||
local ucic = 0
|
||||
require("luci.model.uci")
|
||||
luci.model.uci.set_savedir(luci.model.uci.savedir_default)
|
||||
for i, j in pairs(luci.model.uci.changes()) do
|
||||
for i, j in pairs(require("luci.model.uci").cursor():changes()) do
|
||||
for k, l in pairs(j) do
|
||||
for m, n in pairs(l) do
|
||||
ucic = ucic + 1;
|
||||
|
|
Loading…
Reference in a new issue