• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

processone / ejabberd / 747

27 Jun 2024 01:43PM UTC coverage: 32.123% (+0.8%) from 31.276%
747

push

github

badlop
Set version to 24.06

14119 of 43953 relevant lines covered (32.12%)

614.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

21.89
/src/mod_http_api.erl
1
%%%----------------------------------------------------------------------
2
%%% File    : mod_http_api.erl
3
%%% Author  : Christophe romain <christophe.romain@process-one.net>
4
%%% Purpose : Implements REST API for ejabberd using JSON data
5
%%% Created : 15 Sep 2014 by Christophe Romain <christophe.romain@process-one.net>
6
%%%
7
%%%
8
%%% ejabberd, Copyright (C) 2002-2024   ProcessOne
9
%%%
10
%%% This program is free software; you can redistribute it and/or
11
%%% modify it under the terms of the GNU General Public License as
12
%%% published by the Free Software Foundation; either version 2 of the
13
%%% License, or (at your option) any later version.
14
%%%
15
%%% This program is distributed in the hope that it will be useful,
16
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
17
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18
%%% General Public License for more details.
19
%%%
20
%%% You should have received a copy of the GNU General Public License along
21
%%% with this program; if not, write to the Free Software Foundation, Inc.,
22
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
%%%
24
%%%----------------------------------------------------------------------
25

26
-module(mod_http_api).
27

28
-author('cromain@process-one.net').
29

30
-behaviour(gen_mod).
31

32
-export([start/2, stop/1, reload/3, process/2, depends/2,
33
         format_arg/2,
34
         mod_options/1, mod_doc/0]).
35

36
-include_lib("xmpp/include/xmpp.hrl").
37
-include("logger.hrl").
38
-include("ejabberd_http.hrl").
39
-include("ejabberd_stacktrace.hrl").
40
-include("translate.hrl").
41

42
-define(DEFAULT_API_VERSION, 1000000).
43

44
-define(CT_PLAIN,
45
        {<<"Content-Type">>, <<"text/plain">>}).
46

47
-define(CT_XML,
48
        {<<"Content-Type">>, <<"text/xml; charset=utf-8">>}).
49

50
-define(CT_JSON,
51
        {<<"Content-Type">>, <<"application/json">>}).
52

53
-define(AC_ALLOW_ORIGIN,
54
        {<<"Access-Control-Allow-Origin">>, <<"*">>}).
55

56
-define(AC_ALLOW_METHODS,
57
        {<<"Access-Control-Allow-Methods">>,
58
         <<"GET, POST, OPTIONS">>}).
59

60
-define(AC_ALLOW_HEADERS,
61
        {<<"Access-Control-Allow-Headers">>,
62
         <<"Content-Type, Authorization, X-Admin">>}).
63

64
-define(AC_MAX_AGE,
65
        {<<"Access-Control-Max-Age">>, <<"86400">>}).
66

67
-define(OPTIONS_HEADER,
68
        [?CT_PLAIN, ?AC_ALLOW_ORIGIN, ?AC_ALLOW_METHODS,
69
         ?AC_ALLOW_HEADERS, ?AC_MAX_AGE]).
70

71
-define(HEADER(CType),
72
        [CType, ?AC_ALLOW_ORIGIN, ?AC_ALLOW_HEADERS]).
73

74
%% -------------------
75
%% Module control
76
%% -------------------
77

78
start(_Host, _Opts) ->
79
    ok.
×
80

81
stop(_Host) ->
82
    ok.
×
83

84
reload(_Host, _NewOpts, _OldOpts) ->
85
    ok.
×
86

87
depends(_Host, _Opts) ->
88
    [].
×
89

90
%% ----------
91
%% basic auth
92
%% ----------
93

