From eb012794028e9f5670feb03718c03ad699e8d935 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Fri, 26 Sep 2008 18:16:31 +0000 Subject: Cleanup of some libs. git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1533 ab2d0c66-481e-0410-8bed-d214d4d58bed --- app/acf_www-controller.lua | 2 +- lib/authenticator.lua | 6 +++--- lib/format.lua | 29 ++++++++++++++--------------- lib/fs.lua | 13 ------------- lib/html.lua | 2 +- lib/modelfunctions.lua | 2 +- lib/processinfo.lua | 11 ++++++----- lib/roles.lua | 1 - lib/session.lua | 1 - 9 files changed, 26 insertions(+), 41 deletions(-) diff --git a/app/acf_www-controller.lua b/app/acf_www-controller.lua index 6f114b6..5f5abcd 100644 --- a/app/acf_www-controller.lua +++ b/app/acf_www-controller.lua @@ -245,7 +245,7 @@ mvc.on_load = function (self, parent) self.clientdata.sessionid) if timestamp == nil then -- invalid session id, report event and create new one - sessionlib.record_event(self.conf.sessiondir, + sessionlib.record_event(self.conf.sessiondir, nil, sessionlib.hash_ip_addr(self.conf.clientip)) --logevent("Didn't find session") else diff --git a/lib/authenticator.lua b/lib/authenticator.lua index 857703c..74dfdad 100644 --- a/lib/authenticator.lua +++ b/lib/authenticator.lua @@ -4,7 +4,7 @@ module (..., package.seeall) require("modelfunctions") -require("fs") +require("format") -- This will be the sub-authenticator local auth @@ -77,7 +77,7 @@ local write_settings = function(self, settings, id) -- Password, password_confirm, roles are allowed to not exist, just leave the same id.userid = settings.value.userid.value id.username = settings.value.username.value - if settings.value.password then id.password = fs.md5sum_string(settings.value.password.value) end + if settings.value.password then id.password = format.md5sum_string(settings.value.password.value) end if settings.value.roles then id.roles = table.concat(settings.value.roles.value, ",") end return auth.write_entry(self, passwdtable, "", id.userid, (id.password or "")..":"..(id.username or "")..":"..(id.roles or "")) @@ -130,7 +130,7 @@ authenticate = function(self, userid, password) local id = get_id(userid) if not id then errtxt = "Userid not found" - elseif id.password ~= fs.md5sum_string(password) then + elseif id.password ~= format.md5sum_string(password) then errtxt = "Invalid password" end end diff --git a/lib/format.lua b/lib/format.lua index e19899f..6de19c4 100644 --- a/lib/format.lua +++ b/lib/format.lua @@ -179,7 +179,7 @@ function md5sum_string ( str) local checksum = {} for line in f:lines() do checksum[#checksum + 1] = line - end + end f:close() return checksum[1] end @@ -189,21 +189,20 @@ end -- ex: a="foo"; print(expand_bash_syntax_vars("a=${a}) - > "a=foo" expand_bash_syntax_vars = function ( str ) + local deref = function ( f) + local v = _G + for w in string.gfind(f, "[%w_]+") do + v = v[w] + end + return v + end - local deref = function ( f) - local v = _G - for w in string.gfind(f, "[%w_]+") do - v = v[w] - end - return v - end - - for w in string.gmatch (str, "${[^}]*}" ) do - local rvar = string.sub(w,3,-2) - local rval = ( deref(rvar) or "nil" ) - str = string.gsub (str, w, rval) - end - return (str) + for w in string.gmatch (str, "${[^}]*}" ) do + local rvar = string.sub(w,3,-2) + local rval = ( deref(rvar) or "nil" ) + str = string.gsub (str, w, rval) + end + return (str) end -- Removes the linenum line from str and replaces it with line. diff --git a/lib/fs.lua b/lib/fs.lua index 943fb85..fa58058 100644 --- a/lib/fs.lua +++ b/lib/fs.lua @@ -95,19 +95,6 @@ function md5sum_file ( path ) return checksum end -function md5sum_string ( str) - cmd = "/bin/echo -n " .. str .. "|/usr/bin/md5sum|cut -f 1 -d \" \" " - f = io.popen(cmd) - local checksum = {} - for line in f:lines() do - checksum[#checksum + 1] = line - end - f:close() - return checksum[1] -end - - - -- iterator function for finding dir entries matching filespec (what) -- starting at where, or currentdir if not specified. -- Finds regexes, not fileglobs diff --git a/lib/html.lua b/lib/html.lua index d6f968a..a543659 100644 --- a/lib/html.lua +++ b/lib/html.lua @@ -43,7 +43,7 @@ function html_escape (text ) end -- return a name,value pair as a string. -nv_pair = function ( name, value) +local nv_pair = function ( name, value) if ( name == nil ) then return ( value or "" ) end diff --git a/lib/modelfunctions.lua b/lib/modelfunctions.lua index 9dd1d6b..ef0513c 100644 --- a/lib/modelfunctions.lua +++ b/lib/modelfunctions.lua @@ -17,7 +17,7 @@ end function startstop_service(processname, action) -- action is validated in daemoncontrol - local cmdresult,cmdmessage,cmderror,cmdaction = processinfo.daemoncontrol(processname, action) + local cmdmessage,cmderror = processinfo.daemoncontrol(processname, action) return cfe({ value=cmdmessage or "", errtxt=cmderror, label="Start/Stop result" }) end diff --git a/lib/processinfo.lua b/lib/processinfo.lua index dd15fa8..e1eca4e 100644 --- a/lib/processinfo.lua +++ b/lib/processinfo.lua @@ -30,19 +30,20 @@ function process_botsequence(processname) end function daemoncontrol (process, action) - local cmdmessage = "" + local cmdresult = "" + local cmderrors if (string.lower(action) == "start") or (string.lower(action) == "stop") or (string.lower(action) == "restart") then local file = io.popen( "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin /etc/init.d/" .. process .. " " .. string.lower(action) .. " 2>&1" ) if file ~= nil then - cmdmessage = file:read( "*a" ) + cmdresult = file:read( "*a" ) file:close() end + posix.sleep(2) -- Wait for the process to start|stop else - return false,nil,"Unknown command!",action + cmderrors = "Unknown command!" end - posix.sleep(2) -- Wait for the process to start|stop - return true,cmdmessage,nil,action + return cmdresult,cmderrors end -- the following methods are available: diff --git a/lib/roles.lua b/lib/roles.lua index 8bf9aed..86efe4b 100644 --- a/lib/roles.lua +++ b/lib/roles.lua @@ -1,7 +1,6 @@ --this module is for authorization help and group/role management require ("authenticator") -require ("posix") require ("fs") require ("format") diff --git a/lib/session.lua b/lib/session.lua index bd2bdf6..a48b293 100644 --- a/lib/session.lua +++ b/lib/session.lua @@ -13,7 +13,6 @@ module (..., package.seeall) require "posix" -require "format" minutes_expired_events=30 minutes_count_events=30 -- cgit v1.2.3