diff options
-rwxr-xr-x | tinydns-config-html.lsp | 25 | ||||
-rw-r--r-- | tinydns-controller.lua | 169 | ||||
-rw-r--r-- | tinydns-edit_records-html.lsp | 106 | ||||
-rw-r--r-- | tinydns-model.lua | 60 |
4 files changed, 291 insertions, 69 deletions
diff --git a/tinydns-config-html.lsp b/tinydns-config-html.lsp index 49cfa8c..f0628e9 100755 --- a/tinydns-config-html.lsp +++ b/tinydns-config-html.lsp @@ -39,17 +39,18 @@ local tags = { "status", "version", } displayinfo(myform,tags,"viewonly") ?> +<form name="cmd" action="<?= form.option.link ?>/<?= form.option.action ?>" method="POST"> <H1>CONFIG</H1> <H2>General settings</H2> <? local myform = form.config -local tags = { "listen","cmdeditlisten", } +local tags = { "listen","listen_cmd", } displayinfo(myform,tags) ?> <H2>Locations</H2> <? -local tags = { "locations","cmdeditlocations", "cmdnewlocations", } +local tags = { "locations","locations_cmd", "cmdnewlocations", } displayinfo(myform,tags) ?> @@ -57,58 +58,60 @@ displayinfo(myform,tags) <H2>Records</H2> <H3><? io.write(tostring(form.config.nsourdomain.label) or "NS record") ?></H3> <? -local tags = { "nsourdomain","cmdeditnsourdomain", } +local tags = { "nsourdomain","nsourdomain_cmd", } displayinfo(myform,tags) ?> <H3><? io.write(tostring(form.config.nsdomain.label) or "NS record") ?></H3> <? -local tags = { "nsdomain","cmdeditnsdomain", } +local tags = { "nsdomain","nsdomain_cmd", } displayinfo(myform,tags) ?> <H3><? io.write(tostring(form.config.host.label) or "Hosts record") ?></H3> <? -local tags = { "host","cmdedithost", } +local tags = { "host","host_cmd", } displayinfo(myform,tags) ?> <H3><? io.write(tostring(form.config.alias.label) or "Alias record") ?></H3> <? -local tags = { "alias","cmdeditalias", } +local tags = { "alias","alias_cmd", } displayinfo(myform,tags) ?> <H3><? io.write(tostring(form.config.mx.label) or "MX record") ?></H3> <? -local tags = { "mx","cmdeditmx", } +local tags = { "mx","mx_cmd", } displayinfo(myform,tags) ?> <H3><? io.write(tostring(form.config.ptr.label) or "PTR record") ?></H3> <? -local tags = { "ptr","cmdeditptr", } +local tags = { "ptr","ptr_cmd", } displayinfo(myform,tags) ?> <H3><? io.write(tostring(form.config.cname.label) or "CNAME record") ?></H3> <? -local tags = { "cname","cmdeditcname", } +local tags = { "cname","cname_cmd", } displayinfo(myform,tags) ?> <H3><? io.write(tostring(form.config.soa.label) or "SOA record") ?></H3> <? -local tags = { "soa","cmdeditsoa", } +local tags = { "soa","soa_cmd", } displayinfo(myform,tags) ?> <H3><? io.write(tostring(form.config.generic.label) or "GENERIC record") ?></H3> <? -local tags = { "generic","cmdeditgeneric", } +local tags = { "generic","generic_cmd", } displayinfo(myform,tags) ?> +</form> + <? --[[ ?> <H1>DEGUGGING</H1> <? diff --git a/tinydns-controller.lua b/tinydns-controller.lua index a5f804d..612d1c9 100644 --- a/tinydns-controller.lua +++ b/tinydns-controller.lua @@ -1,5 +1,7 @@ module(..., package.seeall) +local newrecordtxt = "[New]" + local list_redir = function (self) self.conf.action = "status" self.conf.type = "redir" @@ -56,6 +58,24 @@ local function unpackoptions(t,array,descrfield) end end +local function unpackoptionstooriginal(t,array,filter) + for k,v in pairs(t) do + if not (v.option) then + if (type(v) == "table") then + unpackoptionstooriginal(v,array,filter) + end + else + if (v.orgrecordtable) and (v.orgrecordtable[2] == filter) then + table.insert(array, v.orgrecordtable) + end + end + end +end + + +-- ################################################################################ +-- PUBLIC FUNCTIONS + function status(self) local config = {} config.settings = {} @@ -173,15 +193,60 @@ function status(self) } end -function config(self) +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!" + })) + + 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.cmdeditlisten = cfe ({ - name="cmdeditlisten", + config.listen_cmd = cfe ({ + name="listen_cmd", label="Save above changes", value="Save", type="submit", @@ -202,7 +267,7 @@ function config(self) table.insert(config.locations.option, n) end -- Add a [New] record to the options - table.insert(config.locations.option, "[New]") +-- table.insert(config.locations.option, newrecordtxt) -- Set size of the inputbox config.locations.size = #config.locations.option if (#config.locations.option == 1) then @@ -210,8 +275,8 @@ function config(self) end -- Add button - config.cmdeditlocations = cfe ({ - name="cmdeditlocations", + 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]", @@ -233,7 +298,7 @@ function config(self) -- 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, "[New]") +-- table.insert(config.nsourdomain.option, newrecordtxt) -- Set size of the inputbox config.nsourdomain.size = #config.nsourdomain.option if (#config.nsourdomain.option == 1) then @@ -241,13 +306,13 @@ function config(self) end -- Add button - config.cmdeditnsourdomain = cfe ({ - name="cmdeditnsourdomain", + 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", +-- disabled="yes", }) -- Nameservers _________________________________________________________ @@ -264,7 +329,7 @@ function config(self) -- 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, "[New]") +-- table.insert(config.nsdomain.option, newrecordtxt) -- Set size of the inputbox config.nsdomain.size = #config.nsdomain.option if (#config.nsdomain.option == 1) then @@ -272,13 +337,13 @@ function config(self) end -- Add button - config.cmdeditnsdomain = cfe ({ - name="cmdeditnsdomain", + 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", +-- disabled="yes", }) -- Host _________________________________________________________ @@ -296,7 +361,7 @@ function config(self) -- 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, "[New]") +-- table.insert(config.host.option, newrecordtxt) -- Set size of the inputbox config.host.size = #config.host.option if (#config.host.option == 1) then @@ -304,13 +369,13 @@ function config(self) end -- Add button - config.cmdedithost = cfe ({ - name="cmdedithost", + 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", +-- disabled="yes", }) -- Alias _________________________________________________________ @@ -328,7 +393,7 @@ function config(self) -- 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, "[New]") +-- table.insert(config.alias.option, newrecordtxt) -- Set size of the inputbox config.alias.size = #config.alias.option if (#config.alias.option == 1) then @@ -336,13 +401,13 @@ function config(self) end -- Add button - config.cmdeditalias = cfe ({ - name="cmdeditalias", + 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", +-- disabled="yes", }) -- MX _________________________________________________________ @@ -360,7 +425,7 @@ function config(self) -- 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, "[New]") +-- table.insert(config.mx.option, newrecordtxt) -- Set size of the inputbox config.mx.size = #config.mx.option if (#config.mx.option == 1) then @@ -368,13 +433,13 @@ function config(self) end -- Add button - config.cmdeditmx = cfe ({ - name="cmdeditmx", + 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", +-- disabled="yes", }) -- PTR _________________________________________________________ @@ -392,7 +457,7 @@ function config(self) -- 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, "[New]") +-- table.insert(config.ptr.option, newrecordtxt) -- Set size of the inputbox config.ptr.size = #config.ptr.option if (#config.ptr.option == 1) then @@ -400,13 +465,13 @@ function config(self) end -- Add button - config.cmdeditptr = cfe ({ - name="cmdeditptr", + 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", +-- disabled="yes", }) -- Cname _________________________________________________________ @@ -424,7 +489,7 @@ function config(self) -- 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, "[New]") +-- table.insert(config.cname.option, newrecordtxt) -- Set size of the inputbox config.cname.size = #config.cname.option if (#config.cname.option == 1) then @@ -432,13 +497,13 @@ function config(self) end -- Add button - config.cmdeditcname = cfe ({ - name="cmdeditcname", + 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", +-- disabled="yes", }) -- SOA _________________________________________________________ @@ -456,7 +521,7 @@ function config(self) -- 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, "[New]") +-- table.insert(config.soa.option, newrecordtxt) -- Set size of the inputbox config.soa.size = #config.soa.option if (#config.soa.option == 1) then @@ -464,13 +529,13 @@ function config(self) end -- Add button - config.cmdeditsoa = cfe ({ - name="cmdeditsoa", + 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", +-- disabled="yes", }) -- GENERIC _________________________________________________________ @@ -488,7 +553,7 @@ function config(self) -- 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, "[New]") +-- table.insert(config.generic.option, newrecordtxt) -- Set size of the inputbox config.generic.size = #config.generic.option if (#config.generic.option == 1) then @@ -496,13 +561,13 @@ function config(self) end -- Add button - config.cmdeditgeneric = cfe ({ - name="cmdeditgeneric", + 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", +-- disabled="yes", }) @@ -523,18 +588,38 @@ function config(self) 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-edit_records-html.lsp b/tinydns-edit_records-html.lsp new file mode 100644 index 0000000..4241540 --- /dev/null +++ b/tinydns-edit_records-html.lsp @@ -0,0 +1,106 @@ +<? local form = ... ?> +<? +--[[ DEBUG INFORMATION +io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") +io.write(html.cfe_unpack(form)) +io.write("</span>") +--]] +?> + +<? +function displayinfo(myform,tags,viewtype) + for k,v in pairs(tags) do + if (myform[v]) and (myform[v]["value"]) then + local val = myform[v] + io.write("\n\t<DT") + if (#val.errtxt > 0) then + val.class = "error" + io.write(" class='error'") + end + io.write(">" .. val.label .. "</DT>") + io.write("\n\t\t<DD>") + if (viewtype == "viewonly") then + io.write(val.value) + elseif (val.type == "radio") and (type(val.option) == "table") and (#val.option > 0) then + io.write("<span style='display:inline' class='" .. ( val.class or "") .. "'>") + for k1,v1 in pairs(val.option) do + io.write(tostring(v1.label) .. ":") + io.write("<input style='margin-right:20px;margin-left:5px;' type='radio' class='" .. ( val.class or "") .. "' name='" .. val.name .. "'") + if (tostring(val.value) == tostring(v1.value)) then io.write(" checked='yes'") end + io.write(" value='" .. v1.value .. "'>") + end + io.write("</input></span>") + else + io.write(html.form[val.type](val)) + end + if (val.descr) and (#val.descr > 0) then io.write("\n\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>") end + if (#val.errtxt > 0) then io.write("\n\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>") end + io.write("\n\t\t</DD>\n") + end + end +end +?> + +<? +function displayinfo_special(myform) + for i=1,#myform do + local v = myform[i] + if (v) and (v["value"]) then + io.write("\n\t<DT") + if (#v.errtxt > 0) then + v.class = "error" + io.write(" class='error'") + end + io.write(">" .. v.label .. "</DT>") + io.write("\n\t\t<DD>") + io.write(html.form[v.type](v)) + if (v.descr) and (#v.descr > 0) then io.write("\n\t\t<P CLASS='descr'>" .. string.gsub(v.descr, "\n", "<BR>") .. "</P>") end + if (#v.errtxt > 0) then io.write("\n\t\t<P CLASS='error'>" .. string.gsub(v.errtxt, "\n", "<BR>") .. "</P>") end + io.write("\n\t\t</DD>\n") + end + end +end +?> + +<form name="cmd" action="<?= form.option.link ?>/<?= form.option.action ?>" method="POST"> + +<H1>EDIT PROPERTIES</H1> +<DL> +<? +local myform = form.edit +displayinfo_special(myform) +?> + +<? +local tags = {"cmdsave", "cmddelete", } +local myform = form +displayinfo(myform,tags) +?> + +<? -- Add the field that holds the filename +local myform = form.edit.filename +if (type(myform) == "table") then + io.write(html.form[myform.type](myform)) +end +local myform = form.edit.orgrecord +if (type(myform) == "table") then + io.write(html.form[myform.type](myform)) +end +local myform = form.edit.actiontype +if (type(myform) == "table") then + io.write(html.form[myform.type](myform)) +end +?> + +</DL> + +</form> + +<? +---[[ DEBUG INFORMATION +io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") +io.write(html.cfe_unpack(form)) +io.write("</span>") +--]] +?> + diff --git a/tinydns-model.lua b/tinydns-model.lua index 3b5f445..2d57d7d 100644 --- a/tinydns-model.lua +++ b/tinydns-model.lua @@ -186,19 +186,45 @@ end function check_signs(sign) local output = {} local output = {prefix={ - ['.']="Name server for your domain", - ['&']="Name server", - ['=']="Host", - ['+']="Alias", - ['@']="Mail exchanger", - ['=']="Host", - ['^']="PTR record", - ['C']="Canonical Name", - ['Z']="SOA record", - [':']="Generic record", - ['%']="Client location", - }} - output = output[sign] + ['.']="Name server for your domain", + ['&']="Name server", + ['=']="Host", + ['+']="Alias", + ['@']="Mail exchanger", + ['^']="PTR record", + ['C']="Canonical Name", + ['Z']="SOA record", + [':']="Generic record", + ['%']="Client location", + }, + reverse={ + ['nsourdomain']=".", + ['nsdomain']="&", + ['host']="=", + ['alias']="+", + ['mx']="@", + ['ptr']="^", + ['cname']="C", + ['soa']="Z", + [':']=":", + ['locations']="%", + }, + fieldlabels={ + ['.']={"Prefix", "Domain", "IP address", "Name server", "Time to live", "Timestamp", "Location", }, + ['&']={"Prefix", "Domain", "IP address", "Name server", "Time to live", "Timestamp", "Location", }, + ['=']={"Prefix", "Host", "IP address", "Time to live", "Timestamp", "Location", }, + ['+']={"Prefix", "Alias", "IP address", "Time to live", "Timestamp", "Location", }, + ['@']={"Prefix", "Domain", "IP address", "Mail exchanger", "Distance", "Time to live", "Timestamp", "Location", }, + ['^']={"Prefix", "PTR", "Domain name", "Time to live", "Timestamp", "Location", }, + ['C']={"Prefix", "Domain name", "Canonical name", "Time to live", "Timestamp", "Location", }, + ['Z']={"Prefix", "Unknown", "Primary name server", "Contact address", "Serial number", "Refresh time", "Retry time", "Expire time", "Minimum time", "Time to live", "Timestamp", "Location",}, + [':']={"Prefix", "Unknown", "Type of record", "Rdata", "Time to live", "Timestamp", "Location", }, + ['%']={"Prefix", "Location", "IP prefix", }, + }, + } + if (sign) then + output = output[sign] + end return output end @@ -321,9 +347,9 @@ local function filter_table(t1,domains_filtered,filter) for k1,v1 in pairs(t1) do for k2,v2 in pairs(v1) do if (v2.label) then - if ( string.find(filter,v2.label) ) then - table.insert(domains_filtered, v2) - end + if ( string.find(filter,v2.label) ) then + table.insert(domains_filtered, v2) + end end end end @@ -342,6 +368,7 @@ function getconfigobjects(self,filter_type, filter_levels) for kk,vv in pairs(filecontent) do local domaindetails = {} local filecontent_table = split_config_items(vv) + filecontent_table["orgrecord"] = vv -- Create domain information tables local domain @@ -549,6 +576,7 @@ function getconfigobjects(self,filter_type, filter_levels) name=filecontent_table[2], label=filecontent_table[2], option=domainoptions, + orgrecordtable=filecontent_table, }) end |