aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2012-05-09 01:02:00 +0200
committerKim Alvefur <zash@zash.se>2012-05-09 01:02:00 +0200
commit27840ebbf44e9018e705e7c692dc5541d56d6267 (patch)
tree0f9a78459426c25e144b0820e466d4ab52a2043c
parentc0475404c9658fd43fc0089496b48c96361135d1 (diff)
downloadprosody-27840ebbf44e9018e705e7c692dc5541d56d6267.tar.gz
prosody-27840ebbf44e9018e705e7c692dc5541d56d6267.zip
prosodyctl: Replace hack with lfs for checking if a file exists
-rwxr-xr-xprosodyctl24
1 files changed, 12 insertions, 12 deletions
diff --git a/prosodyctl b/prosodyctl
index 1c4d84cd..4511ec2c 100755
--- a/prosodyctl
+++ b/prosodyctl
@@ -614,14 +614,18 @@ function commands.unregister(arg)
end
local openssl = require "util.openssl";
+local lfs = require "lfs";
local cert_commands = {};
+local function ask_overwrite(filename)
+ return lfs.attributes(filename) and not show_yesno("Overwrite "..filename .. "?");
+end
+
function cert_commands.config(arg)
if #arg >= 1 and arg[1] ~= "--help" then
local conf_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".cnf";
- if os.execute("test -f "..conf_filename) == 0
- and not show_yesno("Overwrite "..conf_filename .. "?") then
+ if ask_overwrite(conf_filename) then
return nil, conf_filename;
end
local conf = openssl.config.new();
@@ -651,12 +655,10 @@ end
function cert_commands.key(arg)
if #arg >= 1 and arg[1] ~= "--help" then
local key_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".key";
- if os.execute("test -f "..key_filename) == 0 then
- if not show_yesno("Overwrite "..key_filename .. "?") then
- return nil, key_filename;
- end
- os.remove(key_filename); -- We chmod this file to not have write permissions
+ if ask_overwrite(key_filename) then
+ return nil, key_filename;
end
+ os.remove(key_filename); -- We chmod this file to not have write permissions
local key_size = tonumber(arg[2] or show_prompt("Choose key size (2048):") or 2048);
if openssl.genrsa{out=key_filename, key_size} then
os.execute(("chmod 400 '%s'"):format(key_filename));
@@ -672,8 +674,7 @@ end
function cert_commands.request(arg)
if #arg >= 1 and arg[1] ~= "--help" then
local req_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".req";
- if os.execute("test -f "..req_filename) == 0
- and not show_yesno("Overwrite "..req_filename .. "?") then
+ if ask_overwrite(req_filename) then
return nil, req_filename;
end
local _, key_filename = cert_commands.key({arg[1]});
@@ -691,9 +692,8 @@ end
function cert_commands.generate(arg)
if #arg >= 1 and arg[1] ~= "--help" then
local cert_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".cert";
- if os.execute("test -f "..cert_filename) == 0
- and not show_yesno("Overwrite "..cert_filename .. "?") then
- return nil, cert_filename;
+ if ask_overwrite(cert_filename) then
+ return nil, conf_filename;
end
local _, key_filename = cert_commands.key({arg[1]});
local _, conf_filename = cert_commands.config({arg[1]});