diff options
author | Mika Havela <mika.havela@gmail.com> | 2007-11-22 16:14:52 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2007-11-22 16:14:52 +0000 |
commit | 21f9432147b05601bc323edbe6b0a4c0daa97089 (patch) | |
tree | dc38efad89a91e82dc438177bcacd52c5d8388cf | |
parent | caca5e32230dd0237865d70eae4d6a18d942e1ba (diff) | |
download | acf-openvpn-21f9432147b05601bc323edbe6b0a4c0daa97089.tar.bz2 acf-openvpn-21f9432147b05601bc323edbe6b0a4c0daa97089.tar.xz |
OpenVPN Mainpage,Serverconfig,Connectedclients got more functionallity
git-svn-id: svn://svn.alpinelinux.org/acf/openvpn/trunk@355 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r-- | openvpn-controller.lua | 104 | ||||
-rw-r--r-- | openvpn-logfile-html.lsp | 9 | ||||
-rw-r--r-- | openvpn-model.lua | 119 | ||||
-rw-r--r-- | openvpn-read-html.lsp | 4 | ||||
-rw-r--r-- | openvpn-server_config-html.lsp | 2 | ||||
-rw-r--r-- | openvpn-status_info-html.lsp | 30 |
6 files changed, 92 insertions, 176 deletions
diff --git a/openvpn-controller.lua b/openvpn-controller.lua index a70782e..99a655b 100644 --- a/openvpn-controller.lua +++ b/openvpn-controller.lua @@ -22,103 +22,9 @@ mvc.on_load = function(self, parent) end -local function build_form ( model ) - local viewtable = {} - local configform = {} - local processform = {} - local messageform = {} --- local conflist = model.conflist() - local conflist = "hej" - local formwith = 60 - -- cf.self is a global variable specifiying this controller - -- local url = cf.self or "" - ---[[ table.insert ( messageform , { - type = "label" , - value = "Logfile info" , - text = "Tail file <i><b>/var/log/messages</b></i><BR><font style='color:f00'>(Still working on this function)</font>" - } ) -]]-- - table.insert ( processform , { - type = "label" , - value = "Process information", - text = "Information on if process is running." - } ) - table.insert ( processform , { - type = "formtext", - label = "openvpn process status", --- value = model.status("openvpn") - value = "hej" - } ) - - --- if table.maxn(conflist)==0 then - if 0==0 then - table.insert ( configform , { - type = "label" , - value = "List of valid configurations" , - text = "No valid configurations could be found in <i><b>/etc/openvpn/</b></i><br>A valid config is called *.conf and has got at least the following parameters set: ca, cert, key, dev, proto (and for clients also parameter 'remote')" - } ) - else - -- Generate processlist - configform[1] = { - type = "label", - value = "List of valid configurations" , - text = "List is based on all valid configuration files named <i><b>/etc/openvpn/*.conf</b></i>" - } - for i=1,table.maxn(conflist) do - table.insert ( configform , { - type = "formtext" , --- label = conflist[i].confname , - label = "hej" , --- value = conflist[i].conftype or "" - value = "hej" or "" - } ) - end - end - - --- Define the main table used by the generic view renderer - viewtable[1] = { - type = "label", - value = "GENERAL" - } - viewtable[2] = { - type = "form", - method = "post", - action = "set", - -- Put the 'form' table in the view table - value = processform - } - viewtable[3] = { - type = "form", - method = "post", - action = "set", - --action = cf.self .. "/set", - -- Put the 'form' table in the view table - value = configform - } - viewtable[4] = { - type = "form", - method = "post", - action = "set", - --action = cf.self .. "/set", - -- Put the 'form' table in the view table - value = messageform - } - return viewtable -end - --- Public methods --- <prefix>/hostname/get - - read = function (self) - --local me = {} - --me = cfe{name=conflistfilesaf, value="hej"} + -- FIXME: If return 1 rows go direct to that config-page return ( {conflistfiles = self.model:get_conflist(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, version = self.model:openvpn_version()} ) --- return ({conflistfiles = me}) --- return self.model:get() --- return build_form(self) end @@ -135,12 +41,16 @@ pem_info = function (self) end status_info = function (self) + local configname = self.clientdata.name or "" + -- FIXME: If return 0 rows, goto read + return ( {clientlist = self.model:clientlist(configname), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} ) end unknown_config = function (self) end logfile = function (self) + local configname = self.clientdata.name or "" + -- FIXME: If return 0 rows, goto read + return ( {logfilecontent = self.model:get_logfile(configname), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} ) end - -create = update diff --git a/openvpn-logfile-html.lsp b/openvpn-logfile-html.lsp index c1db75e..a8d64b7 100644 --- a/openvpn-logfile-html.lsp +++ b/openvpn-logfile-html.lsp @@ -2,11 +2,6 @@ <html> <body> <h1>Logfile 'xxx.log'</h1> - -<h2>Details</h2> - -<input type=text style="width:100%;height:500px"></input> - - +<textarea name="" style="width:100%;height:450px;"><? io.write(logfilecontent) ?></textarea> </body> -</html> +</html> diff --git a/openvpn-model.lua b/openvpn-model.lua index f9e8fa2..0f3627b 100644 --- a/openvpn-model.lua +++ b/openvpn-model.lua @@ -10,18 +10,18 @@ require ("fs") -- ################################################################################ -- UNKNOWN -local function read_file_as_array ( path ) - local file, error = io.open(path) - if ( file == nil ) then - return nil, error - end - local f = {} - for line in file:lines() do - table.insert ( f , line ) - end - file:close() - return f -end +--local function read_file_as_array ( path ) +-- local file, error = io.open(path) +-- if ( file == nil ) then +-- return nil, error +-- end +-- local f = {} +-- for line in file:lines() do +-- table.insert ( f , line ) +-- end +-- file:close() +-- return f +--end local function has_init_script ( f ) local initprefix = "/etc/init.d/openvpn" @@ -47,28 +47,31 @@ end local function config_content( f ) local config = {} - local conf_file = fs.read_file_as_array ( "/etc/openvpn/".. f ) + config.name = "/etc/openvpn/" .. f + local conf_file = fs.read_file_as_array ( config.name ) for i=1,table.maxn(conf_file) do local l = conf_file[i] -- Filter out commented lines if not string.find ( l, "^[;#].*" ) then - local a,b = string.match ( l, "([^%s]*)%s(%S*)(.*)$" ) + local a,b = string.match ( l, "^%s*(%S*)%s+(%S*).*$" ) config[a]=b --- config[string.gsub(a, "-", "")]=b end end - config.name = f - -- FIXME Variablenames with '-' causes trouble! - config.log = "xXx" - config.maxclients = "xXx" - config.tls = "xXx" - config.crlverify = "xXx" - if not ( config["local"] ) then config["local"] = "0.0.0.0" end --- if not ( config["log"] ) and ( config[log-append] ) then --- a = "log" --- b = "plupp" --- config.log=config["log-append"] --- end + if not ( config.log ) then + config.log = config["log-append"] + end + 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 return config end @@ -99,11 +102,21 @@ local function check_valid_config ( f ) if not (config.client) or not (config.ca) or not (config.cert) or not (config.key) or not (config.dev) or not (config.proto) or not (config.remote) then config.type = nil config.err = "" - if not (config.ca) then config.err = config.err .. "Check CA; " end - if not (config.cert) then config.err = config.err .. "Check CERT; " end - if not (config.key) then config.err = config.err .. "Check KEY; " end - if not (config.dev) then config.err = config.err .. "Check DEV; " end - if not (config.proto) then config.err = config.err .. "Check PROTO; " end + if not (config.ca) then + config.err = config.err .. "Check CA; " + end + if not (config.cert) then + config.err = config.err .. "Check CERT; " + end + if not (config.key) then + config.err = config.err .. "Check KEY; " + end + if not (config.dev) then + config.err = config.err .. "Check DEV; " + end + if not (config.proto) then + config.err = config.err .. "Check PROTO; " + end if (config.client) or not (config.ca) or not (config.cert) or not (config.key) or not (config.dev) or not (config.proto) or not (config.port) then config.type = nil else @@ -125,14 +138,7 @@ local function list_conffiles() if files then for k,v in ipairs(files) do if string.match (v, "^.*conf$") then --- config = "" --- config = config_content ( v ) --- local conf_type, err = check_valid_config ( v ) --- local isrunning = is_running ("openvpn", v) --- local clientlist, connclients = clientlist () --- table.insert ( configfiles, cfe{ name = v, type = conf_type, test = config.ca, err = err, status = isrunning, clients = connclients } ) table.insert ( configfiles, cfe{ name = v } ) - end end return configfiles @@ -141,29 +147,36 @@ end -- ################################################################################ -- PUBLIC FUNCTIONS -function clientlist() - local countclients = "d" +function clientlist( self, path ) + -- DEBUG +-- local path = "openvpn.conf" local clientlist = {} - local f + local f = "" + local f2 = "" + if ( path ) then +-- config = config_content ( config.name ) +-- config = {} + config = config_content ( path ) + end if (config.status) then - f = fs.read_file_as_array( config.status ) - if (f) then + local f = fs.read_file_as_array( config.status ) + if ( f ) then for k,v in ipairs(f) do -- The reason for this compex regexp is that I want to filter away the first 2-3 rows -- that doesn't mach this regexp. - local clientname,clientip,clientport = string.match ( v, "([^,]*)[,]+([%w]+[.*][%w]+[.*][%w]+[.*][%w]+)[:]([%w]+)" ) + local clientname,clientip,clientport,bytesreceived,bytessent = string.match ( v, "([^,]*)[,]+([%w]+[.*][%w]+[.*][%w]+[.*][%w]+)[:]([%w]+)[,](%w*)[,](%w*)" ) -- Routing table is now intresting at this moment. So stop reading file. if ( v == "ROUTING TABLE" ) then break end if ( clientname ~= nil ) then - table.insert ( clientlist, { name = clientname, ip = clientip , port = clientport } ) + table.insert ( clientlist, cfe{ name = clientname, ip = clientip , virtualip = "xXx.xXx.xXx.xXx", port = clientport, received = bytesreceived, sent = bytessent } ) end end end end - countclients = table.maxn(clientlist) - return clientlist, countclients + local connclients = table.maxn(clientlist) + return clientlist, connclients end function openvpn_version() @@ -176,14 +189,22 @@ end 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) -- 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["maxclients"], clients = connclients, status = isrunning, autostart = autostart_status, dh = config.dh, ca = config.ca, cert = config.cert, key = config.key, tls = config.tls , crl = config.crlverify, 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"] } return serverconfig end +function get_logfile( self, path) + local logcontent = {} + config = config_content ( path ) + local logfilecontent = fs.read_file_as_array ( config.log ) + return logfilecontent +end + function get_conflist () local configlist = {} for k,v in pairs(list_conffiles()) do diff --git a/openvpn-read-html.lsp b/openvpn-read-html.lsp index f22e1a5..b85fe3b 100644 --- a/openvpn-read-html.lsp +++ b/openvpn-read-html.lsp @@ -12,7 +12,7 @@ <TD WIDTH=100>Config</TD> <TD WIDTH=70>Type</TD> <TD WIDTH=70>Status</TD> - <TD WIDTH=130>Connected Clients</TD> + <TD WIDTH=140>Connected Clients</TD> <TD>Notes</TD> </TR> @@ -21,7 +21,7 @@ <TD><?= html.link{value = view.url .. "/" .. view.conflistfiles[i].type .. "_config?config=" .. view.conflistfiles[i].name , label=view.conflistfiles[i].name } ?></TD> <TD><?= view.conflistfiles[i].type ?></TD> <TD><?= view.conflistfiles[i].status ?></TD> - <TD><?= view.conflistfiles[i].clients ?></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> <TD style="color:red"><?= view.conflistfiles[i].err ?></TD> </TR> <? end ?> diff --git a/openvpn-server_config-html.lsp b/openvpn-server_config-html.lsp index 605f0aa..0cc0988 100644 --- a/openvpn-server_config-html.lsp +++ b/openvpn-server_config-html.lsp @@ -14,7 +14,7 @@ <dd><?= view.serverconfig.loca ?>:<?= view.serverconfig.port ?> (<?= view.serverconfig.proto ?>)</dd> <dt>Logfile</dt> -<dd><?= html.link{value = view.url .. "/logfile?name=" .. view.serverconfig.log , label=view.serverconfig.log } ?> (Verbosity level: <?= view.serverconfig.verb ?>)</dd> +<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> diff --git a/openvpn-status_info-html.lsp b/openvpn-status_info-html.lsp index e538cd1..b3f5c8b 100644 --- a/openvpn-status_info-html.lsp +++ b/openvpn-status_info-html.lsp @@ -6,34 +6,24 @@ <TABLE BORDER=0 WIDTH="100%"> <TR style="background:#eee;font-weight:bold;vertical-align:top;"> - <TD WIDTH=120>Common Name<BR>Connected at</TD> - <TD WIDTH=110>Virtual Address</TD> + <TD WIDTH=140>Common Name<BR>Connected at</TD> + <TD WIDTH=140>Virtual Address</TD> <TD WIDTH=140>Real Address</TD> - <TD WIDTH=100>Bytes Received</TD> + <TD WIDTH=140>Bytes Received</TD> <TD>Bytes Sent</TD> </TR> +<? for i = 1, table.maxn(view.clientlist) do ?> <TR> - <TD>XXX</TD> - <TD>XXX.XXX.XXX.XXX</TD> - <TD>XXX.XXX.XXX.XXX:XXXX</TD> - <TD>XXXX</TD> - <TD>XXXX</TD> + <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> </TR> <TR> <TD COLSPAN=5 style="border-bottom: 1px solid #ccc;">YYYY-MM-DD HH:MM:SS (Which is xx minutes ago)</TD> </TR> - - <TR> - <TD>XXX</TD> - <TD>XXX.XXX.XXX.XXX</TD> - <TD>XXX.XXX.XXX.XXX:XXXX</TD> - <TD>XXXX</TD> - <TD>XXXX</TD> - </TR> - <TR> - <TD COLSPAN=5 style="border-bottom: 1px solid #ccc;">YYYY-MM-DD HH:MM:SS (Which is xx minutes ago)</TD> - </TR> - +<? end ?> </TABLE> </body> |