summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2007-11-23 17:09:41 +0000
committerMika Havela <mika.havela@gmail.com>2007-11-23 17:09:41 +0000
commit735ea7df94733372212914677007350f405062a0 (patch)
treea824a8eaccd14e1d2bc01009a42013aedb75ec7e
parentc6ceb72038d970ba894b4d54cd76e157715a07c4 (diff)
downloadacf-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
-rw-r--r--openvpn-controller.lua2
-rw-r--r--openvpn-model.lua112
-rw-r--r--openvpn-read-html.lsp2
-rw-r--r--openvpn-server_config-html.lsp6
-rw-r--r--openvpn-status_info-html.lsp12
-rw-r--r--openvpn-unknown_config-html.lsp8
6 files changed, 126 insertions, 16 deletions
diff --git a/openvpn-controller.lua b/openvpn-controller.lua
index 9597473..c95b63e 100644
--- a/openvpn-controller.lua
+++ b/openvpn-controller.lua
@@ -29,7 +29,7 @@ end
server_config = function (self)
- local configname = self.clientdata.config or ""
+ local configname = self.clientdata.name or ""
return ( {serverconfig = self.model:get_serverconfig(configname), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} )
end
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
diff --git a/openvpn-read-html.lsp b/openvpn-read-html.lsp
index b85fe3b..7f10817 100644
--- a/openvpn-read-html.lsp
+++ b/openvpn-read-html.lsp
@@ -18,7 +18,7 @@
<? for i = 1, table.maxn(view.conflistfiles) do ?>
<TR >
- <TD><?= html.link{value = view.url .. "/" .. view.conflistfiles[i].type .. "_config?config=" .. view.conflistfiles[i].name , label=view.conflistfiles[i].name } ?></TD>
+ <TD><?= html.link{value = view.url .. "/" .. view.conflistfiles[i].type .. "_config?name=" .. view.conflistfiles[i].name , label=view.conflistfiles[i].name } ?></TD>
<TD><?= view.conflistfiles[i].type ?></TD>
<TD><?= view.conflistfiles[i].status ?></TD>
<TD><? if view.conflistfiles[i].clients > 0 then ?><?= html.link{value = view.url .. "/status_info?name=" .. view.conflistfiles[i].name , label=view.conflistfiles[i].clients } ?><? else ?><?= view.conflistfiles[i].clients ?><? end ?></TD>
diff --git a/openvpn-server_config-html.lsp b/openvpn-server_config-html.lsp
index 0cc0988..52e490b 100644
--- a/openvpn-server_config-html.lsp
+++ b/openvpn-server_config-html.lsp
@@ -17,12 +17,12 @@
<dd><?= html.link{value = view.url .. "/logfile?name=" .. view.serverconfig.name , label=view.serverconfig.log } ?> (Verbosity level: <?= view.serverconfig.verb ?>)</dd>
<dt>Configfile</dt>
-<dd><?= html.link{value = view.url .. "/unknown_config?name=" .. view.serverconfig.name , label=view.serverconfig.name } ?></dd>
+<dd><?= html.link{value = view.url .. "/unknown_config?name=" .. view.serverconfig.name , label=view.serverconfig.longname } ?></dd>
<h3>Connected clients status</h3>
<dt>Last status was recorded</dt>
-<dd>YYYY-MM-DD HH:MM:SS (xx minutes ago)</dd>
+<dd><?= view.serverconfig.lastupdate ?> (<?= view.serverconfig.LAST ?> sec ago)</dd>
<dt>Maximum clients</dt>
<dd><?= view.serverconfig.maxclients ?></dd>
@@ -33,7 +33,7 @@
<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)</span></dd>
+<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>
diff --git a/openvpn-status_info-html.lsp b/openvpn-status_info-html.lsp
index b3f5c8b..6aa3cdd 100644
--- a/openvpn-status_info-html.lsp
+++ b/openvpn-status_info-html.lsp
@@ -14,14 +14,14 @@
</TR>
<? for i = 1, table.maxn(view.clientlist) do ?>
<TR>
- <TD><?= view.clientlist[i].name ?></TD>
- <TD><?= view.clientlist[i].virtualip ?></TD>
- <TD><?= view.clientlist[i].ip ?>:<?= view.clientlist[i].port ?></TD>
- <TD><?= view.clientlist[i].received ?></TD>
- <TD><?= view.clientlist[i].sent ?></TD>
+ <TD><?= view.clientlist[i].CN ?></TD>
+ <TD><?= view.clientlist[i].VIRTADDR ?></TD>
+ <TD><?= view.clientlist[i].REALADDR ?></TD>
+ <TD><?= view.clientlist[i].BYTESRCV ?></TD>
+ <TD><?= view.clientlist[i].BYTESSND ?></TD>
</TR>
<TR>
- <TD COLSPAN=5 style="border-bottom: 1px solid #ccc;">YYYY-MM-DD HH:MM:SS (Which is xx minutes ago)</TD>
+ <TD COLSPAN=5 style="border-bottom: 1px solid #ccc;"><?= view.clientlist[i].CONN ?></TD>
</TR>
<? end ?>
diff --git a/openvpn-unknown_config-html.lsp b/openvpn-unknown_config-html.lsp
index 2d33d10..03435f8 100644
--- a/openvpn-unknown_config-html.lsp
+++ b/openvpn-unknown_config-html.lsp
@@ -3,6 +3,14 @@
<body>
<h1>Configuration file '<?= view.configfilecontent.name ?>'</h1>
+<h2>Controlpanel</h2>
+
+<dt>View this as it was a</dt>
+<dd><a href="<?= view.url ?>/server_config?name=<?= view.configfilecontent.shortname ?>">server config</a></dd>
+
+<dt>View this as it was a</dt>
+<dd><a href="<?= view.url ?>/client_config?name=<?= view.configfilecontent.shortname ?>">client config</a></dd>
+
<h2>Details</h2>
<textarea name="" style="width:100%;height:450px;"><?= view.configfilecontent.value ?></textarea>