From 008e476ed54a6d9d3050f38dfc445de0cc2bd052 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Fri, 30 Nov 2007 09:51:20 +0000 Subject: Adding debuginfo for further programming and make config-edit function. git-svn-id: svn://svn.alpinelinux.org/acf/openvpn/trunk@394 ab2d0c66-481e-0410-8bed-d214d4d58bed --- openvpn-client_config-html.lsp | 28 +++++++++++++++++++--- openvpn-controller.lua | 27 +++++++++++++++++++-- openvpn-model.lua | 53 ++++++++++++++++++++++++++++++++--------- openvpn-read-html.lsp | 33 +++++++++++++++++++++++++ openvpn-server_config-html.lsp | 28 +++++++++++++++++++--- openvpn-unknown_config-html.lsp | 42 ++++++++++++++++++++++---------- 6 files changed, 179 insertions(+), 32 deletions(-) diff --git a/openvpn-client_config-html.lsp b/openvpn-client_config-html.lsp index ef0bdaf..c2395ca 100644 --- a/openvpn-client_config-html.lsp +++ b/openvpn-client_config-html.lsp @@ -4,11 +4,33 @@

Client config ''

-

DEUB INFO

+------------ START DEBUG INFORMATION ------------ +

THIS VIEW CONTAINS THE FOLLOWING VARIABLES/TABLES

" .. a .. ": >" .. b .. "<
") +--print ("") +for a,b in pairs(view) do + if not (type(b) == "table") then + print ("" .. a .. ": >" .. b .. "<
") + else + print ("" .. a .. ":...
") + for c,d in pairs(view[a]) do + if not (type(d) == "table") then + print (" { " .. c .. ": >" .. d .. "< }
") + else + print (" { " .. c .. ":...
") + for e,f in pairs(view[a][c]) do + if not (type(f) == "table") then + print (" { { " .. e .. ": >" .. f .. "< } }
") + else + print (" { { " .. e .. ":... (table is not visible at the moment)
") + end + end + end + end + end +a,b,c,d,e,f,g,h,i,j = nil,nil,nil,nil,nil,nil,nil,nil,nil,nil end +print ("------------ END DEBUG INFORMATION ------------
") ?> diff --git a/openvpn-controller.lua b/openvpn-controller.lua index fcc90cb..c2f5a4c 100644 --- a/openvpn-controller.lua +++ b/openvpn-controller.lua @@ -47,8 +47,31 @@ status_info = function (self) end unknown_config = function (self) - local configname = self.clientdata.name or "" - return ( {configfilecontent = self.model:get_filecontent(configname), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} ) + local filename = self.clientdata.name or "" + local filecontent = self.clientdata.modifications or "" + +---[[ + if ( filecontent ~= "") then + local me = ( {configfilecontent = self.model:update_filecontent(filename,filecontent), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } ) + if ( me.configfilecontent == nil ) then + list_redir(self) + else + return me + end + else +---[=[ + local me = ( {configfilecontent = self.model:get_filecontent(filename), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } ) + if ( me.configfilecontent == nil ) then + list_redir(self) + else + return me + end +--]=] +-- return ( {configfilecontent = self.model:get_filecontent(filename), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} ) + + end +--]] + end logfile = function (self) diff --git a/openvpn-model.lua b/openvpn-model.lua index 700bb48..32fc33b 100644 --- a/openvpn-model.lua +++ b/openvpn-model.lua @@ -1,8 +1,11 @@ module (..., package.seeall) require ("posix") +require ("format") require ("fs") +local baseurl = "/etc/openvpn/" + -- no initializer in model - use controller.init for that -- ################################################################################ @@ -22,13 +25,13 @@ end local function config_content( f ) local config = {} - config.name = "/etc/openvpn/" .. f + config.name = baseurl .. 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+(%S*).*$" ) -- Working exept on 'remote xxxxx xxxx' + local a,b = string.match ( l, "^%s*(%S+)%s*(%S*).*$" ) if (a) then config[string.lower(a)]=b end @@ -108,7 +111,7 @@ end local function list_conffiles() local configfiles = {} local config = {} - local files , errstr, errno = posix.dir ( "/etc/openvpn/" ) + local files , errstr, errno = posix.dir ( baseurl ) if files then for k,v in ipairs(files) do if string.match (v, "^.*conf$") then @@ -210,19 +213,46 @@ function openvpn_version() end function get_config ( self, f ) + local path = basename(f) local configresult = {} config = nil - config = config_content ( f ) + config = config_content ( path ) local clientlist, client_count, client_lastupdate, client_lastdatechangediff = clientlist () - local status_isrunning = is_running ("openvpn", f) + local status_isrunning = is_running ("openvpn", path) + if (client_lastupdate == nil) then + config["client_lastupdate"] = "?" + else + config["client_lastupdate"]=client_lastupdate + end + if (client_lastupdate == nil) then + config["client_lastdatechangediff"] = "? min" + else + config["client_lastdatechangediff"]=client_lastdatechangediff + end 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 update_filecontent (self, f, modifications) + name = basename(f) + path = baseurl .. name + local available_files = list_conffiles() + for k,v in pairs(available_files) do + if ( available_files[k].name == name ) then + local file = io.open( path, "w+" ) + local file_result,err = file:write(format.dostounix(modifications)) + file:close() + if (err ~= nil) then + local filedetails = get_config(name) + file_content = {name=name, value=file_result, filedetails=filedetails, err=err} + end + end + end + return file_content +end + function get_logfile( self, path) config = config_content ( path ) local logfilecontent = fs.read_file ( config.log ) @@ -232,18 +262,19 @@ function get_logfile( self, path) return ( { name = config.log, value = logfilecontent } ) end -function get_filecontent( self, path) +function get_filecontent( self, f) + local path = basename(f) local configresult = {} config = config_content ( path ) local file = io.open( config.name ) local file_result = file:read("*a") or "unknown" file:close() + local conf_type, err = check_valid_config ( path ) local filedetails = file_info( config.name ) - file_content = cfe{name=config.name, value=file_result, filedetails=filedetails} + file_content = cfe{name=config.name, value=file_result, type=conf_type, filedetails=filedetails} return file_content end - function get_conflist () local configlist = {} for k,v in pairs(list_conffiles()) do @@ -251,7 +282,7 @@ function get_conflist () 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 } ) + table.insert ( configlist, cfe{ name = v.name, type = conf_type, err = err, status = isrunning, clients = connclients } ) end local countconfigs = table.maxn(configlist) return configlist, countconfigs diff --git a/openvpn-read-html.lsp b/openvpn-read-html.lsp index 58c079d..75215ef 100644 --- a/openvpn-read-html.lsp +++ b/openvpn-read-html.lsp @@ -3,6 +3,39 @@

