4 (c) 2008 Steven Barth <steven@midlink.org>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
16 --- LuCI session library.
17 module("luci.sauth", package.seeall)
20 require("luci.config")
23 luci.config.sauth = luci.config.sauth or {}
24 sessionpath = luci.config.sauth.sessionpath
25 sessiontime = tonumber(luci.config.sauth.sessiontime)
27 --- Manually clean up expired sessions.
30 local files = luci.fs.dir(sessionpath)
36 for i, file in pairs(files) do
37 local fname = sessionpath .. "/" .. file
38 local stat = luci.fs.stat(fname)
39 if stat and stat.type == "regular" and stat.atime + sessiontime < now then
45 --- Prepare session storage by creating the session directory.
47 luci.fs.mkdir(sessionpath)
48 luci.fs.chmod(sessionpath, "a-rwx,u+rwx")
51 --- Read a session and return its content.
52 -- @param id Session identifier
53 -- @return Session data
59 return luci.fs.readfile(sessionpath .. "/" .. id)
63 --- Write session data to a session file.
64 -- @param id Session identifier
65 -- @param data Session data
66 function write(id, data)
67 if not luci.fs.stat(sessionpath) then
70 luci.fs.writefile(sessionpath .. "/" .. id, data)
71 luci.fs.chmod(sessionpath .. "/" .. id, "a-rwx,u+rw")