diff options
author | Mika Havela <mika.havela@gmail.com> | 2007-11-23 17:09:41 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2007-11-23 17:09:41 +0000 |
commit | 735ea7df94733372212914677007350f405062a0 (patch) | |
tree | a824a8eaccd14e1d2bc01009a42013aedb75ec7e /openvpn-model.lua | |
parent | c6ceb72038d970ba894b4d54cd76e157715a07c4 (diff) | |
download | acf-openvpn-735ea7df94733372212914677007350f405062a0.tar.bz2 acf-openvpn-735ea7df94733372212914677007350f405062a0.tar.xz |
Save work for weekend
git-svn-id: svn://svn.alpinelinux.org/acf/openvpn/trunk@362 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'openvpn-model.lua')
-rw-r--r-- | openvpn-model.lua | 112 |
1 files changed, 107 insertions, 5 deletions
diff --git a/openvpn-model.lua b/openvpn-model.lua index 15c791c..22ea045 100644 --- a/openvpn-model.lua +++ b/openvpn-model.lua @@ -98,7 +98,9 @@ local is_running = function( process, parameters ) end end end - return retval +-- return retval + --DEBUG + return path end local function check_valid_config ( f ) @@ -149,9 +151,108 @@ local function list_conffiles() end end +-- FIXME: This should probably go in the time/date library +-- This function gives diff (in seconds) between 'date' and current time. +local function month_to_num ( dt ) + local strsplit = require("split") + -- date is something like "Fri 11 23 10:34:07 2007" + local olddate = strsplit(" ",dt) + local hour,min,sec = string.match ( rawget(olddate,4), "(%d%d):(%d%d):(%d%d)" ) + local olddatetable = { year = rawget(olddate,5), month = rawget(olddate,2), day = rawget(olddate,3), hour = hour, min = min, sec = sec } + + -- fetch current time + local f,err = io.popen("date") + currdate = f:read("*l") + f:close() + local newdate = strsplit(" ",currdate) + local hour,min,sec = string.match ( rawget(newdate,4), "(%d%d):(%d%d):(%d%d)" ) + local month = rawget(newdate,2) + local nummonth = "" + if (string.lower(month) == "jan") then nummonth = "1" end + if (string.lower(month) == "feb") then nummonth = "2" end + if (string.lower(month) == "mar") then nummonth = "3" end + if (string.lower(month) == "apr") then nummonth = "4" end + if (string.lower(month) == "may") then nummonth = "5" end + if (string.lower(month) == "jun") then nummonth = "6" end + if (string.lower(month) == "jul") then nummonth = "7" end + if (string.lower(month) == "aug") then nummonth = "8" end + if (string.lower(month) == "sep") then nummonth = "9" end + if (string.lower(month) == "oct") then nummonth = "10" end + if (string.lower(month) == "nov") then nummonth = "11" end + if (string.lower(month) == "dec") then nummonth = "12" end + local newdatetable = { year = rawget(newdate,6), month = nummonth, day = rawget(newdate,3), hour = hour, min = min, sec = sec } + +-- return os.difftime(os.time(newdatetable),os.time(olddatetable)) + -- Return currdate, olddate, datediff + return os.time(newdatetable), os.time(olddatetable), os.difftime(os.time(newdatetable),os.time(olddatetable)) +end + -- ################################################################################ -- PUBLIC FUNCTIONS + function clientlist( self, path ) + local clientlist = {} + local routinglist = {} + local list = {} + local f = "" + local clientlst = nil + local routinglst = nil + local strsplit = require("split") + if ( path ) then + config = config_content ( path ) + end + if (config.status) then + local f = fs.read_file_as_array( config.status ) + if ( f ) then + for k,v in ipairs(f) do + local col = strsplit(",", v) + if ( col[1] == "ROUTING TABLE" ) then + clientlst = nil + end + + if ( clientlst ) then + table.insert(clientlist, { CN=col[1], + REALADDR=col[2], + BYTESRCV=col[3], + BYTESSND=col[4], + CONN=col[5] } ) + end + if ( routinglst ) then + table.insert(routinglist, { VIRTADDR=col[1], + CN=col[2], + REALADDR=col[3], + LAST=col[4] } ) + end + + if ( col[1] == "Common Name" ) then + clientlst = "YES" + end + if ( col[1] == "ROUTING TABLE" ) then + routinglst = "YES" + end + if ( col[1] == "GLOBAL STATS" ) then + routinglst = nil + end + end + end + end + -- JOIN 'CLIENT_LIST' and 'ROUTING_LIST' TABLES INTO ONE TABLE + for k,v in ipairs(clientlist) do + for kk,vv in ipairs(routinglist) do + if ( v.CN == vv.CN ) then +-- local difftime = month_to_num("Fri 11 23 10:34:07 2007") + table.insert(list, { CN=v.CN, REALADDR=v.REALADDR, BYTESRCV=v.BYTESRCV, BYTESSND=v.BYTESSND, VIRTADDR=vv.VIRTADDR, CONN=v.CONN, LAST = LAST } ) + end + end + end + local connclients = table.maxn(list) + local difftime = "xXx" + -- FIXME: This should probably be modifiead and go into a library!!! + return list, connclients, difftime +end + + +function clientlistWORKING( self, path ) -- DEBUG -- local path = "openvpn.conf" local clientlist = {} @@ -197,11 +298,12 @@ 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) + local clientlist, connclients, lastupdate = clientlist () + local isrunning = is_running ("openvpn", f) +-- local isrunning = f -- 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["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"] } + 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"], longname = config.name, lastupdate = lastupdate } return serverconfig end @@ -222,7 +324,7 @@ function get_config( self, path) if not (logfilecontent) then logfilecontent = "File is empty or missing!" end - return ( { name = config.name, value = logfilecontent } ) + return ( { name = config.name, shortname = path, value = logfilecontent } ) end |