diff options
author | Mika Havela <mika.havela@gmail.com> | 2007-11-29 20:10:01 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2007-11-29 20:10:01 +0000 |
commit | d344c8b256dea3891578341906bb8d20ec6a83f8 (patch) | |
tree | 6ab28576b3364c2401bc39d4419252d6eced3b1e /openvpn-model.lua | |
parent | 2fc04ea00f5a35d751455ab4c70a032749408d0b (diff) | |
download | acf-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
Diffstat (limited to 'openvpn-model.lua')
-rw-r--r-- | openvpn-model.lua | 82 |
1 files changed, 67 insertions, 15 deletions
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 |