diff options
author | Mika Havela <mika.havela@gmail.com> | 2008-04-26 09:59:53 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2008-04-26 09:59:53 +0000 |
commit | 4d2325161be2448fb521b1aacc02965e9dfaba64 (patch) | |
tree | 4ff09a636a69a2600be37c8afc9ef2024b414ed2 | |
parent | 62a1ef945a563c7b9b36dcbe889126825ad57fd2 (diff) | |
download | acf-tinydns-4d2325161be2448fb521b1aacc02965e9dfaba64.tar.bz2 acf-tinydns-4d2325161be2448fb521b1aacc02965e9dfaba64.tar.xz |
Saving work for today.
Create new configfile starts working.
Delete configfile (work in progress - still not working).
Added information on filesize/modifydate on each configfile.
git-svn-id: svn://svn.alpinelinux.org/acf/tinydns/trunk@1048 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r-- | tinydns-confirmaction-html.lsp | 14 | ||||
-rw-r--r-- | tinydns-controller.lua | 56 | ||||
-rw-r--r-- | tinydns-edit-html.lsp | 2 | ||||
-rw-r--r-- | tinydns-expert-html.lsp | 30 | ||||
-rw-r--r-- | tinydns-model.lua | 22 | ||||
-rw-r--r-- | tinydns.roles | 2 |
6 files changed, 116 insertions, 10 deletions
diff --git a/tinydns-confirmaction-html.lsp b/tinydns-confirmaction-html.lsp new file mode 100644 index 0000000..da6753e --- /dev/null +++ b/tinydns-confirmaction-html.lsp @@ -0,0 +1,14 @@ +<? local form = ... +require("viewfunctions") +?> +<? +---[[ 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>") +--]] +?> + +<BR><BR><CENTER><B>DEBUGGING:</B><BR> +This function still doesn't work.<BR> +Need to get the information on what action we are about to execute and what file to use for this actino.</CENTER><BR><BR> diff --git a/tinydns-controller.lua b/tinydns-controller.lua index 652f262..e13f001 100644 --- a/tinydns-controller.lua +++ b/tinydns-controller.lua @@ -235,8 +235,47 @@ function expert(self) actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action ) end + local configopts = self.model:getconfig() + -- Show buttons/fileds for creation of new confifiles + local create = {} + create.name = cfe ({ + name="name", + label="Name of the new configfile", + value=string.gsub(configopts.baseurl.value, "/$", "") .. "/", + }) + create.cmdnew = cfe ({ + name="cmdnew", + label="Create new file", + type="submit", + value="Create", + }) + + -- In case we are trying to create a new configfile + if (self.clientdata.cmdnew) then + if (self.clientdata.name) and + (#self.clientdata.name > 0) and not + (string.gsub(self.clientdata.name, "/$", "") == string.gsub(create.name.value, "/$", "")) then + local createcreated, createerrtxt = self.model:createconfigfile(self.clientdata.name) + if (createerrtxt) and (#createerrtxt > 0) then + create.name.errtxt = createerrtxt + create.name.value = self.clientdata.name + end + else + create.name.errtxt = "Incorrect filename" + end + if (#create.name.errtxt == 0) then + create.cmdnew.descr = "* File was created" + end + end + local status = getstatus(self) - local config = self.model:getfilelist() + + local configfiles = self.model:getfilelist() + local config = {} + for k,v in pairs(configfiles) do + local filedetails = self.model:get_filedetails(v) + table.insert(config,filedetails) + end -- Management buttons (Hide/show buttons local pidofstatus @@ -261,8 +300,9 @@ function expert(self) management = management, config = config, status = status, + create = create, startstop = startstop, - debugclientdata = self.clientdata, + mhdebug = self.clientdata, } end @@ -291,6 +331,16 @@ function edit(self) value="Save", type="submit", }) + file.cmddelete = cfe({ name="cmddelete", + label="Delete this configfile", + value="Delete", + type="submit", + }) + + if (self.clientdata.cmddelete) then + redirect(self, "confirmaction") + end + if (modifications) then file.cmdsave.descr="* Changes has been saved!" end @@ -310,3 +360,5 @@ function edit(self) } end +function confirmaction(self) +end diff --git a/tinydns-edit-html.lsp b/tinydns-edit-html.lsp index 08dee18..ba9a696 100644 --- a/tinydns-edit-html.lsp +++ b/tinydns-edit-html.lsp @@ -40,7 +40,7 @@ io.write(html.form[myform.filecontent.type](myform.filecontent)) <H2>SAVE AND APPLY ABOVE SETTINGS</H2> <DL> <? -local tags = { "cmdsave", } +local tags = { "cmddelete", "cmdsave", } displayinfo(myform,tags) ?> </DL> diff --git a/tinydns-expert-html.lsp b/tinydns-expert-html.lsp index d3248b1..83e8bf7 100644 --- a/tinydns-expert-html.lsp +++ b/tinydns-expert-html.lsp @@ -21,20 +21,38 @@ displayinfo(myform,tags,"viewonly") <h1>CONFIGURATION</h1> <h2>Expert config</h2> -<h3>List of files</h3> +<h3>Edit/View existing configfiles</h3> <DL> + <TABLE> -<? -local myform = form.status.configfiles -for k,v in pairs(myform.value) do -?> + <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> +<? local myform = form.config ?> +<? for i = 1, table.maxn(myform) do ?> <TR> - <TD style="padding-right:20px;white-space:nowrap;"><?= html.link{value = "edit?name=" .. v , label=v } ?></TD> + <TD style="padding-right:20px;white-space:nowrap;"><? io.write(html.link{value = "edit?name=" .. myform[i].filename.value , label=myform[i].filename.value }) ?></TD> + <TD style="padding-right:20px;white-space:nowrap;"><? io.write(myform[i].filesize.value or "--") ?></TD> + <TD style="white-space:nowrap;" width="90%"><? io.write(myform[i].mtime.value or "--") ?></TD> </TR> <? end ?> </TABLE> </DL> +<h3>Create new configfile</h3> +<form action="<?= form.option.script .. "/" .. form.option.prefix .. + form.option.controller .. "/" .. form.option.action .. + (form.option.extra or "") ?>" method="POST"> +<DL> +<? +local myform = form.create +local tags = { "name", "cmdnew", } +displayinfo(myform,tags) +?> +</DL> +</form> <form action="<?= form.option.script .. "/" .. form.option.prefix .. form.option.controller .. "/" .. form.option.action .. diff --git a/tinydns-model.lua b/tinydns-model.lua index 3b91cb3..7ac2495 100644 --- a/tinydns-model.lua +++ b/tinydns-model.lua @@ -7,6 +7,7 @@ require("fs") require("format") require("processinfo") require("daemoncontrol") +require("validator") -- Set variables local configdir @@ -362,12 +363,19 @@ function getconfig(self,filter_type) local config = {} local listenaddr = getopts.getoptsfromfile_onperline(configfile,"IP") or {} + config.listen = cfe({ name = "listen", label="IP address to listen on", value=listenaddr.IP or "", }) + config.baseurl = cfe({ + name = "baseurl", + label="Baseurl for configfiles", + value=baseurl, + }) + return config end @@ -712,3 +720,17 @@ function updatefilecontent (self, filetochange) end return false, "Something went wrong!" end + +function createconfigfile (self, path) + local validfilepath, filepatherror = validator.is_valid_filename(path,baseurl) + if (fs.is_file(path)) then + return false,"File already exists" + end + if (validfilepath) then + fs.write_file(path, "") + return true,nil + else + return false, filepatherror + end + return false, "Something went wrong!" +end diff --git a/tinydns.roles b/tinydns.roles index 111e4c3..6e6fd1f 100644 --- a/tinydns.roles +++ b/tinydns.roles @@ -1,2 +1,2 @@ READ=tinydns:status -UPDATE=tinydns:expert,tinydns:edit +UPDATE=tinydns:expert,tinydns:edit,tinydns:confirmaction |