Software / code / prosody
Comparison
plugins/mod_admin_shell.lua @ 13819:3ee95eb17045 13.0
mod_admin_shell: Add debug:cert_index() command
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 03 Apr 2025 16:54:02 +0100 |
| parent | 13796:c8e534b4f2e2 |
| child | 13823:e78e79f1b5f5 |
comparison
equal
deleted
inserted
replaced
| 13818:8a7dbb291b02 | 13819:3ee95eb17045 |
|---|---|
| 2399 }); | 2399 }); |
| 2400 end | 2400 end |
| 2401 return true, ("%d runners pending"):format(c); | 2401 return true, ("%d runners pending"):format(c); |
| 2402 end | 2402 end |
| 2403 | 2403 |
| 2404 describe_command [[debug:cert_index([path]) - Show Prosody's view of a directory of certs]] | |
| 2405 function def_env.debug:cert_index(path) | |
| 2406 local print = self.session.print; | |
| 2407 local cm = require "core.certmanager"; | |
| 2408 | |
| 2409 path = path or module:get_option("certificates", "certs"); | |
| 2410 | |
| 2411 local sink = logger.add_simple_sink(function (source, level, message) | |
| 2412 if source == "certmanager" then | |
| 2413 self.session.print(source, level, message); | |
| 2414 end | |
| 2415 end); | |
| 2416 | |
| 2417 local index = {}; | |
| 2418 cm.index_certs(path, index) | |
| 2419 | |
| 2420 if not logger.remove_sink(sink) then | |
| 2421 module:log("warn", "Unable to remove log sink"); | |
| 2422 end | |
| 2423 | |
| 2424 local c, max_domain = 0, 8; | |
| 2425 for domain in pairs(index) do | |
| 2426 if #domain > max_domain then | |
| 2427 max_domain = #domain; | |
| 2428 end | |
| 2429 end | |
| 2430 | |
| 2431 print(""); | |
| 2432 | |
| 2433 local row = format_table({ | |
| 2434 { title = "Domain", width = max_domain }; | |
| 2435 { title = "Certificate", width = "100%" }; | |
| 2436 { title = "Service", width = 5 }; | |
| 2437 }, self.session.width); | |
| 2438 print(row()); | |
| 2439 | |
| 2440 for domain, certs in it.sorted_pairs(index) do | |
| 2441 for cert_file, services in it.sorted_pairs(certs) do | |
| 2442 for service in it.sorted_pairs(services) do | |
| 2443 c = c + 1; | |
| 2444 print(row({ domain, cert_file, service })); | |
| 2445 end | |
| 2446 end | |
| 2447 end | |
| 2448 | |
| 2449 print(""); | |
| 2450 | |
| 2451 return true, ("Showing %d certificates in %s"):format(c, path); | |
| 2452 end | |
| 2453 | |
| 2404 def_env.stats = new_section("Commands to show internal statistics"); | 2454 def_env.stats = new_section("Commands to show internal statistics"); |
| 2405 | 2455 |
| 2406 local short_units = { | 2456 local short_units = { |
| 2407 seconds = "s", | 2457 seconds = "s", |
| 2408 bytes = "B", | 2458 bytes = "B", |