Software /
code /
prosody
Comparison
util/prosodyctl/cert.lua @ 11203:d10f59ac7f74
util.prosodyctl.cert: Fix for prompt functions having moved to util.human.io
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 09 Nov 2020 12:38:32 +0100 |
parent | 10871:e5dee71d0ebb |
child | 12104:29765ac7f72f |
comparison
equal
deleted
inserted
replaced
11202:58492b4b85ea | 11203:d10f59ac7f74 |
---|---|
1 local lfs = require "lfs"; | 1 local lfs = require "lfs"; |
2 | 2 |
3 local pctl = require "util.prosodyctl"; | 3 local pctl = require "util.prosodyctl"; |
4 local hi = require "util.human.io"; | |
4 local configmanager = require "core.configmanager"; | 5 local configmanager = require "core.configmanager"; |
5 | 6 |
6 local openssl; | 7 local openssl; |
7 | 8 |
8 local cert_commands = {}; | 9 local cert_commands = {}; |
10 -- If a file already exists, ask if the user wants to use it or replace it | 11 -- If a file already exists, ask if the user wants to use it or replace it |
11 -- Backups the old file if replaced | 12 -- Backups the old file if replaced |
12 local function use_existing(filename) | 13 local function use_existing(filename) |
13 local attrs = lfs.attributes(filename); | 14 local attrs = lfs.attributes(filename); |
14 if attrs then | 15 if attrs then |
15 if pctl.show_yesno(filename .. " exists, do you want to replace it? [y/n]") then | 16 if hi.show_yesno(filename .. " exists, do you want to replace it? [y/n]") then |
16 local backup = filename..".bkp~"..os.date("%FT%T", attrs.change); | 17 local backup = filename..".bkp~"..os.date("%FT%T", attrs.change); |
17 os.rename(filename, backup); | 18 os.rename(filename, backup); |
18 pctl.show_message("%s backed up to %s", filename, backup); | 19 pctl.show_message("%s backed up to %s", filename, backup); |
19 else | 20 else |
20 -- Use the existing file | 21 -- Use the existing file |
65 local tld = arg[1]:match"%.([a-z]+)$"; | 66 local tld = arg[1]:match"%.([a-z]+)$"; |
66 if tld and #tld == 2 and tld ~= "uk" then | 67 if tld and #tld == 2 and tld ~= "uk" then |
67 v = tld:upper(); | 68 v = tld:upper(); |
68 end | 69 end |
69 end | 70 end |
70 nv = pctl.show_prompt(("%s (%s):"):format(k, nv or v)); | 71 nv = hi.show_prompt(("%s (%s):"):format(k, nv or v)); |
71 nv = (not nv or nv == "") and v or nv; | 72 nv = (not nv or nv == "") and v or nv; |
72 if nv:find"[\192-\252][\128-\191]+" then | 73 if nv:find"[\192-\252][\128-\191]+" then |
73 conf.req.string_mask = "utf8only" | 74 conf.req.string_mask = "utf8only" |
74 end | 75 end |
75 conf.distinguished_name[k] = nv ~= "." and nv or nil; | 76 conf.distinguished_name[k] = nv ~= "." and nv or nil; |
97 local key_filename = cert_basedir .. "/" .. arg[1] .. ".key"; | 98 local key_filename = cert_basedir .. "/" .. arg[1] .. ".key"; |
98 if use_existing(key_filename) then | 99 if use_existing(key_filename) then |
99 return nil, key_filename; | 100 return nil, key_filename; |
100 end | 101 end |
101 os.remove(key_filename); -- This file, if it exists is unlikely to have write permissions | 102 os.remove(key_filename); -- This file, if it exists is unlikely to have write permissions |
102 local key_size = tonumber(arg[2] or pctl.show_prompt("Choose key size (2048):") or 2048); | 103 local key_size = tonumber(arg[2] or hi.show_prompt("Choose key size (2048):") or 2048); |
103 local old_umask = pposix.umask("0377"); | 104 local old_umask = pposix.umask("0377"); |
104 if openssl.genrsa{out=key_filename, key_size} then | 105 if openssl.genrsa{out=key_filename, key_size} then |
105 os.execute(("chmod 400 '%s'"):format(key_filename)); | 106 os.execute(("chmod 400 '%s'"):format(key_filename)); |
106 pctl.show_message("Key written to %s", key_filename); | 107 pctl.show_message("Key written to %s", key_filename); |
107 pposix.umask(old_umask); | 108 pposix.umask(old_umask); |