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