94
extract_auth(#request{auth = HTTPAuth, ip = {IP, _}, opts = Opts}) ->
95
    Info = case HTTPAuth of
6✔
96
               {SJID, Pass} ->
97
                   try jid:decode(SJID) of
×
98
                       #jid{luser = User, lserver = Server} ->
99
                           case ejabberd_auth:check_password(User, <<"">>, Server, Pass) of
×
100
                               true ->
101
                                   #{usr => {User, Server, <<"">>}, caller_server => Server};
×
102
                               false ->
103
                                   {error, invalid_auth}
×
104
                           end
105
                   catch _:{bad_jid, _} ->
106
                       {error, invalid_auth}
×
107
                   end;
108
               {oauth, Token, _} ->
109
                   case ejabberd_oauth:check_token(Token) of
×
110
                       {ok, {U, S}, Scope} ->
111
                           #{usr => {U, S, <<"">>}, oauth_scope => Scope, caller_server => S};
×
112
                       {false, Reason} ->
113
                           {error, Reason}
×
114
                   end;
115
               invalid ->
116
                   {error, invalid_auth};
×
117
               _ ->
118
                   #{}
6✔
119
           end,
120
    case Info of
6✔
121
        Map when is_map(Map) ->
122
            Tag = proplists:get_value(tag, Opts, <<>>),
6✔
123
            Map#{caller_module => ?MODULE, ip => IP, tag => Tag};
6✔
124
        _ ->
125
            ?DEBUG("Invalid auth data: ~p", [Info]),
×
126
            Info
×
127
    end.
128

129
%% ------------------
130
%% command processing
131
%% ------------------
132

133
%process(Call, Request) ->
134
%    ?DEBUG("~p~n~p", [Call, Request]), ok;
135
process(_, #request{method = 'POST', data = <<>>}) ->
136
    ?DEBUG("Bad Request: no data", []),
×
137
    badrequest_response(<<"Missing POST data">>);
×
138
process([Call | _], #request{method = 'POST', data = Data, ip = IPPort} = Req) ->
139
    Version = get_api_version(Req),
6✔
140
    try
6✔
141
        Args = extract_args(Data),
6✔
142
        log(Call, Args, IPPort),
6✔
143
        perform_call(Call, Args, Req, Version)
6✔
144
    catch
145
        %% TODO We need to refactor to remove redundant error return formatting
146
        throw:{error, unknown_command} ->
147
            json_format({404, 44, <<"Command not found.">>});
×
148
        _:{error,{_,invalid_json}} = _Err ->
149
            ?DEBUG("Bad Request: ~p", [_Err]),
×
150
            badrequest_response(<<"Invalid JSON input">>);
×
151
        ?EX_RULE(_Class, _Error, Stack) ->
152
            StackTrace = ?EX_STACK(Stack),
×
153
            ?DEBUG("Bad Request: ~p ~p", [_Error, StackTrace]),
×
154
            badrequest_response()
×
155
    end;
156
process([Call | _], #request{method = 'GET', q = Data, ip = {IP, _}} = Req) ->
157
    Version = get_api_version(Req),
×
158
    try
×
159
        Args = case Data of
×
160
                   [{nokey, <<>>}] -> [];
×
161
                   _ -> Data
×
162
               end,
163
        log(Call, Args, IP),
×
164
        perform_call(Call, Args, Req, Version)
×
165
    catch
166
        %% TODO We need to refactor to remove redundant error return formatting
167
        throw:{error, unknown_command} ->
168
            json_format({404, 44, <<"Command not found.">>});
×
169
        ?EX_RULE(_, _Error, Stack) ->
170
            StackTrace = ?EX_STACK(Stack),
×
171
            ?DEBUG("Bad Request: ~p ~p", [_Error, StackTrace]),
×
172
            badrequest_response()
×
173
    end;
174
process([_Call], #request{method = 'OPTIONS', data = <<>>}) ->
175
    {200, ?OPTIONS_HEADER, []};
×
176
process(_, #request{method = 'OPTIONS'}) ->
177
    {400, ?OPTIONS_HEADER, []};
×
178
process(_Path, Request) ->
179
    ?DEBUG("Bad Request: no handler ~p", [Request]),
×
180
    json_error(400, 40, <<"Missing command name.">>).
×
181

182
perform_call(Command, Args, Req, Version) ->
183
    case catch binary_to_existing_atom(Command, utf8) of
6✔
184
        Call when is_atom(Call) ->
185
            case extract_auth(Req) of
6✔
186
                {error, expired} -> invalid_token_response();
×
187
                {error, not_found} -> invalid_token_response();
×
188
                {error, invalid_auth} -> unauthorized_response();
×
189
                Auth when is_map(Auth) ->
190
                    Result = handle(Call, Auth, Args, Version),
6✔
191
                    json_format(Result)
6✔
192
            end;
193
        _ ->
194
            json_error(404, 40, <<"Endpoint not found.">>)
×
195
    end.
196

197
%% Be tolerant to make API more easily usable from command-line pipe.
198
extract_args(<<"\n">>) -> [];
×
199
extract_args(Data) ->
200
    Maps = misc:json_decode(Data),
6✔
201
    maps:to_list(Maps).
6✔
202

203
% get API version N from last "vN" element in URL path
204
get_api_version(#request{path = Path}) ->
205
    get_api_version(lists:reverse(Path));
6✔
206
get_api_version([<<"v", String/binary>> | Tail]) ->
207
    case catch binary_to_integer(String) of
×
208
        N when is_integer(N) ->
209
            N;
×
210
        _ ->
211
            get_api_version(Tail)
×
212
    end;
213
get_api_version([_Head | Tail]) ->
214
    get_api_version(Tail);
12✔
215
get_api_version([]) ->
216
    ?DEFAULT_API_VERSION.
6✔
217

218
%% ----------------
219
%% command handlers
220
%% ----------------
221

222
%% TODO Check accept types of request before decided format of reply.
223

224
% generic ejabberd command handler
225
handle(Call, Auth, Args, Version) when is_atom(Call), is_list(Args) ->
226
    Args2 = [{misc:binary_to_atom(Key), Value} || {Key, Value} <- Args],
6✔
227
    try handle2(Call, Auth, Args2, Version)
6✔
228
    catch throw:not_found ->
229
            {404, <<"not_found">>};
×
230
          throw:{not_found, Why} when is_atom(Why) ->
231
            {404, misc:atom_to_binary(Why)};
×
232
          throw:{not_found, Msg} ->
233
            {404, iolist_to_binary(Msg)};
×
234
          throw:not_allowed ->
235
            {401, <<"not_allowed">>};
×
236
          throw:{not_allowed, Why} when is_atom(Why) ->
237
            {401, misc:atom_to_binary(Why)};
×
238
          throw:{not_allowed, Msg} ->
239
            {401, iolist_to_binary(Msg)};
×
240
          throw:{error, account_unprivileged} ->
241
            {403, 31, <<"Command need to be run with admin privilege.">>};
×
242
          throw:{error, access_rules_unauthorized} ->
243
            {403, 32, <<"AccessRules: Account does not have the right to perform the operation.">>};
×
244
          throw:{invalid_parameter, Msg} ->
245
            {400, iolist_to_binary(Msg)};
×
246
          throw:{error, Why} when is_atom(Why) ->
247
            {400, misc:atom_to_binary(Why)};
×
248
          throw:{error, Msg} ->
249
            {400, iolist_to_binary(Msg)};
×
250
          throw:Error when is_atom(Error) ->
251
            {400, misc:atom_to_binary(Error)};
×
252
          throw:Msg when is_list(Msg); is_binary(Msg) ->
253
            {400, iolist_to_binary(Msg)};
×
254
          ?EX_RULE(Class, Error, Stack) ->
255
            StackTrace = ?EX_STACK(Stack),
×
256
            ?ERROR_MSG("REST API Error: "
×
257
                       "~ts(~p) -> ~p:~p ~p",
258
                       [Call, hide_sensitive_args(Args),
259
                        Class, Error, StackTrace]),
×
260
            {500, <<"internal_error">>}
×
261
    end.
262

263
handle2(Call, Auth, Args, Version) when is_atom(Call), is_list(Args) ->
264
    {ArgsF, ArgsR, _ResultF} = ejabberd_commands:get_command_format(Call, Auth, Version),
6✔
265
    ArgsFormatted = format_args(Call, rename_old_args(Args, ArgsR), ArgsF),
6✔
266
    case ejabberd_commands:execute_command2(Call, ArgsFormatted, Auth, Version) of
6✔
267
        {error, Error} ->
268
            throw(Error);
×
269
        Res ->
270
            format_command_result(Call, Auth, Res, Version)
6✔
271
    end.
272

273
rename_old_args(Args, []) ->
274
    Args;
6✔
275
rename_old_args(Args, [{OldName, NewName} | ArgsR]) ->
276
    Args2 = case lists:keytake(OldName, 1, Args) of
×
277
        {value, {OldName, Value}, ArgsTail} ->
278
            [{NewName, Value} | ArgsTail];
×
279
        false ->
280
            Args
×
281
    end,
282
    rename_old_args(Args2, ArgsR).
×
283

284
get_elem_delete(Call, A, L, F) ->
285
    case proplists:get_all_values(A, L) of
24✔
286
      [Value] -> {Value, proplists:delete(A, L)};
24✔
287
      [_, _ | _] ->
288
          ?INFO_MSG("Command ~ts call rejected, it has duplicate attribute ~w",
×
289
                    [Call, A]),
×
290
          throw({invalid_parameter,
×
291
                 io_lib:format("Request have duplicate argument: ~w", [A])});
292
      [] ->
293
          case F of
×
294
              {list, _} ->
295
                  {[], L};
×
296
              _ ->
297
                  ?INFO_MSG("Command ~ts call rejected, missing attribute ~w",
×
298
                            [Call, A]),
×
299
                  throw({invalid_parameter,
×
300
                         io_lib:format("Request have missing argument: ~w", [A])})
301
          end
302
    end.
303

304
format_args(Call, Args, ArgsFormat) ->
305
    {ArgsRemaining, R} = lists:foldl(fun ({ArgName,
6✔
306
                                           ArgFormat},
307
                                          {Args1, Res}) ->
308
                                             {ArgValue, Args2} =
24✔
309
                                                 get_elem_delete(Call, ArgName,
310
                                                                 Args1, ArgFormat),
311
                                             Formatted = format_arg(ArgValue,
24✔
312
                                                                    ArgFormat),
313
                                             {Args2, Res ++ [Formatted]}
24✔
314
                                     end,
315
                                     {Args, []}, ArgsFormat),
316
    case ArgsRemaining of
6✔
317
      [] -> R;
6✔
318
      L when is_list(L) ->
319
          ExtraArgs = [N || {N, _} <- L],
×
320
          ?INFO_MSG("Command ~ts call rejected, it has unknown arguments ~w",
×
321
              [Call, ExtraArgs]),
×
322
          throw({invalid_parameter,
×
323
                 io_lib:format("Request have unknown arguments: ~w", [ExtraArgs])})
324
    end.
325

326
format_arg({Elements},
327
           {list, {_ElementDefName, {tuple, [{_Tuple1N, Tuple1S}, {_Tuple2N, Tuple2S}]} = Tuple}})
328
    when is_list(Elements) andalso
329
         (Tuple1S == binary orelse Tuple1S == string) ->
330
    lists:map(fun({F1, F2}) ->
×
331
                      {format_arg(F1, Tuple1S), format_arg(F2, Tuple2S)};
×
332
                 ({Val}) when is_list(Val) ->
333
                      format_arg({Val}, Tuple)
×
334
              end, Elements);
335
format_arg(Elements,
336
           {list, {_ElementDefName, {list, _} = ElementDefFormat}})
337
    when is_list(Elements) ->
338
    [{format_arg(Element, ElementDefFormat)}
×
339
     || Element <- Elements];
×
340
format_arg(Elements,
341
           {list, {_ElementDefName, ElementDefFormat}})
342
    when is_list(Elements) ->
343
    [format_arg(Element, ElementDefFormat)
×
344
     || Element <- Elements];
×
345
format_arg({[{Name, Value}]},
346
           {tuple, [{_Tuple1N, Tuple1S}, {_Tuple2N, Tuple2S}]})
347
  when Tuple1S == binary;
348
       Tuple1S == string ->
349
    {format_arg(Name, Tuple1S), format_arg(Value, Tuple2S)};
×
350
format_arg({Elements},
351
           {tuple, ElementsDef})
352
    when is_list(Elements) ->
353
    F = lists:map(fun({TElName, TElDef}) ->
×
354
                          case lists:keyfind(atom_to_binary(TElName, latin1), 1, Elements) of
×
355
                              {_, Value} ->
356
                                  format_arg(Value, TElDef);
×
357
                              _ when TElDef == binary; TElDef == string ->
358
                                  <<"">>;
×
359
                              _ ->
360
                                  ?ERROR_MSG("Missing field ~p in tuple ~p", [TElName, Elements]),
×
361
                                  throw({invalid_parameter,
×
362
                                         io_lib:format("Missing field ~w in tuple ~w", [TElName, Elements])})
363
                          end
364
                  end, ElementsDef),
365
    list_to_tuple(F);
×
366
format_arg(Elements, {list, ElementsDef})
367
    when is_list(Elements) and is_atom(ElementsDef) ->
368
    [format_arg(Element, ElementsDef)
×
369
     || Element <- Elements];
×
370
format_arg(Arg, integer) when is_integer(Arg) -> Arg;
×
371
format_arg(Arg, binary) when is_list(Arg) -> process_unicode_codepoints(Arg);
×
372
format_arg(Arg, binary) when is_binary(Arg) -> Arg;
24✔
373
format_arg(Arg, string) when is_list(Arg) -> Arg;
×
374
format_arg(Arg, string) when is_binary(Arg) -> binary_to_list(Arg);
×
375
format_arg(undefined, binary) -> <<>>;
×
376
format_arg(undefined, string) -> "";
×
377
format_arg(Arg, Format) ->
378
    ?ERROR_MSG("Don't know how to format Arg ~p for format ~p", [Arg, Format]),
×
379
    throw({invalid_parameter,
×
380
           io_lib:format("Arg ~w is not in format ~w",
381
                         [Arg, Format])}).
382

383
process_unicode_codepoints(Str) ->
384
    iolist_to_binary(lists:map(fun(X) when X > 255 -> unicode:characters_to_binary([X]);
×
385
                                  (Y) -> Y
×
386
                               end, Str)).
387

388
%% ----------------
389
%% internal helpers
390
%% ----------------
391

392
format_command_result(Cmd, Auth, Result, Version) ->
393
    {_, _, ResultFormat} = ejabberd_commands:get_command_format(Cmd, Auth, Version),
6✔
394
    case {ResultFormat, Result} of
6✔
395
        {{_, rescode}, V} when V == true; V == ok ->
396
            {200, 0};
6✔
397
        {{_, rescode}, _} ->
398
            {200, 1};
×
399
        {_, {error, ErrorAtom, Code, Msg}} ->
400
            format_error_result(ErrorAtom, Code, Msg);
×
401
        {{_, restuple}, {V, Text}} when V == true; V == ok ->
402
            {200, iolist_to_binary(Text)};
×
403
        {{_, restuple}, {ErrorAtom, Msg}} ->
404
            format_error_result(ErrorAtom, 0, Msg);
×
405
        {{_, {list, _}}, _V} ->
406
            {_, L} = format_result(Result, ResultFormat),
×
407
            {200, L};
×
408
        {{_, {tuple, _}}, _V} ->
409
            {_, T} = format_result(Result, ResultFormat),
×
410
            {200, T};
×
411
        _ ->
412
            OtherResult1 = format_result(Result, ResultFormat),
×
413
            OtherResult2 = case Version of
×
414
                               0 ->
415
                                   {[OtherResult1]};
×
416
                               _ ->
417
                                   {_, Other3} = OtherResult1,
×
418
                                   Other3
×
419
                           end,
420
            {200, OtherResult2}
×
421
    end.
422

423
format_result(Atom, {Name, atom}) ->
424
    {misc:atom_to_binary(Name), misc:atom_to_binary(Atom)};
×
425

426
format_result(Int, {Name, integer}) ->
427
    {misc:atom_to_binary(Name), Int};
×
428

429
format_result([String | _] = StringList, {Name, string}) when is_list(String) ->
430
    Binarized = iolist_to_binary(string:join(StringList, "\n")),
×
431
    {misc:atom_to_binary(Name), Binarized};
×
432

433
format_result(String, {Name, string}) ->
434
    {misc:atom_to_binary(Name), iolist_to_binary(String)};
×
435

436
format_result(Code, {Name, rescode}) ->
437
    {misc:atom_to_binary(Name), Code == true orelse Code == ok};
×
438

439
format_result({Code, Text}, {Name, restuple}) ->
440
    {misc:atom_to_binary(Name),
×
441
     {[{<<"res">>, Code == true orelse Code == ok},
×
442
       {<<"text">>, iolist_to_binary(Text)}]}};
443

444
format_result(Code, {Name, restuple}) ->
445
    {misc:atom_to_binary(Name),
×
446
     {[{<<"res">>, Code == true orelse Code == ok},
×
447
       {<<"text">>, <<"">>}]}};
448

449
format_result(Els, {Name, {list, {_, {tuple, [{_, atom}, _]}} = Fmt}}) ->
450
    {misc:atom_to_binary(Name), {[format_result(El, Fmt) || El <- Els]}};
×
451

452
format_result(Els, {Name, {list, {_, {tuple, [{name, string}, {value, _}]}} = Fmt}}) ->
453
    {misc:atom_to_binary(Name), {[format_result(El, Fmt) || El <- Els]}};
×
454

455
format_result(Els, {Name, {list, Def}}) ->
456
    {misc:atom_to_binary(Name), [element(2, format_result(El, Def)) || El <- Els]};
×
457

458
format_result(Tuple, {_Name, {tuple, [{_, atom}, ValFmt]}}) ->
459
    {Name2, Val} = Tuple,
×
460
    {_, Val2} = format_result(Val, ValFmt),
×
461
    {misc:atom_to_binary(Name2), Val2};
×
462

463
format_result(Tuple, {_Name, {tuple, [{name, string}, {value, _} = ValFmt]}}) ->
464
    {Name2, Val} = Tuple,
×
465
    {_, Val2} = format_result(Val, ValFmt),
×
466
    {iolist_to_binary(Name2), Val2};
×
467

468
format_result(Tuple, {Name, {tuple, Def}}) ->
469
    Els = lists:zip(tuple_to_list(Tuple), Def),
×
470
    {misc:atom_to_binary(Name), {[format_result(El, ElDef) || {El, ElDef} <- Els]}};
×
471

472
format_result(404, {_Name, _}) ->
473
    "not_found".
×
474

475

476
format_error_result(conflict, Code, Msg) ->
477
    {409, Code, iolist_to_binary(Msg)};
×
478
format_error_result(not_exists, Code, Msg) ->
479
    {404, Code, iolist_to_binary(Msg)};
×
480
format_error_result(_ErrorAtom, Code, Msg) ->
481
    {500, Code, iolist_to_binary(Msg)}.
×
482

483
unauthorized_response() ->
484
    json_error(401, 10, <<"You are not authorized to call this command.">>).
×
485

486
invalid_token_response() ->
487
    json_error(401, 10, <<"Oauth Token is invalid or expired.">>).
×
488

489
%% outofscope_response() ->
490
%%     json_error(401, 11, <<"Token does not grant usage to command required scope.">>).
491

492
badrequest_response() ->
493
    badrequest_response(<<"400 Bad Request">>).
×
494
badrequest_response(Body) ->
495
    json_response(400, misc:json_encode(Body)).
×
496

497
json_format({Code, Result}) ->
498
    json_response(Code, misc:json_encode(Result));
6✔
499
json_format({HTMLCode, JSONErrorCode, Message}) ->
500
    json_error(HTMLCode, JSONErrorCode, Message).
×
501

502
json_response(Code, Body) when is_integer(Code) ->
503
    {Code, ?HEADER(?CT_JSON), Body}.
6✔
504

505
%% HTTPCode, JSONCode = integers
506
%% message is binary
507
json_error(HTTPCode, JSONCode, Message) ->
508
    {HTTPCode, ?HEADER(?CT_JSON),
×
509
     misc:json_encode(#{<<"status">> => <<"error">>,
510
                    <<"code">> =>  JSONCode,
511
                    <<"message">> => Message})
512
    }.
513

514
log(Call, Args, {Addr, Port}) ->
515
    AddrS = misc:ip_to_list({Addr, Port}),
6✔
516
    ?INFO_MSG("API call ~ts ~p from ~ts:~p", [Call, hide_sensitive_args(Args), AddrS, Port]);
6✔
517
log(Call, Args, IP) ->
518
    ?INFO_MSG("API call ~ts ~p (~p)", [Call, hide_sensitive_args(Args), IP]).
×
519

520
hide_sensitive_args(Args=[_H|_T]) ->
521
    lists:map( fun({<<"password">>, Password}) -> {<<"password">>, ejabberd_config:may_hide_data(Password)};
6✔
522
         ({<<"newpass">>,NewPassword}) -> {<<"newpass">>, ejabberd_config:may_hide_data(NewPassword)};
×
523
         (E) -> E end,
24✔
524
         Args);
525
hide_sensitive_args(NonListArgs) ->
526
    NonListArgs.
×
527

528
mod_options(_) ->
529
    [].
×
530

531
mod_doc() ->
532
    #{desc =>
×
533
          [?T("This module provides a ReST interface to call "
534
              "_`../../developer/ejabberd-api/index.md|ejabberd API`_ "
535
              "commands using JSON data."), "",
536
           ?T("To use this module, in addition to adding it to the 'modules' "
537
              "section, you must also enable it in 'listen' -> 'ejabberd_http' -> "
538
              "_`listen-options.md#request_handlers|request_handlers`_."), "",
539
           ?T("To use a specific API version N, when defining the URL path "
540
              "in the request_handlers, add a 'vN'. "
541
              "For example: '/api/v2: mod_http_api'"), "",
542
           ?T("To run a command, send a POST request to the corresponding "
543
              "URL: 'http://localhost:5280/api/<command_name>'")],
544
     example =>
545
         ["listen:",
546
          "  -",
547
          "    port: 5280",
548
          "    module: ejabberd_http",
549
          "    request_handlers:",
550
          "      /api: mod_http_api",
551
          "",
552
          "modules:",
553
          "  mod_http_api: {}"]}.
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc