2015-02-02 00:05:09 +01:00
|
|
|
--
|
|
|
|
-- config.lua
|
|
|
|
--
|
|
|
|
-- This file loads the configuration from config files or default values.
|
|
|
|
--
|
|
|
|
|
2015-02-15 13:03:01 +01:00
|
|
|
module('config', package.seeall)
|
2015-02-02 00:05:09 +01:00
|
|
|
|
2016-04-30 12:40:59 +02:00
|
|
|
function get_config()
|
2015-02-12 12:08:52 +01:00
|
|
|
|
|
|
|
-- Load the configuration file
|
|
|
|
local conf_file = assert(io.open(conf_path, "r"), "Configuration file is missing")
|
|
|
|
local conf = json.decode(conf_file:read("*all"))
|
2020-07-27 15:44:58 +02:00
|
|
|
if conf_file ~= nil then
|
|
|
|
conf_file:close()
|
|
|
|
end
|
2015-02-12 12:08:52 +01:00
|
|
|
|
|
|
|
-- Load additional rules from the `.persistent` configuration file.
|
|
|
|
-- The `.persistent` file contains rules that will overwrite previous rules.
|
|
|
|
-- It typically enables you to set custom rules.
|
|
|
|
local persistent_conf_file = io.open(conf_path..".persistent", "r")
|
|
|
|
if persistent_conf_file ~= nil then
|
2020-03-29 19:39:25 +02:00
|
|
|
perm_conf = json.decode(persistent_conf_file:read("*all"))
|
|
|
|
persistent_conf_file:close()
|
|
|
|
for k, v in pairs(perm_conf) do
|
2015-02-12 12:08:52 +01:00
|
|
|
|
|
|
|
-- If the configuration key already exists and is a table, merge it
|
|
|
|
if conf[k] and type(v) == "table" then
|
|
|
|
for subk, subv in pairs(v) do
|
|
|
|
if type(subk) == "number" then
|
|
|
|
table.insert(conf[k], subv)
|
|
|
|
else
|
|
|
|
conf[k][subk] = subv
|
|
|
|
end
|
|
|
|
end
|
2015-02-02 00:05:09 +01:00
|
|
|
|
2015-02-12 12:08:52 +01:00
|
|
|
-- Else just take the persistent rule's value
|
|
|
|
else
|
|
|
|
conf[k] = v
|
2017-09-16 18:49:37 +02:00
|
|
|
end
|
2015-02-12 12:08:52 +01:00
|
|
|
end
|
|
|
|
end
|
2015-02-02 00:05:09 +01:00
|
|
|
|
|
|
|
|
2015-02-12 12:08:52 +01:00
|
|
|
-- Default configuration values
|
|
|
|
default_conf = {
|
|
|
|
portal_scheme = "https",
|
2017-09-16 18:49:37 +02:00
|
|
|
portal_path = "/ssowat/",
|
2015-02-12 12:08:52 +01:00
|
|
|
local_portal_domain = "yunohost.local",
|
|
|
|
domains = { conf["portal_domain"], "yunohost.local" },
|
|
|
|
session_timeout = 60 * 60 * 24, -- one day
|
|
|
|
session_max_timeout = 60 * 60 * 24 * 7, -- one week
|
|
|
|
login_arg = "sso_login",
|
|
|
|
ldap_host = "localhost",
|
|
|
|
ldap_group = "ou=users,dc=yunohost,dc=org",
|
|
|
|
ldap_identifier = "uid",
|
2017-09-16 19:22:47 +02:00
|
|
|
ldap_enforce_crypt = true,
|
|
|
|
skipped_urls = {},
|
2015-02-12 12:08:52 +01:00
|
|
|
ldap_attributes = {"uid", "givenname", "sn", "cn", "homedirectory", "mail", "maildrop"},
|
|
|
|
allow_mail_authentication = true,
|
2019-02-12 20:18:19 +01:00
|
|
|
default_language = "en",
|
2019-10-03 20:42:01 +02:00
|
|
|
theme = "default",
|
|
|
|
logging = "fatal" -- Only log fatal messages by default (so apriori nothing)
|
2015-02-12 12:08:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-- Load default values unless they are set in the configuration file.
|
|
|
|
for param, default_value in pairs(default_conf) do
|
|
|
|
conf[param] = conf[param] or default_value
|
|
|
|
end
|
2015-02-02 00:05:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-02-12 12:08:52 +01:00
|
|
|
-- If you access the SSO by a local domain, change the portal domain to
|
|
|
|
-- avoid unwanted redirections.
|
|
|
|
if ngx.var.host == conf["local_portal_domain"] then
|
|
|
|
conf["original_portal_domain"] = conf["portal_domain"]
|
|
|
|
conf["portal_domain"] = conf["local_portal_domain"]
|
2015-02-02 00:05:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-02-12 12:08:52 +01:00
|
|
|
-- Build portal full URL out of the configuration values
|
|
|
|
conf.portal_url = conf["portal_scheme"].."://"..
|
|
|
|
conf["portal_domain"]..
|
|
|
|
conf["portal_path"]
|
2015-02-02 00:05:09 +01:00
|
|
|
|
|
|
|
|
2015-02-12 12:08:52 +01:00
|
|
|
-- Always skip the portal to avoid redirection looping.
|
2020-05-21 21:51:55 +02:00
|
|
|
table.insert(conf["permissions"]["core_skipped"]["uris"], conf["portal_domain"]..conf["portal_path"])
|
2015-02-02 00:05:09 +01:00
|
|
|
|
|
|
|
|
2015-02-12 12:08:52 +01:00
|
|
|
-- Set the prefered language from the `Accept-Language` header
|
|
|
|
conf.lang = ngx.req.get_headers()["Accept-Language"]
|
2015-02-02 00:05:09 +01:00
|
|
|
|
2015-02-12 12:08:52 +01:00
|
|
|
if conf.lang then
|
2015-02-15 13:03:01 +01:00
|
|
|
conf.lang = string.sub(conf.lang, 1, 2)
|
2015-02-12 12:08:52 +01:00
|
|
|
end
|
2015-02-02 00:05:09 +01:00
|
|
|
|
2015-02-12 12:08:52 +01:00
|
|
|
return conf
|
|
|
|
end
|