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

processone / ejabberd / 1212

18 Nov 2025 12:37PM UTC coverage: 33.784% (+0.003%) from 33.781%
1212

push

github

badlop
mod_conversejs: Improve link to conversejs in WebAdmin (#4495)

Until now, the WebAdmin menu included a link to the first request handler
with mod_conversejs that the admin configured in ejabberd.yml
That link included the authentication credentials hashed as URI arguments
if using HTTPS. Then process/2 extracted those arguments and passed them
as autologin options to Converse.

From now, mod_conversejs automatically adds a request_handler nested in
webadmin subpath. The webadmin menu links to that converse URI; this allows
to access the HTTP auth credentials, no need to explicitly pass them.
process/2 extracts this HTTP auth and passes autologin options to Converse.
Now scram password storage is supported too.

This minimum configuration allows WebAdmin to access Converse:

listen:
  -
    port: 5443
    module: ejabberd_http
    tls: true
    request_handlers:
      /admin: ejabberd_web_admin
      /ws: ejabberd_http_ws
modules:
  mod_conversejs:
    conversejs_resources: "/home/conversejs/12.0.0/dist"

0 of 12 new or added lines in 1 file covered. (0.0%)

11290 existing lines in 174 files now uncovered.

15515 of 45924 relevant lines covered (33.78%)

1277.8 hits per line

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

31.75
/src/mod_stats.erl
1
%%%----------------------------------------------------------------------
2
%%% File    : mod_stats.erl
3
%%% Author  : Alexey Shchepin <alexey@process-one.net>
4
%%% Purpose : Basic statistics.
5
%%% Created : 11 Jan 2003 by Alexey Shchepin <alexey@process-one.net>
6
%%%
7
%%%
8
%%% ejabberd, Copyright (C) 2002-2025   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_stats).
27

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

30
-protocol({xep, 39, '0.6.0', '0.1.0', "complete", ""}).
31

32
-behaviour(gen_mod).
33

34
-export([start/2, stop/1, reload/3, process_iq/1,
35
         mod_options/1, depends/2, mod_doc/0]).
36

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

41
start(_Host, _Opts) ->
42
    {ok, [{iq_handler, ejabberd_local, ?NS_STATS, process_iq}]}.
144✔
43

44
stop(_Host) ->
45
    ok.
144✔
46

47
reload(_Host, _NewOpts, _OldOpts) ->
48
    ok.
×
49

50
depends(_Host, _Opts) ->
51
    [].
180✔
52

