summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-03-28 11:44:58 +0000
committerMika Havela <mika.havela@gmail.com>2008-03-28 11:44:58 +0000
commit70b28419e50d7947ab1220517e5c3495aca73a93 (patch)
treeda6e5122d68befca005f27b4dff04af7911bf870
parentc2af45dbef7d1cd8036bb6f94e03649bd2e9b786 (diff)
downloadacf-alpine-baselayout-70b28419e50d7947ab1220517e5c3495aca73a93.tar.bz2
acf-alpine-baselayout-70b28419e50d7947ab1220517e5c3495aca73a93.tar.xz
Cleaned up 'read' tab so it only allows read (no edit actions).
git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@856 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--interfaces-config-html.lsp45
-rw-r--r--interfaces-controller.lua3
-rw-r--r--interfaces-model.lua30
-rw-r--r--interfaces-read-html.lsp116
-rw-r--r--interfaces-update-html.lsp48
5 files changed, 185 insertions, 57 deletions
diff --git a/interfaces-config-html.lsp b/interfaces-config-html.lsp
new file mode 100644
index 0000000..e3a13e9
--- /dev/null
+++ b/interfaces-config-html.lsp
@@ -0,0 +1,45 @@
+<? local view = ... ?>
+
+<h1>Interfaces file</h1>
+
+<h2>New interface</h2>
+<dl>
+<dt>Create new interface</dt>
+<dd>[<a href="create?iface=">Create</a>]</dd>
+</dl>
+
+<h2>Existing interface(s)</h2>
+
+<? for i=0,table.maxn(view.iface) do
+ local iface=""
+ if i > 0 then do
+ j = view.iface[i]
+ iface = j.name.value ?>
+<h3><?= j.name.value ?></h3>
+<dl>
+<dt>Method</dt>
+<dd><?= j.method.value ?></dd>
+<? if ( j.method.value == "dhcp" ) then ?>
+ <dt>Hostname</dt>
+ <dd><?= j.address.value ?></dd>
+<? elseif ( j.address.value ~= "" ) then?>
+ <dt>Address</dt>
+ <dd><?= j.address.value ?>/<?= j.netmask.value ?></dd>
+<? end ?>
+<? if (j.comment.value ~= "") then ?>
+ <dt>Comments</dt>
+ <dd><?= j.comment.value ?></dd>
+<? end ?>
+
+<? local val = {value="update", type="submit", option="", errtxt=""}?>
+
+<dt>Modify this interface</dt>
+<dd>[<a href="<?= view.actions.link .. "update?iface=" .. j.name.value ?>">update</a>]
+[<a href="<?= view.actions.link .. "delete?iface=" .. j.name.value ?>">delete</a>]</dd>
+</dl>
+<? end ?>
+<? end ?>
+<? end ?>
+
+
+
diff --git a/interfaces-controller.lua b/interfaces-controller.lua
index ad4ba05..1a33bc2 100644
--- a/interfaces-controller.lua
+++ b/interfaces-controller.lua
@@ -39,6 +39,7 @@ end
read = function (self )
local iface = self.model.get_all_interfaces()
+ local status = self.model.get_status()
-- these actions are available for each interface
-- **FIXME** This is technically wrong. The controller should pass
-- the "script" "prefix" "controller" "action" as separate fields,
@@ -47,7 +48,7 @@ read = function (self )
local actions = { link = ENV["SCRIPT_NAME"] .. self.conf.prefix ..
self.conf.controller .. "/",
action = { "create", "read", "update", "delete" } }
- return ( { actions = actions, iface = iface } )
+ return ( { actions = actions, iface = iface, status=status } )
end
diff --git a/interfaces-model.lua b/interfaces-model.lua
index b0d3b05..efc5ed9 100644
--- a/interfaces-model.lua
+++ b/interfaces-model.lua
@@ -15,13 +15,26 @@ local iface = { tags = { "name", "comment", "method", "address",
"netmask", "gateway", "hostname", "provider",
"pre-up", "up", "down", "post-down" },
methods = { "dhcp", "static", "ppp", "loopback", "manual" },
+ label = { ['name']="Interface names" ,
+ ['comment']="Comments",
+ ['method']="Method",
+ ['address']="Address",
+ ['netmask']="Netmask",
+ ['gateway']="Gateway",
+ ['hostname']="Hostname",
+ ['provider']="Provider",
+ ['pre-up']="'pre-up' actions",
+ ['up']="'up' actions",
+ ['down']="'down' actions",
+ ['post-down']="'post-down' actions",
+ },
-- lowlevel functions will insert file and array here
}
-- Lowlevel functions - they do things directly to iface.
+local filename = "/etc/network/interfaces"
iface.read_file = function ()
- local filename = "/etc/network/interfaces"
iface.file = cfe { name=filename, filename=filename }
local file = io.open(filename)
local rc = false
@@ -49,14 +62,14 @@ iface.write_file = function ()
function iface.iface_type ( )
local f = {}
for k,v in pairs(iface.tags) do
- f[v] = cfe { name = v }
+ f[v] = cfe { name = v, label = (iface.label[v] or "") }
end
for k,v in pairs ({"comment", "pre-up", "up", "down", "post-down"}) do
f[v].type ="longtext"
end
-
+
f.method.type = "select"
f.method.option = iface.methods
return (f)
@@ -141,6 +154,7 @@ function iface.unpack_interfaces ()
local param, val =
string.match(line, "(%S+)%s*(.*)$")
if (param) then
+ if not (array[count][param]) then array[count][param] = {} end
array[count][param].value =
iface.append (array[count][param].value, val)
end
@@ -281,4 +295,12 @@ end
delete_iface_by_name = iface.delete
-
+get_status = function ()
+ local status = {}
+ status.interfacesfile = cfe({
+ name="interfacesfile",
+ label="Interfaces file",
+ value=filename,
+ })
+ return status
+end
diff --git a/interfaces-read-html.lsp b/interfaces-read-html.lsp
index e3a13e9..8400151 100644
--- a/interfaces-read-html.lsp
+++ b/interfaces-read-html.lsp
@@ -1,45 +1,77 @@
-<? local view = ... ?>
-
-<h1>Interfaces file</h1>
-
-<h2>New interface</h2>
-<dl>
-<dt>Create new interface</dt>
-<dd>[<a href="create?iface=">Create</a>]</dd>
-</dl>
-
-<h2>Existing interface(s)</h2>
-
-<? for i=0,table.maxn(view.iface) do
- local iface=""
- if i > 0 then do
- j = view.iface[i]
- iface = j.name.value ?>
-<h3><?= j.name.value ?></h3>
-<dl>
-<dt>Method</dt>
-<dd><?= j.method.value ?></dd>
-<? if ( j.method.value == "dhcp" ) then ?>
- <dt>Hostname</dt>
- <dd><?= j.address.value ?></dd>
-<? elseif ( j.address.value ~= "" ) then?>
- <dt>Address</dt>
- <dd><?= j.address.value ?>/<?= j.netmask.value ?></dd>
-<? end ?>
-<? if (j.comment.value ~= "") then ?>
- <dt>Comments</dt>
- <dd><?= j.comment.value ?></dd>
-<? end ?>
-
-<? local val = {value="update", type="submit", option="", errtxt=""}?>
-
-<dt>Modify this interface</dt>
-<dd>[<a href="<?= view.actions.link .. "update?iface=" .. j.name.value ?>">update</a>]
-[<a href="<?= view.actions.link .. "delete?iface=" .. j.name.value ?>">delete</a>]</dd>
-</dl>
-<? end ?>
-<? end ?>
-<? end ?>
+<? 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,viewonly)
+ for k,v in pairs(tags) do
+ if (myform[v]) and (myform[v]["value"]) then
+ local val = myform[v]
+ io.write("\t<DT")
+ if (#val.errtxt > 0) then
+ val.class = "error"
+ io.write(" class='error'")
+ end
+ io.write(">" .. val.label .. "</DT>\n")
+ if (viewonly) then
+ io.write("\t\t<DD>" .. val.value .. "\n")
+ else
+ io.write("\t\t<DD>" .. html.form[val.type](val) .. "\n")
+ end
+ if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end
+ if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end
+ io.write("\t\t</DD>\n")
+ end
+ end
+end
+?>
+
+<H1>SYSTEM INFO</H1>
+<DL>
+<?
+local myform = form.status
+local tags = { "interfacesfile" }
+displayinfo(myform,tags,"viewonly")
+?>
+</DL>
+
+<H2>Configurations</H2>
+<DL>
+<?
+local myform = form.iface
+io.write("<DT>Configured interfaces</DT><DD>")
+for k,v in pairs(myform) do
+ local myform=v
+ if (myform.name.value ~= "") then
+ io.write("<TABLE STYLE='margin-bottom:10px'>")
+ io.write("<TR><TD COLSPAN=2 STYLE='font-weight:bold;'><IMG SRC='/static/tango/16x16/devices/network-wired.png' width='16' height='16'> " .. (myform.name.value or '') .. "</TD></TR>")
+
+ local tags = {"method", "address", "netmask", "gateway", "provider", "hostname", "pre-up", "up", "down", "post-down", "comment", }
+ for k1,v1 in pairs(tags) do
+ if (myform[v1]['value'] ~= "") then
+ io.write("<TR><TD WIDTH='120px' STYLE='font-weight:bold;padding-left:25px;'>" .. myform[v1]['label'] .. "</TD>")
+ io.write("<TD>" .. string.gsub(myform[v1]['value'], "\n", "<BR>") .. "</TD></TR>")
+ end
+ end
+ io.write("</TABLE>")
+ end
+
+end
+io.write("</DD>")
+?>
+</DL>
+
+<?
+--[[ 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/interfaces-update-html.lsp b/interfaces-update-html.lsp
index 09743f3..228e8e0 100644
--- a/interfaces-update-html.lsp
+++ b/interfaces-update-html.lsp
@@ -1,11 +1,45 @@
<? 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,viewonly)
+ io.write("<DL>")
+ for k,v in pairs(tags) do
+ if (myform[v]) and (myform[v]["value"]) then
+ local val = myform[v]
+ io.write("\t<DT")
+ if (#val.errtxt > 0) then
+ val.class = "error"
+ io.write(" class='error'")
+ end
+ io.write(">" .. val.label .. "</DT>\n")
+ if (viewonly) then
+ io.write("\t\t<DD>" .. val.value .. "\n")
+ else
+ io.write("\t\t<DD>" .. html.form[val.type](val) .. "\n")
+ end
+ if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end
+ if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end
+ io.write("\t\t</DD>\n")
+ end
+ end
+ io.write("</DL>")
+end
+?>
+
<h1>Update Interface <?= form.value.name.value ?></h1>
<form action="<?= form.option.script .. "/" .. form.option.prefix ..
form.option.controller .. "/" .. form.option.action ..
form.option.extra ?>" method="POST">
-<? local myform = form.value
+<?
-- We redefine the list of tags from the model (iface_tags) because
-- the VIEW can choose the order to display the data. The Controller
@@ -14,15 +48,9 @@
-- In this case, we don't show "name" - since its already known
local tags = { "comment", "method", "address", "netmask", "gateway",
"hostname", "provider", "pre-up", "up", "down", "post-down", "cmd" }
+local myform = form.value
+displayinfo(myform,tags)
-for i,v in pairs(tags) do
- local val = myform[v] ?>
-<dt><? if (val.label) then io.write(val.label) else io.write (v) end ?></dt>
- <? if val.name == "" then
- val.name = v
- end
- ?>
- <dd><?= html.form[val.type](val) ?></dd>
-<? end ?>
+?>
</form>