summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tinydns-edit-html.lsp137
-rw-r--r--tinydns-model.lua7
2 files changed, 127 insertions, 17 deletions
diff --git a/tinydns-edit-html.lsp b/tinydns-edit-html.lsp
index 93887dd..f1a2f50 100644
--- a/tinydns-edit-html.lsp
+++ b/tinydns-edit-html.lsp
@@ -1,5 +1,117 @@
<? local form, viewlibrary = ... ?>
<? require("viewfunctions") ?>
+
+<script type="text/javascript" src="/js/jquery-latest.js"></script>
+<script type="text/javascript">
+ var editEntry = '<td> \
+ <a href="javascript:;"><img src="/skins/static/tango/16x16/actions/list-add.png" width="16" height="16" title="Add item below this record"></a> \
+ <a href="javascript:;"><img src="/skins/static/tango/16x16/actions/list-remove.png" width="16" height="16" title="Remove this record"></a> \
+ <a href="javascript:;"><img src="/skins/static/tango/16x16/actions/document-properties.png" width="16" height="16" title="Edit this record"></a> \
+ </td>';
+
+ addLinks = function(rows){
+ rows.each(function(){
+ $(this).prepend(editEntry);
+ $(this).find("td > a:eq(0)").click(addLine);
+ $(this).find("td > a:eq(1)").click(deleteLine);
+ $(this).find("td > a:eq(2)").click(editLine);
+ $(this).find("td:eq(1)").dblclick(editLine);
+ });
+ }
+ addLine = function(){
+ addLinks($(this).parent().parent().after('<tr><td></td></tr>').next());
+ };
+ deleteLine = function(){
+ $(this).parent().parent().replaceWith();
+ };
+ function Entry(entryType,descr,num,descr0,descr1,descr2,descr3,descr4,descr5,descr6,descr7,descr8,descr9,descr10){
+ this.entryType=entryType;
+ this.descr=descr;
+ this.num=num;this.descriptions=new Array(11)
+ this.descriptions[0]=descr0;this.descriptions[1]=descr1;this.descriptions[2]=descr2;this.descriptions[3]=descr3;this.descriptions[4]=descr4;this.descriptions[5]=descr5;this.descriptions[6]=descr6;this.descriptions[7]=descr7;this.descriptions[8]=descr8;this.descriptions[9]=descr9;this.descriptions[10]=descr10;
+ };
+
+ var entryTypes = new Array(14);
+ entryTypes[0]=new Entry("","Empty line",0);
+ entryTypes[1]=new Entry(";","Comment line",1,"Comment");
+ entryTypes[2]=new Entry("#","Comment line",1,"Comment");
+ entryTypes[3]=new Entry(".","Name server",6,"Domain","IP address","Name server","Time to live","Timestamp","Location");
+ entryTypes[4]=new Entry("&","Delegate subdomain",6,"Domain","IP address","Name server","Time to live","Timestamp","Location");
+ entryTypes[5]=new Entry("=","Host",5,"Host","IP address","Time to live","Timestamp","Location");
+ entryTypes[6]=new Entry("+","Alias",5,"Alias","IP address","Time to live","Timestamp","Location");
+ entryTypes[7]=new Entry("@","Mail exchanger",7,"Domain","IP address","Mail exchanger","Distance","Time to live","Timestamp","Location");
+ entryTypes[8]=new Entry("'","Text record",5,"Domain","Text Record","Time to live","Timestamp","Location");
+ entryTypes[9]=new Entry("^","Reverse record",5,"PTR","Domain name","Time to live","Timestamp","Location");
+ entryTypes[10]=new Entry("C","Canonical name",5,"Domain","Canonical name","Time to live","Timestamp","Location");
+ entryTypes[11]=new Entry("Z","SOA record",11,"Domain","Primary name server","Contact address","Serial number","Refresh time","Retry time","Expire time","Minimum time","Time to live","Timestamp","Location");
+ entryTypes[12]=new Entry(":","Generic record",6,"Domain","Record type","Record data","Time to live","Timestamp","Location");
+ entryTypes[13]=new Entry("%","Client location",2,"Location","IP prefix");
+
+ createForm = function(entry){
+ var entrytext = entry.text();
+ var entryType = entryTypes[0];
+ var form = '<select>';
+ var typechar = entrytext.charAt(0);
+ if (typechar == null) typechar = "";
+ for (i=0; i<14; i++) {
+ form = form + '<option ';
+ if (typechar == entryTypes[i].entryType){
+ entryType=entryTypes[i];
+ form = form + 'selected ';
+ };
+ form = form + 'value="' + entryTypes[i].entryType + '">' + entryTypes[i].entryType + ' (' + entryTypes[i].descr + ')</option>';
+ };
+ form = form + "</select><br><dl>";
+ entrytext = entrytext.substring(1,entrytext.length);
+ var entries = entrytext.split(":");
+ for (i=0; i<entryType.num; i++){
+ if (entries[i] == null) entries[i] = "";
+ form = form + '<dt>' + entryType.descriptions[i] + '</dt><dd><input type="text" value="' + entries[i] + '"></dd>';
+ };
+ form = form + "</dl>";
+ entry.empty().append(form);
+ entry.find("select").change(function(){
+ var entry = $(this).parent();
+ finishForm(entry);
+ createForm(entry);
+ });
+ };
+ finishForm = function(entry){
+ var entrytext = entry.find("select").val() + entry.find("input").map(function(){
+ return $(this).val();
+ }).get().join(":");
+ entry.empty().append(entrytext);
+ };
+ editLine = function(){
+ var parent = $(this).parent()
+ if (parent.is("td")) {
+ parent = parent.parent();
+ };
+ var entry = parent.find("td:eq(1)");
+ if (entry.find("select").is("select")){
+ finishForm(entry);
+ } else {
+ createForm(entry);
+ }
+ };
+ submitFile = function(){
+ var file = ""
+ var lines = $("#entries").find("tr").find("td:eq(1)");
+ lines.each(function(){
+ if (jQuery(this).find("select").is("select")){
+ finishForm(jQuery(this));
+ }
+ file = file + this.innerText + "\n";
+ });
+ $("input:eq(1)").val(file);
+ };
+
+ $(function(){
+ addLinks($("#entries").find("tr"));
+ $("input.submit").click(submitFile);
+ })
+</script>
+
<?
--[[ DEBUG INFORMATION
io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
@@ -19,24 +131,21 @@ displayitem(form.value.mtime)
?>
</DL>
-<H3>FILE CONTENT</H3>
+<H3>FILE ENTRIES</H3>
<? if form.descr then ?><P CLASS='descr'><?= string.gsub(form.descr, "\n", "<BR>") ?></P><? end ?>
<? if form.errtxt then ?><P CLASS='error'><?= string.gsub(form.errtxt, "\n", "<BR>") ?></P><? end ?>
-<form action="" method="POST">
-<input type="hidden" name="filename" value="<?= form.value.filename.value ?>">
-<textarea name="filecontent">
-<?= form.value.filecontent.value ?>
-</textarea>
+<TABLE id="entries">
+<? for line in string.gmatch(form.value.filecontent.value.."\n", "([^\n]*)\n") do ?>
+ <TR>
+ <TD><?= line ?></TD>
+ </TR>
+<? end ?>
+</TABLE>
<? if form.value.filecontent.errtxt then ?><P CLASS='error'><?= string.gsub(form.value.filecontent.errtxt, "\n", "<BR>") ?></P><? end ?>
+<form action="" method="POST">
+<input type="hidden" name="filename" value="<?= form.value.filename.value ?>">
+<input type="hidden" name="filecontent" value="">
<H2>SAVE AND APPLY ABOVE SETTINGS</H2>
<DL><DT>Save/Apply above settings</DT><DD><input class="submit" type="submit" name="<?= form.option ?>" value="Save"></DD></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 fa0632f..e75f937 100644
--- a/tinydns-model.lua
+++ b/tinydns-model.lua
@@ -18,13 +18,13 @@ local configdir = "/etc/"..processname
local descr = {
prefix={
['.']="Name server for your domain (NS + A + SOA)",
- ['&']="Deletegate subdomain (NS + A)",
+ ['&']="Delegate subdomain (NS + A)",
['=']="Host (A + PTR)",
['+']="Alias (A, no PTR)",
['@']="Mail exchanger (MX)",
["'"]="Text record (TXT)",
['^']="Reverse record (PTR)",
- ['C']="Canonical Name (CNAME)",
+ ['C']="Canonical name (CNAME)",
['Z']="SOA record (SOA)",
[':']="Generic record",
['%']="Client location",
@@ -309,7 +309,8 @@ function updatefilecontent (path, modifications)
if not (fs.is_file(path)) then
errtxt = "Not a filename"
elseif (validfilename(path)) then
- fs.write_file(path, format.dostounix(modifications))
+ modifications = string.gsub(format.dostounix(modifications), "\n*$", "")
+ fs.write_file(path, modifications)
success = true
else
errtxt = "Not a valid filename!"