2015-02-02 00:05:09 +01:00
|
|
|
--
|
|
|
|
-- init.lua
|
|
|
|
--
|
|
|
|
-- This is the initialization file of SSOwat. It is called once at the Nginx
|
|
|
|
-- server's start.
|
2023-07-15 19:51:31 +02:00
|
|
|
-- Consequently, all the variables declared (along with libraries and
|
2015-02-02 00:05:09 +01:00
|
|
|
-- translations) in this file will be *persistent* from one HTTP request to
|
|
|
|
-- another.
|
|
|
|
--
|
|
|
|
|
2013-10-20 16:38:49 +02:00
|
|
|
-- Remove prepending '@' & trailing 'init.lua'
|
|
|
|
script_path = string.sub(debug.getinfo(1).source, 2, -9)
|
|
|
|
-- Include local libs in package.path
|
|
|
|
package.path = package.path .. ";"..script_path.."?.lua"
|
|
|
|
|
2021-12-26 17:01:56 +01:00
|
|
|
-- Load cookie secret
|
2023-07-15 19:51:31 +02:00
|
|
|
-- IMPORTANT (though to be confirmed?)
|
|
|
|
-- in this context, the code is ran as root therefore we don't have to
|
|
|
|
-- add www-data in the file permissions, which could otherwise lead
|
|
|
|
-- to comprised apps running with the www-data group to read the secret file?
|
|
|
|
local config = require("config")
|
2024-01-30 20:52:23 +01:00
|
|
|
COOKIE_SECRET = config.get_cookie_secret()
|
2013-10-15 10:11:39 +02:00
|
|
|
|
2023-07-15 19:51:31 +02:00
|
|
|
--
|
|
|
|
-- Init logger
|
|
|
|
--
|
|
|
|
|
|
|
|
local log_file = "/var/log/nginx/ssowat.log"
|
|
|
|
|
2019-10-03 20:42:48 +02:00
|
|
|
-- Make sure the log file exists and we can write in it
|
|
|
|
io.popen("touch "..log_file)
|
|
|
|
io.popen("chown www-data "..log_file)
|
|
|
|
io.popen("chmod u+w "..log_file)
|
|
|
|
|
2023-07-15 19:51:31 +02:00
|
|
|
local Logging = require("logging")
|
|
|
|
local appender = function(self, level, message)
|
|
|
|
|
|
|
|
-- Output to log file
|
|
|
|
local fp = io.open(log_file, "a")
|
|
|
|
local str = string.format("[%-6s%s] %s\n", level:upper(), os.date(), message)
|
|
|
|
fp:write(str)
|
|
|
|
fp:close()
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
logger = Logging.new(appender)
|
|
|
|
|
2024-03-26 01:09:01 +01:00
|
|
|
logger:setLevel(Logging.DEBUG)
|
2023-07-15 19:51:31 +02:00
|
|
|
|
|
|
|
|
2015-02-02 00:05:09 +01:00
|
|
|
-- You should see that in your Nginx error logs by default
|
2013-10-20 17:24:44 +02:00
|
|
|
ngx.log(ngx.INFO, "SSOwat ready")
|