summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2007-11-29 20:10:01 +0000
committerMika Havela <mika.havela@gmail.com>2007-11-29 20:10:01 +0000
commitd344c8b256dea3891578341906bb8d20ec6a83f8 (patch)
tree6ab28576b3364c2401bc39d4419252d6eced3b1e
parent2fc04ea00f5a35d751455ab4c70a032749408d0b (diff)
downloadacf-openvpn-d344c8b256dea3891578341906bb8d20ec6a83f8.tar.bz2
acf-openvpn-d344c8b256dea3891578341906bb8d20ec6a83f8.tar.xz
Reorganazing code
git-svn-id: svn://svn.alpinelinux.org/acf/openvpn/trunk@390 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--openvpn-client_config-html.lsp24
-rw-r--r--openvpn-controller.lua6
-rw-r--r--openvpn-model.lua82
-rw-r--r--openvpn-server_config-html.lsp31
-rw-r--r--openvpn-unknown_config-html.lsp31
5 files changed, 138 insertions, 36 deletions
diff --git a/openvpn-client_config-html.lsp b/openvpn-client_config-html.lsp
index 68576d9..e80388a 100644
--- a/openvpn-client_config-html.lsp
+++ b/openvpn-client_config-html.lsp
@@ -2,22 +2,34 @@
<html>
<body>
<h1>Client config '<?= view.config.name ?>'</h1>
+
+<? ---[[ DEBUG INFORMATION...?>
+<h2>DEUB INFO</h2>
+<?
+for a,b in pairs(view.config) do
+print ("<b>" .. a .. "</b>: >" .. b .. "<<BR>")
+end
+?>
+<? --]] ?>
+
+
+<? ---[[ ?>
<h2>Client settings</h2>
<dt>Mode</dt>
<dd>client</dd>
<dt>User device</dt>
-<dd><?= view.config.device ?></dd>
+<dd><?= view.config.dev ?></dd>
<dt>Remote server</dt>
-<dd><?= view.config.remote ?> (<?= view.config.proto ?>)</dd>
+<dd><?= view.config.remote ?>:<?= view.config.remoteport ?> (<?= view.config.proto ?>)</dd>
<dt>Logfile</dt>
-<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>
+<dd><? if ( view.config.log ) then ?><?= html.link{value = view.url .. "/logfile?name=" .. view.config.linkname , label=view.config.log } ?><? else ?>Syslog<? end ?> (Verbosity level: <?= view.config.verb ?>)</dd>
<dt>View/Modify configfile</dt>
-<dd><?= html.link{value = view.url .. "/unknown_config?name=" .. view.config.name , label=view.config.longname } ?></dd>
+<dd><?= html.link{value = view.url .. "/unknown_config?name=" .. view.config.linkname , label=view.config.name } ?></dd>
<h3>Client properties</h3>
@@ -33,7 +45,7 @@
<h2>Startup options</h2>
<dt>Process running</dt>
-<dd><input type="checkbox" disabled <? if (view.config.status ~= "") then io.write("checked='yes'") end ?>></dd>
+<dd><input type="checkbox" disabled <? if (view.config.status_isrunning ~= "") then io.write("checked='yes'") end ?>></dd>
<h2>Certificate files</h2>
@@ -61,7 +73,7 @@
<dt>CRL Verify File</dt>
<dd><?= html.link{value = view.url .. "/pem_info?name=" .. view.config.crl , label=view.config.crl } ?> (client side)</dd>
<? end ?>
-
+<? --]] ?>
</body>
</html>
diff --git a/openvpn-controller.lua b/openvpn-controller.lua
index e6ef0ad..fcc90cb 100644
--- a/openvpn-controller.lua
+++ b/openvpn-controller.lua
@@ -30,12 +30,12 @@ end
server_config = function (self)
local configname = self.clientdata.name or ""
- return ( {config = self.model:get_serverconfig(configname), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} )
+ return ( {config = self.model:get_config(configname), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} )
end
client_config = function (self)
local configname = self.clientdata.name or ""
- return ( {config = self.model:get_serverconfig(configname), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} )
+ return ( {config = self.model:get_config(configname), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} )
end
pem_info = function (self)
@@ -48,7 +48,7 @@ end
unknown_config = function (self)
local configname = self.clientdata.name or ""
- return ( {configfilecontent = self.model:get_config(configname), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} )
+ return ( {configfilecontent = self.model:get_filecontent(configname), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} )
end
logfile = function (self)
diff --git a/openvpn-model.lua b/openvpn-model.lua
index 47aa726..3ff389e 100644
--- a/openvpn-model.lua
+++ b/openvpn-model.lua
@@ -7,6 +7,18 @@ require ("fs")
-- ################################################################################
-- LOCAL FUNCTIONS
+local function file_info ( path )
+ require("posix")
+ local filedetails = posix.stat(path)
+ filedetails["owner"]=rawget((posix.getpasswd(filedetails["uid"])),"name")
+ filedetails["group"]=rawget((posix.getgroup(filedetails["gid"])),"name")
+ filedetails["atimelong"]=os.date("%c", filedetails["atime"])
+ filedetails["mtimelong"]=os.date("%c", filedetails["mtime"])
+ filedetails["longname"]=path
+ filedetails["name"]=basename(path)
+ filedetails["size"]=filedetails["size"] .. " bytes"
+ return filedetails
+end
local function config_content( f )
local config = {}
@@ -17,10 +29,11 @@ local function config_content( f )
-- Filter out commented lines
if not string.find ( l, "^[;#].*" ) then
local a,b = string.match ( l, "^%s*(%S*)%s+(%S*).*$" ) -- Working exept on 'remote xxxxx xxxx'
- -- FIXME: Problem with clients 'remote' values (the port num to the remote)
--- local a,b = string.match ( l, "^%s*(%S*)%s+(.*)%s+$" ) -- This brakes client/server check
if (a) then
- config[a]=b
+ config[string.lower(a)]=b
+ end
+ if (a == "remote") then
+ config["remoteport"]=string.match ( l, "^%s*%S+%s+%S+%s+(%S*)" )
end
end
end
@@ -33,6 +46,7 @@ local function config_content( f )
if not ( config["local"] ) then
config["local"] = "0.0.0.0"
end
+ config["linkname"]=basename(f)
return config
end
@@ -170,7 +184,7 @@ function clientlist( self, path )
end
end
end
- connclients = table.maxn(list)
+ connclients = table.maxn(clientlist)
if ( connclients > 0 ) then
-- FIXME: If possible, use lib/date.lua instead of the following code.
local lastdatechange = libdate.date_to_seconds(datechange)
@@ -195,17 +209,21 @@ function openvpn_version()
return openvpnversion
end
-function get_serverconfig ( self, f )
- local serverconfig = {}
+function get_config ( self, f )
+ local configresult = {}
+ config = nil
config = config_content ( f )
- local clientlist, connclients, lastupdate, lastdatechangediff = clientlist ()
- local isrunning = is_running ("openvpn", f)
- serverconfig = cfe{ name = f, device = config.dev, log = config.log, verb = config.verb, maxclients = config["max-clients"], clients = connclients, status = isrunning, 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, lastdatechangetxt = lastdatechangetxt, lastdatechangediff = lastdatechangediff, remote = config.remote }
- return serverconfig
+ local clientlist, client_count, client_lastupdate, client_lastdatechangediff = clientlist ()
+ local status_isrunning = is_running ("openvpn", f)
+ config["client_count"]=client_count
+ config["client_lastupdate"]=client_lastupdate
+ config["client_lastdatechangediff"]=client_lastdatechangediff
+ config["status_isrunning"]=status_isrunning
+ configresult = config
+ return configresult
end
function get_logfile( self, path)
- local logcontent = {}
config = config_content ( path )
local logfilecontent = fs.read_file ( config.log )
if not (logfilecontent) then
@@ -214,14 +232,48 @@ function get_logfile( self, path)
return ( { name = config.log, value = logfilecontent } )
end
-function get_config( self, path)
- local logcontent = {}
+--[[
+function get_filecontent (self, name)
+-- local path = baseurl .. name
+ file_content = nil
+ local available_files = get_conflist()
+ for k,v in pairs(available_files) do
+ if ( available_files[k].name == name ) then
+ local file = io.open( name )
+ local file_result = file:read("*a") or "unknown"
+ file:close()
+ local filedetails = file_info(name)
+ file_content = cfe{name=name, value=file_result, filedetails=filedetails}
+ end
+ end
+ return available_files
+end
+--]]
+function get_filecontent( self, path)
+ local path = "VoIp.conf"
+ local configresult = {}
config = config_content ( path )
- local logfilecontent = fs.read_file ( config.name )
+ local file = io.open( config.name )
+ local file_result = file:read("*a") or "unknown"
+ file:close()
+ local filedetails = file_info( config.name )
+ file_content = cfe{name=config.name, value=file_result, filedetails=filedetails}
+
+--[[
+
+
+ local filecontent = fs.read_file ( config.name )
if not (logfilecontent) then
logfilecontent = "File is empty or missing!"
end
- return ( { name = config.name, shortname = path, value = logfilecontent } )
+ local filedetails = file_info(path)
+ file_content = {name=name, value=file_result, filedetails=filedetails, err=err}
+
+ config["filecontent"]=filecontent
+ configresult = config
+--]]
+ return file_content
+-- return ( { name = config.name, shortname = path, value = logfilecontent } )
end
diff --git a/openvpn-server_config-html.lsp b/openvpn-server_config-html.lsp
index 9a26db7..fc60ec2 100644
--- a/openvpn-server_config-html.lsp
+++ b/openvpn-server_config-html.lsp
@@ -2,39 +2,52 @@
<html>
<body>
<h1>Server config '<?= view.config.name ?>'</h1>
+
+
+<? --[[ DEBUG INFORMATION...?>
+<h2>DEUB INFO</h2>
+<?
+for a,b in pairs(view.config) do
+print ("<b>" .. a .. "</b>: " .. b .. "<BR>")
+end
+?>
+<? --]] ?>
+
+
<h2>Server settings</h2>
<dt>Mode</dt>
<dd>server</dd>
<dt>User device</dt>
-<dd><?= view.config.device ?></dd>
+<dd><?= view.config.dev ?></dd>
<dt>Listens on</dt>
-<dd><?= view.config.loca ?>:<?= view.config.port ?> (<?= view.config.proto ?>)</dd>
+<dd><?= view.config["local"] ?>:<?= view.config.port ?> (<?= view.config.proto ?>)</dd>
<dt>Logfile</dt>
-<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>
+<dd><? if ( view.config.log ) then ?><?= html.link{value = view.url .. "/logfile?name=" .. view.config.linkname , label=view.config.log } ?><? else ?>Syslog<? end ?> (Verbosity level: <?= view.config.verb ?>)</dd>
<dt>View/Modify configfile</dt>
-<dd><?= html.link{value = view.url .. "/unknown_config?name=" .. view.config.name , label=view.config.longname } ?></dd>
+<dd><?= html.link{value = view.url .. "/unknown_config?name=" .. view.config.linkname , label=view.config.name } ?></dd>
<h3>Connected clients status</h3>
<dt>Last status was recorded</dt>
-<dd><?= view.config.lastdatechangetxt ?> (This was <b><?= view.config.lastdatechangediff ?></b> ago)</dd>
+<dd><?= view.config.client_lastupdate ?> (This was <b><?= view.config.client_lastdatechangediff ?></b> ago)</dd>
<dt>Maximum clients</dt>
-<dd><?= view.config.maxclients ?></dd>
+<dd><?= view.config["max-clients"] ?></dd>
<dt>Connected clients</dt>
-<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>
+<dd><? if ( view.config.client_count > 0 ) then ?><?= html.link{value = view.url .. "/status_info?name=" .. view.config.linkname , label=view.config.client_count } ?><? else ?><?= view.config.client_count ?><? end ?></dd>
<h2>Startup options</h2>
<dt>Process running</dt>
-<dd><input type="checkbox" disabled <? if (view.config.status ~= "") then io.write("checked='yes'") end ?>></dd>
+<dd><input type="checkbox" disabled <? if (view.config.status_isrunning ~= "") then io.write("checked='yes'") end ?>></dd>
+<? ---[[ ?>
<h2>Certificate files</h2>
@@ -68,6 +81,6 @@
<dd><?= html.link{value = view.url .. "/pem_info?name=" .. view.config.crl , label=view.config.crl } ?></dd>
<? end ?>
-
+<? --]] ?>
</body>
</html>
diff --git a/openvpn-unknown_config-html.lsp b/openvpn-unknown_config-html.lsp
index 03435f8..302ea56 100644
--- a/openvpn-unknown_config-html.lsp
+++ b/openvpn-unknown_config-html.lsp
@@ -3,17 +3,42 @@
<body>
<h1>Configuration file '<?= view.configfilecontent.name ?>'</h1>
+<? --[[ DEBUG INFORMATION...?>
+<h2>DEUB INFO</h2>
+<?
+for a,b in pairs(view.configfilecontent.filedetails) do
+print ("<b>" .. a .. "</b>: >" .. b .. "<<BR>")
+end
+?>
+<? --]] ?>
+
+<h2>Details</h2>
+
+<dt>File name</dt>
+<dd><?= view.configfilecontent.filedetails.longname ?></dd>
+
+<dt>File size</dt>
+<dd><?= view.configfilecontent.filedetails.size ?></dd>
+
+<dt>Last modified</dt>
+<dd><?= view.configfilecontent.filedetails.mtimelong ?></dd>
+
+
<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>
+<dd><a href="<?= view.url ?>/server_config?name=<?= view.configfilecontent.linkname ?>">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>
+<dd><a href="<?= view.url ?>/client_config?name=<?= view.configfilecontent.linkname ?>">client config</a></dd>
<h2>Details</h2>
-<textarea name="" style="width:100%;height:450px;"><?= view.configfilecontent.value ?></textarea>
+<form name="myform" action="" method="POST">
+<input name="name" type="hidden" value="<?= view.configfilecontent.linkname ?>" style="width:100%">
+<textarea name="modifications" style="width:100%;height:400px;"><?= view.configfilecontent.value ?></textarea>
+
+<input type="submit" name="cmd" value="update"></form>
</body>
</html>