Comparison

prosodyctl @ 8117:66d8f6b3c3ef

prosodyctl: Delay reporting of successful certificate imports until all done
author Kim Alvefur <zash@zash.se>
date Sat, 22 Apr 2017 19:11:26 +0200
parent 8111:3cbb311f8468
child 8118:f8c52010bd37
comparison
equal deleted inserted replaced
8116:76ac8b617402 8117:66d8f6b3c3ef
871 local owner, group; 871 local owner, group;
872 if pposix.getuid() == 0 then -- We need root to change ownership 872 if pposix.getuid() == 0 then -- We need root to change ownership
873 owner = config.get("*", "prosody_user") or "prosody"; 873 owner = config.get("*", "prosody_user") or "prosody";
874 group = config.get("*", "prosody_group") or owner; 874 group = config.get("*", "prosody_group") or owner;
875 end 875 end
876 local imported = {};
876 for _, host in ipairs(hostnames) do 877 for _, host in ipairs(hostnames) do
877 for _, dir in ipairs(arg) do 878 for _, dir in ipairs(arg) do
878 if lfs.attributes(dir .. "/" .. host .. "/fullchain.pem") 879 if lfs.attributes(dir .. "/" .. host .. "/fullchain.pem")
879 and lfs.attributes(dir .. "/" .. host .. "/privkey.pem") then 880 and lfs.attributes(dir .. "/" .. host .. "/privkey.pem") then
880 copy(dir .. "/" .. host .. "/fullchain.pem", cert_basedir .. "/" .. host .. ".crt", nil, owner, group); 881 copy(dir .. "/" .. host .. "/fullchain.pem", cert_basedir .. "/" .. host .. ".crt", nil, owner, group);
881 copy(dir .. "/" .. host .. "/privkey.pem", cert_basedir .. "/" .. host .. ".key", "0377", owner, group); 882 copy(dir .. "/" .. host .. "/privkey.pem", cert_basedir .. "/" .. host .. ".key", "0377", owner, group);
882 show_message("Imported certificate and key for "..host); 883 table.insert(imported, host);
883 elseif lfs.attributes(dir .. "/" .. host .. ".crt") 884 elseif lfs.attributes(dir .. "/" .. host .. ".crt")
884 and lfs.attributes(dir .. "/" .. host .. ".key") then 885 and lfs.attributes(dir .. "/" .. host .. ".key") then
885 copy(dir .. "/" .. host .. ".crt", cert_basedir .. "/" .. host .. ".crt", nil, owner, group); 886 copy(dir .. "/" .. host .. ".crt", cert_basedir .. "/" .. host .. ".crt", nil, owner, group);
886 copy(dir .. "/" .. host .. ".key", cert_basedir .. "/" .. host .. ".key", "0377", owner, group); 887 copy(dir .. "/" .. host .. ".key", cert_basedir .. "/" .. host .. ".key", "0377", owner, group);
887 show_message("Imported certificate and key for "..host); 888 table.insert(imported, host);
888 else 889 else
889 show_warning("No certificate for host "..host.." found :("); 890 show_warning("No certificate for host "..host.." found :(");
890 end 891 end
891 -- TODO Additional checks 892 -- TODO Additional checks
892 -- Certificate names matches the hostname 893 -- Certificate names matches the hostname
893 -- Private key matches public key in certificate 894 -- Private key matches public key in certificate
894 end 895 end
896 end
897 if imported[1] then
898 show_message("Imported certificate and key for hosts "..table.concat(imported, ", "));
895 end 899 end
896 end 900 end
897 901
898 function commands.cert(arg) 902 function commands.cert(arg)
899 if #arg >= 1 and arg[1] ~= "--help" then 903 if #arg >= 1 and arg[1] ~= "--help" then