From 50f946418c3fbd5fd32f5218b177920a065a53ac Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Thu, 6 Dec 2012 00:53:52 +0000 Subject: Interfaces: Move iface structure to a separate file and use it in view to determine which options to display The previous method meant that each option was defined in both the model and in the view. Now, everything is defined in the model, and the view just hides / shows as desired. --- interfaces-definitions.lua | 61 ++++++++++++++++++ interfaces-model.lua | 71 ++------------------- interfaces-update-html.lsp | 156 ++++++++++++--------------------------------- 3 files changed, 108 insertions(+), 180 deletions(-) create mode 100644 interfaces-definitions.lua diff --git a/interfaces-definitions.lua b/interfaces-definitions.lua new file mode 100644 index 0000000..9b6704a --- /dev/null +++ b/interfaces-definitions.lua @@ -0,0 +1,61 @@ +module (..., package.seeall) +-- Definitions of interface cfe's / options + required = { + comment = {type="longtext", label="Comments", seq=2}, + auto = {type="boolean", value=false, label="Auto bring-up", seq=3}, + name = {label="Interface Name", seq=1}, + family = {type="select", label="Address Family", option={"inet", "ipx", "inet6"}, seq=4}, + method = {type="select", label="Method", option={"loopback", "static", "manual", "dhcp", "bootp", "ppp", "wvdial", "dynamic", "v4tunnel"}, seq=5}, + ['pre-up'] = {type="longtext", label="'pre-up' actions", seq=100}, + up = {type="longtext", label="'up' actions", seq=101}, + down = {type="longtext", label="'down' actions", seq=102}, + ['post-down'] = {type="longtext", label="'post-down' actions", seq=103}, + } + family_methods = { + inet = {"loopback", "static", "manual", "dhcp", "bootp", "ppp", "wvdial"}, + ipx = {"static", "dynamic"}, + inet6 = {"loopback", "static", "manual", "v4tunnel"}, + } + method_options = { + inet = { + static = {"address", "netmask", "broadcast", "network", "metric", "gateway", "pointopoint", "media", "hwaddress", "mtu"}, + dhcp = {"hostname", "leasehours", "leasetime", "vendor", "client", "hwaddress"}, + bootp = {"bootfile", "server", "hwaddr"}, + ppp = {"provider"}, + wvdial = {"provider"}, + }, + ipx = { + static = {"frame", "netnum"}, + dynamic = {"frame"}, + }, + inet6 ={ + static = {"address", "netmask", "gateway", "media", "hwaddress", "mtu"}, + v4tunnel = {"address", "netmask", "endpoint", "local", "gateway", "ttl"}, + }, + } + optional = { + address = {label="Address", seq=6}, + netmask = {label="Netmask", seq=7}, + endpoint = {label="Endpoint address", seq=8}, + ['local'] = {label="Local address", seq=9}, + broadcast = {label="Broadcast address", seq=10}, + network = {label="Network address", seq=11}, + metric = {label="Routing metric", seq=12}, + gateway = {label="Default gateway", seq=13}, + pointopoint = {label="Point-to-point address", seq=14}, + media = {label="Medium type", seq=15}, + hostname = {label="Hostname", seq=16}, + leasehours = {label="Preferred lease time (hours)", seq=17}, + leasetime = {label="Preferred lease time (seconds)", seq=18}, + vendor = {label="Vendor class identifier", seq=19}, + client = {label="Client identifier", seq=20}, + hwaddress = {label="Hardware address", seq=21}, + mtu = {label="MTU size", seq=22}, + bootfile = {label="Boot file", seq=23}, + server = {label="Server address", seq=24}, + hwaddr = {label="Hardware address", seq=25}, + provider = {label="Provider name", seq=26}, + frame = {label="Ethernet frame type", seq=27}, + netnum = {label="Network number", seq=28}, + ttl = {label="TTL setting", seq=29}, + } diff --git a/interfaces-model.lua b/interfaces-model.lua index 59e16ba..1e86b8c 100644 --- a/interfaces-model.lua +++ b/interfaces-model.lua @@ -14,67 +14,7 @@ local array -- iface is a local table with cfes for the various parts of interface definitions -- Depending on the address family and corresponding method, different options are valid -local iface = { - required = { - comment = {type="longtext", label="Comments", seq=2}, - auto = {type="boolean", value=false, label="Auto bring-up", seq=3}, - name = {label="Interface Name", seq=1}, - family = {type="select", label="Address Family", option={"inet", "ipx", "inet6"}, seq=4}, - method = {type="select", label="Method", option={"loopback", "static", "manual", "dhcp", "bootp", "ppp", "wvdial", "dynamic", "v4tunnel"}, seq=5}, - ['pre-up'] = {type="longtext", label="'pre-up' actions", seq=100}, - up = {type="longtext", label="'up' actions", seq=101}, - down = {type="longtext", label="'down' actions", seq=102}, - ['post-down'] = {type="longtext", label="'post-down' actions", seq=103}, - }, - family_methods = { - inet = {"loopback", "static", "manual", "dhcp", "bootp", "ppp", "wvdial"}, - ipx = {"static", "dynamic"}, - inet6 = {"loopback", "static", "manual", "v4tunnel"}, - }, - method_options = { - inet = { - static = {"address", "netmask", "broadcast", "network", "metric", "gateway", "pointopoint", "media", "hwaddress", "mtu"}, - dhcp = {"hostname", "leasehours", "leasetime", "vendor", "client", "hwaddress"}, - bootp = {"bootfile", "server", "hwaddr"}, - ppp = {"provider"}, - wvdial = {"provider"}, - }, - ipx = { - static = {"frame", "netnum"}, - dynamic = {"frame"}, - }, - inet6 ={ - static = {"address", "netmask", "gateway", "media", "hwaddress", "mtu"}, - v4tunnel = {"address", "netmask", "endpoint", "local", "gateway", "ttl"}, - }, - }, - optional = { - address = {label="Address", seq=6}, - netmask = {label="Netmask", seq=7}, - endpoint = {label="Endpoint address", seq=8}, - ['local'] = {label="Local address", seq=9}, - broadcast = {label="Broadcast address", seq=10}, - network = {label="Network address", seq=11}, - metric = {label="Routing metric", seq=12}, - gateway = {label="Default gateway", seq=13}, - pointopoint = {label="Point-to-point address", seq=14}, - media = {label="Medium type", seq=15}, - hostname = {label="Hostname", seq=16}, - leasehours = {label="Preferred lease time (hours)", seq=17}, - leasetime = {label="Preferred lease time (seconds)", seq=18}, - vendor = {label="Vendor class identifier", seq=19}, - client = {label="Client identifier", seq=20}, - hwaddress = {label="Hardware address", seq=21}, - mtu = {label="MTU size", seq=22}, - bootfile = {label="Boot file", seq=23}, - server = {label="Server address", seq=24}, - hwaddr = {label="Hardware address", seq=25}, - provider = {label="Provider name", seq=26}, - frame = {label="Ethernet frame type", seq=27}, - netnum = {label="Network number", seq=28}, - ttl = {label="TTL setting", seq=29}, - }, -} +local iface = require("alpine-baselayout/interfaces-definitions") -- Create an interface structure with all options local get_blank_iface = function () @@ -297,15 +237,18 @@ end get_iface_by_name = function(self, clientdata) -- if the name is blank, then return a blank iface with error + local ret unpack_interfaces() local rc, idx = arrayindex(clientdata.name or "") if rc == false then - local ret = get_blank_iface() + ret = get_blank_iface() ret.value.name.value = name ret.value.name.errtxt = "Interface does not exist" - return ret + else + ret = array[idx] end - return array[idx] + ret.value.name.readonly = true + return ret end get_iface = function(self, clientdata) diff --git a/interfaces-update-html.lsp b/interfaces-update-html.lsp index 06c88e0..579b9b2 100644 --- a/interfaces-update-html.lsp +++ b/interfaces-update-html.lsp @@ -1,89 +1,35 @@ <% local form, viewlibrary, page_info = ... require("htmlviewfunctions") html = require("acf.html") +require("json") + +-- iface is a local table with cfes for the various parts of interface definitions +-- Depending on the address family and corresponding method, different options are valid +local iface = require("alpine-baselayout/interfaces-definitions") +for name,value in pairs(iface.optional) do + form.value[name].class = "optional" +end %>

<%= html.html_escape(form.label) %><% if page_info.action == "update" then io.write(html.html_escape(" - "..form.value.name.value)) end %>

<% - if page_info.action == "update" then - form.value.name.readonly = true - end - local order = {"name", "comment", "auto", "family", "method", "pre-up", "up", "down", "post-down"} - htmlviewfunctions.displayform(form, order) + htmlviewfunctions.displayform(form, nil, nil, page_info, 2) %> -- cgit v1.2.3