Thu, 22 Jun 2023 21:29:31 +0100
main: Tweaks for prosody trunk (use unbound, fix HTTPS client)
0 | 1 | local LUA_WEB_APP_FRAMEWORK = os.getenv("LUA_WEB_APP_FRAMEWORK"); |
2 | ||
3 | if LUA_WEB_APP_FRAMEWORK then | |
4 | package.path = ("%s/?.lua;%s"):format(LUA_WEB_APP_FRAMEWORK, package.path); | |
5 | package.cpath = ("%s/?.so;%s"):format(LUA_WEB_APP_FRAMEWORK, package.cpath); | |
6 | end | |
7 | ||
14
afcc217db356
main: Tweaks for prosody trunk (use unbound, fix HTTPS client)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
8 | package.preload["net.adns"] = function () |
afcc217db356
main: Tweaks for prosody trunk (use unbound, fix HTTPS client)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
9 | return (require "net.unbound"); |
afcc217db356
main: Tweaks for prosody trunk (use unbound, fix HTTPS client)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
10 | end; |
0 | 11 | local ssl = require "ssl"; |
12 | local server = require "net.server_epoll"; | |
13 | local envload = require"util.envload"; | |
14 | local logger = require "util.logger"; | |
15 | ||
16 | package.loaded["net.server"] = server; -- COMPAT this module from Prosody can't be loaded outside of prosody | |
17 | ||
18 | local log = logger.init("main"); | |
19 | ||
20 | local config = { | |
21 | loglevel = "debug"; | |
22 | }; | |
23 | ||
24 | local logfile = io.stderr; | |
25 | ||
26 | local function log2file(source, level, message, ...) | |
27 | logfile:write(os.date("!%Y-%m-%dT%H:%M:%SZ"), "\t", source, "\t", level, "\t", message:format(...), "\n"); | |
28 | end | |
29 | ||
30 | local function init(config_file) | |
31 | if type(config_file) ~= "table" then | |
32 | setmetatable(config, { __index = { ENV = os.getenv } }); | |
33 | local ok, err = envload.envloadfile(config_file or "./config.lua", config); | |
34 | if ok then ok, err = pcall(ok); end | |
35 | setmetatable(config, nil); | |
36 | if not ok then log2file("config", "error", "Parse failed: %s", err or "Unknown error"); end | |
37 | else | |
38 | config = config_file; | |
39 | end | |
40 | ||
41 | local events = require"util.events".new(); | |
42 | ||
43 | -- Set up logging to stdout | |
44 | logger.reset(); | |
45 | local logsink = log2file; | |
46 | if config.logfile then | |
47 | if config.logfile == "*stdout" then | |
48 | logfile = io.stdout; | |
49 | elseif config.logfile == "*stderr" then | |
50 | logfile = io.stderr; | |
51 | else | |
52 | logfile = assert(io.open(config.logfile, "a")); | |
53 | end | |
54 | end | |
55 | if logfile then | |
56 | logfile:setvbuf("line"); | |
57 | for _, level in ipairs{"error", "warn", "info", "debug"} do | |
58 | logger.add_level_sink(level, logsink); | |
59 | if config.loglevel == level then break; end | |
60 | end | |
61 | end | |
62 | log("debug", "Logging ready"); | |
63 | ||
14
afcc217db356
main: Tweaks for prosody trunk (use unbound, fix HTTPS client)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
64 | -- Configure HTTP client |
afcc217db356
main: Tweaks for prosody trunk (use unbound, fix HTTPS client)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
65 | require "net.http".default.options.sslctx = server.tls_builder(".") |
afcc217db356
main: Tweaks for prosody trunk (use unbound, fix HTTPS client)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
66 | :apply({mode="client", protocol="sslv23", options="no_sslv2",capath="/etc/ssl/certs"}) |
afcc217db356
main: Tweaks for prosody trunk (use unbound, fix HTTPS client)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
67 | :build(); |
afcc217db356
main: Tweaks for prosody trunk (use unbound, fix HTTPS client)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
68 | |
0 | 69 | require "http".init(config, events); |
70 | ||
71 | -- Load optional extensions specified in the config | |
72 | for _, ext in ipairs(config.extensions or {}) do | |
73 | require("extensions."..ext).init(config, events); | |
74 | end | |
75 | end | |
76 | ||
77 | local function run() | |
78 | server.loop(); | |
79 | end | |
80 | ||
81 | if arg then | |
82 | init(...); | |
83 | run(); | |
84 | else | |
85 | return { | |
86 | init = init, | |
87 | run = run, | |
88 | }; | |
89 | end | |
90 | ||
91 |