comparison mod_dnsupdate/mod_dnsupdate.lua @ 6221:52e239aa96af

mod_dnsupdate: Use modulemanager to check which of c2s and s2s are enabled This also makes it deny services that are disabled
author Kim Alvefur <zash@zash.se>
date Mon, 12 May 2025 12:16:25 +0200
parents b6e390a97c85
children 62adec551585
comparison
equal deleted inserted replaced
6220:b6e390a97c85 6221:52e239aa96af
1 module:set_global(); 1 module:set_global();
2 2
3 local config = require "core.configmanager"; 3 local config = require "core.configmanager";
4 local modulemanager = require "core.modulemanager";
4 local argparse = require "util.argparse"; 5 local argparse = require "util.argparse";
5 local dns = require"net.adns".resolver(); 6 local dns = require"net.adns".resolver();
6 local async = require "util.async"; 7 local async = require "util.async";
7 local set = require "util.set"; 8 local set = require "util.set";
8 local nameprep = require"util.encodings".stringprep.nameprep; 9 local nameprep = require"util.encodings".stringprep.nameprep;
9 local idna_to_ascii = require"util.encodings".idna.to_ascii; 10 local idna_to_ascii = require"util.encodings".idna.to_ascii;
10 11
11 local virtualhost_services = { "xmpp-client"; "xmpps-client"; "xmpp-server"; "xmpps-server" } 12 local services = { "xmpp-client"; "xmpps-client"; "xmpp-server"; "xmpps-server" }
12 local component_services = { "xmpp-server"; "xmpps-server" }
13 13
14 local function validate_dnsname_option(options, option_name, default) 14 local function validate_dnsname_option(options, option_name, default)
15 local host = options[option_name]; 15 local host = options[option_name];
16 if host == nil then return default end 16 if host == nil then return default end
17 local normalized = nameprep(host); 17 local normalized = nameprep(host);
54 local ihost = idna_to_ascii(vhost); 54 local ihost = idna_to_ascii(vhost);
55 if not ihost then 55 if not ihost then
56 module:log("error", "Host %q fails IDNA", vhost); 56 module:log("error", "Host %q fails IDNA", vhost);
57 return 1; 57 return 1;
58 end 58 end
59 local is_component = config.get(vhost, "component_module"); 59 if not config.get(vhost, "component_module") and not config.get(vhost, "defined") then
60 if not is_component and not config.get(vhost, "defined") then
61 module:log("error", "Host %q is not defined in the config", vhost); 60 module:log("error", "Host %q is not defined in the config", vhost);
62 return 1; 61 return 1;
63 end 62 end
64
65 local services = virtualhost_services;
66 if is_component then services = component_services; end
67 63
68 local domain = validate_dnsname_option(opts, "domain"); 64 local domain = validate_dnsname_option(opts, "domain");
69 if not domain then 65 if not domain then
70 module:log("error", "--domain is required"); 66 module:log("error", "--domain is required");
71 return 1; 67 return 1;
83 ["xmpp-client"] = module:get_option_array("c2s_ports", { 5222 }); 79 ["xmpp-client"] = module:get_option_array("c2s_ports", { 5222 });
84 ["xmpp-server"] = module:get_option_array("s2s_ports", { 5269 }); 80 ["xmpp-server"] = module:get_option_array("s2s_ports", { 5269 });
85 ["xmpps-client"] = module:get_option_array("c2s_direct_tls_ports", {}); 81 ["xmpps-client"] = module:get_option_array("c2s_direct_tls_ports", {});
86 ["xmpps-server"] = module:get_option_array("s2s_direct_tls_ports", {}); 82 ["xmpps-server"] = module:get_option_array("s2s_direct_tls_ports", {});
87 }; 83 };
84
85 local modules_enabled = modulemanager.get_modules_for_host(vhost);
86 print(modules_enabled)
87 if not modules_enabled:contains("c2s") then
88 configured_ports["xmpp-client"] = {};
89 configured_ports["xmpps-client"] = {};
90 end
91 if not modules_enabled:contains("s2s") then
92 configured_ports["xmpp-server"] = {};
93 configured_ports["xmpps-server"] = {};
94 end
88 95
89 if opts.multiplex then 96 if opts.multiplex then
90 for opt, ports in pairs(configured_ports) do 97 for opt, ports in pairs(configured_ports) do
91 ports:append(module:get_option_array(opt:sub(1, 5) == "xmpps" and "ssl_ports" or "ports", {})); 98 ports:append(module:get_option_array(opt:sub(1, 5) == "xmpps" and "ssl_ports" or "ports", {}));
92 end 99 end