* CBI updates
This commit is contained in:
parent
93c55f3c5d
commit
ef01ff75db
8 changed files with 71 additions and 19 deletions
|
@ -104,6 +104,26 @@ function Map.__init__(self, config, ...)
|
||||||
self.template = "cbi/map"
|
self.template = "cbi/map"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Map.parse(self)
|
||||||
|
self.ucidata = ffluci.model.uci.show(self.config)
|
||||||
|
if not self.ucidata then
|
||||||
|
error("Unable to read UCI data: " .. self.config)
|
||||||
|
else
|
||||||
|
self.ucidata = self.ucidata[self.config]
|
||||||
|
end
|
||||||
|
Node.parse(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Map.render(self)
|
||||||
|
self.ucidata = ffluci.model.uci.show(self.config)
|
||||||
|
if not self.ucidata then
|
||||||
|
error("Unable to read UCI data: " .. self.config)
|
||||||
|
else
|
||||||
|
self.ucidata = self.ucidata[self.config]
|
||||||
|
end
|
||||||
|
Node.render(self)
|
||||||
|
end
|
||||||
|
|
||||||
function Map.section(self, class, ...)
|
function Map.section(self, class, ...)
|
||||||
if instanceof(class, AbstractSection) then
|
if instanceof(class, AbstractSection) then
|
||||||
local obj = class(...)
|
local obj = class(...)
|
||||||
|
@ -116,11 +136,6 @@ function Map.section(self, class, ...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Map.read(self)
|
|
||||||
self.ucidata = self.ucidata or ffluci.model.uci.show(self.config)[self.config]
|
|
||||||
return self.ucidata
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
AbstractSection
|
AbstractSection
|
||||||
]]--
|
]]--
|
||||||
|
@ -181,6 +196,15 @@ function TypedSection.__init__(self, ...)
|
||||||
self.valid = nil
|
self.valid = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function TypedSection.parse(self)
|
||||||
|
for k, v in pairs(self:ucisections()) do
|
||||||
|
for i, node in ipairs(self.children) do
|
||||||
|
node.section = k
|
||||||
|
node:parse()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function TypedSection.render_children(self, section)
|
function TypedSection.render_children(self, section)
|
||||||
for k, node in ipairs(self.children) do
|
for k, node in ipairs(self.children) do
|
||||||
node.section = section
|
node.section = section
|
||||||
|
@ -190,7 +214,7 @@ end
|
||||||
|
|
||||||
function TypedSection.ucisections(self)
|
function TypedSection.ucisections(self)
|
||||||
local sections = {}
|
local sections = {}
|
||||||
for k, v in pairs(self.map:read()) do
|
for k, v in pairs(self.map.ucidata) do
|
||||||
if v[".type"] == self.sectiontype then
|
if v[".type"] == self.sectiontype then
|
||||||
sections[k] = v
|
sections[k] = v
|
||||||
end
|
end
|
||||||
|
@ -217,14 +241,20 @@ function AbstractValue.__init__(self, option, ...)
|
||||||
self.default = nil
|
self.default = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function AbstractValue.formvalue(self)
|
function AbstractValue.formvalue(self)
|
||||||
local key = "uci."..self.map.config.."."..self.section.."."..self.option
|
local key = "cbid."..self.map.config.."."..self.section.."."..self.option
|
||||||
return ffluci.http.formvalue(key)
|
return ffluci.http.formvalue(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function AbstractValue.parse(self)
|
||||||
|
local fvalue = self:validate(self:formvalue())
|
||||||
|
if fvalue and not (fvalue == self:ucivalue()) then
|
||||||
|
self:write(fvalue)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function AbstractValue.ucivalue(self)
|
function AbstractValue.ucivalue(self)
|
||||||
return self.map:read()[self.section][self.option]
|
return self.map.ucidata[self.section][self.option]
|
||||||
end
|
end
|
||||||
|
|
||||||
function AbstractValue.validate(self, value)
|
function AbstractValue.validate(self, value)
|
||||||
|
@ -232,7 +262,7 @@ function AbstractValue.validate(self, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
function AbstractValue.write(self, value)
|
function AbstractValue.write(self, value)
|
||||||
ffluci.model.uci.set(self.config, self.section, self.option, value)
|
return ffluci.model.uci.set(self.config, self.section, self.option, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ end
|
||||||
function error500(message)
|
function error500(message)
|
||||||
ffluci.http.status(500, "Internal Server Error")
|
ffluci.http.status(500, "Internal Server Error")
|
||||||
|
|
||||||
if not pcall(ffluci.template.render, "error500") then
|
if not pcall(ffluci.template.render, "error500", {message=message}) then
|
||||||
ffluci.http.textheader()
|
ffluci.http.textheader()
|
||||||
print(message)
|
print(message)
|
||||||
end
|
end
|
||||||
|
@ -171,8 +171,13 @@ function cbi(request)
|
||||||
|
|
||||||
i18n.loadc(request.module)
|
i18n.loadc(request.module)
|
||||||
|
|
||||||
stat, map = pcall(cbi.load, path)
|
local stat, map = pcall(cbi.load, path)
|
||||||
if stat then
|
if stat then
|
||||||
|
local stat, err = pcall(map.parse, map)
|
||||||
|
if not stat then
|
||||||
|
disp.error500(err)
|
||||||
|
return
|
||||||
|
end
|
||||||
tmpl.render("cbi/header")
|
tmpl.render("cbi/header")
|
||||||
map:render()
|
map:render()
|
||||||
tmpl.render("cbi/footer")
|
tmpl.render("cbi/footer")
|
||||||
|
@ -202,8 +207,13 @@ function dynamic(request)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
stat, map = pcall(cbi.load, path)
|
local stat, map = pcall(cbi.load, path)
|
||||||
if stat then
|
if stat then
|
||||||
|
local stat, err = pcall(map.parse, map)
|
||||||
|
if not stat then
|
||||||
|
disp.error500(err)
|
||||||
|
return
|
||||||
|
end
|
||||||
tmpl.render("cbi/header")
|
tmpl.render("cbi/header")
|
||||||
map:render()
|
map:render()
|
||||||
tmpl.render("cbi/footer")
|
tmpl.render("cbi/footer")
|
||||||
|
|
|
@ -28,6 +28,13 @@ module("ffluci.fs", package.seeall)
|
||||||
|
|
||||||
require("lfs")
|
require("lfs")
|
||||||
|
|
||||||
|
-- Checks whether a file exists
|
||||||
|
function isfile(filename)
|
||||||
|
local fp = io.open(path, "r")
|
||||||
|
if file then file:close() end
|
||||||
|
return file ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
-- Returns the content of file
|
-- Returns the content of file
|
||||||
function readfile(filename)
|
function readfile(filename)
|
||||||
local fp = io.open(filename)
|
local fp = io.open(filename)
|
||||||
|
|
|
@ -161,7 +161,7 @@ function validate(value, cast_number, cast_int, valid)
|
||||||
if type(valid) == "function" then
|
if type(valid) == "function" then
|
||||||
value = valid(value)
|
value = valid(value)
|
||||||
elseif type(valid) == "table" then
|
elseif type(valid) == "table" then
|
||||||
if not ffluci.util.contains(valid, value) then
|
if not contains(valid, value) then
|
||||||
value = nil
|
value = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
|
<input type="submit" /> <input type="reset" />
|
||||||
</form>
|
</form>
|
||||||
<%+footer%>
|
<%+footer%>
|
|
@ -4,5 +4,4 @@
|
||||||
<br />
|
<br />
|
||||||
<% self:render_children() %>
|
<% self:render_children() %>
|
||||||
<br />
|
<br />
|
||||||
<input type="submit" /> <input type="reset" />
|
|
||||||
</div>
|
</div>
|
||||||
|
|
5
src/ffluci/view/error500.htm
Normal file
5
src/ffluci/view/error500.htm
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<%+header%>
|
||||||
|
<h1>500 Internal Server Error</h1>
|
||||||
|
<p>Sorry, the server encountered an unexpected error.</p>
|
||||||
|
<tt><%=message%></tt>
|
||||||
|
<%+footer%>
|
|
@ -9,10 +9,10 @@ require("ffluci.http").htmlheader()
|
||||||
<!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">
|
||||||
<head>
|
<head>
|
||||||
<link rel="stylesheet" type="text/css" href="<%=media%>/cascade.css" />
|
<link rel="stylesheet" type="text/css" href="<%=media%>/cascade.css" />
|
||||||
<link rel="stylesheet" type="text/css" href="<%=media%>/css/<%=req.category%>_<%=req.module%>.css" />
|
<link rel="stylesheet" type="text/css" href="<%=media%>/css/<%=req.category%>_<%=req.module%>.css" />
|
||||||
<title>FFLuCI</title>
|
<link rel="stylesheet" type="text/css" href="<%=media%>/css/<%=req.category%>_<%=req.module%>/<%=req.action%>.css" />
|
||||||
<% if addheaders then write(addheaders) end %>
|
<title>FFLuCI</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="header">
|
<div id="header">
|
||||||
|
|
Loading…
Reference in a new issue