Comparison

util/prosodyctl/cert.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 12786:5d4957c8a972
comparison
equal deleted inserted replaced
12974:ba409c67353b 12975:d10957394a3c
1 local lfs = require "lfs"; 1 local lfs = require "lfs";
2 2
3 local pctl = require "util.prosodyctl"; 3 local pctl = require "prosody.util.prosodyctl";
4 local hi = require "util.human.io"; 4 local hi = require "prosody.util.human.io";
5 local configmanager = require "core.configmanager"; 5 local configmanager = require "prosody.core.configmanager";
6 6
7 local openssl; 7 local openssl;
8 8
9 local cert_commands = {}; 9 local cert_commands = {};
10 10
22 return true; 22 return true;
23 end 23 end
24 end 24 end
25 end 25 end
26 26
27 local have_pposix, pposix = pcall(require, "util.pposix"); 27 local have_pposix, pposix = pcall(require, "prosody.util.pposix");
28 local cert_basedir = prosody.paths.data == "." and "./certs" or prosody.paths.data; 28 local cert_basedir = prosody.paths.data == "." and "./certs" or prosody.paths.data;
29 if have_pposix and pposix.getuid() == 0 then 29 if have_pposix and pposix.getuid() == 0 then
30 -- FIXME should be enough to check if this directory is writable 30 -- FIXME should be enough to check if this directory is writable
31 local cert_dir = configmanager.get("*", "certificates") or "certs"; 31 local cert_dir = configmanager.get("*", "certificates") or "certs";
32 cert_basedir = configmanager.resolve_relative_path(prosody.paths.config, cert_dir); 32 cert_basedir = configmanager.resolve_relative_path(prosody.paths.config, cert_dir);
217 local owner, group; 217 local owner, group;
218 if pposix.getuid() == 0 then -- We need root to change ownership 218 if pposix.getuid() == 0 then -- We need root to change ownership
219 owner = configmanager.get("*", "prosody_user") or "prosody"; 219 owner = configmanager.get("*", "prosody_user") or "prosody";
220 group = configmanager.get("*", "prosody_group") or owner; 220 group = configmanager.get("*", "prosody_group") or owner;
221 end 221 end
222 local cm = require "core.certmanager"; 222 local cm = require "prosody.core.certmanager";
223 local files_by_name = {} 223 local files_by_name = {}
224 for _, dir in ipairs(arg) do 224 for _, dir in ipairs(arg) do
225 cm.index_certs(dir, files_by_name); 225 cm.index_certs(dir, files_by_name);
226 end 226 end
227 local imported = {}; 227 local imported = {};
269 end 269 end
270 end 270 end
271 271
272 local function cert(arg) 272 local function cert(arg)
273 if #arg >= 1 and arg[1] ~= "--help" then 273 if #arg >= 1 and arg[1] ~= "--help" then
274 openssl = require "util.openssl"; 274 openssl = require "prosody.util.openssl";
275 lfs = require "lfs"; 275 lfs = require "lfs";
276 local cert_dir_attrs = lfs.attributes(cert_basedir); 276 local cert_dir_attrs = lfs.attributes(cert_basedir);
277 if not cert_dir_attrs then 277 if not cert_dir_attrs then
278 pctl.show_warning("The directory %s does not exist", cert_basedir); 278 pctl.show_warning("The directory %s does not exist", cert_basedir);
279 return 1; -- TODO Should we create it? 279 return 1; -- TODO Should we create it?
301 return 1; 301 return 1;
302 end 302 end
303 end 303 end
304 return cert_commands[subcmd](arg); 304 return cert_commands[subcmd](arg);
305 elseif subcmd == "check" then 305 elseif subcmd == "check" then
306 return require "util.prosodyctl.check".check({"certs"}); 306 return require "prosody.util.prosodyctl.check".check({"certs"});
307 end 307 end
308 end 308 end
309 pctl.show_usage("cert config|request|generate|key|import", "Helpers for generating X.509 certificates and keys.") 309 pctl.show_usage("cert config|request|generate|key|import", "Helpers for generating X.509 certificates and keys.")
310 for _, cmd in pairs(cert_commands) do 310 for _, cmd in pairs(cert_commands) do
311 print() 311 print()