From d344c8b256dea3891578341906bb8d20ec6a83f8 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Thu, 29 Nov 2007 20:10:01 +0000 Subject: Reorganazing code git-svn-id: svn://svn.alpinelinux.org/acf/openvpn/trunk@390 ab2d0c66-481e-0410-8bed-d214d4d58bed --- openvpn-client_config-html.lsp | 24 +++++++++--- openvpn-controller.lua | 6 +-- openvpn-model.lua | 82 +++++++++++++++++++++++++++++++++-------- openvpn-server_config-html.lsp | 31 +++++++++++----- openvpn-unknown_config-html.lsp | 31 ++++++++++++++-- 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 @@

Client config ''

+ + +

DEUB INFO

+" .. a .. ": >" .. b .. "<
") +end +?> + + + +

Client settings

Mode
client
User device
-
+
Remote server
-
()
+
: ()
Logfile
-
Syslog (Verbosity level: )
+
Syslog (Verbosity level: )
View/Modify configfile
-
+

Client properties

@@ -33,7 +45,7 @@

Startup options

Process running
-
>
+
>

Certificate files

@@ -61,7 +73,7 @@
CRL Verify File
(client side)
- + 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 @@

Server config ''

+ + + +

DEUB INFO

+" .. a .. ": " .. b .. "
") +end +?> + + +

Server settings

Mode
server
User device
-
+
Listens on
-
: ()
+
: ()
Logfile
-
Syslog (Verbosity level: )
+
Syslog (Verbosity level: )
View/Modify configfile
-
+

Connected clients status

Last status was recorded
-
(This was ago)
+
(This was ago)
Maximum clients
-
+
Connected clients
-
0 ) then ?>
+
0 ) then ?>

Startup options

Process running
-
>
+
>
+

Certificate files

@@ -68,6 +81,6 @@
- + 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 @@

Configuration file ''

+ +

DEUB INFO

+" .. a .. ": >" .. b .. "<
") +end +?> + + +

Details

+ +
File name
+
+ +
File size
+
+ +
Last modified
+
+ +

Controlpanel

View this as it was a
-
server config
+
server config
View this as it was a
-
client config
+
client config

Details

- +
+ + + +
-- cgit v1.2.3