diff options
author | Mika Havela <mika.havela@gmail.com> | 2007-11-30 09:51:20 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2007-11-30 09:51:20 +0000 |
commit | 008e476ed54a6d9d3050f38dfc445de0cc2bd052 (patch) | |
tree | 6c12ea469022896071d1ea8a80e1150ba3071910 | |
parent | 4914226cda432c9d865b83dd116ecce005182e26 (diff) | |
download | acf-openvpn-008e476ed54a6d9d3050f38dfc445de0cc2bd052.tar.bz2 acf-openvpn-008e476ed54a6d9d3050f38dfc445de0cc2bd052.tar.xz |
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
-rw-r--r-- | openvpn-client_config-html.lsp | 28 | ||||
-rw-r--r-- | openvpn-controller.lua | 27 | ||||
-rw-r--r-- | openvpn-model.lua | 53 | ||||
-rw-r--r-- | openvpn-read-html.lsp | 33 | ||||
-rw-r--r-- | openvpn-server_config-html.lsp | 28 | ||||
-rw-r--r-- | 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 @@ <h1>Client config '<?= view.config.name ?>'</h1> <? --[[ DEBUG INFORMATION...?> -<h2>DEUB INFO</h2> +<span style='color:#D2691E;font-family:courier;'>------------ START DEBUG INFORMATION ------------ +<h3>THIS VIEW CONTAINS THE FOLLOWING VARIABLES/TABLES</h2> <? -for a,b in pairs(view.config) do -print ("<b>" .. a .. "</b>: >" .. b .. "<<BR>") +--print ("<span style='color:darkblue;font-family:courier;'>") +for a,b in pairs(view) do + if not (type(b) == "table") then + print ("<b>" .. a .. "</b>: ><span2 style='color:black'>" .. b .. "</span2><<BR>") + else + print ("<b>" .. a .. "</b>:...<BR>") + for c,d in pairs(view[a]) do + if not (type(d) == "table") then + print ("<b> { " .. c .. "</b>: ><span2 style='color:black'>" .. d .. "</span2>< <B> }</B><BR>") + else + print ("<b> { " .. c .. "</b>:...<BR>") + for e,f in pairs(view[a][c]) do + if not (type(f) == "table") then + print ("<b> { { " .. e .. "</b>: ><span2 style='color:black'>" .. f .. "</span2>< <B> } }</B><BR>") + else + print ("<b> { { " .. e .. "</b>:... (table is not visible at the moment)<BR>") + 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 ------------</span>") ?> <? --]] ?> 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 @@ <html> <body> <h1>Welcome</h1> + + +<? --[[ DEBUG INFORMATION...?> +<span style='color:#D2691E;font-family:courier;'>------------ START DEBUG INFORMATION ------------ +<h3>THIS VIEW CONTAINS THE FOLLOWING VARIABLES/TABLES</h2> +<? +--print ("<span style='color:darkblue;font-family:courier;'>") +for a,b in pairs(view) do + if not (type(b) == "table") then + print ("<b>" .. a .. "</b>: ><span2 style='color:black'>" .. b .. "</span2><<BR>") + else + print ("<b>" .. a .. "</b>:...<BR>") + for c,d in pairs(view[a]) do + if not (type(d) == "table") then + print ("<b> { " .. c .. "</b>: ><span2 style='color:black'>" .. d .. "</span2>< <B> }</B><BR>") + else + print ("<b> { " .. c .. "</b>:...<BR>") + for e,f in pairs(view[a][c]) do + if not (type(f) == "table") then + print ("<b> { { " .. e .. "</b>: ><span2 style='color:black'>" .. f .. "</span2>< <B> } }</B><BR>") + else + print ("<b> { { " .. e .. "</b>:... (table is not visible at the moment)<BR>") + 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 ------------</span>") +?> +<? --]] ?> + <h2>Available configs</h2> <TABLE BORDER=0 WIDTH="100%"> <TR style="background:#eee;font-weight:bold;vertical-align:top;"> 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 @@ <? --[[ DEBUG INFORMATION...?> -<h2>DEUB INFO</h2> +<span style='color:#D2691E;font-family:courier;'>------------ START DEBUG INFORMATION ------------ +<h3>THIS VIEW CONTAINS THE FOLLOWING VARIABLES/TABLES</h2> <? -for a,b in pairs(view.config) do -print ("<b>" .. a .. "</b>: " .. b .. "<BR>") +--print ("<span style='color:darkblue;font-family:courier;'>") +for a,b in pairs(view) do + if not (type(b) == "table") then + print ("<b>" .. a .. "</b>: ><span2 style='color:black'>" .. b .. "</span2><<BR>") + else + print ("<b>" .. a .. "</b>:...<BR>") + for c,d in pairs(view[a]) do + if not (type(d) == "table") then + print ("<b> { " .. c .. "</b>: ><span2 style='color:black'>" .. d .. "</span2>< <B> }</B><BR>") + else + print ("<b> { " .. c .. "</b>:...<BR>") + for e,f in pairs(view[a][c]) do + if not (type(f) == "table") then + print ("<b> { { " .. e .. "</b>: ><span2 style='color:black'>" .. f .. "</span2>< <B> } }</B><BR>") + else + print ("<b> { { " .. e .. "</b>:... (table is not visible at the moment)<BR>") + 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 ------------</span>") ?> <? --]] ?> 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 @@ <h1>Configuration file '<?= view.configfilecontent.name ?>'</h1> <? --[[ DEBUG INFORMATION...?> -<h2>DEUB INFO</h2> +<span style='color:#D2691E;font-family:courier;'>------------ START DEBUG INFORMATION ------------ +<h3>THIS VIEW CONTAINS THE FOLLOWING VARIABLES/TABLES</h2> <? -for a,b in pairs(view.configfilecontent.filedetails) do -print ("<b>" .. a .. "</b>: >" .. b .. "<<BR>") +--print ("<span style='color:darkblue;font-family:courier;'>") +for a,b in pairs(view) do + if not (type(b) == "table") then + print ("<b>" .. a .. "</b>: ><span2 style='color:black'>" .. b .. "</span2><<BR>") + else + print ("<b>" .. a .. "</b>:...<BR>") + for c,d in pairs(view[a]) do + if not (type(d) == "table") then + print ("<b> { " .. c .. "</b>: ><span2 style='color:black'>" .. d .. "</span2>< <B> }</B><BR>") + else + print ("<b> { " .. c .. "</b>:...<BR>") + for e,f in pairs(view[a][c]) do + if not (type(f) == "table") then + print ("<b> { { " .. e .. "</b>: ><span2 style='color:black'>" .. f .. "</span2>< <B> } }</B><BR>") + else + print ("<b> { { " .. e .. "</b>:... (table is not visible at the moment)<BR>") + 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 ------------</span>") ?> <? --]] ?> @@ -23,19 +45,13 @@ end <dt>Last modified</dt> <dd><?= view.configfilecontent.filedetails.mtimelong ?></dd> +<dt>This config looks like a</dt> +<dd><a href="<?= view.url ?>/<?= view.configfilecontent.type ?>_config?name=<?= view.configfilecontent.name ?>"><?= view.configfilecontent.type ?></a> config</a></dd> -<h2>Controlpanel</h2> - -<dt>View this as it was a</dt> -<dd><a href="<?= view.url ?>/server_config?name=<?= view.configfilecontent.linkname ?>">server config</a></dd> - -<dt>View this as it was a</dt> -<dd><a href="<?= view.url ?>/client_config?name=<?= view.configfilecontent.linkname ?>">client config</a></dd> - -<h2>Details</h2> +<h2>Content</h2> <form name="myform" action="" method="POST"> -<input name="name" type="hidden" value="<?= view.configfilecontent.linkname ?>" style="width:100%"> +<input name="name" type="hidden" value="<?= view.configfilecontent.name ?>" style="width:100%"> <textarea name="modifications" style="width:100%;height:400px;"><?= view.configfilecontent.value ?></textarea> <input type="submit" name="cmd" value="update"></form> |