summaryrefslogtreecommitdiffstats
path: root/openvpn-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'openvpn-model.lua')
-rw-r--r--openvpn-model.lua53
1 files changed, 42 insertions, 11 deletions
diff --git a/openvpn-model.lua b/openvpn-model.lua
index 700bb48..32fc33b 100644
--- a/openvpn-model.lua
+++ b/openvpn-model.lua
@@ -1,8 +1,11 @@
module (..., package.seeall)
require ("posix")
+require ("format")
require ("fs")
+local baseurl = "/etc/openvpn/"
+
-- no initializer in model - use controller.init for that
-- ################################################################################
@@ -22,13 +25,13 @@ end
local function config_content( f )
local config = {}
- config.name = "/etc/openvpn/" .. f
+ config.name = baseurl .. f
local conf_file = fs.read_file_as_array ( config.name )
for i=1,table.maxn(conf_file) do
local l = conf_file[i]
-- Filter out commented lines
if not string.find ( l, "^[;#].*" ) then
- local a,b = string.match ( l, "^%s*(%S*)%s+(%S*).*$" ) -- Working exept on 'remote xxxxx xxxx'
+ local a,b = string.match ( l, "^%s*(%S+)%s*(%S*).*$" )
if (a) then
config[string.lower(a)]=b
end
@@ -108,7 +111,7 @@ end
local function list_conffiles()
local configfiles = {}
local config = {}
- local files , errstr, errno = posix.dir ( "/etc/openvpn/" )
+ local files , errstr, errno = posix.dir ( baseurl )
if files then
for k,v in ipairs(files) do
if string.match (v, "^.*conf$") then
@@ -210,19 +213,46 @@ function openvpn_version()
end
function get_config ( self, f )
+ local path = basename(f)
local configresult = {}
config = nil
- config = config_content ( f )
+ config = config_content ( path )
local clientlist, client_count, client_lastupdate, client_lastdatechangediff = clientlist ()
- local status_isrunning = is_running ("openvpn", f)
+ local status_isrunning = is_running ("openvpn", path)
+ if (client_lastupdate == nil) then
+ config["client_lastupdate"] = "?"
+ else
+ config["client_lastupdate"]=client_lastupdate
+ end
+ if (client_lastupdate == nil) then
+ config["client_lastdatechangediff"] = "? min"
+ else
+ config["client_lastdatechangediff"]=client_lastdatechangediff
+ end
config["client_count"]=client_count
- config["client_lastupdate"]=client_lastupdate
- config["client_lastdatechangediff"]=client_lastdatechangediff
config["status_isrunning"]=status_isrunning
configresult = config
return configresult
end
+function update_filecontent (self, f, modifications)
+ name = basename(f)
+ path = baseurl .. name
+ local available_files = list_conffiles()
+ for k,v in pairs(available_files) do
+ if ( available_files[k].name == name ) then
+ local file = io.open( path, "w+" )
+ local file_result,err = file:write(format.dostounix(modifications))
+ file:close()
+ if (err ~= nil) then
+ local filedetails = get_config(name)
+ file_content = {name=name, value=file_result, filedetails=filedetails, err=err}
+ end
+ end
+ end
+ return file_content
+end
+
function get_logfile( self, path)
config = config_content ( path )
local logfilecontent = fs.read_file ( config.log )
@@ -232,18 +262,19 @@ function get_logfile( self, path)
return ( { name = config.log, value = logfilecontent } )
end
-function get_filecontent( self, path)
+function get_filecontent( self, f)
+ local path = basename(f)
local configresult = {}
config = config_content ( path )
local file = io.open( config.name )
local file_result = file:read("*a") or "unknown"
file:close()
+ local conf_type, err = check_valid_config ( path )
local filedetails = file_info( config.name )
- file_content = cfe{name=config.name, value=file_result, filedetails=filedetails}
+ file_content = cfe{name=config.name, value=file_result, type=conf_type, filedetails=filedetails}
return file_content
end
-
function get_conflist ()
local configlist = {}
for k,v in pairs(list_conffiles()) do
@@ -251,7 +282,7 @@ function get_conflist ()
local conf_type, err = check_valid_config ( v.name )
local isrunning = is_running ("openvpn", v.name)
local clientlist, connclients = clientlist ()
- table.insert ( configlist, cfe{ name = v.name, type = conf_type, test = config.ca, err = err, status = isrunning, clients = connclients } )
+ table.insert ( configlist, cfe{ name = v.name, type = conf_type, err = err, status = isrunning, clients = connclients } )
end
local countconfigs = table.maxn(configlist)
return configlist, countconfigs