diff options
-rw-r--r-- | app/acf_www-controller.lua | 19 | ||||
-rw-r--r-- | lib/Makefile | 3 | ||||
-rw-r--r-- | lib/session.lua | 40 |
3 files changed, 14 insertions, 48 deletions
diff --git a/app/acf_www-controller.lua b/app/acf_www-controller.lua index 881cc3e..affdfba 100644 --- a/app/acf_www-controller.lua +++ b/app/acf_www-controller.lua @@ -1,5 +1,5 @@ --[[ Code for the Alpine Configuration WEB framework - Written for Alpine Configuration Framework (ACF) -- see www.alpinelinux.org + see http://wiki.alpinelinux.org Copyright (C) 2007 Nathan Angelacos Licensed under the terms of GPL2 ]]-- @@ -28,20 +28,12 @@ mvc.on_load = function (self, parent) local x=require("session") if FORM.sessionid then local timestamp - timestamp , self.session = x.load_session(self.conf.sessiondir , FORM.sessionid) + timestamp , self.session = x.load_session(self.conf.sessiondir, + FORM.sessionid) self.session.id = FORM.sessionid else self.session.id = nil end - logit ("acf_www-controller mvc.on_load activated" ) -end - -mvc.pre_exec = function () - logit ("acf_www-controller mvc.pre_exec activated") -end - -mvc.post_exec = function () - logit ("acf_www-controller mvc.post_exec activated") end @@ -207,8 +199,3 @@ cfe = function ( optiontable ) return me end - --- syslog something -logit = function ( ... ) - os.execute ( "logger \"" .. ... .. "\"" ) -end 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 |