summaryrefslogtreecommitdiffstats
path: root/interfaces-model.lua
diff options
context:
space:
mode:
authorZach LeBar <zach@zachlebar.com>2012-03-21 15:06:32 +0000
committerZach LeBar <zach@zachlebar.com>2012-03-21 15:09:16 +0000
commit0874f88bc25066248c28b16d3bbf1ab5cd1f2611 (patch)
tree28ee52ea1b8a44eeff8453b6264953a2ab2665bd /interfaces-model.lua
parent6d638ac9d28eac2c144d229359b64c0edaee2b4d (diff)
downloadacf-alpine-baselayout-master.tar.bz2
acf-alpine-baselayout-master.tar.xz
Change all -controller.lua files to use new handle_form() functions found in acf_www-controller.lua instead of the controllerfunctions.lua version and also instead of redirect_to_referrer(). Made corresponding changes to vmail-model .lua to make everything work.HEADmaster
Diffstat (limited to 'interfaces-model.lua')
-rw-r--r--interfaces-model.lua98
1 files changed, 74 insertions, 24 deletions
diff --git a/interfaces-model.lua b/interfaces-model.lua
index 04a1d6c..5d3f9fe 100644
--- a/interfaces-model.lua
+++ b/interfaces-model.lua
@@ -3,9 +3,10 @@
module (..., package.seeall)
require("modelfunctions")
-require("fs")
-require("format")
+fs = require("acf.fs")
+format = require("acf.format")
+local processname = "networking"
local filename = "/etc/network/interfaces"
local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin "
@@ -18,15 +19,15 @@ local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
-- directory for all we know) The public module functions are defined
-- further below
-local iface = { tags = { comment = {type="longtext", label="Comments"},
- auto = {type="boolean", value=false, label="Auto bring-up"},
- name = {label="Interface Name"},
- family = {type="select", label="Address Family", option={"inet", "ipx", "inet6"}},
- ['pre-up'] = {type="longtext", label="'pre-up' actions"},
- up = {type="longtext", label="'up' actions"},
- down = {type="longtext", label="'down' actions"},
- ['post-down'] = {type="longtext", label="'post-down' actions"} },
- method_tag = {type="select", label="Method"},
+local iface = { tags = { 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},
+ ['pre-up'] = {type="longtext", label="'pre-up' actions", seq=6},
+ up = {type="longtext", label="'up' actions", seq=7},
+ down = {type="longtext", label="'down' actions", seq=8},
+ ['post-down'] = {type="longtext", label="'post-down' actions", seq=9} },
+ method_tag = {type="select", label="Method", seq=5},
family_methods = { inet = {"loopback", "static", "manual",
"dhcp", "bootp", "ppp", "wvdial"},
ipx = {"static", "dynamic"},
@@ -366,15 +367,41 @@ end
get_all_interfaces = iface.unpack_interfaces
-get_iface_by_name = iface.read
+get_iface_by_name = function(clientdata)
+ return iface.read(clientdata.name or "")
+end
-get_iface = iface.iface_type
+get_iface = function(clientdata)
+ return iface.iface_type(clientdata.family, clientdata.method)
+end
create_iface = iface.add_after
update_iface = iface.update
-delete_iface_by_name = iface.delete
+get_delete_iface_by_name = function(clientdata)
+ local result = {}
+ result.iface = cfe({ value=clientdata.name or "", label="Interface Name" })
+
+ return cfe({ type="group", value=result, label="Interface Name" })
+end
+
+delete_iface_by_name = function(deleterequest)
+
+ if deleterequest.value.iface.value and deleterequest.value.iface.value ~= "" then
+ local res, err = iface.delete(deleterequest.value.iface.value)
+ end
+
+ if res then
+ deleterequest.descr = res
+ end
+
+ if not res and err then
+ delterequest.errtxt = err
+ end
+
+ return deleterequest
+end
get_status = function ()
local status = {}
@@ -446,35 +473,58 @@ get_addresses = function()
return cfe({ type="structure", value=retval, label="Interface IP Addresses" })
end
-ifup_by_name = function (name)
- name = name or ""
+get_ifup_by_name = function(clientdata)
+ local result = {}
+ result.iface = cfe({ value=clientdata.name or "", label="Interface Name" })
+
+ return cfe({ type="group", value=result, label="Interface Name" })
+end
+
+ifup_by_name = function (ifuprequest)
+ name = ifuprequest.value.iface.value or ""
local cmd = path.."ifup "..name
local f = io.popen(format.escapespecialcharacters(cmd))
local cmdresult = f:read("*a")
f:close()
if cmdresult == "" then
- cmdresult = "Interface up"
+ ifuprequest.descr = "Interface up"
end
- return cfe({ type="longtext", value=cmdresult, label="ifup "..name })
+ return ifuprequest
end
+get_ifdown_by_name = function(clientdata)
+ local result = {}
+ result.iface = cfe({ value=clientdata.name or "", label="Interface Name" })
-ifdown_by_name = function (name)
- name = name or ""
+ return cfe({ type="group", value=result, label="Interface Name" })
+end
+
+ifdown_by_name = function (ifdownrequest)
+ name = ifdownrequest.value.iface.value or ""
local cmd = path.."ifdown "..name
local f = io.popen(format.escapespecialcharacters(cmd))
local cmdresult = f:read("*a")
f:close()
if cmdresult == "" then
- cmdresult = "Interface down"
+ ifdownrequest.descr = "Interface down"
end
- return cfe({ type="longtext", value=cmdresult, label="ifdown "..name })
+ return ifdownrequest
+end
+
+get_restartnetworking = function(clientdata)
+ --return modelfunctions.get_startstop(processname)
+ local actions = {}
+ actions[1] = "restart"
+ local service = cfe({ type="hidden", value="networking", label="Service Name" })
+ local startstop = cfe({ type="group", label="Reload Modules", value={servicename=service}, option=actions, errtxt=errtxt })
+
+ return startstop
end
-restartnetworking = function()
- return modelfunctions.startstop_service("networking", "restart")
+restartnetworking = function(startstop)
+ return modelfunctions.startstop_service(startstop, "restart")
end