* Rewrote ffluci.http, ffluci.model.uci
* WARNING: API CHANGES FOR ffluci.http and ffluci.model.uci
This commit is contained in:
parent
2d95ace789
commit
cc729464f9
26 changed files with 512 additions and 292 deletions
|
@ -3,12 +3,14 @@ LUAC_OPTIONS = -s
|
||||||
|
|
||||||
FILES = ffluci/debug.lua ffluci/view/*.htm ffluci/view/cbi/*.htm ffluci/i18n/*
|
FILES = ffluci/debug.lua ffluci/view/*.htm ffluci/view/cbi/*.htm ffluci/i18n/*
|
||||||
|
|
||||||
CFILES = ffluci/bits.lua ffluci/util.lua ffluci/http.lua ffluci/fs.lua \
|
CFILES = ffluci/bits.lua ffluci/util.lua \
|
||||||
ffluci/sys.lua ffluci/model/uci.lua ffluci/model/ipkg.lua \
|
ffluci/sgi/haserl.lua \
|
||||||
ffluci/config.lua ffluci/i18n.lua ffluci/template.lua \
|
ffluci/http.lua ffluci/fs.lua ffluci/sys.lua \
|
||||||
|
ffluci/model/uci/wrapper.lua ffluci/model/uci/libuci.lua ffluci/model/uci.lua \
|
||||||
|
ffluci/model/ipkg.lua ffluci/config.lua ffluci/i18n.lua ffluci/template.lua \
|
||||||
ffluci/cbi.lua ffluci/dispatcher.lua ffluci/menu.lua ffluci/init.lua
|
ffluci/cbi.lua ffluci/dispatcher.lua ffluci/menu.lua ffluci/init.lua
|
||||||
|
|
||||||
DIRECTORIES = ffluci/model/cbi ffluci/model/menu ffluci/controller ffluci/i18n ffluci/view/cbi
|
DIRECTORIES = ffluci/model/cbi ffluci/model/menu ffluci/controller ffluci/i18n ffluci/view/cbi ffluci/model/uci ffluci/sgi
|
||||||
|
|
||||||
OUTDIRS = $(DIRECTORIES:%=dist/%)
|
OUTDIRS = $(DIRECTORIES:%=dist/%)
|
||||||
INFILES = $(CFILES:%=src/%)
|
INFILES = $(CFILES:%=src/%)
|
||||||
|
|
2
core/contrib/webuci_bootstrap.lua
Normal file
2
core/contrib/webuci_bootstrap.lua
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
package.path = "/usr/lib/lua/?.lua;/usr/lib/lua/?/init.lua;" .. package.path
|
||||||
|
package.cpath = "/usr/lib/lua/?.so;" .. package.cpath
|
|
@ -119,14 +119,9 @@ function Map.__init__(self, config, ...)
|
||||||
self.config = config
|
self.config = config
|
||||||
self.template = "cbi/map"
|
self.template = "cbi/map"
|
||||||
self.uci = ffluci.model.uci.Session()
|
self.uci = ffluci.model.uci.Session()
|
||||||
self.ucidata = self.uci:show(self.config)
|
self.ucidata = self.uci:sections(self.config)
|
||||||
if not self.ucidata then
|
if not self.ucidata then
|
||||||
error("Unable to read UCI data: " .. self.config)
|
error("Unable to read UCI data: " .. self.config)
|
||||||
else
|
|
||||||
if not self.ucidata[self.config] then
|
|
||||||
self.ucidata[self.config] = {}
|
|
||||||
end
|
|
||||||
self.ucidata = self.ucidata[self.config]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -249,7 +244,7 @@ function AbstractSection.parse_optionals(self, section)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if field and field:len() > 0 and self.dynamic then
|
if field and #field > 0 and self.dynamic then
|
||||||
self:add_dynamic(field)
|
self:add_dynamic(field)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -267,12 +262,10 @@ function AbstractSection.parse_dynamic(self, section)
|
||||||
end
|
end
|
||||||
|
|
||||||
local arr = ffluci.util.clone(self:cfgvalue(section))
|
local arr = ffluci.util.clone(self:cfgvalue(section))
|
||||||
local form = ffluci.http.formvalue("cbid."..self.config.."."..section)
|
local form = ffluci.http.formvaluetable("cbid."..self.config.."."..section)
|
||||||
if type(form) == "table" then
|
|
||||||
for k, v in pairs(form) do
|
for k, v in pairs(form) do
|
||||||
arr[k] = v
|
arr[k] = v
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
for key,val in pairs(arr) do
|
for key,val in pairs(arr) do
|
||||||
local create = true
|
local create = true
|
||||||
|
@ -440,15 +433,13 @@ function TypedSection.parse(self)
|
||||||
|
|
||||||
-- Remove
|
-- Remove
|
||||||
crval = "cbi.rts." .. self.config
|
crval = "cbi.rts." .. self.config
|
||||||
name = ffluci.http.formvalue(crval)
|
name = ffluci.http.formvaluetable(crval)
|
||||||
if type(name) == "table" then
|
|
||||||
for k,v in pairs(name) do
|
for k,v in pairs(name) do
|
||||||
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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
for i, k in ipairs(self:cfgsections()) do
|
for i, k in ipairs(self:cfgsections()) do
|
||||||
AbstractSection.parse_dynamic(self, k)
|
AbstractSection.parse_dynamic(self, k)
|
||||||
|
|
|
@ -45,7 +45,7 @@ main.lang = "de"
|
||||||
|
|
||||||
|
|
||||||
-- Now overwrite with UCI values
|
-- Now overwrite with UCI values
|
||||||
local ucidata = ffluci.model.uci.show("luci")
|
local ucidata = ffluci.model.uci.sections("luci")
|
||||||
if ucidata and ucidata.luci then
|
if ucidata then
|
||||||
ffluci.util.update(ffluci.config, ucidata.luci)
|
ffluci.util.update(ffluci.config, ucidata)
|
||||||
end
|
end
|
|
@ -87,9 +87,6 @@ require("ffluci.template")
|
||||||
require("ffluci.config")
|
require("ffluci.config")
|
||||||
require("ffluci.sys")
|
require("ffluci.sys")
|
||||||
|
|
||||||
|
|
||||||
local tree = {}
|
|
||||||
|
|
||||||
-- Sets privilege for given category
|
-- Sets privilege for given category
|
||||||
function assign_privileges(category)
|
function assign_privileges(category)
|
||||||
local cp = ffluci.config.category_privileges
|
local cp = ffluci.config.category_privileges
|
||||||
|
@ -100,6 +97,18 @@ function assign_privileges(category)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Builds a URL from a triple of category, module and action
|
||||||
|
function build_url(category, module, action)
|
||||||
|
category = category or "public"
|
||||||
|
module = module or "index"
|
||||||
|
action = action or "index"
|
||||||
|
|
||||||
|
local pattern = ffluci.http.get_script_name() .. "/%s/%s/%s"
|
||||||
|
return pattern:format(category, module, action)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Dispatches the "request"
|
-- Dispatches the "request"
|
||||||
function dispatch(req)
|
function dispatch(req)
|
||||||
request = req
|
request = req
|
||||||
|
@ -117,10 +126,11 @@ end
|
||||||
|
|
||||||
-- Sends a 404 error code and renders the "error404" template if available
|
-- Sends a 404 error code and renders the "error404" template if available
|
||||||
function error404(message)
|
function error404(message)
|
||||||
|
ffluci.http.set_status(404, "Not Found")
|
||||||
message = message or "Not Found"
|
message = message or "Not Found"
|
||||||
|
|
||||||
if not pcall(ffluci.template.render, "error404") then
|
if not pcall(ffluci.template.render, "error404") then
|
||||||
ffluci.http.textheader()
|
ffluci.http.set_content_type("text/plain")
|
||||||
print(message)
|
print(message)
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
|
@ -128,10 +138,10 @@ end
|
||||||
|
|
||||||
-- Sends a 500 error code and renders the "error500" template if available
|
-- Sends a 500 error code and renders the "error500" template if available
|
||||||
function error500(message)
|
function error500(message)
|
||||||
ffluci.http.status(500, "Internal Server Error")
|
ffluci.http.set_status(500, "Internal Server Error")
|
||||||
|
|
||||||
if not pcall(ffluci.template.render, "error500", {message=message}) then
|
if not pcall(ffluci.template.render, "error500", {message=message}) then
|
||||||
ffluci.http.textheader()
|
ffluci.http.set_content_type("text/plain")
|
||||||
print(message)
|
print(message)
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
|
@ -212,7 +222,7 @@ end
|
||||||
-- Internal Dispatcher Functions --
|
-- Internal Dispatcher Functions --
|
||||||
|
|
||||||
function _action(request)
|
function _action(request)
|
||||||
local action = getfenv()["action_" .. request.action:gsub("-", "_")]
|
local action = getfenv(2)["action_" .. request.action:gsub("-", "_")]
|
||||||
local i18n = require("ffluci.i18n")
|
local i18n = require("ffluci.i18n")
|
||||||
|
|
||||||
if action then
|
if action then
|
||||||
|
|
|
@ -27,86 +27,8 @@ limitations under the License.
|
||||||
|
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
ENV = ENV or {}
|
|
||||||
FORM = FORM or {}
|
|
||||||
module("ffluci.http", package.seeall)
|
module("ffluci.http", package.seeall)
|
||||||
|
|
||||||
require("ffluci.util")
|
if ENV and ENV.HASERLVER then
|
||||||
|
require("ffluci.sgi.haserl")
|
||||||
-- Sets HTTP-Status-Header
|
|
||||||
function status(code, message)
|
|
||||||
print("Status: " .. tostring(code) .. " " .. message)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- Asks the browser to redirect to "url"
|
|
||||||
function redirect(url, qs)
|
|
||||||
if qs then
|
|
||||||
url = url .. "?" .. qs
|
|
||||||
end
|
|
||||||
|
|
||||||
status(302, "Found")
|
|
||||||
print("Location: " .. url .. "\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- Same as redirect but accepts category, module and action for internal use
|
|
||||||
function request_redirect(category, module, action, ...)
|
|
||||||
category = category or "public"
|
|
||||||
module = module or "index"
|
|
||||||
action = action or "index"
|
|
||||||
|
|
||||||
local pattern = script_name() .. "/%s/%s/%s"
|
|
||||||
redirect(pattern:format(category, module, action), ...)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- Returns the User's IP
|
|
||||||
function remote_addr()
|
|
||||||
return ENV.REMOTE_ADDR
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- Returns the script name
|
|
||||||
function script_name()
|
|
||||||
return ENV.SCRIPT_NAME
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- Gets form value from key
|
|
||||||
function formvalue(key, default)
|
|
||||||
local c = formvalues()
|
|
||||||
|
|
||||||
for match in key:gmatch("[%w-_]+") do
|
|
||||||
c = c[match]
|
|
||||||
if c == nil then
|
|
||||||
return default
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return c
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- Returns a table of all COOKIE, GET and POST Parameters
|
|
||||||
function formvalues()
|
|
||||||
return FORM
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- Prints plaintext content-type header
|
|
||||||
function textheader()
|
|
||||||
print("Content-Type: text/plain\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- Prints html content-type header
|
|
||||||
function htmlheader()
|
|
||||||
print("Content-Type: text/html\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- Prints xml content-type header
|
|
||||||
function xmlheader()
|
|
||||||
print("Content-Type: text/xml\n")
|
|
||||||
end
|
end
|
|
@ -25,5 +25,5 @@ limitations under the License.
|
||||||
]]--
|
]]--
|
||||||
module("ffluci", package.seeall)
|
module("ffluci", package.seeall)
|
||||||
|
|
||||||
__version__ = "0.3"
|
__version__ = "0.4"
|
||||||
__appname__ = "FFLuCI"
|
__appname__ = "FFLuCI"
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
--[[
|
--[[
|
||||||
FFLuCI - UCI wrapper library
|
FFLuCI - UCI mpdel
|
||||||
|
|
||||||
Description:
|
Description:
|
||||||
Wrapper for the /sbin/uci application, syntax of implemented functions
|
Generalized UCI model
|
||||||
is comparable to the syntax of the uci application
|
|
||||||
|
|
||||||
Any return value of false or nil can be interpreted as an error
|
|
||||||
|
|
||||||
|
|
||||||
ToDo: Reimplement in Lua
|
|
||||||
|
|
||||||
FileId:
|
FileId:
|
||||||
$Id$
|
$Id$
|
||||||
|
@ -30,24 +24,12 @@ limitations under the License.
|
||||||
|
|
||||||
]]--
|
]]--
|
||||||
module("ffluci.model.uci", package.seeall)
|
module("ffluci.model.uci", package.seeall)
|
||||||
require("ffluci.util")
|
|
||||||
require("ffluci.fs")
|
|
||||||
require("ffluci.sys")
|
|
||||||
|
|
||||||
-- The OS uci command
|
-- Test whether to load libuci-Wrapper or /sbin/uci-Wrapper
|
||||||
ucicmd = "uci"
|
if pcall(require, "uci") then
|
||||||
|
Session = require("ffluci.model.uci.libuci").Session
|
||||||
-- Session class
|
|
||||||
Session = ffluci.util.class()
|
|
||||||
|
|
||||||
-- Session constructor
|
|
||||||
function Session.__init__(self, path, uci)
|
|
||||||
uci = uci or ucicmd
|
|
||||||
if path then
|
|
||||||
self.ucicmd = uci .. " -P " .. path
|
|
||||||
else
|
else
|
||||||
self.ucicmd = uci
|
Session = require("ffluci.model.uci.wrapper").Session
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- The default Session
|
-- The default Session
|
||||||
|
@ -61,156 +43,48 @@ end
|
||||||
|
|
||||||
|
|
||||||
-- Wrapper for "uci add"
|
-- Wrapper for "uci add"
|
||||||
function Session.add(self, config, section_type)
|
|
||||||
return self:_uci("add " .. _path(config) .. " " .. _path(section_type))
|
|
||||||
end
|
|
||||||
|
|
||||||
function add(...)
|
function add(...)
|
||||||
return default:add(...)
|
return default:add(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Wrapper for "uci changes"
|
-- Wrapper for "uci changes"
|
||||||
function Session.changes(self, config)
|
|
||||||
return self:_uci("changes " .. _path(config))
|
|
||||||
end
|
|
||||||
|
|
||||||
function changes(...)
|
function changes(...)
|
||||||
return default:changes(...)
|
return default:changes(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Wrapper for "uci commit"
|
-- Wrapper for "uci commit"
|
||||||
function Session.commit(self, config)
|
|
||||||
return self:_uci2("commit " .. _path(config))
|
|
||||||
end
|
|
||||||
|
|
||||||
function commit(...)
|
function commit(...)
|
||||||
return default:commit(...)
|
return default:commit(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Wrapper for "uci del"
|
-- Wrapper for "uci del"
|
||||||
function Session.del(self, config, section, option)
|
|
||||||
return self:_uci2("del " .. _path(config, section, option))
|
|
||||||
end
|
|
||||||
|
|
||||||
function del(...)
|
function del(...)
|
||||||
return default:del(...)
|
return default:del(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Wrapper for "uci get"
|
-- Wrapper for "uci get"
|
||||||
function Session.get(self, config, section, option)
|
|
||||||
return self:_uci("get " .. _path(config, section, option))
|
|
||||||
end
|
|
||||||
|
|
||||||
function get(...)
|
function get(...)
|
||||||
return default:get(...)
|
return default:get(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Wrapper for "uci revert"
|
-- Wrapper for "uci revert"
|
||||||
function Session.revert(self, config)
|
|
||||||
return self:_uci2("revert " .. _path(config))
|
|
||||||
end
|
|
||||||
|
|
||||||
function revert(...)
|
function revert(...)
|
||||||
return default:revert(...)
|
return default:revert(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Wrapper for "uci show"
|
-- Wrapper for "uci show"
|
||||||
function Session.show(self, config, ...)
|
function sections(...)
|
||||||
return self:_uci3("show " .. _path(config), ...)
|
return default:sections(...)
|
||||||
end
|
|
||||||
|
|
||||||
function show(...)
|
|
||||||
return default:show(...)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Wrapper for "uci set"
|
-- Wrapper for "uci set"
|
||||||
function Session.set(self, config, section, option, value)
|
|
||||||
return self:_uci2("set " .. _path(config, section, option, value))
|
|
||||||
end
|
|
||||||
|
|
||||||
function set(...)
|
function set(...)
|
||||||
return default:set(...)
|
return default:set(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Internal functions --
|
|
||||||
|
|
||||||
function Session._uci(self, cmd)
|
|
||||||
local res = ffluci.sys.exec(self.ucicmd .. " 2>/dev/null " .. cmd)
|
|
||||||
|
|
||||||
if res:len() == 0 then
|
|
||||||
return nil
|
|
||||||
else
|
|
||||||
return res:sub(1, res:len()-1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Session._uci2(self, cmd)
|
|
||||||
local res = ffluci.sys.exec(self.ucicmd .. " 2>&1 " .. cmd)
|
|
||||||
|
|
||||||
if res:len() > 0 then
|
|
||||||
return false, res
|
|
||||||
else
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Session._uci3(self, cmd, raw)
|
|
||||||
local res = ffluci.sys.execl(self.ucicmd .. " 2>&1 " .. cmd)
|
|
||||||
if res[1] and res[1]:sub(1, self.ucicmd:len()+1) == self.ucicmd..":" then
|
|
||||||
return nil, res[1]
|
|
||||||
end
|
|
||||||
|
|
||||||
if raw then
|
|
||||||
return table.concat(res, "\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
tbl = {}
|
|
||||||
|
|
||||||
for k,line in pairs(res) do
|
|
||||||
c, s, t = line:match("^([^.]-)%.([^.]-)=(.-)$")
|
|
||||||
if c then
|
|
||||||
tbl[c] = tbl[c] or {}
|
|
||||||
tbl[c][".order"] = tbl[c][".order"] or {}
|
|
||||||
|
|
||||||
tbl[c][s] = {}
|
|
||||||
table.insert(tbl[c][".order"], s)
|
|
||||||
tbl[c][s][".type"] = t
|
|
||||||
end
|
|
||||||
|
|
||||||
c, s, o, v = line:match("^([^.]-)%.([^.]-)%.([^.]-)=(.-)$")
|
|
||||||
if c then
|
|
||||||
tbl[c][s][o] = v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return tbl
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Build path (config.section.option=value) and prevent command injection
|
|
||||||
function _path(...)
|
|
||||||
local result = ""
|
|
||||||
|
|
||||||
-- Not using ipairs because it is not reliable in case of nil arguments
|
|
||||||
arg.n = nil
|
|
||||||
for k,v in pairs(arg) do
|
|
||||||
if v then
|
|
||||||
v = tostring(v)
|
|
||||||
if k == 1 then
|
|
||||||
result = "'" .. v:gsub("['.]", "") .. "'"
|
|
||||||
elseif k < 4 then
|
|
||||||
result = result .. ".'" .. v:gsub("['.]", "") .. "'"
|
|
||||||
elseif k == 4 then
|
|
||||||
result = result .. "='" .. v:gsub("'", "") .. "'"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return result
|
|
||||||
end
|
|
162
core/src/ffluci/model/uci/libuci.lua
Normal file
162
core/src/ffluci/model/uci/libuci.lua
Normal file
|
@ -0,0 +1,162 @@
|
||||||
|
--[[
|
||||||
|
FFLuCI - UCI libuci wrapper
|
||||||
|
|
||||||
|
Description:
|
||||||
|
Wrapper for the libuci Lua bindings
|
||||||
|
|
||||||
|
FileId:
|
||||||
|
$Id$
|
||||||
|
|
||||||
|
License:
|
||||||
|
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
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
]]--
|
||||||
|
|
||||||
|
module("ffluci.model.uci.libuci", package.seeall)
|
||||||
|
|
||||||
|
require("ffluci.util")
|
||||||
|
require("ffluci.fs")
|
||||||
|
require("ffluci.sys")
|
||||||
|
|
||||||
|
-- The OS uci command
|
||||||
|
ucicmd = "uci"
|
||||||
|
|
||||||
|
-- Session class
|
||||||
|
Session = ffluci.util.class()
|
||||||
|
|
||||||
|
-- Session constructor
|
||||||
|
function Session.__init__(self, path, uci)
|
||||||
|
uci = uci or ucicmd
|
||||||
|
if path then
|
||||||
|
self.ucicmd = uci .. " -P " .. path
|
||||||
|
else
|
||||||
|
self.ucicmd = uci
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session.add(self, config, section_type)
|
||||||
|
return self:_uci("add " .. _path(config) .. " " .. _path(section_type))
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session.changes(self, config)
|
||||||
|
return self:_uci("changes " .. _path(config))
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session.commit(self, config)
|
||||||
|
return self:_uci2("commit " .. _path(config))
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session.del(self, config, section, option)
|
||||||
|
return self:_uci2("del " .. _path(config, section, option))
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session.get(self, config, section, option)
|
||||||
|
return self:_uci("get " .. _path(config, section, option))
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session.revert(self, config)
|
||||||
|
return self:_uci2("revert " .. _path(config))
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session.sections(self, config)
|
||||||
|
if not config then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local r1, r2 = self:_uci3("show " .. _path(config))
|
||||||
|
if type(r1) == "table" then
|
||||||
|
return r1[config]
|
||||||
|
else
|
||||||
|
return nil, r2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session.set(self, config, section, option, value)
|
||||||
|
return self:_uci2("set " .. _path(config, section, option, value))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- Internal functions --
|
||||||
|
|
||||||
|
|
||||||
|
function Session._uci(self, cmd)
|
||||||
|
local res = ffluci.sys.exec(self.ucicmd .. " 2>/dev/null " .. cmd)
|
||||||
|
|
||||||
|
if res:len() == 0 then
|
||||||
|
return nil
|
||||||
|
else
|
||||||
|
return res:sub(1, res:len()-1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session._uci2(self, cmd)
|
||||||
|
local res = ffluci.sys.exec(self.ucicmd .. " 2>&1 " .. cmd)
|
||||||
|
|
||||||
|
if res:len() > 0 then
|
||||||
|
return false, res
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session._uci3(self, cmd)
|
||||||
|
local res = ffluci.sys.execl(self.ucicmd .. " 2>&1 " .. cmd)
|
||||||
|
if res[1] and res[1]:sub(1, self.ucicmd:len()+1) == self.ucicmd..":" then
|
||||||
|
return nil, res[1]
|
||||||
|
end
|
||||||
|
|
||||||
|
tbl = {}
|
||||||
|
|
||||||
|
for k,line in pairs(res) do
|
||||||
|
c, s, t = line:match("^([^.]-)%.([^.]-)=(.-)$")
|
||||||
|
if c then
|
||||||
|
tbl[c] = tbl[c] or {}
|
||||||
|
tbl[c][".order"] = tbl[c][".order"] or {}
|
||||||
|
|
||||||
|
tbl[c][s] = {}
|
||||||
|
table.insert(tbl[c][".order"], s)
|
||||||
|
tbl[c][s][".type"] = t
|
||||||
|
end
|
||||||
|
|
||||||
|
c, s, o, v = line:match("^([^.]-)%.([^.]-)%.([^.]-)=(.-)$")
|
||||||
|
if c then
|
||||||
|
tbl[c][s][o] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return tbl
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Build path (config.section.option=value) and prevent command injection
|
||||||
|
function _path(...)
|
||||||
|
local result = ""
|
||||||
|
|
||||||
|
-- Not using ipairs because it is not reliable in case of nil arguments
|
||||||
|
arg.n = nil
|
||||||
|
for k,v in pairs(arg) do
|
||||||
|
if v then
|
||||||
|
v = tostring(v)
|
||||||
|
if k == 1 then
|
||||||
|
result = "'" .. v:gsub("['.]", "") .. "'"
|
||||||
|
elseif k < 4 then
|
||||||
|
result = result .. ".'" .. v:gsub("['.]", "") .. "'"
|
||||||
|
elseif k == 4 then
|
||||||
|
result = result .. "='" .. v:gsub("'", "") .. "'"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
165
core/src/ffluci/model/uci/wrapper.lua
Normal file
165
core/src/ffluci/model/uci/wrapper.lua
Normal file
|
@ -0,0 +1,165 @@
|
||||||
|
--[[
|
||||||
|
FFLuCI - UCI wrapper library
|
||||||
|
|
||||||
|
Description:
|
||||||
|
Wrapper for the /sbin/uci application, syntax of implemented functions
|
||||||
|
is comparable to the syntax of the uci application
|
||||||
|
|
||||||
|
Any return value of false or nil can be interpreted as an error
|
||||||
|
|
||||||
|
FileId:
|
||||||
|
$Id$
|
||||||
|
|
||||||
|
License:
|
||||||
|
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
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
]]--
|
||||||
|
|
||||||
|
module("ffluci.model.uci.wrapper", package.seeall)
|
||||||
|
|
||||||
|
require("ffluci.util")
|
||||||
|
require("ffluci.fs")
|
||||||
|
require("ffluci.sys")
|
||||||
|
|
||||||
|
-- The OS uci command
|
||||||
|
ucicmd = "uci"
|
||||||
|
|
||||||
|
-- Session class
|
||||||
|
Session = ffluci.util.class()
|
||||||
|
|
||||||
|
-- Session constructor
|
||||||
|
function Session.__init__(self, path, uci)
|
||||||
|
uci = uci or ucicmd
|
||||||
|
if path then
|
||||||
|
self.ucicmd = uci .. " -P " .. path
|
||||||
|
else
|
||||||
|
self.ucicmd = uci
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session.add(self, config, section_type)
|
||||||
|
return self:_uci("add " .. _path(config) .. " " .. _path(section_type))
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session.changes(self, config)
|
||||||
|
return self:_uci("changes " .. _path(config))
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session.commit(self, config)
|
||||||
|
return self:_uci2("commit " .. _path(config))
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session.del(self, config, section, option)
|
||||||
|
return self:_uci2("del " .. _path(config, section, option))
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session.get(self, config, section, option)
|
||||||
|
return self:_uci("get " .. _path(config, section, option))
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session.revert(self, config)
|
||||||
|
return self:_uci2("revert " .. _path(config))
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session.sections(self, config)
|
||||||
|
if not config then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local r1, r2 = self:_uci3("show " .. _path(config))
|
||||||
|
if type(r1) == "table" then
|
||||||
|
return r1[config]
|
||||||
|
else
|
||||||
|
return nil, r2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session.set(self, config, section, option, value)
|
||||||
|
return self:_uci2("set " .. _path(config, section, option, value))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- Internal functions --
|
||||||
|
|
||||||
|
|
||||||
|
function Session._uci(self, cmd)
|
||||||
|
local res = ffluci.sys.exec(self.ucicmd .. " 2>/dev/null " .. cmd)
|
||||||
|
|
||||||
|
if res:len() == 0 then
|
||||||
|
return nil
|
||||||
|
else
|
||||||
|
return res:sub(1, res:len()-1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session._uci2(self, cmd)
|
||||||
|
local res = ffluci.sys.exec(self.ucicmd .. " 2>&1 " .. cmd)
|
||||||
|
|
||||||
|
if res:len() > 0 then
|
||||||
|
return false, res
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Session._uci3(self, cmd)
|
||||||
|
local res = ffluci.sys.execl(self.ucicmd .. " 2>&1 " .. cmd)
|
||||||
|
if res[1] and res[1]:sub(1, self.ucicmd:len()+1) == self.ucicmd..":" then
|
||||||
|
return nil, res[1]
|
||||||
|
end
|
||||||
|
|
||||||
|
tbl = {}
|
||||||
|
|
||||||
|
for k,line in pairs(res) do
|
||||||
|
c, s, t = line:match("^([^.]-)%.([^.]-)=(.-)$")
|
||||||
|
if c then
|
||||||
|
tbl[c] = tbl[c] or {}
|
||||||
|
tbl[c][".order"] = tbl[c][".order"] or {}
|
||||||
|
|
||||||
|
tbl[c][s] = {}
|
||||||
|
table.insert(tbl[c][".order"], s)
|
||||||
|
tbl[c][s][".type"] = t
|
||||||
|
end
|
||||||
|
|
||||||
|
c, s, o, v = line:match("^([^.]-)%.([^.]-)%.([^.]-)=(.-)$")
|
||||||
|
if c then
|
||||||
|
tbl[c][s][o] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return tbl
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Build path (config.section.option=value) and prevent command injection
|
||||||
|
function _path(...)
|
||||||
|
local result = ""
|
||||||
|
|
||||||
|
-- Not using ipairs because it is not reliable in case of nil arguments
|
||||||
|
arg.n = nil
|
||||||
|
for k,v in pairs(arg) do
|
||||||
|
if v then
|
||||||
|
v = tostring(v)
|
||||||
|
if k == 1 then
|
||||||
|
result = "'" .. v:gsub("['.]", "") .. "'"
|
||||||
|
elseif k < 4 then
|
||||||
|
result = result .. ".'" .. v:gsub("['.]", "") .. "'"
|
||||||
|
elseif k == 4 then
|
||||||
|
result = result .. "='" .. v:gsub("'", "") .. "'"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
89
core/src/ffluci/sgi/haserl.lua
Normal file
89
core/src/ffluci/sgi/haserl.lua
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
--[[
|
||||||
|
FFLuCI - SGI-Module for Haserl
|
||||||
|
|
||||||
|
Description:
|
||||||
|
Server Gateway Interface for Haserl
|
||||||
|
|
||||||
|
FileId:
|
||||||
|
$Id$
|
||||||
|
|
||||||
|
License:
|
||||||
|
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
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
]]--
|
||||||
|
module("ffluci.sgi.haserl", package.seeall)
|
||||||
|
|
||||||
|
ENV = ENV or {}
|
||||||
|
FORM = FORM or {}
|
||||||
|
require("ffluci.util")
|
||||||
|
|
||||||
|
-- HTTP interface
|
||||||
|
|
||||||
|
-- Returns a table of all COOKIE, GET and POST Parameters
|
||||||
|
function ffluci.http.formvalues(prefix)
|
||||||
|
return FORM
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Gets form value from key
|
||||||
|
function ffluci.http.formvalue(key, default)
|
||||||
|
local c = ffluci.http.formvalues()
|
||||||
|
|
||||||
|
for match in key:gmatch("[%w-_]+") do
|
||||||
|
c = c[match]
|
||||||
|
if c == nil then
|
||||||
|
return default
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return c
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Gets a table of values with a certain prefix
|
||||||
|
function ffluci.http.formvaluetable(prefix)
|
||||||
|
return formvalue(prefix, {})
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Returns the User's IP
|
||||||
|
function ffluci.http.get_remote_addr()
|
||||||
|
return ENV.REMOTE_ADDR
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Returns the script name
|
||||||
|
function ffluci.http.get_script_name()
|
||||||
|
return ENV.SCRIPT_NAME
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Asks the browser to redirect to "url"
|
||||||
|
function ffluci.http.redirect(url, qs)
|
||||||
|
if qs then
|
||||||
|
url = url .. "?" .. qs
|
||||||
|
end
|
||||||
|
|
||||||
|
set_status(302, "Found")
|
||||||
|
print("Location: " .. url .. "\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Set Content-Type
|
||||||
|
function ffluci.http.set_content_type(type)
|
||||||
|
print("Content-Type: "..type.."\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Sets HTTP-Status-Header
|
||||||
|
function ffluci.http.set_status(code, message)
|
||||||
|
print("Status: " .. tostring(code) .. " " .. message)
|
||||||
|
end
|
|
@ -54,7 +54,7 @@ compiler_enable_bytecode = false
|
||||||
viewns = {
|
viewns = {
|
||||||
translate = ffluci.i18n.translate,
|
translate = ffluci.i18n.translate,
|
||||||
config = function(...) return ffluci.model.uci.get(...) or "" end,
|
config = function(...) return ffluci.model.uci.get(...) or "" end,
|
||||||
controller = ffluci.http.script_name(),
|
controller = ffluci.http.get_script_name(),
|
||||||
media = ffluci.config.main.mediaurlbase,
|
media = ffluci.config.main.mediaurlbase,
|
||||||
write = io.write,
|
write = io.write,
|
||||||
include = function(name) Template(name):render(getfenv(2)) end,
|
include = function(name) Template(name):render(getfenv(2)) end,
|
||||||
|
|
|
@ -5,7 +5,7 @@ local req = require("ffluci.dispatcher").request
|
||||||
local menu = require("ffluci.menu").get()[req.category]
|
local menu = require("ffluci.menu").get()[req.category]
|
||||||
menu = menu or {}
|
menu = menu or {}
|
||||||
require("ffluci.i18n").loadc("default")
|
require("ffluci.i18n").loadc("default")
|
||||||
require("ffluci.http").htmlheader()
|
require("ffluci.http").set_content_type("text/html")
|
||||||
%><?xml version="1.0" encoding="utf-8"?>
|
%><?xml version="1.0" encoding="utf-8"?>
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
|
|
@ -6,10 +6,10 @@ function action_wizard()
|
||||||
end
|
end
|
||||||
|
|
||||||
local ifaces = {}
|
local ifaces = {}
|
||||||
local wldevs = ffluci.model.uci.show("wireless")
|
local wldevs = ffluci.model.uci.sections("wireless")
|
||||||
|
|
||||||
if wldevs then
|
if wldevs then
|
||||||
for k, v in pairs(wldevs.wireless) do
|
for k, v in pairs(wldevs) do
|
||||||
if v[".type"] == "wifi-device" then
|
if v[".type"] == "wifi-device" then
|
||||||
table.insert(ifaces, k)
|
table.insert(ifaces, k)
|
||||||
end
|
end
|
||||||
|
@ -55,9 +55,9 @@ function configure_freifunk()
|
||||||
uci:set("network", "ffdhcp", "ipaddr", dhcpip)
|
uci:set("network", "ffdhcp", "ipaddr", dhcpip)
|
||||||
uci:set("network", "ffdhcp", "netmask", uci:get("freifunk", "community", "dhcpmask"))
|
uci:set("network", "ffdhcp", "netmask", uci:get("freifunk", "community", "dhcpmask"))
|
||||||
|
|
||||||
local dhcp = uci:show("dhcp")
|
local dhcp = uci:sections("dhcp")
|
||||||
if dhcp then
|
if dhcp then
|
||||||
for k, v in pairs(dhcp.dhcp) do
|
for k, v in pairs(dhcp) do
|
||||||
if v[".type"] == "dhcp" and v.interface == "ffdhcp" then
|
if v[".type"] == "dhcp" and v.interface == "ffdhcp" then
|
||||||
uci:del("dhcp", k)
|
uci:del("dhcp", k)
|
||||||
end
|
end
|
||||||
|
@ -72,9 +72,9 @@ function configure_freifunk()
|
||||||
uci:set("dhcp", sk, "leasetime", "30m")
|
uci:set("dhcp", sk, "leasetime", "30m")
|
||||||
end
|
end
|
||||||
|
|
||||||
local splash = uci:show("luci_splash")
|
local splash = uci:sections("luci_splash")
|
||||||
if splash then
|
if splash then
|
||||||
for k, v in pairs(splash.luci_splash) do
|
for k, v in pairs(splash) do
|
||||||
if v[".type"] == "iface" then
|
if v[".type"] == "iface" then
|
||||||
uci:del("luci_splash", k)
|
uci:del("luci_splash", k)
|
||||||
end
|
end
|
||||||
|
@ -86,8 +86,8 @@ function configure_freifunk()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Configure OLSR
|
-- Configure OLSR
|
||||||
if ffluci.http.formvalue("olsr") and uci:show("olsr") then
|
if ffluci.http.formvalue("olsr") and uci:sections("olsr") then
|
||||||
for k, v in pairs(uci:show("olsr").olsr) do
|
for k, v in pairs(uci:sections("olsr")) do
|
||||||
if v[".type"] == "Interface" or v[".type"] == "LoadPlugin" then
|
if v[".type"] == "Interface" or v[".type"] == "LoadPlugin" then
|
||||||
uci:del("olsr", k)
|
uci:del("olsr", k)
|
||||||
end
|
end
|
||||||
|
@ -122,14 +122,13 @@ function configure_freifunk()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Configure Wifi
|
-- Configure Wifi
|
||||||
local wifi = ffluci.http.formvalue("wifi")
|
local wcfg = uci:sections("wireless")
|
||||||
local wcfg = uci:show("wireless")
|
if wcfg then
|
||||||
if type(wifi) == "table" and wcfg then
|
for iface, v in pairs(wcfg) do
|
||||||
for iface, v in pairs(wifi) do
|
if v[".type"] == "wifi-device" and ffluci.http.formvalue("wifi."..iface) then
|
||||||
if wcfg.wireless[iface] then
|
|
||||||
-- Cleanup
|
-- Cleanup
|
||||||
for k, v in pairs(wcfg.wireless) do
|
for k, j in pairs(wcfg) do
|
||||||
if v[".type"] == "wifi-iface" and v.device == iface then
|
if j[".type"] == "wifi-iface" and j.device == iface then
|
||||||
uci:del("wireless", k)
|
uci:del("wireless", k)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -152,5 +151,5 @@ function configure_freifunk()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
ffluci.http.request_redirect("admin", "uci", "changes")
|
ffluci.http.redirect(ffluci.dispatcher.build_url("admin", "uci", "changes"))
|
||||||
end
|
end
|
|
@ -61,8 +61,7 @@ function action_packages()
|
||||||
|
|
||||||
|
|
||||||
-- Packets to be installed
|
-- Packets to be installed
|
||||||
local install = ffluci.http.formvalue("install")
|
local install = submit and ffluci.http.formvaluetable("install")
|
||||||
install = (type(install) == "table" and submit) and install or nil
|
|
||||||
|
|
||||||
-- Install from URL
|
-- Install from URL
|
||||||
local url = ffluci.http.formvalue("url")
|
local url = ffluci.http.formvalue("url")
|
||||||
|
@ -82,8 +81,7 @@ function action_packages()
|
||||||
|
|
||||||
|
|
||||||
-- Remove packets
|
-- Remove packets
|
||||||
local remove = ffluci.http.formvalue("remove")
|
local remove = submit and ffluci.http.formvaluetable("remove")
|
||||||
remove = (type(remove) == "table" and submit) and remove or nil
|
|
||||||
if remove then
|
if remove then
|
||||||
for k, v in pairs(remove) do
|
for k, v in pairs(remove) do
|
||||||
void, remove[k] = ipkg.remove(k)
|
void, remove[k] = ipkg.remove(k)
|
||||||
|
@ -187,7 +185,7 @@ function action_upgrade()
|
||||||
if plat and imgname then
|
if plat and imgname then
|
||||||
local kpattern = nil
|
local kpattern = nil
|
||||||
if keepcfg then
|
if keepcfg then
|
||||||
local files = ffluci.model.uci.show("luci", "flash_keep")
|
local files = ffluci.model.uci.sections("luci").flash_keep
|
||||||
if files.luci and files.luci.flash_keep then
|
if files.luci and files.luci.flash_keep then
|
||||||
kpattern = ""
|
kpattern = ""
|
||||||
for k,v in pairs(files.luci.flash_keep) do
|
for k,v in pairs(files.luci.flash_keep) do
|
||||||
|
|
|
@ -6,14 +6,14 @@ function action_activate()
|
||||||
os.execute("luci-splash add "..mac.." >/dev/null 2>&1")
|
os.execute("luci-splash add "..mac.." >/dev/null 2>&1")
|
||||||
ffluci.http.redirect(ffluci.model.uci.get("freifunk", "community", "homepage"))
|
ffluci.http.redirect(ffluci.model.uci.get("freifunk", "community", "homepage"))
|
||||||
else
|
else
|
||||||
ffluci.http.request_redirect()
|
ffluci.http.redirect(ffluci.dispatcher.build_url())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function action_accepted()
|
function action_accepted()
|
||||||
ffluci.http.request_redirect()
|
ffluci.http.redirect(ffluci.dispatcher.build_url())
|
||||||
end
|
end
|
||||||
|
|
||||||
function action_unknown()
|
function action_unknown()
|
||||||
ffluci.http.request_redirect()
|
ffluci.http.redirect(ffluci.dispatcher.build_url())
|
||||||
end
|
end
|
|
@ -10,7 +10,7 @@ s.addremove = true
|
||||||
s.anonymous = true
|
s.anonymous = true
|
||||||
|
|
||||||
iface = s:option(ListValue, "interface", "Schnittstelle")
|
iface = s:option(ListValue, "interface", "Schnittstelle")
|
||||||
for k, v in pairs(ffluci.model.uci.show("network").network) do
|
for k, v in pairs(ffluci.model.uci.sections("network")) do
|
||||||
if v[".type"] == "interface" and k ~= "loopback" then
|
if v[".type"] == "interface" and k ~= "loopback" then
|
||||||
iface:value(k)
|
iface:value(k)
|
||||||
s:depends("interface", k) -- Only change sections with existing interfaces
|
s:depends("interface", k) -- Only change sections with existing interfaces
|
||||||
|
|
|
@ -8,7 +8,7 @@ s.addremove = true
|
||||||
s.anonymous = true
|
s.anonymous = true
|
||||||
|
|
||||||
iface = s:option(ListValue, "interface", "Schnittstelle")
|
iface = s:option(ListValue, "interface", "Schnittstelle")
|
||||||
for k, v in pairs(ffluci.model.uci.show("network").network) do
|
for k, v in pairs(ffluci.model.uci.sections("network")) do
|
||||||
if v[".type"] == "interface" and k ~= "loopback" then
|
if v[".type"] == "interface" and k ~= "loopback" then
|
||||||
iface:value(k)
|
iface:value(k)
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,7 +51,7 @@ i.dynamic = true
|
||||||
|
|
||||||
network = i:option(ListValue, "Interface", "Netzwerkschnittstellen")
|
network = i:option(ListValue, "Interface", "Netzwerkschnittstellen")
|
||||||
network:value("")
|
network:value("")
|
||||||
for k, v in pairs(ffluci.model.uci.show("network").network) do
|
for k, v in pairs(ffluci.model.uci.sections("network")) do
|
||||||
if v[".type"] == "interface" and k ~= "loopback" then
|
if v[".type"] == "interface" and k ~= "loopback" then
|
||||||
network:value(k)
|
network:value(k)
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ s.addremove = true
|
||||||
s.anonymous = true
|
s.anonymous = true
|
||||||
|
|
||||||
iface = s:option(ListValue, "network", "Schnittstelle")
|
iface = s:option(ListValue, "network", "Schnittstelle")
|
||||||
for k, v in pairs(ffluci.model.uci.show("network").network) do
|
for k, v in pairs(ffluci.model.uci.sections("network")) do
|
||||||
if v[".type"] == "interface" and k ~= "loopback" then
|
if v[".type"] == "interface" and k ~= "loopback" then
|
||||||
iface:value(k)
|
iface:value(k)
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ s.anonymous = true
|
||||||
s:option(Value, "ssid", "Netzkennung (ESSID)").maxlength = 32
|
s:option(Value, "ssid", "Netzkennung (ESSID)").maxlength = 32
|
||||||
|
|
||||||
device = s:option(ListValue, "device", "Gerät")
|
device = s:option(ListValue, "device", "Gerät")
|
||||||
local d = ffluci.model.uci.show("wireless").wireless
|
local d = ffluci.model.uci.sections("wireless")
|
||||||
if d then
|
if d then
|
||||||
for k, v in pairs(d) do
|
for k, v in pairs(d) do
|
||||||
if v[".type"] == "wifi-device" then
|
if v[".type"] == "wifi-device" then
|
||||||
|
@ -22,7 +22,7 @@ end
|
||||||
|
|
||||||
network = s:option(ListValue, "network", "Netzwerk", "WLAN-Netz zu Netzwerk hinzufügen")
|
network = s:option(ListValue, "network", "Netzwerk", "WLAN-Netz zu Netzwerk hinzufügen")
|
||||||
network:value("")
|
network:value("")
|
||||||
for k, v in pairs(ffluci.model.uci.show("network").network) do
|
for k, v in pairs(ffluci.model.uci.sections("network")) do
|
||||||
if v[".type"] == "interface" and k ~= "loopback" then
|
if v[".type"] == "interface" and k ~= "loopback" then
|
||||||
network:value(k)
|
network:value(k)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<%+header%>
|
<%+header%>
|
||||||
<% local contact = ffluci.model.uci.show("freifunk").freifunk.contact %>
|
<% local contact = ffluci.model.uci.sections("freifunk").contact %>
|
||||||
<h1><%:contact Kontakt%></h1>
|
<h1><%:contact Kontakt%></h1>
|
||||||
<table cellspacing="0" cellpadding="6">
|
<table cellspacing="0" cellpadding="6">
|
||||||
<tr><th><%:nickname Pseudonym%>:</th><td><%=contact.nickname%></td></tr>
|
<tr><th><%:nickname Pseudonym%>:</th><td><%=contact.nickname%></td></tr>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<%+header%>
|
<%+header%>
|
||||||
<% local ff = ffluci.model.uci.show("freifunk").freifunk %>
|
<% local ff = ffluci.model.uci.sections("freifunk") %>
|
||||||
<h1><%:hellonet Hallo und willkommen im Netz von%> <%=ff.community.name%>!</h1>
|
<h1><%:hellonet Hallo und willkommen im Netz von%> <%=ff.community.name%>!</h1>
|
||||||
<p><%:public1 Wir sind eine Initiative zur Schaffung eines freien, offenen und unabhängigen Funknetzwerks auf WLAN-Basis.%><br />
|
<p><%:public1 Wir sind eine Initiative zur Schaffung eines freien, offenen und unabhängigen Funknetzwerks auf WLAN-Basis.%><br />
|
||||||
<%:public2 Dies ist der Zugangspunkt %><%=ffluci.sys.hostname()%>. <%:public3 Er wird betrieben von %>
|
<%:public2 Dies ist der Zugangspunkt %><%=ffluci.sys.hostname()%>. <%:public3 Er wird betrieben von %>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<%
|
<%
|
||||||
ffluci.http.textheader()
|
ffluci.http.set_content_type("text/plain")
|
||||||
for k, v in pairs(ffluci.sys.wifi.getiwconfig()) do
|
for k, v in pairs(ffluci.sys.wifi.getiwconfig()) do
|
||||||
%>
|
%>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<%
|
<%
|
||||||
ffluci.http.textheader()
|
ffluci.http.set_content_type("text/plain")
|
||||||
for iface, cells in pairs(ffluci.sys.wifi.iwscan()) do
|
for iface, cells in pairs(ffluci.sys.wifi.iwscan()) do
|
||||||
for i, cell in ipairs(cells) do
|
for i, cell in ipairs(cells) do
|
||||||
%>
|
%>
|
||||||
|
|
|
@ -3,7 +3,7 @@ module("ffluci.controller.rpc.luciinfo", package.seeall)
|
||||||
function action_index()
|
function action_index()
|
||||||
local uci = ffluci.model.uci.StateSession()
|
local uci = ffluci.model.uci.StateSession()
|
||||||
|
|
||||||
ffluci.http.textheader()
|
ffluci.http.set_content_type("text/plain")
|
||||||
|
|
||||||
-- General
|
-- General
|
||||||
print("luciinfo.api=1")
|
print("luciinfo.api=1")
|
||||||
|
@ -26,8 +26,14 @@ function action_index()
|
||||||
|
|
||||||
|
|
||||||
-- Freifunk
|
-- Freifunk
|
||||||
local ff = uci:show("freifunk", true) or ""
|
local ff = uci:sections("freifunk") or {}
|
||||||
print(ff)
|
for k, v in pairs(ff) do
|
||||||
|
if k:sub(1, 1) ~= "." then
|
||||||
|
for i, j in pairs(v) do
|
||||||
|
print("freifunk." .. k .. "." .. i .. "=" .. j)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function sanitize(val)
|
function sanitize(val)
|
||||||
|
|
Loading…
Reference in a new issue