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)
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)
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)
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
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)
$Id$
-%>
-<% local c = luci.model.uci.get_all("freifunk", "community") %>
+<% local c = luci.model.uci.cursor():get_all("freifunk", "community") %>
<h1>Willkommen!</h1>
<p>
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")
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)
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)
-- 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
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"])
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
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
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
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
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
})
end
end
- uci.save_state("luci_splash")
+ uci:save("luci_splash")
end
main(arg)
\ No newline at end of file
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
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()
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()
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 )
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
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
+++ /dev/null
-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;
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>
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;
/* 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)
{
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 {
if (!p)
break;
-@@ -374,11 +424,12 @@
+@@ -374,11 +429,12 @@
static int
uci_lua_delete(lua_State *L)
{
goto error;
err = uci_delete(ctx, &ptr);
-@@ -387,7 +438,7 @@
+@@ -387,7 +443,7 @@
if (s)
free(s);
if (err)
lua_pushboolean(L, (err == 0));
return 1;
}
-@@ -395,6 +446,7 @@
+@@ -395,6 +451,7 @@
static int
uci_lua_set(lua_State *L)
{
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);
/* 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;
/* 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);
if (istable) {
for (i = 2; i <= lua_objlen(L, nargs); i++) {
-@@ -458,7 +516,7 @@
+@@ -458,7 +521,7 @@
error:
if (err)
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)
{
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);
goto err;
uci_lookup_ptr(ctx, &ptr, NULL, false);
-@@ -562,16 +621,16 @@
+@@ -562,16 +626,16 @@
}
static void
if (!p)
return;
}
-@@ -596,6 +655,7 @@
+@@ -596,6 +660,7 @@
static int
uci_lua_changes(lua_State *L)
{
const char *package = NULL;
char **config = NULL;
int nargs;
-@@ -603,9 +663,9 @@
+@@ -603,9 +668,9 @@
nargs = lua_gettop(L);
switch(nargs) {
break;
default:
luaL_error(L, "invalid argument count");
-@@ -613,13 +673,13 @@
+@@ -613,13 +678,13 @@
lua_newtable(L);
if (package) {
}
}
-@@ -628,29 +688,53 @@
+@@ -628,29 +693,53 @@
}
static int
{ "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 },
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
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)
-- 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
end
for i, config in ipairs(self.parsechain) do
- uci.unload(config)
+ self.uci:unload(config)
end
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
-- 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"])
self.err_invalid = true
end
- if name and name:len() > 0 then
+ if name and #name > 0 then
self:create(name)
end
end
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
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")
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
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
-- @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
-- @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
-- @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
-- @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 } )
)
--- 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)
--- 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
--- 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)
--- 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
--- 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
--- 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
--- 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
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)
\ No newline at end of file
]]--
module("luci.tools.webadmin", package.seeall)
-require("luci.model.uci")
+local uci = require("luci.model.uci")
require("luci.sys")
require("luci.ip")
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)
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
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"])
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
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"]
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"
)
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")
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},
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
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
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
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 = {}
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
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
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"]
end
end)
-luci.model.uci.foreach("network", "alias",
+uci:foreach("network", "alias",
function (section)
iface:value(section[".name"])
s:depends("interface", section[".name"])
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
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
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
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"))
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
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")
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"))
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
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 = {}
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
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
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
-- 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
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
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
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 = {}
-- 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 = {}
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)
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
+++ /dev/null
---[[
-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
\ No newline at end of file
-%>
<%+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>
-%>
<%+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%>
$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"
_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
<%
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;
<%
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;
<%
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;