diff options
author | Mika Havela <mika.havela@gmail.com> | 2007-11-22 16:14:52 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2007-11-22 16:14:52 +0000 |
commit | 21f9432147b05601bc323edbe6b0a4c0daa97089 (patch) | |
tree | dc38efad89a91e82dc438177bcacd52c5d8388cf /openvpn-model.lua | |
parent | caca5e32230dd0237865d70eae4d6a18d942e1ba (diff) | |
download | acf-openvpn-21f9432147b05601bc323edbe6b0a4c0daa97089.tar.bz2 acf-openvpn-21f9432147b05601bc323edbe6b0a4c0daa97089.tar.xz |
OpenVPN Mainpage,Serverconfig,Connectedclients got more functionallity
git-svn-id: svn://svn.alpinelinux.org/acf/openvpn/trunk@355 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'openvpn-model.lua')
-rw-r--r-- | openvpn-model.lua | 119 |
1 files changed, 70 insertions, 49 deletions
diff --git a/openvpn-model.lua b/openvpn-model.lua index f9e8fa2..0f3627b 100644 --- a/openvpn-model.lua +++ b/openvpn-model.lua @@ -10,18 +10,18 @@ require ("fs") -- ################################################################################ -- UNKNOWN -local function read_file_as_array ( path ) - local file, error = io.open(path) - if ( file == nil ) then - return nil, error - end - local f = {} - for line in file:lines() do - table.insert ( f , line ) - end - file:close() - return f -end +--local function read_file_as_array ( path ) +-- local file, error = io.open(path) +-- if ( file == nil ) then +-- return nil, error +-- end +-- local f = {} +-- for line in file:lines() do +-- table.insert ( f , line ) +-- end +-- file:close() +-- return f +--end local function has_init_script ( f ) local initprefix = "/etc/init.d/openvpn" @@ -47,28 +47,31 @@ end local function config_content( f ) local config = {} - local conf_file = fs.read_file_as_array ( "/etc/openvpn/".. f ) + config.name = "/etc/openvpn/" .. 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*)(.*)$" ) + local a,b = string.match ( l, "^%s*(%S*)%s+(%S*).*$" ) config[a]=b --- config[string.gsub(a, "-", "")]=b end end - config.name = f - -- FIXME Variablenames with '-' causes trouble! - config.log = "xXx" - config.maxclients = "xXx" - config.tls = "xXx" - config.crlverify = "xXx" - if not ( config["local"] ) then config["local"] = "0.0.0.0" end --- if not ( config["log"] ) and ( config[log-append] ) then --- a = "log" --- b = "plupp" --- config.log=config["log-append"] --- end + if not ( config.log ) then + config.log = config["log-append"] + end + if not ( config["max-clients"] ) then + config["max-clients"] = "Unlimited" + end + if not ( config["tls-auth"] ) then + config["tls-auth"] = "" + end + if not ( config["crl-verify"] ) then + config["crl-verify"] = "" + end + if not ( config["local"] ) then + config["local"] = "0.0.0.0" + end return config end @@ -99,11 +102,21 @@ local function check_valid_config ( f ) if not (config.client) or not (config.ca) or not (config.cert) or not (config.key) or not (config.dev) or not (config.proto) or not (config.remote) then config.type = nil config.err = "" - if not (config.ca) then config.err = config.err .. "Check CA; " end - if not (config.cert) then config.err = config.err .. "Check CERT; " end - if not (config.key) then config.err = config.err .. "Check KEY; " end - if not (config.dev) then config.err = config.err .. "Check DEV; " end - if not (config.proto) then config.err = config.err .. "Check PROTO; " end + if not (config.ca) then + config.err = config.err .. "Check CA; " + end + if not (config.cert) then + config.err = config.err .. "Check CERT; " + end + if not (config.key) then + config.err = config.err .. "Check KEY; " + end + if not (config.dev) then + config.err = config.err .. "Check DEV; " + end + if not (config.proto) then + config.err = config.err .. "Check PROTO; " + end if (config.client) or not (config.ca) or not (config.cert) or not (config.key) or not (config.dev) or not (config.proto) or not (config.port) then config.type = nil else @@ -125,14 +138,7 @@ local function list_conffiles() if files then for k,v in ipairs(files) do if string.match (v, "^.*conf$") then --- config = "" --- config = config_content ( v ) --- local conf_type, err = check_valid_config ( v ) --- local isrunning = is_running ("openvpn", v) --- local clientlist, connclients = clientlist () --- table.insert ( configfiles, cfe{ name = v, type = conf_type, test = config.ca, err = err, status = isrunning, clients = connclients } ) table.insert ( configfiles, cfe{ name = v } ) - end end return configfiles @@ -141,29 +147,36 @@ end -- ################################################################################ -- PUBLIC FUNCTIONS -function clientlist() - local countclients = "d" +function clientlist( self, path ) + -- DEBUG +-- local path = "openvpn.conf" local clientlist = {} - local f + local f = "" + local f2 = "" + if ( path ) then +-- config = config_content ( config.name ) +-- config = {} + config = config_content ( path ) + end if (config.status) then - f = fs.read_file_as_array( config.status ) - if (f) then + local f = fs.read_file_as_array( config.status ) + if ( f ) then for k,v in ipairs(f) do -- The reason for this compex regexp is that I want to filter away the first 2-3 rows -- that doesn't mach this regexp. - local clientname,clientip,clientport = string.match ( v, "([^,]*)[,]+([%w]+[.*][%w]+[.*][%w]+[.*][%w]+)[:]([%w]+)" ) + local clientname,clientip,clientport,bytesreceived,bytessent = string.match ( v, "([^,]*)[,]+([%w]+[.*][%w]+[.*][%w]+[.*][%w]+)[:]([%w]+)[,](%w*)[,](%w*)" ) -- Routing table is now intresting at this moment. So stop reading file. if ( v == "ROUTING TABLE" ) then break end if ( clientname ~= nil ) then - table.insert ( clientlist, { name = clientname, ip = clientip , port = clientport } ) + table.insert ( clientlist, cfe{ name = clientname, ip = clientip , virtualip = "xXx.xXx.xXx.xXx", port = clientport, received = bytesreceived, sent = bytessent } ) end end end end - countclients = table.maxn(clientlist) - return clientlist, countclients + local connclients = table.maxn(clientlist) + return clientlist, connclients end function openvpn_version() @@ -176,14 +189,22 @@ end function get_serverconfig ( self, f ) local serverconfig = {} config = config_content ( f ) + -- FIXME: change nex row to clientlist(config.name) local clientlist, connclients = clientlist () local isrunning = is_running ("openvpn", config.name) -- FIXME: Get status for autostart_status = 'rc_status | grep this process' local autostart_status = "" - serverconfig = cfe{ name = f, device = config.dev, log = config.log, verb = config.verb, maxclients = config["maxclients"], clients = connclients, status = isrunning, autostart = autostart_status, dh = config.dh, ca = config.ca, cert = config.cert, key = config.key, tls = config.tls , crl = config.crlverify, port = config.port, proto = config.proto, loca = config["local"] } + serverconfig = cfe{ name = f, device = config.dev, log = config.log, verb = config.verb, maxclients = config["max-clients"], clients = connclients, status = isrunning, autostart = autostart_status, dh = config.dh, ca = config.ca, cert = config.cert, key = config.key, tls = config["tls-auth"] , crl = config["crl-verify"], port = config.port, proto = config.proto, loca = config["local"] } return serverconfig end +function get_logfile( self, path) + local logcontent = {} + config = config_content ( path ) + local logfilecontent = fs.read_file_as_array ( config.log ) + return logfilecontent +end + function get_conflist () local configlist = {} for k,v in pairs(list_conffiles()) do |