prosodyctl
changeset 5532 d5cbcdcdb2f7
parent 5470 a62c1d4ec4ab
child 5534 522e99b898a0
child 5545 d22416f8a836
equal deleted inserted replaced
5531:483f795f6f99 5532:d5cbcdcdb2f7
   652 	return lfs.attributes(filename) and not show_yesno("Overwrite "..filename .. "?");
   652 	return lfs.attributes(filename) and not show_yesno("Overwrite "..filename .. "?");
   653 end
   653 end
   654 
   654 
   655 function cert_commands.config(arg)
   655 function cert_commands.config(arg)
   656 	if #arg >= 1 and arg[1] ~= "--help" then
   656 	if #arg >= 1 and arg[1] ~= "--help" then
   657 		local conf_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".cnf";
   657 		local conf_filename = (CFG_DATADIR or "./certs") .. "/" .. arg[1] .. ".cnf";
   658 		if ask_overwrite(conf_filename) then
   658 		if ask_overwrite(conf_filename) then
   659 			return nil, conf_filename;
   659 			return nil, conf_filename;
   660 		end
   660 		end
   661 		local conf = openssl.config.new();
   661 		local conf = openssl.config.new();
   662 		conf:from_prosody(hosts, config, arg);
   662 		conf:from_prosody(hosts, config, arg);
   685 	end
   685 	end
   686 end
   686 end
   687 
   687 
   688 function cert_commands.key(arg)
   688 function cert_commands.key(arg)
   689 	if #arg >= 1 and arg[1] ~= "--help" then
   689 	if #arg >= 1 and arg[1] ~= "--help" then
   690 		local key_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".key";
   690 		local key_filename = (CFG_DATADIR or "./certs") .. "/" .. arg[1] .. ".key";
   691 		if ask_overwrite(key_filename) then
   691 		if ask_overwrite(key_filename) then
   692 			return nil, key_filename;
   692 			return nil, key_filename;
   693 		end
   693 		end
   694 		os.remove(key_filename); -- This file, if it exists is unlikely to have write permissions
   694 		os.remove(key_filename); -- This file, if it exists is unlikely to have write permissions
   695 		local key_size = tonumber(arg[2] or show_prompt("Choose key size (2048):") or 2048);
   695 		local key_size = tonumber(arg[2] or show_prompt("Choose key size (2048):") or 2048);
   707 	end
   707 	end
   708 end
   708 end
   709 
   709 
   710 function cert_commands.request(arg)
   710 function cert_commands.request(arg)
   711 	if #arg >= 1 and arg[1] ~= "--help" then
   711 	if #arg >= 1 and arg[1] ~= "--help" then
   712 		local req_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".req";
   712 		local req_filename = (CFG_DATADIR or "./certs") .. "/" .. arg[1] .. ".req";
   713 		if ask_overwrite(req_filename) then
   713 		if ask_overwrite(req_filename) then
   714 			return nil, req_filename;
   714 			return nil, req_filename;
   715 		end
   715 		end
   716 		local _, key_filename = cert_commands.key({arg[1]});
   716 		local _, key_filename = cert_commands.key({arg[1]});
   717 		local _, conf_filename = cert_commands.config(arg);
   717 		local _, conf_filename = cert_commands.config(arg);
   725 	end
   725 	end
   726 end
   726 end
   727 
   727 
   728 function cert_commands.generate(arg)
   728 function cert_commands.generate(arg)
   729 	if #arg >= 1 and arg[1] ~= "--help" then
   729 	if #arg >= 1 and arg[1] ~= "--help" then
   730 		local cert_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".crt";
   730 		local cert_filename = (CFG_DATADIR or "./certs") .. "/" .. arg[1] .. ".crt";
   731 		if ask_overwrite(cert_filename) then
   731 		if ask_overwrite(cert_filename) then
   732 			return nil, cert_filename;
   732 			return nil, cert_filename;
   733 		end
   733 		end
   734 		local _, key_filename = cert_commands.key({arg[1]});
   734 		local _, key_filename = cert_commands.key({arg[1]});
   735 		local _, conf_filename = cert_commands.config(arg);
   735 		local _, conf_filename = cert_commands.config(arg);