diff options
Diffstat (limited to 'openntpd-config-html.lsp')
-rw-r--r-- | openntpd-config-html.lsp | 190 |
1 files changed, 101 insertions, 89 deletions
diff --git a/openntpd-config-html.lsp b/openntpd-config-html.lsp index dd330a7..88450e7 100644 --- a/openntpd-config-html.lsp +++ b/openntpd-config-html.lsp @@ -1,109 +1,121 @@ -<? local view = ... ?> +<? local form = ... ?> -<h1>SYSTEM INFO</h1> +<? +--[[ 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>") +--]] +?> -<dl> -<dt>Program status</dt> -<dd><? if (view.status.enabled) then io.write('Enabled') else io.write('Disabled') end ?></dd> +<? +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 +?> -<dt>Program version</dt> -<dd><?= view.status.version ?></dd> -</dl> +<H1>SYSTEM INFO</H1> +<DL> +<? +local myform = form.status +local tags = { "status", "version", } +displayinfo(myform,tags,"viewonly") +?> +</DL> -<h1>CONFIGURATION</h1> +<h1>CONFIGURATION</h1> <H2>Advanced config</H2> <H3>General settings</H3> - +<DL> <form name="cmd" action="" method="POST"> +<? +local myform = form.config +local tags = { "setstimeonstartup", "cmdsavesetstimeonstartup", } +displayinfo(myform,tags) +?> +</DL> -<dl> -<dt>Set time immediately at startup</dt> -<dd><input type="checkbox" name="settings_startup" <? if (view.status.setstimeonstartup) then io.write("checked") end ?>></dd> - -<dt>Save the above settings</dt> -<dd><input name="settings_cmd" class="submit" type="submit" value="Save"> (see above) -</dd> - -</dl> -</form> <h3>'SET TIME' OPTIONS</h3> - -<form name="cmd" action="" method="POST"> - -<dl> -<dt>Timeserver hosts...</dt> -<dd> -<select name="hosts_list" size="3"> -<? if (view.config.variables.servers) then -for i = 1, table.maxn(view.config.variables.servers) do ?> - <option value="servers <? io.write(view.config.variables.servers[i].value) ?>"><? io.write(view.config.variables.servers[i].value) ?> (pool)</option> -<? end end ?> -<? if (view.config.variables.server) then -for i = 1, table.maxn(view.config.variables.server) do ?> - <option value="server <? io.write(view.config.variables.server[i].value) ?>"><? io.write(view.config.variables.server[i].value) ?></option> -<? end end ?> -</select><BR> -In most cases you could use <i><b>pool.ntp.org</b></i> or <i><b>[countryname].pool.ntp.org</i></b> (if listed in <i><b>http://www.pool.ntp.org/</b></i>). -<? if (view.errors.hosts_list) then io.write("<p class=error>"..view.errors.hosts_list.."</p>") end ?></dd> - -<dt>Delete selected host</dt> -<dd><input name="hosts_cmd" class="submit" type="submit" value="Delete"> (see above)</dd> - -<dt <? if (view.errors.hosts_add) then io.write("class=error") end ?>>Host to add</dt> -<dd><input type="text" name="hosts_add" class="text" value="<?= view.errors.hosts_add_orgvalue or "" ?>"><? if (view.errors.hosts_add) then io.write("<p class=error>"..view.errors.hosts_add.."</p>") end ?></dd> - -<dt <? if (view.errors.hosts_type) then io.write("class=error") end ?>>Type of above server</dt> -<dd><span style="display:inline">Single server:<input type="radio" name="hosts_type" value="server"> Server pool:<input type="radio" name="hosts_type" value="servers"></span><? if (view.errors.hosts_type) then io.write("<p class=error>"..view.errors.hosts_type.."</p>") end ?></dd> - -<dt>Add new host</dt> -<dd><input name="hosts_cmd" class="submit"type="submit" value="Add"></dd> -</dl> +<DL> +<? +local myform = form.config +local tags = { "hosts_list", "hosts_cmd_delete", "hosts_add", "hosts_type", "hosts_cmd_add", } +displayinfo(myform,tags) +?> </form> +</DL> -<h3>'PRESENT TIME' OPTIONS (ACT AS TIME SERVER)</h3> +<h3>'PRESENT TIME' OPTIONS (ACT AS TIME SERVER)</h3> <form name="cmd" action="" method="POST"> -<dl> -<dt>Listen on address...</dt> -<dd> -<select name="listen_list" size="3"> -<? if (view.config.variables.listen) then -for i = 1, table.maxn(view.config.variables.listen) do ?> - <option value="listen on <? io.write(view.config.variables.listen[i].value) ?>"><? io.write(view.config.variables.listen[i].value) ?></option> -<? end end ?> -</select><BR>Empty list = Listening (acting as server) is disabled<br>"*" = Listen on all local addresses -<? if (view.errors.listen_list) then io.write("<p class=error>"..view.errors.listen_list.."</p>") end ?> -</dd> - -<dt>Delete selected address</dt> -<dd><input name="listen_cmd" type="submit" class="submit" value="Delete"> (see above)</dd> - -<dt>Add new listen address</dt> -<dd><input name="listen_add" type="text" class="text" value=""> <input name="listen_cmd" type="submit" class="submit" value="Add"><? if (view.errors.listen_add) then io.write("<p class=error>"..view.errors.listen_add.."</p>") end ?></dd> -</dl> -</form> - -<H1>MANAGEMENT</H1> - -<dl> -<dt>Program controll-panel</dt> -<dd><form name="cmd" action="" method="POST"> -<input type=submit class="submit" name="cmd" value="start"> -<input type=submit class="submit" name="cmd" value="stop"> -<input type=submit class="submit" name="cmd" value="restart"> -</form></dd> - -<? if (view.startstop) and (view.startstop.cmdresult) then ?> -<dt>Previous action result</dt> -<dd><pre><?= view.startstop.cmdresult?></pre></dd> -<? end ?> -</dl> +<DL> +<? +local myform = form.config +local tags = { "listen_list", "listen_cmd_delete", "listen_add", "listen_cmd_add", } +displayinfo(myform,tags) +?> +</DL> + + +<? -- MANAGEMENT BUTTONS +local cmdform = form.management +local cmdresult = form.cmdmanagement +local tags = { "start", "stop", "restart" } +if (cmdform) and (cmdform[tags[1]]) then + + io.write('<form name="management" action="" method="POST">') + io.write('<H1>MANAGEMENT</H1>') + io.write('<dl>') + io.write('<dt>' .. cmdform[tags[1]]["label"] .. '</dt>') + io.write('<dd>') + for k,v in pairs(tags) do + if (cmdform[v]) then + io.write(html.form[cmdform[v].type](cmdform[v])) + end + end + io.write('</dd>') + + if (cmdresult) and (cmdresult.action) and (#cmdresult.action.descr > 0) then + io.write('<dt>' .. cmdresult.label .. '</dt>') + io.write('<dd><pre>' .. cmdresult.action.descr .. '</pre></dd>') + end + io.write('</dl></form>') +end ?> <? --[[ DEBUG INFORMATION -require("debugs") -io.write(debugs.variables(view)) +io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") +io.write(html.cfe_unpack(form)) +io.write("</span>") --]] ?> |