summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-04-09 14:04:34 +0000
committerMika Havela <mika.havela@gmail.com>2008-04-09 14:04:34 +0000
commitbb6adcea06e97df7d1f6bd01fe1e7bfa199de4f5 (patch)
treeb3764ceaa4d9ff34493bba9ca2300f35645994ff
parent3bfa521583a43058c1e2b1c7b89f5d5bcf59f94b (diff)
downloadacf-tinydns-bb6adcea06e97df7d1f6bd01fe1e7bfa199de4f5.tar.bz2
acf-tinydns-bb6adcea06e97df7d1f6bd01fe1e7bfa199de4f5.tar.xz
Cleaned up code. Added start/stop/restart buttons.
git-svn-id: svn://svn.alpinelinux.org/acf/tinydns/trunk@979 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--tinydns-controller.lua550
-rw-r--r--tinydns-expert-html.lsp15
-rw-r--r--tinydns-model.lua9
3 files changed, 85 insertions, 489 deletions
diff --git a/tinydns-controller.lua b/tinydns-controller.lua
index 47bb8d7..b8c2b6b 100644
--- a/tinydns-controller.lua
+++ b/tinydns-controller.lua
@@ -69,6 +69,41 @@ local function unpackoptionstooriginal(t,array,filter)
end
end
+local function displaycmdmanagement(pidofstatus)
+ -- Add a management buttons
+ local management = {}
+ management.start = cfe({ name="cmdmanagement",
+ label="Program control-panel",
+ value="Start",
+ type="submit",
+ })
+ management.stop = cfe({ name="cmdmanagement",
+ label="Program control-panel",
+ value="Stop",
+ type="submit",
+ })
+ management.restart = cfe({ name="cmdmanagement",
+ label="Program control-panel",
+ value="Restart",
+ type="submit",
+ })
+ -- next CFE can be used to present the result of the previous action
+ management.actionresult = cfe({ name="actionresult",
+ label="Previous action result",
+ descr="", --Content of this variable is displayed as <PRE> ... </PRE> in BLACK text
+ errtxt="", --Content of this variable is displayed as <PRE> ... </PRE> in RED text
+ })
+
+ -- Disable management buttons based on if the process is running or not
+ if (pidofstatus) then
+ management.start.disabled = "yes"
+ else
+ management.stop.disabled = "yes"
+ management.restart.disabled = "yes"
+ end
+
+ return management
+end
-- ################################################################################
-- PUBLIC FUNCTIONS
@@ -197,25 +232,43 @@ function status(self)
}
end
function expert(self)
- local cmdmanagement, cmdmanagementresult
+ -- Start/Stop/Restart process
+ local cmdmanagement, actionresult
if ( self.clientdata.cmdmanagement) then
- cmdmanagement = cfe({
+ cmdmanagement = cfe({
+ name="cmdmanagement",
+ label="Previous action result",
+ action=cfe({
name="cmdmanagement",
- value=string.lower(self.clientdata.cmdmanagement),
- })
- cmdmanagementresult, cmdmanagement = self.model:startstop_service( cmdmanagement )
+ value=string.lower(self.clientdata.cmdmanagement), -- This row contains start/stop/restart (one of these commands)
+ }),
+ })
+ actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action )
end
local status = getstatus(self)
local config = self.model:getfilelist()
+ -- Management buttons (Hide/show buttons
+ local pidofstatus
+ if (string.lower(status.status.value) == "enabled" ) then pidofstatus = true end
+ management = displaycmdmanagement(pidofstatus)
+ if (actionresult) then
+ management.actionresult.descr=cmdmanagement.descr
+ management.actionresult.errtxt=cmdmanagement.errtxt
+ end
+ if (status) and (status.version) and (#status.version.value == 0) then
+ management.start.disabled = "yes"
+ management.stop.disabled = "yes"
+ management.restart.disabled = "yes"
+ end
+
return {
option={ script=ENV["SCRIPT_NAME"],
prefix=self.conf.prefix,
controller = self.conf.controller,
action = "expert",
link = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, },
- cmdmanagement = cmdmanagement,
management = management,
config = config,
status = status,
@@ -226,24 +279,11 @@ function expert(self)
end
function edit(self)
- local cmdmanagement, cmdmanagementresult, modifications
- if ( self.clientdata.cmdmanagement) then
- cmdmanagement = cfe({
- name="cmdmanagement",
- value=string.lower(self.clientdata.cmdmanagement),
- })
- cmdmanagementresult, cmdmanagement = self.model:startstop_service( cmdmanagement )
- end
-- Save changes
if ( self.clientdata.cmdsave) then
local filetochange = cfe ({ name=self.clientdata.name, value=self.clientdata.filecontent, })
modifications = self.model:updatefilecontent(filetochange)
--- if not (modifications) then
--- self.conf.action = "status"
--- self.conf.type = "redir"
--- error (self.conf)
--- end
end
if not (self.model:valid_filename(self.clientdata.name)) then
@@ -270,11 +310,10 @@ function edit(self)
option={ script=ENV["SCRIPT_NAME"],
prefix=self.conf.prefix,
controller = self.conf.controller,
- action = "edit",
+ action = "edit",
+ extra = "",
link = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, },
- cmdmanagement = cmdmanagement,
modifications = modifications,
- management = management,
file = file,
status = status,
startstop = startstop,
@@ -282,470 +321,3 @@ function edit(self)
}
end
---[=[
-function edit_records(self,types,record,errormessage)
- local recorddetails = {}
- local edit = {}
- local config=self.model:getconfig()
-
- -- Fetch the original record into a table
- local availablesigns = self.model.check_signs()
- local prefix = availablesigns["reverse"][types]
- local domainopts = {}
- local domainoptions = self.model.getconfigobjects(self,prefix)
- local descrfield = 2 -- This is the filed that is shown as description (in the select-box)
- unpackoptionstooriginal(domainoptions, domainopts,string.match(record, "^%S*"))
- domainopts=unpack(domainopts)
-
- -- Display the inputfields (with the original record)
- local numfields = math.max(#domainopts,#availablesigns["fieldlabels"][prefix])
- for fieldnum=2,tonumber(numfields) do
- edit[fieldnum] = cfe({
- name=fieldnum,
- value=domainopts[fieldnum],
- label=availablesigns["fieldlabels"][prefix][fieldnum] or "",
- })
- end
-
- table.insert(edit, cfe({
- name=#edit,
- label="DEBUG: Original record",
- value=domainopts.orgrecord,
- errtxt="This field will go away soon! It's only for debugging!"
- }))
-
- -- Adding select-boxes
- local locationselectbox
- local locationfileds = {
- ['.']=7,
- ['&']=7,
- ['=']=6,
- ['+']=6,
- ['@']=8,
- ['^']=6,
- ['C']=6,
- ['Z']=12,
- [':']=7,
- }
- locationselectbox = locationfileds[prefix]
- if (locationselectbox) then
- local locations=self.model.getlocations(self)
- edit[locationselectbox]["option"] = {}
- edit[locationselectbox]["type"] = "select"
- table.insert(edit[locationselectbox]["option"], "")
- for v in pairs(locations or {}) do
- table.insert(edit[locationselectbox]["option"], v)
- end
- -- IF the value is not one of the existing options, then warn and add this option.
- for k,v in pairs(edit[locationselectbox]["option"]) do
- edit[locationselectbox]["errtxt"] = "'" .. edit[locationselectbox]["value"] .. "' is defined as a location!"
- if (tostring(v) == tostring(edit[locationselectbox]["value"])) then
- edit[locationselectbox]["errtxt"] = ""
- break
- end
- end
- -- Now add this option to the list (just to show what it was)
- if (#edit[locationselectbox]["errtxt"] > 0) then
- table.insert(edit[locationselectbox]["option"], edit[locationselectbox]["value"])
- end
- end
-
- return {
- edit=edit,
- option={ script=ENV["SCRIPT_NAME"],
- prefix=self.conf.prefix,
- controller = self.conf.controller,
- action = "config",
- link = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, },
- cmdsave=cmdsave,
- cmddelete=cmddelete,
- clientdata=clientdata,
- debugtypes=types,
- debugrecord=string.match(record, "^%S*"),
- }
-end
-function config(self,messages)
- local config = self.model.getconfig(self)
- local debug = self.model.getdebug(self)
- local availablesigns = self.model.check_signs("prefix")
-
- -- LISTEN _________________________________________________________
- -- Add button
- config.listen_cmd = cfe ({
- name="listen_cmd",
- label="Save above changes",
- value="Save",
- type="submit",
- disabled="yes",
- })
-
-
- -- LOCATIONS _________________________________________________________
- local locations=self.model.getlocations(self)
- config.locations = cfe ({
- name="locations",
- label="Locations",
- option={},
- type="select",
- })
- -- Add options
- for n in pairs(locations) do
- table.insert(config.locations.option, n)
- end
- -- Add a [New] record to the options
--- table.insert(config.locations.option, newrecordtxt)
- -- Set size of the inputbox
- config.locations.size = #config.locations.option
- if (#config.locations.option == 1) then
- config.locations.size = #config.locations.option + 1
- end
-
- -- Add button
- config.locations_cmd = cfe ({
- name="locations_cmd",
- label="Edit above location",
- value="Edit",
- descr="Mark a item in '" .. config.locations.label .. "'-list before pressing [Edit]",
- type="submit",
- disabled="yes",
- })
-
- -- Nameservers _________________________________________________________
- local prefix = "."
- local domainopts = {}
- local domainoptions = self.model.getconfigobjects(self,prefix)
- local descrfield = 2 -- This is the filed that is shown as description (in the select-box)
- unpackoptions(domainoptions, domainopts,descrfield)
- config.nsourdomain = cfe ({
- name="nsourdomain",
- type="select",
- label=availablesigns[prefix],
- option=domainopts,
--- descr="Above records look like '.fqdn:ip:x:ttl:timestamp:lo' when they are in the config-file.",
- })
- -- Add a [New] record to the options
--- table.insert(config.nsourdomain.option, newrecordtxt)
- -- Set size of the inputbox
- config.nsourdomain.size = #config.nsourdomain.option
- if (#config.nsourdomain.option == 1) then
- config.nsourdomain.size = #config.nsourdomain.option + 1
- end
-
- -- Add button
- config.nsourdomain_cmd = cfe ({
- name="nsourdomain_cmd",
- label="Edit above item",
- value="Edit",
- descr="Mark a item in '" .. config.nsourdomain.label .. "'-list before pressing [Edit]",
- type="submit",
--- disabled="yes",
- })
-
- -- Nameservers _________________________________________________________
- local prefix = "&"
- local domainoptions = self.model.getconfigobjects(self,prefix)
- local domainopts = {}
- local descrfield = 2 -- This is the filed that is shown as description (in the select-box)
- unpackoptions(domainoptions, domainopts,descrfield)
- config.nsdomain = cfe ({
- name="nsdomain",
- label=availablesigns[prefix],
- type="select",
- option=domainopts,
--- descr="Above records look like '&fqdn:ip:x:ttl:timestamp:lo' when they are in the config-file.",
- })
- -- Add a [New] record to the options
--- table.insert(config.nsdomain.option, newrecordtxt)
- -- Set size of the inputbox
- config.nsdomain.size = #config.nsdomain.option
- if (#config.nsdomain.option == 1) then
- config.nsdomain.size = #config.nsdomain.option + 1
- end
-
- -- Add button
- config.nsdomain_cmd = cfe ({
- name="nsdomain_cmd",
- label="Edit above item",
- value="Edit",
- descr="Mark a item in '" .. config.nsdomain.label .. "'-list before pressing [Edit]",
- type="submit",
--- disabled="yes",
- })
-
- -- Host _________________________________________________________
- local prefix = "="
- local domainoptions = self.model.getconfigobjects(self,prefix)
- local domainopts = {}
- -- Filter out options
- local descrfield = 2 -- This is the filed that is shown as description (in the select-box)
- unpackoptions(domainoptions, domainopts,descrfield)
- config.host = cfe ({
- name="host",
- label=availablesigns[prefix],
- type="select",
- option=domainopts,
--- descr="Above records look like '=fqdn:ip:ttl:timestamp:lo' when they are in the config-file.",
- })
- -- Add a [New] record to the options
--- table.insert(config.host.option, newrecordtxt)
- -- Set size of the inputbox
- config.host.size = #config.host.option
- if (#config.host.option == 1) then
- config.host.size = #config.host.option + 1
- end
-
- -- Add button
- config.host_cmd = cfe ({
- name="host_cmd",
- label="Edit above item",
- value="Edit",
- descr="Mark a item in '" .. config.host.label .. "'-list before pressing [Edit]",
- type="submit",
--- disabled="yes",
- })
-
- -- Alias _________________________________________________________
- local prefix = "+"
- local domainoptions = self.model.getconfigobjects(self,prefix)
- local domainopts = {}
- -- Filter out options
- local descrfield = 2 -- This is the filed that is shown as description (in the select-box)
- unpackoptions(domainoptions, domainopts,descrfield)
- config.alias = cfe ({
- name="alias",
- label=availablesigns[prefix],
- type="select",
- option=domainopts,
--- descr="Above records look like '+fqdn:ip:ttl:timestamp:lo' when they are in the config-file.",
- })
- -- Add a [New] record to the options
--- table.insert(config.alias.option, newrecordtxt)
- -- Set size of the inputbox
- config.alias.size = #config.alias.option
- if (#config.alias.option == 1) then
- config.alias.size = #config.alias.option + 1
- end
-
- -- Add button
- config.alias_cmd = cfe ({
- name="alias_cmd",
- label="Edit above item",
- value="Edit",
- descr="Mark a item in '" .. config.alias.label .. "'-list before pressing [Edit]",
- type="submit",
--- disabled="yes",
- })
-
- -- MX _________________________________________________________
- local prefix = "@"
- local domainoptions = self.model.getconfigobjects(self,prefix)
- local domainopts = {}
- -- Filter out options
- local descrfield = 2 -- This is the filed that is shown as description (in the select-box)
- unpackoptions(domainoptions, domainopts,descrfield)
- config.mx = cfe ({
- name="mx",
- label=availablesigns[prefix],
- type="select",
- option=domainopts,
--- descr="Above records look like '@fqdn:ip:x:dist:ttl:timestamp:lo' when they are in the config-file.",
- })
- -- Add a [New] record to the options
--- table.insert(config.mx.option, newrecordtxt)
- -- Set size of the inputbox
- config.mx.size = #config.mx.option
- if (#config.mx.option == 1) then
- config.mx.size = #config.mx.option + 1
- end
-
- -- Add button
- config.mx_cmd = cfe ({
- name="mx_cmd",
- label="Edit above item",
- value="Edit",
- descr="Mark a item in '" .. config.mx.label .. "'-list before pressing [Edit]",
- type="submit",
--- disabled="yes",
- })
-
- -- PTR _________________________________________________________
- local prefix = "^"
- local domainoptions = self.model.getconfigobjects(self,prefix)
- local domainopts = {}
- -- Filter out options
- local descrfield = 2 -- This is the filed that is shown as description (in the select-box)
- unpackoptions(domainoptions, domainopts,descrfield)
- config.ptr = cfe ({
- name="ptr",
- label=availablesigns[prefix],
- type="select",
- option=domainopts,
--- descr="Above records look like '^fqdn:p:ttl:timestamp:lo' when they are in the config-file.",
- })
- -- Add a [New] record to the options
--- table.insert(config.ptr.option, newrecordtxt)
- -- Set size of the inputbox
- config.ptr.size = #config.ptr.option
- if (#config.ptr.option == 1) then
- config.ptr.size = #config.ptr.option + 1
- end
-
- -- Add button
- config.ptr_cmd = cfe ({
- name="ptr_cmd",
- label="Edit above item",
- value="Edit",
- descr="Mark a item in '" .. config.ptr.label .. "'-list before pressing [Edit]",
- type="submit",
--- disabled="yes",
- })
-
- -- Cname _________________________________________________________
- local prefix = "C"
- local domainoptions = self.model.getconfigobjects(self,prefix)
- local domainopts = {}
- -- Filter out options
- local descrfield = 2 -- This is the filed that is shown as description (in the select-box)
- unpackoptions(domainoptions, domainopts,descrfield)
- config.cname = cfe ({
- name="cname",
- label=availablesigns[prefix],
- type="select",
- option=domainopts,
--- descr="Above records look like 'Cfqdn:p:ttl:timestamp:lo' when they are in the config-file.",
- })
- -- Add a [New] record to the options
--- table.insert(config.cname.option, newrecordtxt)
- -- Set size of the inputbox
- config.cname.size = #config.cname.option
- if (#config.cname.option == 1) then
- config.cname.size = #config.cname.option + 1
- end
-
- -- Add button
- config.cname_cmd = cfe ({
- name="cname_cmd",
- label="Edit above item",
- value="Edit",
- descr="Mark a item in '" .. config.cname.label .. "'-list before pressing [Edit]",
- type="submit",
--- disabled="yes",
- })
-
- -- SOA _________________________________________________________
- local prefix = "Z"
- local domainoptions = self.model.getconfigobjects(self,prefix)
- local domainopts = {}
- -- Filter out options
- local descrfield = 2 -- This is the filed that is shown as description (in the select-box)
- unpackoptions(domainoptions, domainopts,descrfield)
- config.soa = cfe ({
- name="soa",
- label=availablesigns[prefix],
- type="select",
- option=domainopts,
--- descr="Above records look like 'Zfqdn:mname:rname:ser:ref:ret:exp:min:ttl:timestamp:lo' when they are in the config-file.",
- })
- -- Add a [New] record to the options
--- table.insert(config.soa.option, newrecordtxt)
- -- Set size of the inputbox
- config.soa.size = #config.soa.option
- if (#config.soa.option == 1) then
- config.soa.size = #config.soa.option + 1
- end
-
- -- Add button
- config.soa_cmd = cfe ({
- name="soa_cmd",
- label="Edit above item",
- value="Edit",
- descr="Mark a item in '" .. config.soa.label .. "'-list before pressing [Edit]",
- type="submit",
--- disabled="yes",
- })
-
- -- GENERIC _________________________________________________________
- local prefix = ":"
- local domainoptions = self.model.getconfigobjects(self,prefix)
- local domainopts = {}
- -- Filter out options
- local descrfield = 2 -- This is the filed that is shown as description (in the select-box)
- unpackoptions(domainoptions, domainopts,descrfield)
- config.generic = cfe ({
- name="generic",
- label=availablesigns[prefix],
- type="select",
- option=domainopts,
--- descr="Above records look like ':fqdn:n:rdata:ttl:timestamp:lo' when they are in the config-file.",
- })
- -- Add a [New] record to the options
--- table.insert(config.generic.option, newrecordtxt)
- -- Set size of the inputbox
- config.generic.size = #config.generic.option
- if (#config.generic.option == 1) then
- config.generic.size = #config.generic.option + 1
- end
-
- -- Add button
- config.generic_cmd = cfe ({
- name="generic_cmd",
- label="Edit above item",
- value="Edit",
- descr="Mark a item in '" .. config.generic.label .. "'-list before pressing [Edit]",
- type="submit",
--- disabled="yes",
- })
-
-
- -- DEBUGGING
- local level1 = {}
- local level2 = {}
- local level3 = {}
- local domainoptions = self.model.getconfigobjects(self)
- for k1,v1 in pairs(domainoptions) do
- table.insert(level1, v1.label)
- for k2,v2 in pairs(v1) do
- table.insert(level2, v2.label)
- if (type(v2) == "table") then
- for k3,v3 in pairs(v2) do
- table.insert(level3, v3.label)
- end
- end
- end
- end
-
---[[
- config.debuglevels = cfe ({
- name="debuglevels",
- label="Level1",
- type="select",
- option=domainoptions,
- })
---]]
-
-
- -- Redirect if button is pressed ***********************************
- local tags = {"locations", "nsourdomain", "nsdomain", "host", "alias", "mx", "ptr", "cname", "soa", "generic", }
- for k,tag in pairs(tags) do
- if (self.clientdata[tag .. "_cmd"]) and (self.clientdata[tag]) then
- self.conf.action = "edit_records"
- self.conf.type = "redir"
- return edit_records(self,tag, self.clientdata[tag])
- elseif (self.clientdata[tag .. "_cmd"]) and not (self.clientdata[tag]) then
- config[tag .. "_cmd"]["errtxt"] = "You need to specify a record to edit!"
- end
- end
-
-
- return ({
- status=getstatus(self),
- config=config,
- option={ script=ENV["SCRIPT_NAME"],
- prefix=self.conf.prefix,
- controller = self.conf.controller,
- action = "config",
- link = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, },
-
- })
-end
---]=]
diff --git a/tinydns-expert-html.lsp b/tinydns-expert-html.lsp
index 45089e7..d3248b1 100644
--- a/tinydns-expert-html.lsp
+++ b/tinydns-expert-html.lsp
@@ -35,3 +35,18 @@ for k,v in pairs(myform.value) do
</TABLE>
</DL>
+
+<form action="<?= form.option.script .. "/" .. form.option.prefix ..
+ form.option.controller .. "/" .. form.option.action ..
+ (form.option.extra or "") ?>" method="POST">
+<?
+-- Management buttons
+local myform = form.management
+local tags = { "start", "stop", "restart" }
+if (myform) then
+ io.write("<H1>MANAGEMENT</H1>\n<DL>")
+ displaymanagement(myform,tags)
+ io.write("</DL>")
+end
+?>
+</form>
diff --git a/tinydns-model.lua b/tinydns-model.lua
index ad83798..3b91cb3 100644
--- a/tinydns-model.lua
+++ b/tinydns-model.lua
@@ -6,6 +6,7 @@ require("getopts")
require("fs")
require("format")
require("processinfo")
+require("daemoncontrol")
-- Set variables
local configdir
@@ -262,6 +263,14 @@ end
-- ################################################################################
-- PUBLIC FUNCTIONS
+function startstop_service ( self, action )
+ local cmd = action.value
+ local cmdresult,cmdmessage,cmderror,cmdaction = daemoncontrol.daemoncontrol(processname, cmd)
+ action.descr=cmdmessage
+ action.errtxt=cmderror
+ return cmdresult,action
+end
+
function valid_filename(self,path)
return validfilename(path)
end