summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantinos Kallas <konstantinos.kallas@hotmail.com>2017-07-17 11:39:27 +0300
committerKonstantinos Kallas <konstantinos.kallas@hotmail.com>2017-07-17 11:39:27 +0300
commit8fe551cc68ac7ddce26c4f33e5db36fbd98a1590 (patch)
tree0f312d5d59968251f25cda52d809cd3342766275 /src
parentRemove httpdir from some function arguments as we now use the built in ejabbe... (diff)
Add a stub for the list-certificates command
Diffstat (limited to 'src')
-rw-r--r--src/ejabberd_acme.erl19
-rw-r--r--src/ejabberd_admin.erl20
2 files changed, 39 insertions, 0 deletions
diff --git a/src/ejabberd_acme.erl b/src/ejabberd_acme.erl
index 43d9eae2..25ae0ce1 100644
--- a/src/ejabberd_acme.erl
+++ b/src/ejabberd_acme.erl
@@ -2,8 +2,10 @@
-export([%% Ejabberdctl Commands
get_certificates/2,
+ list_certificates/1,
%% Command Options Validity
is_valid_account_opt/1,
+ is_valid_verbose_opt/1,
%% Misc
generate_key/0,
%% Debugging Scenarios
@@ -39,6 +41,23 @@ is_valid_account_opt("old-account") -> true;
is_valid_account_opt("new-account") -> true;
is_valid_account_opt(_) -> false.
+-spec is_valid_verbose_opt(string()) -> boolean().
+is_valid_verbose_opt("plain") -> true;
+is_valid_verbose_opt("verbose") -> true;
+is_valid_verbose_opt(_) -> false.
+
+%%
+%% List Certificates
+%%
+
+list_certificates(Verbose) ->
+ {ok, Certs} = read_certificates_persistent(),
+ case Verbose of
+ "plain" ->
+ [{Domain, certificate} || {Domain, _Cert} <- Certs];
+ "verbose" ->
+ Certs
+ end.
%%
%% Get Certificate
diff --git a/src/ejabberd_admin.erl b/src/ejabberd_admin.erl
index 2d255f1e..c3e7f598 100644
--- a/src/ejabberd_admin.erl
+++ b/src/ejabberd_admin.erl
@@ -46,6 +46,7 @@
import_file/1, import_dir/1,
%% Acme
get_certificate/1,
+ list_certificates/1,
%% Purge DB
delete_expired_messages/0, delete_old_messages/1,
%% Mnesia
@@ -251,6 +252,15 @@ get_commands_spec() ->
args_desc = ["Whether to create a new account or use the existing one"],
args = [{option, string}],
result = {certificate, string}},
+ #ejabberd_commands{name = list_certificates, tags = [acme],
+ desc = "Lists all curently handled certificates and their respective domains",
+ module = ?MODULE, function = list_certificates,
+ args_desc = ["Whether to print the whole certificate or just some metadata. Possible values: plain | verbose"],
+ args = [{option, string}],
+ result = {certificates, {list,
+ {certificate, {tuple,
+ [{domain, string},
+ {cert, string}]}}}}},
#ejabberd_commands{name = import_piefxis, tags = [mnesia],
desc = "Import users data from a PIEFXIS file (XEP-0227)",
@@ -564,6 +574,16 @@ get_certificate(UseNewAccount) ->
{invalid_option, String}
end.
+list_certificates(Verbose) ->
+ case ejabberd_acme:is_valid_verbose_opt(Verbose) of
+ true ->
+ ejabberd_acme:list_certificates(Verbose);
+ false ->
+ String = io_lib:format("Invalid verbose option: ~p", [Verbose]),
+ {invalid_option, String}
+ end.
+
+
%%%
%%% Purge DB
%%%