view mod_persisthosts/mod_persisthosts.lua @ 4270:243f7b0dbf35

mod_http_oauth2: Reduce authorization code validity time to 2 minutes RFC 6749 states > A maximum authorization code lifetime of 10 minutes is RECOMMENDED. So 15 minutes was way too long. I was thinking 5 minutes at first but since this should generally be instant, I settled on 2 minutes as a large guesstimate on how slow it might be on slow links.
author Kim Alvefur <zash@zash.se>
date Sun, 22 Nov 2020 18:46:25 +0100
parents 366fadb5c6e5
children
line wrap: on
line source

-- mod_persisthosts
module:set_global();

local set = require"util.set";
local stat = require"lfs".attributes;
local resolve_relative_path = require"core.configmanager".resolve_relative_path;

local vhost_path = module:get_option_string("persisthosts_path", "conf.d");
local path_pattern = resolve_relative_path(prosody.paths.config, vhost_path) .. "/%s.cfg.lua";

local original = set.new();
original:include(prosody.hosts);

module:hook("host-activated", function(host)
	if not original:contains(host) then
		local path = path_pattern:format(host);
		if not stat(path) then
			local fh, err = io.open(path, "w");
			if fh then
				fh:write(("VirtualHost%q\n"):format(host));
				module:fire_event("host-persisted", { host = host, file = fh });
				fh:close();
				module:log("info", "Config file for host '%s' created", host);
			else
				module:log("error", "Could not open '%s' for writing: %s", path, err or "duno");
			end
		else
			module:log("debug", "File '%s' existed already", path);
		end
	else
		module:log("debug", "VirtualHost '%s' existed already", host);
	end
end);