Software / code / prosody
Comparison
prosodyctl @ 4872:b2059452fb55
prosodyctl: Improve help messages for cert commands
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 13 May 2012 15:02:38 +0200 |
| parent | 4827:fefbfd76d2d3 |
| child | 4878:80ab7c50608d |
comparison
equal
deleted
inserted
replaced
| 4871:b2d177f2febc | 4872:b2059452fb55 |
|---|---|
| 647 conf_file:close(); | 647 conf_file:close(); |
| 648 print(""); | 648 print(""); |
| 649 show_message("Config written to " .. conf_filename); | 649 show_message("Config written to " .. conf_filename); |
| 650 return nil, conf_filename; | 650 return nil, conf_filename; |
| 651 else | 651 else |
| 652 show_usage("cert config HOSTNAME", "builds a config for OpenSSL") | 652 show_usage("cert config HOSTNAME [HOSTNAME+]", "Builds a certificate config file covering the supplied hostname(s)") |
| 653 end | 653 end |
| 654 end | 654 end |
| 655 | 655 |
| 656 function cert_commands.key(arg) | 656 function cert_commands.key(arg) |
| 657 if #arg >= 1 and arg[1] ~= "--help" then | 657 if #arg >= 1 and arg[1] ~= "--help" then |
| 666 show_message("Key written to ".. key_filename); | 666 show_message("Key written to ".. key_filename); |
| 667 return nil, key_filename; | 667 return nil, key_filename; |
| 668 end | 668 end |
| 669 show_message("There was a problem, see OpenSSL output"); | 669 show_message("There was a problem, see OpenSSL output"); |
| 670 else | 670 else |
| 671 show_usage("cert key HOSTNAME <bits>", "Generates a RSA key") | 671 show_usage("cert key HOSTNAME <bits>", "Generates a RSA key named HOSTNAME.key\n " |
| 672 .."Promps for a key size if none given") | |
| 672 end | 673 end |
| 673 end | 674 end |
| 674 | 675 |
| 675 function cert_commands.request(arg) | 676 function cert_commands.request(arg) |
| 676 if #arg >= 1 and arg[1] ~= "--help" then | 677 if #arg >= 1 and arg[1] ~= "--help" then |
| 677 local req_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".req"; | 678 local req_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".req"; |
| 678 if ask_overwrite(req_filename) then | 679 if ask_overwrite(req_filename) then |
| 679 return nil, req_filename; | 680 return nil, req_filename; |
| 680 end | 681 end |
| 681 local _, key_filename = cert_commands.key({arg[1]}); | 682 local _, key_filename = cert_commands.key({arg[1]}); |
| 682 local _, conf_filename = cert_commands.config({arg[1]}); | 683 local _, conf_filename = cert_commands.config(arg); |
| 683 if openssl.req{new=true, key=key_filename, utf8=true, config=conf_filename, out=req_filename} then | 684 if openssl.req{new=true, key=key_filename, utf8=true, config=conf_filename, out=req_filename} then |
| 684 show_message("Certificate request written to ".. req_filename); | 685 show_message("Certificate request written to ".. req_filename); |
| 685 else | 686 else |
| 686 show_message("There was a problem, see OpenSSL output"); | 687 show_message("There was a problem, see OpenSSL output"); |
| 687 end | 688 end |
| 688 else | 689 else |
| 689 show_usage("cert request HOSTNAME", "Generates a certificate request") | 690 show_usage("cert request HOSTNAME [HOSTNAME+]", "Generates a certificate request for the supplied hostname(s)") |
| 690 end | 691 end |
| 691 end | 692 end |
| 692 | 693 |
| 693 function cert_commands.generate(arg) | 694 function cert_commands.generate(arg) |
| 694 if #arg >= 1 and arg[1] ~= "--help" then | 695 if #arg >= 1 and arg[1] ~= "--help" then |
| 695 local cert_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".cert"; | 696 local cert_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".cert"; |
| 696 if ask_overwrite(cert_filename) then | 697 if ask_overwrite(cert_filename) then |
| 697 return nil, conf_filename; | 698 return nil, conf_filename; |
| 698 end | 699 end |
| 699 local _, key_filename = cert_commands.key({arg[1]}); | 700 local _, key_filename = cert_commands.key({arg[1]}); |
| 700 local _, conf_filename = cert_commands.config({arg[1]}); | 701 local _, conf_filename = cert_commands.config(arg); |
| 701 local ret; | 702 local ret; |
| 702 if key_filename and conf_filename and cert_filename | 703 if key_filename and conf_filename and cert_filename |
| 703 and openssl.req{new=true, x509=true, nodes=true, key=key_filename, | 704 and openssl.req{new=true, x509=true, nodes=true, key=key_filename, |
| 704 days=365, sha1=true, utf8=true, config=conf_filename, out=cert_filename} then | 705 days=365, sha1=true, utf8=true, config=conf_filename, out=cert_filename} then |
| 705 show_message("Certificate written to ".. cert_filename); | 706 show_message("Certificate written to ".. cert_filename); |
| 706 else | 707 else |
| 707 show_message("There was a problem, see OpenSSL output"); | 708 show_message("There was a problem, see OpenSSL output"); |
| 708 end | 709 end |
| 709 else | 710 else |
| 710 show_usage("cert generate HOSTNAME", "Generates a self-signed certificate") | 711 show_usage("cert generate HOSTNAME [HOSTNAME+]", "Generates a self-signed certificate for the current hostname(s)") |
| 711 end | 712 end |
| 712 end | 713 end |
| 713 | 714 |
| 714 function commands.cert(arg) | 715 function commands.cert(arg) |
| 715 if #arg >= 1 and arg[1] ~= "--help" then | 716 if #arg >= 1 and arg[1] ~= "--help" then |
| 716 local subcmd = table.remove(arg, 1); | 717 local subcmd = table.remove(arg, 1); |
| 717 if type(cert_commands[subcmd]) == "function" then | 718 if type(cert_commands[subcmd]) == "function" then |
| 718 if not hosts[arg[1]] then | 719 if not arg[1] then |
| 720 show_message"You need to supply at least one hostname" | |
| 721 arg = { "--help" }; | |
| 722 end | |
| 723 if arg[1] ~= "--help" and not hosts[arg[1]] then | |
| 719 show_message(error_messages["no-such-host"]); | 724 show_message(error_messages["no-such-host"]); |
| 720 return | 725 return |
| 721 end | 726 end |
| 722 return cert_commands[subcmd](arg); | 727 return cert_commands[subcmd](arg); |
| 723 end | 728 end |
| 724 end | 729 end |
| 725 show_usage("cert config|request|generate|key", "Helpers for X.509 certificates.") | 730 show_usage("cert config|request|generate|key", "Helpers for generating X.509 certificates and keys.") |
| 726 end | 731 end |
| 727 | 732 |
| 728 --------------------- | 733 --------------------- |
| 729 | 734 |
| 730 if command and command:match("^mod_") then -- Is a command in a module | 735 if command and command:match("^mod_") then -- Is a command in a module |