summaryrefslogtreecommitdiffstats
path: root/openvpn-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'openvpn-model.lua')
-rw-r--r--openvpn-model.lua90
1 files changed, 54 insertions, 36 deletions
diff --git a/openvpn-model.lua b/openvpn-model.lua
index 22ea045..d9c88f6 100644
--- a/openvpn-model.lua
+++ b/openvpn-model.lua
@@ -53,7 +53,8 @@ local function config_content( f )
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*).*$" )
+ 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+$" ) -- This brakes client/server check
if (a) then
config[a]=b
end
@@ -65,12 +66,6 @@ local function config_content( f )
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
@@ -81,26 +76,23 @@ end
local is_running = function( process, parameters )
local strsplit = require("split")
local retval = ""
- local pidofsx,error = io.popen("pidof " .. process ,r)
- local pidofs = strsplit(" ", pidofsx:read("*a"))
+ local tst = ""
+ local pidofsx, error = io.popen("pidof " .. process ,r)
+ local pidofs = string.gsub(pidofsx:read("*a"), "\n", "")
pidofsx:close()
- if ( pidofs ~= nil ) then
- for k,v in pairs(pidofs) do
+-- if ( pidofs ~= nil ) then
+ for v in string.gmatch(pidofs, "%S+") do
local path = string.gsub("/proc/".. v .. "/cmdline", "%s", "")
- local f = io.open(path)
- if (f) then
- local file_resultx = f:read("*a")
- local file_result = string.match(file_resultx, parameters)
+ local f,err = io.open(path,r)
+ local file_resultx = f:read("*a")
+ local file_result = string.match(file_resultx, parameters)
f:close()
- end
if ( file_result ) then
retval = "Running"
end
end
- end
--- return retval
- --DEBUG
- return path
+-- end
+ return retval
end
local function check_valid_config ( f )
@@ -153,20 +145,8 @@ 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 function monthabbr_to_num ( month )
local nummonth = ""
if (string.lower(month) == "jan") then nummonth = "1" end
if (string.lower(month) == "feb") then nummonth = "2" end
@@ -180,12 +160,43 @@ local function month_to_num ( dt )
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
+ return nummonth
+end
+
+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 = monthabbr_to_num(rawget(newdate,2))
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
+local function minmax_date ( userdate )
+ local maxdate = 0
+ local mindate = 0
+ local f,err = io.popen("date +%Y ")
+ currdate = f:read("*l")
+ f:close()
+ local year,month,date,hour,min,sec = string.gmatch ( currdate, "(%d%d%d%d)%s+(%w+)%s+(%d%d)" )
+-- local month = rawget(systemdate,2)
+-- local newdatetable = { year = rawget(systemdate,6), month = nummonth, day = rawget(systemdate,3), hour = hour, min = min, sec = sec }
+
+-- return os.difftime(os.time(newdatetable),os.time(olddatetable))
+ -- Return currdate, olddate, datediff
+ return os.time(userdate[2])
+end
-- ################################################################################
-- PUBLIC FUNCTIONS
@@ -193,6 +204,7 @@ end
function clientlist( self, path )
local clientlist = {}
local routinglist = {}
+ local datechange = {}
local list = {}
local f = ""
local clientlst = nil
@@ -222,6 +234,12 @@ function clientlist( self, path )
CN=col[2],
REALADDR=col[3],
LAST=col[4] } )
+ table.insert(datechange, { year="2007",
+ month=monthabbr_to_num("may"),
+ day="10",
+ hour="15",
+ min="12",
+ sec="13" } )
end
if ( col[1] == "Common Name" ) then
@@ -240,13 +258,13 @@ function clientlist( self, path )
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")
+ local maxdatesec, mindatesec = minmax_date(datechange)
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"
+ local difftime = maxdatesec
-- FIXME: This should probably be modifiead and go into a library!!!
return list, connclients, difftime
end
@@ -303,7 +321,7 @@ function get_serverconfig ( self, 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"], longname = config.name, lastupdate = lastupdate }
+ 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, remote = config.remote }
return serverconfig
end