diff options
author | Mika Havela <mika.havela@gmail.com> | 2007-11-21 16:10:53 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2007-11-21 16:10:53 +0000 |
commit | e407dc6d06978f3a42aa4376d7c16c2d1c72113d (patch) | |
tree | 76e462a36243afa0ca0bfe71ee2b4c9e7e24b85d | |
parent | 178d3b86a6e8b41de5b1d854c34c8f93b483444a (diff) | |
download | acf-openvpn-e407dc6d06978f3a42aa4376d7c16c2d1c72113d.tar.bz2 acf-openvpn-e407dc6d06978f3a42aa4376d7c16c2d1c72113d.tar.xz |
OpenVPNs first page starts to take chape
git-svn-id: svn://svn.alpinelinux.org/acf/openvpn/trunk@353 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r-- | openvpn-controller.lua | 9 | ||||
-rw-r--r-- | openvpn-model.lua | 208 | ||||
-rw-r--r-- | openvpn-read-html.lsp | 10 | ||||
-rw-r--r-- | openvpn-server_config-html.lsp | 2 |
4 files changed, 122 insertions, 107 deletions
diff --git a/openvpn-controller.lua b/openvpn-controller.lua index 52dbfe9..6500a9e 100644 --- a/openvpn-controller.lua +++ b/openvpn-controller.lua @@ -113,9 +113,9 @@ end read = function (self) - local me = {} - me = cfe{name=conflistfilesaf, value="hej"} - return ( {conflistfiles = self.model:list_conffiles(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, version = self.model:openvpn_version()} ) + --local me = {} + --me = cfe{name=conflistfilesaf, value="hej"} + 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) @@ -123,7 +123,8 @@ end server_config = function (self) - return ( {url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} ) + local config = self.clientdata.config or "" + return ( {serverconfig = self.model:get_serverconfig(config), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} ) end client_config = function (self) diff --git a/openvpn-model.lua b/openvpn-model.lua index 5d17dbb..b0607ab 100644 --- a/openvpn-model.lua +++ b/openvpn-model.lua @@ -6,8 +6,10 @@ require ("fs") -- no initializer in model - use controller.init for that + -- ################################################################################ --- LOCAL FUNCTIONS +-- UNKNOWN + local function read_file_as_array ( path ) local file, error = io.open(path) if ( file == nil ) then @@ -21,27 +23,46 @@ local function read_file_as_array ( path ) return f end -local function is_cmdline(path, name) - local f = io.open(path.."/cmdline") - if f == nil then - return false - end - local line = f:read() - f:close() - if line == nil then - return false +local function has_init_script ( f ) + local initprefix = "/etc/init.d/openvpn" + local file = initprefix .. "." .. f + if f ~= "openvpn" then + if ( fs.is_file(file)) then + init = "yes" + else + init = nil + end + else + if ( fs.is_file(initprefix)) then + init = "yes" + else + init = nil + end end - local arg0 = string.gsub(line, string.char(0)..".*", "") - return posix.basename(arg0) == name + return init end +-- ################################################################################ +-- LOCAL FUNCTIONS - +local function config_content( f ) + local config = {} + local conf_file = fs.read_file_as_array ( "/etc/openvpn/".. f ) + 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*)(.*)$" ) + config[a]=b + end + end + return config +end local is_running = function( process, parameters ) strsplit = require("split") - local retval = nil + local retval = "" local pidofsx,error = io.popen("pidof " .. process ,r) local pidofs = strsplit(" ", pidofsx:read("*a")) pidofsx:close() @@ -60,88 +81,78 @@ local is_running = function( process, parameters ) return retval end -local function has_init_script ( f ) - local initprefix = "/etc/init.d/openvpn" - local file = initprefix .. "." .. f - if f ~= "openvpn" then - if ( fs.is_file(file)) then - init = "yes" +local function check_valid_config ( f ) + config.err = "" + 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 (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 - init = nil + config.type = "server" + config.err = "" end else - if ( fs.is_file(initprefix)) then - init = "yes" - else - init = nil - end + config.type = "client" + config.err = "" end - return init + if not (config.type) then config.type = "unknown" end + return config.type, config.err end -local function check_valid_config ( f ) - conf_ca = "" - conf_auth = "" - conf_type = "server" - conf_cert = "" - conf_key = "" - conf_dev = "" - conf_proto = "" - conf_remote = "" - conf_dev = "" - local conf_file_content = read_file_as_array( "/etc/openvpn/".. f ) - for i =1,table.maxn(conf_file_content) do - local lin = conf_file_content[i] - -- Filter out commented lines - if not string.find ( lin, "^[;#].*" ) then - -- The following code could probably de done much easier - -- Check for parameter of a valid configuration - if string.find ( lin, "^ca[%s \v]" ) then - conf_ca="ca" - end - if string.find ( lin, "^auth\-user\-pass[%s \v]" ) then - conf_auth="auth-user-pass" - end - if string.find ( lin, "^client[%s$]" ) then - conf_type = "client" - end - if string.find ( lin, "^cert[%s \v]" ) then - conf_cert = "cert" - end - if string.find ( lin, "^key[%s \v]" ) then - conf_key = "key" - end - if string.find ( lin, "^dev[%s \v]" ) then - conf_dev = "dev" - end - if string.find ( lin, "^proto[%s \v]" ) then - conf_proto = "proto" - end - if string.find ( lin, "^remote[%s \v]" ) then - conf_remote = "remote" +local function list_conffiles() + local configfiles = {} + local config = {} + local files , errstr, errno = posix.dir ( "/etc/openvpn/" ) + 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 end - -- Check if config is invalid (missing parameters) - if conf_type == "client" then - if conf_dev == "" or conf_remote == "" then - conf_type="unknown" - end - else - if conf_dev == "" or conf_port == "" then - conf_type="unknown" - end - end - return conf_type -end - -local function list_rootfolder() - local files , errstr, errno = posix.dir ( "/etc/openvpn/" ) - return files end -- ################################################################################ -- PUBLIC FUNCTIONS +function clientlist() + local countclients = "d" + local clientlist = {} + local f + if (config.status) then + 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]+)" ) + -- 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 } ) + end + end + end + end + countclients = table.maxn(clientlist) + return clientlist, countclients +end + function openvpn_version() local f,error = io.popen("/usr/sbin/openvpn --version") openvpnversion = f:read("*l") @@ -149,23 +160,24 @@ function openvpn_version() return openvpnversion end -function list_conffiles() - conlistfiles = {} - local files = list_rootfolder() - if files then - for a,b in ipairs(files) do - if string.match (b, "^.*conf$") then - local conf_type = check_valid_config ( b ) --- local init_script = is_running ( string.gsub(b, "(%w+)(\..*)", "%1") ) - -- local init_script = string.gsub(b, "(%w+)(\..*)", "%1") - local init_script = is_running ("openvpn", b) - table.insert ( conlistfiles, cfe{ value = b, type = conf_type, init = init_script} ) - end - end - return conlistfiles - end +function get_serverconfig ( f ) + local serverconfig = {} + serverconfig = cfe{ name = f } + return serverconfig end +function get_conflist () + local configlist = {} + for k,v in pairs(list_conffiles()) do + config = config_content ( v.name ) + local conf_type, err = check_valid_config ( v.name ) + local isrunning = is_running ("openvpn", v.name) + local clientlist, connclients = clientlist () + table.insert ( configlist, cfe{ name = v.name, type = conf_type, test = config.ca, err = err, status = isrunning, clients = connclients } ) + end + local countconfigs = table.maxn(configlist) + return configlist, countconfigs +end get = function (self) return list_conffiles() end diff --git a/openvpn-read-html.lsp b/openvpn-read-html.lsp index 00a419a..f22e1a5 100644 --- a/openvpn-read-html.lsp +++ b/openvpn-read-html.lsp @@ -12,15 +12,17 @@ <TD WIDTH=100>Config</TD> <TD WIDTH=70>Type</TD> <TD WIDTH=70>Status</TD> - <TD>Connected Clients</TD> + <TD WIDTH=130>Connected Clients</TD> + <TD>Notes</TD> </TR> <? for i = 1, table.maxn(view.conflistfiles) do ?> <TR > - <TD><?= html.link{value = view.url .. "/" .. view.conflistfiles[i].type .. "_config?config=" .. view.conflistfiles[i].value , label=view.conflistfiles[i].value } ?></TD> + <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><? if view.conflistfiles[i].init then ?><?= view.conflistfiles[i].init ?><? end ?></TD> - <TD>xxx</TD> + <TD><?= view.conflistfiles[i].status ?></TD> + <TD><?= view.conflistfiles[i].clients ?></TD> + <TD style="color:red"><?= view.conflistfiles[i].err ?></TD> </TR> <? end ?> </TABLE> diff --git a/openvpn-server_config-html.lsp b/openvpn-server_config-html.lsp index 6c26398..1e7467b 100644 --- a/openvpn-server_config-html.lsp +++ b/openvpn-server_config-html.lsp @@ -1,7 +1,7 @@ <? local view = ... ?> <html> <body> -<h1>Server config 'xxx.conf'</h1> +<h1>Server config '<?= view.serverconfig.name ?>'</h1> <h2>Server settings</h2> <dt>Mode</dt> |