summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--provisioning-controller.lua8
l---------provisioning-editfile-html.lsp1
-rw-r--r--provisioning-listfiles-html.lsp20
-rw-r--r--provisioning-model.lua95
-rw-r--r--provisioning.menu1
-rw-r--r--provisioning.roles4
6 files changed, 125 insertions, 4 deletions
diff --git a/provisioning-controller.lua b/provisioning-controller.lua
index b71589a..60b5e9e 100644
--- a/provisioning-controller.lua
+++ b/provisioning-controller.lua
@@ -107,3 +107,11 @@ end
editoptions = function( self )
return controllerfunctions.handle_form(self, function() return self.model.get_param_options(self.clientdata.param_id) end, self.model.set_param_options, self.clientdata, "Save", "Edit Parameter Options", "Parameter Options Saved")
end
+
+listfiles = function( self )
+ return self.model.list_files()
+end
+
+editfile = function( self )
+ return controllerfunctions.handle_form(self, function() return self.model.get_filedetails(self.clientdata.filename) end, self.model.update_filedetails, self.clientdata, "Save", "Edit Script File", "Script File Saved")
+end
diff --git a/provisioning-editfile-html.lsp b/provisioning-editfile-html.lsp
new file mode 120000
index 0000000..15b1930
--- /dev/null
+++ b/provisioning-editfile-html.lsp
@@ -0,0 +1 @@
+../filedetails-html.lsp \ No newline at end of file
diff --git a/provisioning-listfiles-html.lsp b/provisioning-listfiles-html.lsp
new file mode 100644
index 0000000..29bb43e
--- /dev/null
+++ b/provisioning-listfiles-html.lsp
@@ -0,0 +1,20 @@
+<% local view, viewlibrary, page_info, session = ...
+require("viewfunctions")
+%>
+
+<% displaycommandresults({"editfile"}, session) %>
+
+<h1>Provisioning Script Files</h1>
+<DL><TABLE>
+ <TR style="background:#eee;font-weight:bold;">
+ <TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">File</TD>
+ <TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">Size</TD>
+ <TD style="white-space:nowrap;text-align:left;" class="header">Last Modified</TD>
+ </TR>
+
+<%
+ for k,v in ipairs( view.value ) do
+ io.write( "<tr><td><a href=\"" .. html.html_escape(page_info.script .. page_info.prefix .. page_info.controller) .. "/editfile?filename=" .. html.html_escape(v.filename) .. "&redir=" .. html.html_escape(page_info.orig_action) .. "\">" .. html.html_escape(v.filename) .. "</a></td><td>" .. html.html_escape(v.size) .."</td><td>" .. html.html_escape(v.mtime) .."</td></tr>\n" )
+ end
+%>
+</TABLE></DL>
diff --git a/provisioning-model.lua b/provisioning-model.lua
index 848c7ad..3618194 100644
--- a/provisioning-model.lua
+++ b/provisioning-model.lua
@@ -16,9 +16,14 @@ local DatabasePassword
local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin "
local baseurl = "/etc/provisioning/templates/"
+local updatedevicescriptfile = "/etc/provisioning/update_device.lua"
+local updatedeviceparamsscriptfile = "/etc/provisioning/update_device_params.lua"
local env
local con
+local saved_devices = {}
+local saved_device_params = {}
+
-- if a table_creation_script does not create the named table or throw an exception then you will get an infinite loop, so be careful
local table_creation_scripts = {
-- List of all available templates
@@ -308,6 +313,62 @@ validateparam = function(p)
return true
end
+local function callscript(script, value, oldvalue)
+ local functions = {
+ getselectresponse=getselectresponse,
+ runsqlcommand=runsqlcommand,
+ get_device=get_device,
+ get_device_params=get_device_params,
+ }
+ local env = {}
+ setmetatable (env, {__index = _G})
+ -- loadfile loads into the global environment
+ -- so we set env 0, not env 1
+ setfenv (0, env)
+ local f = loadfile(script)
+ if (f) then f(functions, value, oldvalue) end
+ setfenv (0, _G)
+end
+
+local function validatefiledetails(filedetails)
+ local success = true
+
+ -- Validate that contents are valid lua code
+ local env = {}
+ setmetatable (env, {__index = _G})
+ -- loadfile loads into the global environment
+ -- so we set env 0, not env 1
+ setfenv (0, env)
+ local f,err = loadstring(filedetails.value.filecontent.value)
+ if not (f) then
+ success = false
+ filedetails.value.filecontent.errtxt = "Invalid Lua code\n"..(err or "")
+ end
+ setfenv (0, _G)
+ -- setmetatable (self.conf.app_hooks, {})
+
+ return success, filedetails
+end
+
+local duplicatestructure
+duplicatestructure = function(value, saved)
+ saved = saved or {}
+ if type(value) == "table" then
+ if saved[value] then
+ return saved[value]
+ else
+ local output = {}
+ saved[value] = output
+ for k,v in pairs(value) do
+ output[k] = duplicatestructure(v, saved)
+ end
+ return output
+ end
+ else
+ return value
+ end
+end
+
-- ################################################################################
-- PUBLIC FUNCTIONS
@@ -1053,7 +1114,10 @@ get_device = function(device_id)
errtxt = err
end
- return cfe({ type="group", value=retval, label="Provisioning Device", errtxt=errtxt })
+ -- Save the device for later use
+ local output = cfe({ type="group", value=retval, label="Provisioning Device", errtxt=errtxt })
+ if device_id and device_id ~= "" then saved_devices[device_id] = duplicatestructure(output) end
+ return output
end
create_device = function(device)
@@ -1110,6 +1174,8 @@ update_device = function(device, create)
sql = "COMMIT"
runsqlcommand(sql)
+
+ callscript(updatedevicescriptfile, device, saved_devices[device.value.device_id.value])
end
if connected then databasedisconnect() end
end)
@@ -1229,7 +1295,11 @@ get_device_params = function(device_id, editable)
errtxt = err
end
end
- return cfe({ type="group", value=retval, label="Provisioning Device Parameters", errtxt=errtxt })
+
+ -- Save the device for later use
+ local output = cfe({ type="group", value=retval, label="Provisioning Device Parameters", errtxt=errtxt })
+ if device_id and device_id ~= "" then saved_device_params[device_id] = duplicatestructure(output) end
+ return output
end
set_editable_device_params = function(params)
@@ -1277,6 +1347,8 @@ set_device_params = function(params, editable)
sql = "COMMIT"
runsqlcommand(sql)
+
+ callscript(updatedeviceparamsscriptfile, params, saved_device_params[params.value.device_id.value])
end
if connected then databasedisconnect() end
end)
@@ -1508,3 +1580,22 @@ set_param_options = function(options)
end
return options
end
+
+function get_filedetails(filename)
+ return modelfunctions.getfiledetails(filename, {updatedevicescriptfile, updatedeviceparamsscriptfile})
+end
+
+function update_filedetails(filedetails)
+ return modelfunctions.setfiledetails(filedetails, {updatedevicescriptfile, updatedeviceparamsscriptfile}, validatefiledetails)
+end
+
+function list_files()
+ local retval = {}
+ for i,file in ipairs({updatedevicescriptfile, updatedeviceparamsscriptfile}) do
+ local details = fs.stat(file) or {}
+ details.filename = file
+ table.insert(retval, details)
+ end
+ table.sort(retval, function(a,b) return a.filename < b.filename end)
+ return cfe({ type="structure", value=retval, label="List of Provisioning Script files" })
+end
diff --git a/provisioning.menu b/provisioning.menu
index dd7dd86..7c05049 100644
--- a/provisioning.menu
+++ b/provisioning.menu
@@ -6,3 +6,4 @@ Applications 89Provisioning Templates listtemplates
Applications 89Provisioning Classes listclasses
Applications 89Provisioning Param_Groups listgroups
Applications 89Provisioning Params listparams
+Applications 89Provisioning Script_Files listfiles
diff --git a/provisioning.roles b/provisioning.roles
index dca63b2..431c98b 100644
--- a/provisioning.roles
+++ b/provisioning.roles
@@ -1,5 +1,5 @@
GUEST=provisioning:getdevicevalues
USER=
EDITOR=provisioning:searchdevices,provisioning:listdevices,provisioning:editdevice,provisioning:createdevice,provisioning:duplicatedevice,provisioning:deletedevice
-EXPERT=provisioning:listtemplates,provisioning:edittemplate,provisioning:createtemplate,provisioning:deletetemplate,provisioning:listclasses,provisioning:editclass,provisioning:createclass,provisioning:deleteclass,provisioning:listgroups,provisioning:editgroup,provisioning:creategroup,provisioning:deletegroup,provisioning:listparams,provisioning:editparam,provisioning:createparam,provisioning:deleteparam,provisioning:overridedeviceparams,provisioning:editoptions
-ADMIN=provisioning:listtemplates,provisioning:edittemplate,provisioning:createtemplate,provisioning:deletetemplate,provisioning:searchdevices,provisioning:listdevices,provisioning:editdevice,provisioning:createdevice,provisioning:duplicatedevice,provisioning:deletedevice,provisioning:listclasses,provisioning:editclass,provisioning:createclass,provisioning:deleteclass,provisioning:listgroups,provisioning:editgroup,provisioning:creategroup,provisioning:deletegroup,provisioning:listparams,provisioning:editparam,provisioning:createparam,provisioning:deleteparam,provisioning:editdeviceparams,provisioning:overridedeviceparams,provisioning:editoptions
+EXPERT=provisioning:listtemplates,provisioning:edittemplate,provisioning:createtemplate,provisioning:deletetemplate,provisioning:listclasses,provisioning:editclass,provisioning:createclass,provisioning:deleteclass,provisioning:listgroups,provisioning:editgroup,provisioning:creategroup,provisioning:deletegroup,provisioning:listparams,provisioning:editparam,provisioning:createparam,provisioning:deleteparam,provisioning:overridedeviceparams,provisioning:editoptions,provisioning:listfiles,provisioning:editfile
+ADMIN=provisioning:listtemplates,provisioning:edittemplate,provisioning:createtemplate,provisioning:deletetemplate,provisioning:searchdevices,provisioning:listdevices,provisioning:editdevice,provisioning:createdevice,provisioning:duplicatedevice,provisioning:deletedevice,provisioning:listclasses,provisioning:editclass,provisioning:createclass,provisioning:deleteclass,provisioning:listgroups,provisioning:editgroup,provisioning:creategroup,provisioning:deletegroup,provisioning:listparams,provisioning:editparam,provisioning:createparam,provisioning:deleteparam,provisioning:editdeviceparams,provisioning:overridedeviceparams,provisioning:editoptions,provisioning:listfiles,provisioning:editfile