Welcome

+ + + +------------ START DEBUG INFORMATION ------------ +

THIS VIEW CONTAINS THE FOLLOWING VARIABLES/TABLES

+") +for a,b in pairs(view) do + if not (type(b) == "table") then + print ("" .. a .. ": >" .. b .. "<
") + else + print ("" .. a .. ":...
") + for c,d in pairs(view[a]) do + if not (type(d) == "table") then + print (" { " .. c .. ": >" .. d .. "< }
") + else + print (" { " .. c .. ":...
") + for e,f in pairs(view[a][c]) do + if not (type(f) == "table") then + print (" { { " .. e .. ": >" .. f .. "< } }
") + else + print (" { { " .. e .. ":... (table is not visible at the moment)
") + end + end + end + end + end +a,b,c,d,e,f,g,h,i,j = nil,nil,nil,nil,nil,nil,nil,nil,nil,nil +end +print ("------------ END DEBUG INFORMATION ------------
") +?> + +

Available configs

diff --git a/openvpn-server_config-html.lsp b/openvpn-server_config-html.lsp index fc60ec2..511e48a 100644 --- a/openvpn-server_config-html.lsp +++ b/openvpn-server_config-html.lsp @@ -5,11 +5,33 @@ -

DEUB INFO

+------------ START DEBUG INFORMATION ------------ +

THIS VIEW CONTAINS THE FOLLOWING VARIABLES/TABLES

" .. a .. ": " .. b .. "
") +--print ("") +for a,b in pairs(view) do + if not (type(b) == "table") then + print ("" .. a .. ": >" .. b .. "<
") + else + print ("" .. a .. ":...
") + for c,d in pairs(view[a]) do + if not (type(d) == "table") then + print (" { " .. c .. ": >" .. d .. "< }
") + else + print (" { " .. c .. ":...
") + for e,f in pairs(view[a][c]) do + if not (type(f) == "table") then + print (" { { " .. e .. ": >" .. f .. "< } }
") + else + print (" { { " .. e .. ":... (table is not visible at the moment)
") + end + end + end + end + end +a,b,c,d,e,f,g,h,i,j = nil,nil,nil,nil,nil,nil,nil,nil,nil,nil end +print ("------------ END DEBUG INFORMATION ------------
") ?> diff --git a/openvpn-unknown_config-html.lsp b/openvpn-unknown_config-html.lsp index 302ea56..db577a7 100644 --- a/openvpn-unknown_config-html.lsp +++ b/openvpn-unknown_config-html.lsp @@ -4,11 +4,33 @@

Configuration file ''

-

DEUB INFO

+------------ START DEBUG INFORMATION ------------ +

THIS VIEW CONTAINS THE FOLLOWING VARIABLES/TABLES

" .. a .. ": >" .. b .. "<
") +--print ("") +for a,b in pairs(view) do + if not (type(b) == "table") then + print ("" .. a .. ": >" .. b .. "<
") + else + print ("" .. a .. ":...
") + for c,d in pairs(view[a]) do + if not (type(d) == "table") then + print (" { " .. c .. ": >" .. d .. "< }
") + else + print (" { " .. c .. ":...
") + for e,f in pairs(view[a][c]) do + if not (type(f) == "table") then + print (" { { " .. e .. ": >" .. f .. "< } }
") + else + print (" { { " .. e .. ":... (table is not visible at the moment)
") + end + end + end + end + end +a,b,c,d,e,f,g,h,i,j = nil,nil,nil,nil,nil,nil,nil,nil,nil,nil end +print ("------------ END DEBUG INFORMATION ------------
") ?> @@ -23,19 +45,13 @@ end
Last modified
+
This config looks like a
+
config
-

Controlpanel

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

Details

+

Content

- + -- cgit v1.2.3