Software / code / prosody
Comparison
util/prosodyctl/check.lua @ 12975:d10957394a3c
util: Prefix module imports with prosody namespace
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 17 Mar 2023 16:23:16 +0100 |
| parent | 12899:09b101a3b3e1 |
| child | 13122:45458ecaacae |
comparison
equal
deleted
inserted
replaced
| 12974:ba409c67353b | 12975:d10957394a3c |
|---|---|
| 1 local configmanager = require "core.configmanager"; | 1 local configmanager = require "prosody.core.configmanager"; |
| 2 local show_usage = require "util.prosodyctl".show_usage; | 2 local show_usage = require "prosody.util.prosodyctl".show_usage; |
| 3 local show_warning = require "util.prosodyctl".show_warning; | 3 local show_warning = require "prosody.util.prosodyctl".show_warning; |
| 4 local is_prosody_running = require "util.prosodyctl".isrunning; | 4 local is_prosody_running = require "prosody.util.prosodyctl".isrunning; |
| 5 local parse_args = require "util.argparse".parse; | 5 local parse_args = require "prosody.util.argparse".parse; |
| 6 local dependencies = require "util.dependencies"; | 6 local dependencies = require "prosody.util.dependencies"; |
| 7 local socket = require "socket"; | 7 local socket = require "socket"; |
| 8 local socket_url = require "socket.url"; | 8 local socket_url = require "socket.url"; |
| 9 local jid_split = require "util.jid".prepped_split; | 9 local jid_split = require "prosody.util.jid".prepped_split; |
| 10 local modulemanager = require "core.modulemanager"; | 10 local modulemanager = require "prosody.core.modulemanager"; |
| 11 local async = require "util.async"; | 11 local async = require "prosody.util.async"; |
| 12 local httputil = require "util.http"; | 12 local httputil = require "prosody.util.http"; |
| 13 | 13 |
| 14 local function check_ojn(check_type, target_host) | 14 local function check_ojn(check_type, target_host) |
| 15 local http = require "net.http"; -- .new({}); | 15 local http = require "prosody.net.http"; -- .new({}); |
| 16 local json = require "util.json"; | 16 local json = require "prosody.util.json"; |
| 17 | 17 |
| 18 local response, err = async.wait_for(http.request( | 18 local response, err = async.wait_for(http.request( |
| 19 ("https://observe.jabber.network/api/v1/check/%s"):format(httputil.urlencode(check_type)), | 19 ("https://observe.jabber.network/api/v1/check/%s"):format(httputil.urlencode(check_type)), |
| 20 { | 20 { |
| 21 method="POST", | 21 method="POST", |
| 39 local success = decoded_body["success"]; | 39 local success = decoded_body["success"]; |
| 40 return success == true, nil; | 40 return success == true, nil; |
| 41 end | 41 end |
| 42 | 42 |
| 43 local function check_probe(base_url, probe_module, target) | 43 local function check_probe(base_url, probe_module, target) |
| 44 local http = require "net.http"; -- .new({}); | 44 local http = require "prosody.net.http"; -- .new({}); |
| 45 local params = httputil.formencode({ module = probe_module; target = target }) | 45 local params = httputil.formencode({ module = probe_module; target = target }) |
| 46 local response, err = async.wait_for(http.request(base_url .. "?" .. params)); | 46 local response, err = async.wait_for(http.request(base_url .. "?" .. params)); |
| 47 | 47 |
| 48 if not response then return false, err; end | 48 if not response then return false, err; end |
| 49 | 49 |
| 60 end | 60 end |
| 61 return false, "Probe endpoint did not return a success status"; | 61 return false, "Probe endpoint did not return a success status"; |
| 62 end | 62 end |
| 63 | 63 |
| 64 local function check_turn_service(turn_service, ping_service) | 64 local function check_turn_service(turn_service, ping_service) |
| 65 local ip = require "util.ip"; | 65 local ip = require "prosody.util.ip"; |
| 66 local stun = require "net.stun"; | 66 local stun = require "prosody.net.stun"; |
| 67 | 67 |
| 68 -- Create UDP socket for communication with the server | 68 -- Create UDP socket for communication with the server |
| 69 local sock = assert(require "socket".udp()); | 69 local sock = assert(require "socket".udp()); |
| 70 sock:setsockname("*", 0); | 70 sock:setsockname("*", 0); |
| 71 sock:setpeername(turn_service.host, turn_service.port); | 71 sock:setpeername(turn_service.host, turn_service.port); |
| 302 return 1; | 302 return 1; |
| 303 elseif opts_err == "param-not-found" then | 303 elseif opts_err == "param-not-found" then |
| 304 print("Error: Unknown parameter: "..opts_info); | 304 print("Error: Unknown parameter: "..opts_info); |
| 305 return 1; | 305 return 1; |
| 306 end | 306 end |
| 307 local array = require "util.array"; | 307 local array = require "prosody.util.array"; |
| 308 local set = require "util.set"; | 308 local set = require "prosody.util.set"; |
| 309 local it = require "util.iterators"; | 309 local it = require "prosody.util.iterators"; |
| 310 local ok = true; | 310 local ok = true; |
| 311 local function disabled_hosts(host, conf) return host ~= "*" and conf.enabled ~= false; end | 311 local function disabled_hosts(host, conf) return host ~= "*" and conf.enabled ~= false; end |
| 312 local function enabled_hosts() return it.filter(disabled_hosts, pairs(configmanager.getconfig())); end | 312 local function enabled_hosts() return it.filter(disabled_hosts, pairs(configmanager.getconfig())); end |
| 313 if not (what == nil or what == "disabled" or what == "config" or what == "dns" or what == "certs" or what == "connectivity" or what == "turn") then | 313 if not (what == nil or what == "disabled" or what == "config" or what == "dns" or what == "certs" or what == "connectivity" or what == "turn") then |
| 314 show_warning("Don't know how to check '%s'. Try one of 'config', 'dns', 'certs', 'disabled', 'turn' or 'connectivity'.", what); | 314 show_warning("Don't know how to check '%s'. Try one of 'config', 'dns', 'certs', 'disabled', 'turn' or 'connectivity'.", what); |
| 704 end | 704 end |
| 705 | 705 |
| 706 print("Done.\n"); | 706 print("Done.\n"); |
| 707 end | 707 end |
| 708 if not what or what == "dns" then | 708 if not what or what == "dns" then |
| 709 local dns = require "net.dns"; | 709 local dns = require "prosody.net.dns"; |
| 710 pcall(function () | 710 pcall(function () |
| 711 local unbound = require"net.unbound"; | 711 local unbound = require"prosody.net.unbound"; |
| 712 dns = unbound.dns; | 712 dns = unbound.dns; |
| 713 end) | 713 end) |
| 714 local idna = require "util.encodings".idna; | 714 local idna = require "prosody.util.encodings".idna; |
| 715 local ip = require "util.ip"; | 715 local ip = require "prosody.util.ip"; |
| 716 local c2s_ports = set.new(configmanager.get("*", "c2s_ports") or {5222}); | 716 local c2s_ports = set.new(configmanager.get("*", "c2s_ports") or {5222}); |
| 717 local s2s_ports = set.new(configmanager.get("*", "s2s_ports") or {5269}); | 717 local s2s_ports = set.new(configmanager.get("*", "s2s_ports") or {5269}); |
| 718 local c2s_tls_ports = set.new(configmanager.get("*", "c2s_direct_tls_ports") or {}); | 718 local c2s_tls_ports = set.new(configmanager.get("*", "c2s_direct_tls_ports") or {}); |
| 719 local s2s_tls_ports = set.new(configmanager.get("*", "s2s_direct_tls_ports") or {}); | 719 local s2s_tls_ports = set.new(configmanager.get("*", "s2s_direct_tls_ports") or {}); |
| 720 | 720 |
| 767 end | 767 end |
| 768 end | 768 end |
| 769 end | 769 end |
| 770 end | 770 end |
| 771 | 771 |
| 772 local local_addresses = require"util.net".local_addresses() or {}; | 772 local local_addresses = require"prosody.util.net".local_addresses() or {}; |
| 773 | 773 |
| 774 for addr in it.values(local_addresses) do | 774 for addr in it.values(local_addresses) do |
| 775 if not ip.new_ip(addr).private then | 775 if not ip.new_ip(addr).private then |
| 776 external_addresses:add(addr); | 776 external_addresses:add(addr); |
| 777 else | 777 else |
| 1070 end | 1070 end |
| 1071 end | 1071 end |
| 1072 if not what or what == "certs" then | 1072 if not what or what == "certs" then |
| 1073 local cert_ok; | 1073 local cert_ok; |
| 1074 print"Checking certificates..." | 1074 print"Checking certificates..." |
| 1075 local x509_verify_identity = require"util.x509".verify_identity; | 1075 local x509_verify_identity = require"prosody.util.x509".verify_identity; |
| 1076 local create_context = require "core.certmanager".create_context; | 1076 local create_context = require "prosody.core.certmanager".create_context; |
| 1077 local ssl = dependencies.softreq"ssl"; | 1077 local ssl = dependencies.softreq"ssl"; |
| 1078 -- local datetime_parse = require"util.datetime".parse_x509; | 1078 -- local datetime_parse = require"util.datetime".parse_x509; |
| 1079 local load_cert = ssl and ssl.loadcertificate; | 1079 local load_cert = ssl and ssl.loadcertificate; |
| 1080 -- or ssl.cert_from_pem | 1080 -- or ssl.cert_from_pem |
| 1081 if not ssl then | 1081 if not ssl then |