summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorNathan Angelacos <nangel@tetrasec.net>2007-11-14 20:50:02 +0000
committerNathan Angelacos <nangel@tetrasec.net>2007-11-14 20:50:02 +0000
commit2093384b4aa4068d721aef4006a9d8a4666c5378 (patch)
tree56b2c1324e8fd870a72a3525209f59de05333c63 /lib
parent0d14e4cb5636a57c674a7076ab1605802cea85a2 (diff)
downloadacf-core-2093384b4aa4068d721aef4006a9d8a4666c5378.tar.bz2
acf-core-2093384b4aa4068d721aef4006a9d8a4666c5378.tar.xz
app/acf_www-controller.lua removed logit references
lib/session.lua use posix lib/Makefile remove reference to ed.lua git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@303 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile3
-rw-r--r--lib/session.lua40
2 files changed, 11 insertions, 32 deletions
diff --git a/lib/Makefile b/lib/Makefile
index 0c65ca1..bf7d2b9 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,7 +1,6 @@
include ../config.mk
-LIB_DIST=ed.lua\
- fs.lua\
+LIB_DIST=fs.lua\
html.lua\
join.lua\
log_view.lua\
diff --git a/lib/session.lua b/lib/session.lua
index f23f5a5..19d35cc 100644
--- a/lib/session.lua
+++ b/lib/session.lua
@@ -3,6 +3,8 @@
module (..., package.seeall)
+require "posix"
+
local b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"
-- Return a sessionid of at least size bits length
@@ -18,6 +20,8 @@ random_hash = function (size)
return str
end
+-- FIXME: only hashes ipv4
+
hash_ip_addr = function (string)
local str = ""
for i in string.gmatch(string, "%d+") do
@@ -74,7 +78,7 @@ function serialize (name, value, saved )
end
save_session = function( sessionpath, session, sessiontable)
- local file = io.open(sessionpath .. "/" .. session , "w")
+ local file = io.open(sessionpath .. "/session." .. session , "w")
if file then
file:write ( "-- This is an ACF session table.\nlocal timestamp=" .. os.time() )
file:write ( "\nlocal " )
@@ -88,20 +92,6 @@ save_session = function( sessionpath, session, sessiontable)
end
---- FIXME: This is really a generic "test if file exists" thing.
-
--- Tests if a session is valid
--- Returns true if valid, false if not
-session_is_valid = function (session)
- local file = io.open(session)
- if file then
- file:close()
- return true
- else
- return false
- end
-end
-
-- Loads a session
-- Returns a timestamp (when the session data was saved) and the session table.
load_session = function ( sessionpath, session )
@@ -110,9 +100,9 @@ load_session = function ( sessionpath, session )
if #session == 0 then
return nil, {}
end
- session = sessionpath .. "/" .. session
- if (session_is_valid(session)) then
- local file = io.open(session)
+ session = sessionpath .. "/session." .. session
+ if (posix.stat(session)) then
+ local file = io.open(session)
return dofile(session)
else
return nil, {}
@@ -120,24 +110,14 @@ load_session = function ( sessionpath, session )
end
-- unlinks a session
-invalidate_session = function (sessionpath, session)
+unlink_session = function (sessionpath, session)
if type(session) ~= "string" then return nil end
local s = string.gsub (session, "[^" .. b64 .. "]", "")
if s ~= session then
return nil
end
- session = sessionpath .. "/" .. s
+ session = sessionpath .. "/session." .. s
os.remove (session)
return nil
end
-
-expire_old_sessions = function ( sessiondir )
- file = io.popen("ls " .. sessiondir )
- x = file:read("*a")
- file:close()
- for a in string.gmatch(x, "[^%c]+") do
- timestamp, foo = load_session ( sessiondir .. "/" .. a )
- print ( a .. " is " .. os.time() - timestamp .. " seconds old")
- end
-end