diff options
-rw-r--r-- | alpine-baselayout.roles | 4 | ||||
-rw-r--r-- | cron-controller.lua | 4 | ||||
-rw-r--r-- | cron-listjobs-html.lsp | 28 | ||||
-rw-r--r-- | cron-model.lua | 52 | ||||
l--------- | cron-movejob-html.lsp | 1 |
5 files changed, 73 insertions, 16 deletions
diff --git a/alpine-baselayout.roles b/alpine-baselayout.roles index 7c54f1c..d72cd66 100644 --- a/alpine-baselayout.roles +++ b/alpine-baselayout.roles @@ -1,5 +1,5 @@ GUEST=health:system,hostname:read USER=cron:status,cron:startstop,health:storage,health:proc,health:network,health:modules,health:networkstats,interfaces:status,interfaces:read,interfaces:restart,logfiles:status,logfiles:view,logfiles:download,logfiles:tail,modules:status,skins:update,skins:read,syslog:status,syslog:loginfo,syslog:startstop,rc:status EDITOR=cron:listjobs,hostname:edit,interfaces:delete,interfaces:create,interfaces:update,interfaces:ifup,interfaces:ifdown,logfiles:delete,syslog:config,rc:edit -EXPERT=cron:editjob,cron:deletejob,cron:createjob,cron:expert,syslog:expert,interfaces:editintfile,modules:edit,modules:reload -ADMIN=cron:status,cron:startstop,cron:listjobs,cron:editjob,cron:deletejob,cron:createjob,cron:expert,health:system,hostname:read,health:storage,health:proc,health:network,health:modules,health:networkstats,interfaces:status,interfaces:read,interfaces:restart,logfiles:status,logfiles:view,logfiles:download,logfiles:tail,modules:status,skins:update,skins:read,syslog:status,syslog:loginfo,syslog:startstop,rc:status,hostname:edit,interfaces:delete,interfaces:create,interfaces:update,interfaces:ifup,interfaces:ifdown,logfiles:delete,syslog:config,rc:edit,syslog:expert,interfaces:editintfile,modules:edit,modules:reload,password:edit +EXPERT=cron:editjob,cron:deletejob,cron:movejob,cron:createjob,cron:expert,syslog:expert,interfaces:editintfile,modules:edit,modules:reload +ADMIN=cron:status,cron:startstop,cron:listjobs,cron:editjob,cron:deletejob,cron:movejob,cron:createjob,cron:expert,health:system,hostname:read,health:storage,health:proc,health:network,health:modules,health:networkstats,interfaces:status,interfaces:read,interfaces:restart,logfiles:status,logfiles:view,logfiles:download,logfiles:tail,modules:status,skins:update,skins:read,syslog:status,syslog:loginfo,syslog:startstop,rc:status,hostname:edit,interfaces:delete,interfaces:create,interfaces:update,interfaces:ifup,interfaces:ifdown,logfiles:delete,syslog:config,rc:edit,syslog:expert,interfaces:editintfile,modules:edit,modules:reload,password:edit diff --git a/cron-controller.lua b/cron-controller.lua index 9d6fe7b..a420cc9 100644 --- a/cron-controller.lua +++ b/cron-controller.lua @@ -25,6 +25,10 @@ function deletejob(self) return self:redirect_to_referrer(self.model.delete_job(self.clientdata.name)) end +function movejob(self) + return controllerfunctions.handle_form(self, self.model.get_move_job, self.model.move_job, self.clientdata, "Move", "Move Job", "Job Moved") +end + function createjob(self) return controllerfunctions.handle_form(self, self.model.create_new_job, self.model.create_job, self.clientdata, "Create", "Create New Job", "New Job Created") end diff --git a/cron-listjobs-html.lsp b/cron-listjobs-html.lsp index d9705e0..1968bad 100644 --- a/cron-listjobs-html.lsp +++ b/cron-listjobs-html.lsp @@ -1,13 +1,30 @@ <% local view, viewlibrary, page_info, session = ... %> <% require("viewfunctions") %> -<% displaycommandresults({"editjob", "deletejob"}, session) %> +<% displaycommandresults({"editjob", "deletejob", "movejob"}, session) %> <% displaycommandresults({"createjob"}, session, true) %> <% if viewlibrary and viewlibrary.dispatch_component then viewlibrary.dispatch_component("status") end %> +<% -- set up the form for the move action +local formstart = '<form action="'..html.html_escape(page_info.script .. page_info.prefix .. page_info.controller .. "/movejob")..'" method="POST">' +formstart = formstart .. '<input type="hidden" name="name" value="' +local formend = '">\n<select name="period" style="width:150px">' +for i,tabl in ipairs(view.value) do + if i == 1 then + formend = formend .. '<option selected value="'..tabl.period..'">'..tabl.period..'</option>' + else + formend = formend .. '<option value="'..tabl.period..'">'..tabl.period..'</option>' + end +end +formend = formend .. '</select>\n<input class="submit" type="submit" name="Move" value="Move"></form>' +local function createmoveform(name) + io.write(formstart, name, formend) +end +%> + <H1>Cron Jobs</H1> <% for i,tabl in ipairs(view.value) do %> <H2><%= html.html_escape(tabl.period) %></H2> @@ -16,16 +33,19 @@ No jobs <% else %> <TABLE> <TR style="background:#eee;font-weight:bold;"> - <TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">Action</TD> - <TD style="white-space:nowrap;text-align:left;" class="header">Job</TD> + <TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">Job</TD> + <TD style="white-space:nowrap;text-align:left;" class="header">Action</TD> + <TD style="white-space:nowrap;text-align:left;" class="header"></TD> </TR> <% for i,job in ipairs(tabl.jobs) do %> <TR> + <TD style="white-space:nowrap;"><%= html.html_escape(string.gsub(job, "^.*/", "")) %></TD> <TD style="padding-right:20px;white-space:nowrap;"> <%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/editjob?name="..job.."&redir="..page_info.orig_action, label="Edit "} %> <%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/deletejob?name="..job, label="Delete "} %> + </TD><TD> + <% createmoveform(job, tabl.period) %> </TD> - <TD style="white-space:nowrap;"><%= html.html_escape(string.gsub(job, "^.*/", "")) %></TD> </TR> <% end %> </TABLE> diff --git a/cron-model.lua b/cron-model.lua index c5ccf7b..46f4b16 100644 --- a/cron-model.lua +++ b/cron-model.lua @@ -18,7 +18,7 @@ local function list_periods() if not periods then periods = {} local file = fs.read_file(configfile) or "" - for dir in string.gmatch(file, "/etc/periodic/(%S+)") do + for dir in string.gmatch(file, baseurl.."(%S+)") do periods[#periods+1] = dir end --[[ local reverseperiods = {} @@ -34,6 +34,20 @@ local function list_periods() return periods end +local function list_jobs() + local jobs = {} + local alljobs = {} + for i,period in ipairs(list_periods()) do + local temp = {period=period, jobs={}} + for file in fs.find("[^.]+", baseurl..period) do + table.insert(temp.jobs, file) + table.insert(alljobs, file) + end + jobs[#jobs+1] = temp + end + return jobs, alljobs +end + local function validate_filename(name) local success = false for i,per in ipairs(list_periods()) do @@ -57,15 +71,7 @@ function getstatus() end function listjobs() - local jobs = {} - for i,period in ipairs(list_periods()) do - local temp = {period=period, jobs={}} - for file in fs.find("[^.]+", baseurl..period) do - table.insert(temp.jobs, file) - end - jobs[#jobs+1] = temp - end - return cfe({ type="structure", value=jobs, label="Cron Jobs" }) + return cfe({ type="structure", value=list_jobs(), label="Cron Jobs" }) end function read_job(filename) @@ -86,10 +92,36 @@ function delete_job(filename) return retval end +function get_move_job() + local move = {} + move.name = cfe({ type="select", label="Name", option=select(2, list_jobs()) }) + move.period = cfe({ type="select", label="Period", option=list_periods() }) + move.name.value = move.name.option[1] or "" + move.period.value = move.period.option[1] or "" + return cfe({ type="group", value=move, label="Move Job" }) +end + +function move_job(move) + local success = modelfunctions.validateselect(move.value.name) + success = modelfunctions.validateselect(move.value.period) and success + + if success then + local newpath = baseurl .. move.value.period.value .. "/" .. basename(move.value.name.value) + fs.move_file(move.value.name.value, newpath) + move.value.name.option = select(2, list_jobs()) + move.value.name.value = newpath + else + move.errtxt = "Failed to move job" + end + + return move +end + function create_new_job() local newjob = {} newjob.name = cfe({ label="Name" }) newjob.period = cfe({ type="select", label="Period", option=list_periods() }) + newjob.period.value = newjob.period.option[1] or "" return cfe({ type="group", value=newjob, label="Create New Job" }) end diff --git a/cron-movejob-html.lsp b/cron-movejob-html.lsp new file mode 120000 index 0000000..4b6b762 --- /dev/null +++ b/cron-movejob-html.lsp @@ -0,0 +1 @@ +../form-html.lsp
\ No newline at end of file |