From 70b28419e50d7947ab1220517e5c3495aca73a93 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Fri, 28 Mar 2008 11:44:58 +0000 Subject: 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 --- interfaces-config-html.lsp | 45 ++++++++++++++++++ interfaces-controller.lua | 3 +- interfaces-model.lua | 30 ++++++++++-- interfaces-read-html.lsp | 116 +++++++++++++++++++++++++++++---------------- interfaces-update-html.lsp | 48 +++++++++++++++---- 5 files changed, 185 insertions(+), 57 deletions(-) create mode 100644 interfaces-config-html.lsp 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 @@ + + +

Interfaces file

+ +

New interface

+
+
Create new interface
+
[Create]
+
+ +

Existing interface(s)

+ + 0 then do + j = view.iface[i] + iface = j.name.value ?> +

+
+
Method
+
+ +
Hostname
+
+ +
Address
+
/
+ + +
Comments
+
+ + + + +
Modify this interface
+
[update] +[delete]
+
+ + + + + + 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 @@ - - -

Interfaces file

- -

New interface

-
-
Create new interface
-
[Create]
-
- -

Existing interface(s)

- - 0 then do - j = view.iface[i] - iface = j.name.value ?> -

-
-
Method
-
- -
Hostname
-
- -
Address
-
/
- - -
Comments
-
- - - - -
Modify this interface
-
[update] -[delete]
-
- - - + +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> + 0) then + val.class = "error" + io.write(" class='error'") + end + io.write(">" .. val.label .. "\n") + if (viewonly) then + io.write("\t\t
" .. val.value .. "\n") + else + io.write("\t\t
" .. html.form[val.type](val) .. "\n") + end + if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end + if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end + io.write("\t\t
\n") + end + end +end +?> + +

SYSTEM INFO

+
+ +
+ +

Configurations

+
+Configured interfaces
") +for k,v in pairs(myform) do + local myform=v + if (myform.name.value ~= "") then + io.write("") + io.write("") + + 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("") + io.write("") + end + end + io.write("
" .. (myform.name.value or '') .. "
" .. myform[v1]['label'] .. "" .. string.gsub(myform[v1]['value'], "\n", "
") .. "
") + end + +end +io.write("
") +?> +
+ +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> 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 @@ +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> + +") + for k,v in pairs(tags) do + if (myform[v]) and (myform[v]["value"]) then + local val = myform[v] + io.write("\t 0) then + val.class = "error" + io.write(" class='error'") + end + io.write(">" .. val.label .. "\n") + if (viewonly) then + io.write("\t\t
" .. val.value .. "\n") + else + io.write("\t\t
" .. html.form[val.type](val) .. "\n") + end + if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end + if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end + io.write("\t\t
\n") + end + end + io.write("") +end +?> +

Update Interface

" method="POST"> - -
- -
- +?>
-- cgit v1.2.3