[enh] Handle local domain (yunohost.local by default) as a main domain replacement

This commit is contained in:
kload 2014-09-13 23:21:21 +02:00
parent f32f278105
commit 2e1117beff

View file

@ -41,7 +41,8 @@ end
default_conf = { default_conf = {
portal_scheme = "https", portal_scheme = "https",
portal_path = "/ssowat", portal_path = "/ssowat",
domains = { conf["portal_domain"] }, local_portal_domain = "yunohost.local",
domains = { conf["portal_domain"], "yunohost.local" },
session_timeout = 60 * 60 * 24, -- one day session_timeout = 60 * 60 * 24, -- one day
session_max_timeout = 60 * 60 * 24 * 7, -- one week session_max_timeout = 60 * 60 * 24 * 7, -- one week
login_arg = "sso_login", login_arg = "sso_login",
@ -57,6 +58,11 @@ for param, default_value in pairs(default_conf) do
conf[param] = conf[param] or default_value conf[param] = conf[param] or default_value
end end
if ngx.var.host == conf["local_portal_domain"] then
conf["original_portal_domain"] = conf["portal_domain"]
conf["portal_domain"] = conf["local_portal_domain"]
end
local portal_url = conf["portal_scheme"].."://".. local portal_url = conf["portal_scheme"].."://"..
conf["portal_domain"].. conf["portal_domain"]..
conf["portal_path"] conf["portal_path"]
@ -198,6 +204,9 @@ function has_access (user, url)
return true return true
end end
for u, _ in pairs(conf["users"][user]) do for u, _ in pairs(conf["users"][user]) do
if ngx.var.host == conf["local_portal_domain"] then
u = string.gsub(u, conf["original_portal_domain"], conf["local_portal_domain"])
end
if string.starts(url, string.sub(u, 1, -2)) then return true end if string.starts(url, string.sub(u, 1, -2)) then return true end
end end
return false return false
@ -411,6 +420,9 @@ function get_data_for(view)
} }
for url, name in pairs(conf["users"][user]) do for url, name in pairs(conf["users"][user]) do
if ngx.var.host == conf["local_portal_domain"] then
url = string.gsub(url, conf["original_portal_domain"], conf["local_portal_domain"])
end
table.insert(data["app"], { url = url, name = name }) table.insert(data["app"], { url = url, name = name })
end end
end end