summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2007-11-26 16:59:51 +0000
committerMika Havela <mika.havela@gmail.com>2007-11-26 16:59:51 +0000
commit84505f46e62bb2db4f68777000c5f65826ea4dad (patch)
treea295496f433193ce59fcafcbab823a08549111d6
parent735ea7df94733372212914677007350f405062a0 (diff)
downloadacf-openvpn-84505f46e62bb2db4f68777000c5f65826ea4dad.tar.bz2
acf-openvpn-84505f46e62bb2db4f68777000c5f65826ea4dad.tar.xz
Added some functionallity on client-config viewing and some other small changes.
git-svn-id: svn://svn.alpinelinux.org/acf/openvpn/trunk@366 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--openvpn-client_config-html.lsp43
-rw-r--r--openvpn-controller.lua5
-rw-r--r--openvpn-model.lua90
-rw-r--r--openvpn-read-html.lsp2
-rw-r--r--openvpn-server_config-html.lsp47
5 files changed, 108 insertions, 79 deletions
diff --git a/openvpn-client_config-html.lsp b/openvpn-client_config-html.lsp
index cd0c754..68576d9 100644
--- a/openvpn-client_config-html.lsp
+++ b/openvpn-client_config-html.lsp
@@ -1,23 +1,23 @@
<? local view = ... ?>
<html>
<body>
-<h1>Client config 'xxx.conf'</h1>
+<h1>Client config '<?= view.config.name ?>'</h1>
<h2>Client settings</h2>
<dt>Mode</dt>
<dd>client</dd>
<dt>User device</dt>
-<dd>xxx</dd>
+<dd><?= view.config.device ?></dd>
<dt>Remote server</dt>
-<dd>xxx.xxx.xxx.xxx:xxxx (xxx)</dd>
+<dd><?= view.config.remote ?> (<?= view.config.proto ?>)</dd>
<dt>Logfile</dt>
-<dd><?= html.link{value = view.url .. "/logfile?name=xxx" , label="xxx.log" } ?> (Verbosity level: x)</dd>
+<dd><? if ( view.config.log ) then ?><?= html.link{value = view.url .. "/logfile?name=" .. view.config.name , label=view.config.log } ?><? else ?>Syslog<? end ?> (Verbosity level: <?= view.config.verb ?>)</dd>
-<dt>Configfile</dt>
-<dd><?= html.link{value = view.url .. "/unknown_config?name=xxx" , label="xxx.conf" } ?></dd>
+<dt>View/Modify configfile</dt>
+<dd><?= html.link{value = view.url .. "/unknown_config?name=" .. view.config.name , label=view.config.longname } ?></dd>
<h3>Client properties</h3>
@@ -33,33 +33,34 @@
<h2>Startup options</h2>
<dt>Process running</dt>
-<dd><input type="checkbox">xxx</input></dd>
-
-<dt>Init.d script exists</dt>
-<dd><input type="checkbox">xxx</input></dd>
-
-<dt>Autostarts at boot</dt>
-<dd><input type="checkbox">xxx</input></dd>
+<dd><input type="checkbox" disabled <? if (view.config.status ~= "") then io.write("checked='yes'") end ?>></dd>
<h2>Certificate files</h2>
-<dt>DH</dt>
-<dd><?= html.link{value = view.url .. "/pem_info?name=xxx" , label="xxx.pem" } ?></dd>
-
+<? if (view.config.ca) then ?>
<dt>CA Certificate</dt>
-<dd><?= html.link{value = view.url .. "/pem_info?name=xxx" , label="xxx.pem" } ?></dd>
+<dd><?= html.link{value = view.url .. "/pem_info?name=" .. view.config.ca , label=view.config.ca } ?></dd>
+<? end ?>
+<? if (view.config.cert) then ?>
<dt>Client Certificate</dt>
-<dd><?= html.link{value = view.url .. "/pem_info?name=xxx" , label="xxx.pem" } ?></dd>
+<dd><?= html.link{value = view.url .. "/pem_info?name=" .. view.config.cert , label=view.config.cert } ?></dd>
+<? end ?>
+<? if (view.config.key) then ?>
<dt>Client Private Key</dt>
-<dd><?= html.link{value = view.url .. "/pem_info?name=xxx" , label="xxx.pem" } ?></dd>
+<dd><?= html.link{value = view.url .. "/pem_info?name=" .. view.config.key , label=view.config.key } ?></dd>
+<? end ?>
+<? if (view.config.tls) then ?>
<dt>TLS Authentication</dt>
-<dd><?= html.link{value = view.url .. "/pem_info?name=xxx" , label="xxx.pem" } ?></dd>
+<dd><?= html.link{value = view.url .. "/pem_info?name=" .. view.config.tls , label=view.config.tls } ?></dd>
+<? end ?>
+<? if (view.config.crl) then ?>
<dt>CRL Verify File</dt>
-<dd><?= html.link{value = view.url .. "/pem_info?name=xxx" , label="xxx.pem" } ?> (client side)</dd>
+<dd><?= html.link{value = view.url .. "/pem_info?name=" .. view.config.crl , label=view.config.crl } ?> (client side)</dd>
+<? end ?>
</body>
diff --git a/openvpn-controller.lua b/openvpn-controller.lua
index c95b63e..e6ef0ad 100644
--- a/openvpn-controller.lua
+++ b/openvpn-controller.lua
@@ -30,11 +30,12 @@ end
server_config = function (self)
local configname = self.clientdata.name or ""
- return ( {serverconfig = self.model:get_serverconfig(configname), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} )
+ return ( {config = self.model:get_serverconfig(configname), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} )
end
client_config = function (self)
- return ( {url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} )
+ local configname = self.clientdata.name or ""
+ return ( {config = self.model:get_serverconfig(configname), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} )
end
pem_info = function (self)
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
diff --git a/openvpn-read-html.lsp b/openvpn-read-html.lsp
index 7f10817..af5cd53 100644
--- a/openvpn-read-html.lsp
+++ b/openvpn-read-html.lsp
@@ -9,7 +9,7 @@
<h2>Available configs</h2>
<TABLE BORDER=0 WIDTH="100%">
<TR style="background:#eee;font-weight:bold;vertical-align:top;">
- <TD WIDTH=100>Config</TD>
+ <TD WIDTH=140>Config</TD>
<TD WIDTH=70>Type</TD>
<TD WIDTH=70>Status</TD>
<TD WIDTH=140>Connected Clients</TD>
diff --git a/openvpn-server_config-html.lsp b/openvpn-server_config-html.lsp
index 52e490b..c5b28b6 100644
--- a/openvpn-server_config-html.lsp
+++ b/openvpn-server_config-html.lsp
@@ -1,63 +1,72 @@
<? local view = ... ?>
<html>
<body>
-<h1>Server config '<?= view.serverconfig.name ?>'</h1>
+<h1>Server config '<?= view.config.name ?>'</h1>
<h2>Server settings</h2>
<dt>Mode</dt>
<dd>server</dd>
<dt>User device</dt>
-<dd><?= view.serverconfig.device ?></dd>
+<dd><?= view.config.device ?></dd>
<dt>Listens on</dt>
-<dd><?= view.serverconfig.loca ?>:<?= view.serverconfig.port ?> (<?= view.serverconfig.proto ?>)</dd>
+<dd><?= view.config.loca ?>:<?= view.config.port ?> (<?= view.config.proto ?>)</dd>
<dt>Logfile</dt>
-<dd><?= html.link{value = view.url .. "/logfile?name=" .. view.serverconfig.name , label=view.serverconfig.log } ?> (Verbosity level: <?= view.serverconfig.verb ?>)</dd>
+<dd><? if ( view.config.log ) then ?><?= html.link{value = view.url .. "/logfile?name=" .. view.config.name , label=view.config.log } ?><? else ?>Syslog<? end ?> (Verbosity level: <?= view.config.verb ?>)</dd>
-<dt>Configfile</dt>
-<dd><?= html.link{value = view.url .. "/unknown_config?name=" .. view.serverconfig.name , label=view.serverconfig.longname } ?></dd>
+<dt>View/Modify configfile</dt>
+<dd><?= html.link{value = view.url .. "/unknown_config?name=" .. view.config.name , label=view.config.longname } ?></dd>
<h3>Connected clients status</h3>
<dt>Last status was recorded</dt>
-<dd><?= view.serverconfig.lastupdate ?> (<?= view.serverconfig.LAST ?> sec ago)</dd>
+<dd><?= view.config.lastupdate ?></dd>
<dt>Maximum clients</dt>
-<dd><?= view.serverconfig.maxclients ?></dd>
+<dd><?= view.config.maxclients ?></dd>
<dt>Connected clients</dt>
-<dd><?= html.link{value = view.url .. "/status_info?name=" .. view.serverconfig.name , label=view.serverconfig.clients } ?></dd>
+<dd><? if ( view.config.clients > 0 ) then ?><?= html.link{value = view.url .. "/status_info?name=" .. view.config.name , label=view.config.clients } ?><? else ?><?= view.config.clients ?><? end ?></dd>
<h2>Startup options</h2>
<dt>Process running</dt>
-<dd><input type="checkbox" disabled <? if (view.serverconfig.status ~= "") then io.write("checked='yes'") end ?>><span style="color:green">(TODO: Make this checkbox to start/stop this process)(((<?= view.serverconfig.status ?>)))</span></dd>
-
-<dt>Autostarts at boot</dt>
-<dd><input type="checkbox" disabled <? if (view.serverconfig.autostart ~= "") then io.write("checked='yes'") end ?>><span style="color:green">(TODO: Make this checkbox to 'rc_add'/'rc_delete')</span></dd>
+<dd><input type="checkbox" disabled <? if (view.config.status ~= "") then io.write("checked='yes'") end ?>></dd>
<h2>Certificate files</h2>
+<? if (view.config.dh) then ?>
<dt>DH</dt>
-<dd><?= html.link{value = view.url .. "/pem_info?name=" .. view.serverconfig.dh , label=view.serverconfig.dh } ?></dd>
+<dd><?= html.link{value = view.url .. "/pem_info?name=" .. view.config.dh , label=view.config.dh } ?></dd>
+<? end ?>
+<? if (view.config.ca) then ?>
<dt>CA Certificate</dt>
-<dd><?= html.link{value = view.url .. "/pem_info?name=" .. view.serverconfig.ca , label=view.serverconfig.ca } ?></dd>
+<dd><?= html.link{value = view.url .. "/pem_info?name=" .. view.config.ca , label=view.config.ca } ?></dd>
+<? end ?>
+<? if (view.config.cert) then ?>
<dt>Server Certificate</dt>
-<dd><?= html.link{value = view.url .. "/pem_info?name=" .. view.serverconfig.cert , label=view.serverconfig.cert } ?></dd>
+<dd><?= html.link{value = view.url .. "/pem_info?name=" .. view.config.cert , label=view.config.cert } ?></dd>
+<? end ?>
+<? if (view.config.key) then ?>
<dt>Server Private Key</dt>
-<dd><?= html.link{value = view.url .. "/pem_info?name=" .. view.serverconfig.key , label=view.serverconfig.key } ?></dd>
+<dd><?= html.link{value = view.url .. "/pem_info?name=" .. view.config.key , label=view.config.key } ?></dd>
+<? end ?>
+<? if (view.config.tls) then ?>
<dt>TLS Authentication</dt>
-<dd><?= html.link{value = view.url .. "/pem_info?name=" .. view.serverconfig.tls , label=view.serverconfig.tls } ?></dd>
+<dd><?= html.link{value = view.url .. "/pem_info?name=" .. view.config.tls , label=view.config.tls } ?></dd>
+<? end ?>
+<? if (view.config.crl) then ?>
<dt>CRL Verify File</dt>
-<dd><?= html.link{value = view.url .. "/pem_info?name=" .. view.serverconfig.crl , label=view.serverconfig.crl } ?></dd>
+<dd><?= html.link{value = view.url .. "/pem_info?name=" .. view.config.crl , label=view.config.crl } ?></dd>
+<? end ?>
</body>