53
process_iq(#iq{type = set, lang = Lang} = IQ) ->
54
    Txt = ?T("Value 'set' of 'type' attribute is not allowed"),
×
55
    xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
×
56
process_iq(#iq{type = get, to = To, lang = Lang,
57
               sub_els = [#stats{} = Stats]} = IQ) ->
UNCOV
58
    Node = str:tokens(Stats#stats.node, <<"/">>),
10✔
UNCOV
59
    Names = [Name || #stat{name = Name} <- Stats#stats.list],
10✔
UNCOV
60
    case get_local_stats(To#jid.server, Node, Names, Lang) of
10✔
61
        {result, List} ->
UNCOV
62
            xmpp:make_iq_result(IQ, Stats#stats{list = List});
10✔
63
        {error, Error} ->
64
            xmpp:make_error(IQ, Error)
×
65
    end.
66

67
-define(STAT(Name), #stat{name = Name}).
68

69
get_local_stats(_Server, [], [], _Lang) ->
UNCOV
70
    {result,
2✔
71
     [?STAT(<<"users/online">>), ?STAT(<<"users/total">>),
72
      ?STAT(<<"users/all-hosts/online">>),
73
      ?STAT(<<"users/all-hosts/total">>)]};
74
get_local_stats(Server, [], Names, _Lang) ->
UNCOV
75
    {result,
8✔
UNCOV
76
     lists:map(fun (Name) -> get_local_stat(Server, [], Name)
8✔
77
               end,
78
               Names)};
79
get_local_stats(_Server, [<<"running nodes">>, _],
80
                [], _Lang) ->
81
    {result,
×
82
     [?STAT(<<"time/uptime">>), ?STAT(<<"time/cputime">>),
83
      ?STAT(<<"users/online">>),
84
      ?STAT(<<"transactions/committed">>),
85
      ?STAT(<<"transactions/aborted">>),
86
      ?STAT(<<"transactions/restarted">>),
87
      ?STAT(<<"transactions/logged">>)]};
88
get_local_stats(_Server, [<<"running nodes">>, ENode],
89
                Names, Lang) ->
90
    case search_running_node(ENode) of
×
91
      false ->
92
            Txt = ?T("No running node found"),
×
93
            {error, xmpp:err_item_not_found(Txt, Lang)};
×
94
      Node ->
95
          {result,
×
96
           lists:map(fun (Name) -> get_node_stat(Node, Name) end,
×
97
                     Names)}
98
    end;
99
get_local_stats(_Server, _, _, Lang) ->
100
    Txt = ?T("No statistics found for this item"),
×
101
    {error, xmpp:err_feature_not_implemented(Txt, Lang)}.
×
102

103
-define(STATVAL(Val, Unit), #stat{name = Name, units = Unit, value = Val}).
104

105
-define(STATERR(Code, Desc),
106
        #stat{name = Name,
107
              error = #stat_error{code = Code, reason = Desc}}).
108

109
get_local_stat(Server, [], Name)
110
    when Name == <<"users/online">> ->
UNCOV
111
    case catch ejabberd_sm:get_vh_session_list(Server) of
2✔
112
      {'EXIT', _Reason} ->
113
          ?STATERR(500, <<"Internal Server Error">>);
×
114
      Users ->
UNCOV
115
          ?STATVAL((integer_to_binary(length(Users))),
2✔
116
                   <<"users">>)
117
    end;
118
get_local_stat(Server, [], Name)
119
    when Name == <<"users/total">> ->
UNCOV
120
    case catch
2✔
121
           ejabberd_auth:count_users(Server)
122
        of
123
      {'EXIT', _Reason} ->
124
          ?STATERR(500, <<"Internal Server Error">>);
×
125
      NUsers ->
UNCOV
126
          ?STATVAL((integer_to_binary(NUsers)),
2✔
127
                   <<"users">>)
128
    end;
129
get_local_stat(_Server, [], Name)
130
    when Name == <<"users/all-hosts/online">> ->
UNCOV
131
    Users = ejabberd_sm:connected_users_number(),
2✔
UNCOV
132
    ?STATVAL((integer_to_binary(Users)), <<"users">>);
2✔
133
get_local_stat(_Server, [], Name)
134
    when Name == <<"users/all-hosts/total">> ->
UNCOV
135
    NumUsers = lists:foldl(fun (Host, Total) ->
2✔
136
                                   ejabberd_auth:count_users(Host)
UNCOV
137
                                     + Total
20✔
138
                           end,
139
                           0, ejabberd_option:hosts()),
UNCOV
140
    ?STATVAL((integer_to_binary(NumUsers)),
2✔
141
             <<"users">>);
142
get_local_stat(_Server, _, Name) ->
143
    ?STATERR(404, <<"Not Found">>).
×
144

145
get_node_stat(Node, Name)
146
    when Name == <<"time/uptime">> ->
147
    case catch ejabberd_cluster:call(Node, erlang, statistics,
×
148
                        [wall_clock])
149
        of
150
      {badrpc, _Reason} ->
151
          ?STATERR(500, <<"Internal Server Error">>);
×
152
      CPUTime ->
153
            ?STATVAL(str:format("~.3f",        [element(1, CPUTime) / 1000]),
×
154
                   <<"seconds">>)
155
    end;
156
get_node_stat(Node, Name)
157
    when Name == <<"time/cputime">> ->
158
    case catch ejabberd_cluster:call(Node, erlang, statistics, [runtime])
×
159
        of
160
      {badrpc, _Reason} ->
161
          ?STATERR(500, <<"Internal Server Error">>);
×
162
      RunTime ->
163
          ?STATVAL(str:format("~.3f", [element(1, RunTime) / 1000]),
×
164
                   <<"seconds">>)
165
    end;
166
get_node_stat(Node, Name)
167
    when Name == <<"users/online">> ->
168
    case catch ejabberd_cluster:call(Node, ejabberd_sm,
×
169
                        dirty_get_my_sessions_list, [])
170
        of
171
      {badrpc, _Reason} ->
172
          ?STATERR(500, <<"Internal Server Error">>);
×
173
      Users ->
174
          ?STATVAL((integer_to_binary(length(Users))),
×
175
                   <<"users">>)
176
    end;
177
get_node_stat(Node, Name)
178
    when Name == <<"transactions/committed">> ->
179
    case catch ejabberd_cluster:call(Node, mnesia, system_info,
×
180
                        [transaction_commits])
181
        of
182
      {badrpc, _Reason} ->
183
          ?STATERR(500, <<"Internal Server Error">>);
×
184
      Transactions ->
185
          ?STATVAL((integer_to_binary(Transactions)),
×
186
                   <<"transactions">>)
187
    end;
188
get_node_stat(Node, Name)
189
    when Name == <<"transactions/aborted">> ->
190
    case catch ejabberd_cluster:call(Node, mnesia, system_info,
×
191
                        [transaction_failures])
192
        of
193
      {badrpc, _Reason} ->
194
          ?STATERR(500, <<"Internal Server Error">>);
×
195
      Transactions ->
196
          ?STATVAL((integer_to_binary(Transactions)),
×
197
                   <<"transactions">>)
198
    end;
199
get_node_stat(Node, Name)
200
    when Name == <<"transactions/restarted">> ->
201
    case catch ejabberd_cluster:call(Node, mnesia, system_info,
×
202
                        [transaction_restarts])
203
        of
204
      {badrpc, _Reason} ->
205
          ?STATERR(500, <<"Internal Server Error">>);
×
206
      Transactions ->
207
          ?STATVAL((integer_to_binary(Transactions)),
×
208
                   <<"transactions">>)
209
    end;
210
get_node_stat(Node, Name)
211
    when Name == <<"transactions/logged">> ->
212
    case catch ejabberd_cluster:call(Node, mnesia, system_info,
×
213
                        [transaction_log_writes])
214
        of
215
      {badrpc, _Reason} ->
216
          ?STATERR(500, <<"Internal Server Error">>);
×
217
      Transactions ->
218
          ?STATVAL((integer_to_binary(Transactions)),
×
219
                   <<"transactions">>)
220
    end;
221
get_node_stat(_, Name) ->
222
    ?STATERR(404, <<"Not Found">>).
×
223

224
search_running_node(SNode) ->
225
    search_running_node(SNode,
×
226
                        mnesia:system_info(running_db_nodes)).
227

228
search_running_node(_, []) -> false;
×
229
search_running_node(SNode, [Node | Nodes]) ->
230
    case iolist_to_binary(atom_to_list(Node)) of
×
231
      SNode -> Node;
×
232
      _ -> search_running_node(SNode, Nodes)
×
233
    end.
234

235
mod_options(_Host) ->
236
    [].
180✔
237

238
mod_doc() ->
239
    #{desc =>
×
240
          [?T("This module adds support for "
241
              "https://xmpp.org/extensions/xep-0039.html"
242
              "[XEP-0039: Statistics Gathering]. This protocol "
243
              "allows you to retrieve the following statistics "
244
              "from your ejabberd server:"), "",
245
           ?T("- Total number of registered users on the current "
246
              "virtual host (users/total)."), "",
247
           ?T("- Total number of registered users on all virtual "
248
              "hosts (users/all-hosts/total)."), "",
249
           ?T("- Total number of online users on the current "
250
              "virtual host (users/online)."), "",
251
           ?T("- Total number of online users on all virtual "
252
              "hosts (users/all-hosts/online)."), "",
253
           ?T("NOTE: The protocol extension is deferred and seems "
254
              "like even a few clients that were supporting it "
255
              "are now abandoned. So using this module makes "
256
              "very little sense.")]}.
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

© 2026 Coveralls, Inc