• 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

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

25
-module(mod_private_sql).
26
-behaviour(mod_private).
27

28
%% API
29
-export([init/2, set_data/3, get_data/3, get_all_data/2, del_data/2,
30
    del_data/3, get_users_with_data/2, count_users_with_data/2,
31
    import/3, export/1]).
32
-export([sql_schemas/0]).
33

34
-include_lib("xmpp/include/xmpp.hrl").
35
-include("mod_private.hrl").
36
-include("ejabberd_sql_pt.hrl").
37
-include("logger.hrl").
38

39
%%%===================================================================
40
%%% API
41
%%%===================================================================
42
init(Host, _Opts) ->
UNCOV
43
    ejabberd_sql_schema:update_schema(Host, ?MODULE, sql_schemas()),
7✔
UNCOV
44
    ok.
7✔
45

46
sql_schemas() ->
UNCOV
47
    [#sql_schema{
7✔
48
        version = 1,
49
        tables =
50
            [#sql_table{
51
                name = <<"private_storage">>,
52
                columns =
53
                    [#sql_column{name = <<"username">>, type = text},
54
                     #sql_column{name = <<"server_host">>, type = text},
55
                     #sql_column{name = <<"namespace">>, type = text},
56
                     #sql_column{name = <<"data">>, type = text},
57
                     #sql_column{name = <<"created_at">>, type = timestamp,
58
                                 default = true}],
59
                indices = [#sql_index{
60
                              columns = [<<"server_host">>, <<"username">>,
61
                                         <<"namespace">>],
62
                              unique = true}]}]}].
63

64
set_data(LUser, LServer, Data) ->
UNCOV
65
    F = fun() ->
21✔
UNCOV
66
                lists:foreach(
21✔
67
                  fun({XMLNS, El}) ->
UNCOV
68
                          SData = fxml:element_to_binary(El),
21✔
UNCOV
69
                          ?SQL_UPSERT_T(
21✔
70
                             "private_storage",
71
                             ["!username=%(LUser)s",
72
                              "!server_host=%(LServer)s",
73
                              "!namespace=%(XMLNS)s",
74
                              "data=%(SData)s"])
75
                  end, Data)
76
        end,
UNCOV
77
    case ejabberd_sql:sql_transaction(LServer, F) of
21✔
78
        {atomic, ok} ->
UNCOV
79
            ok;
21✔
80
        _ ->
81
            {error, db_failure}
×
82
    end.
83

84
get_data(LUser, LServer, XMLNS) ->
UNCOV
85
    case ejabberd_sql:sql_query(
58✔
86
           LServer,
UNCOV
87
           ?SQL("select @(data)s from private_storage"
58✔
88
                " where username=%(LUser)s and %(LServer)H"
89
                " and namespace=%(XMLNS)s")) of
90
        {selected, [{SData}]} ->
UNCOV
91
            parse_element(LUser, LServer, SData);
14✔
92
        {selected, []} ->
UNCOV
93
            error;
44✔
94
        _ ->
95
            {error, db_failure}
×
96
    end.
97

98
get_all_data(LUser, LServer) ->
UNCOV
99
    case ejabberd_sql:sql_query(
14✔
100
           LServer,
UNCOV
101
           ?SQL("select @(namespace)s, @(data)s from private_storage"
14✔
102
                " where username=%(LUser)s and %(LServer)H")) of
103
        {selected, []} ->
UNCOV
104
            error;
7✔
105
        {selected, Res} ->
UNCOV
106
            {ok, lists:flatmap(
7✔
107
                   fun({_, SData}) ->
UNCOV
108
                           case parse_element(LUser, LServer, SData) of
7✔
UNCOV
109
                               {ok, El} -> [El];
7✔
110
                               error -> []
×
111
                           end
112
                   end, Res)};
113
        _ ->
114
            {error, db_failure}
×
115
    end.
116

117
del_data(LUser, LServer) ->
UNCOV
118
    case ejabberd_sql:sql_query(
14✔
119
           LServer,
UNCOV
120
           ?SQL("delete from private_storage"
14✔
121
                " where username=%(LUser)s and %(LServer)H")) of
122
        {updated, _} ->
UNCOV
123
            ok;
14✔
124
        _ ->
125
            {error, db_failure}
×
126
    end.
127

128
-spec del_data(binary(), binary(), binary()) -> ok | {error, any()}.
129
del_data(LUser, LServer, NS) ->
130
    case ejabberd_sql:sql_query(
×
131
           LServer,
132
           ?SQL("delete from private_storage"
×
133
                " where username=%(LUser)s and namespace=%(NS)s and %(LServer)H")) of
134
        {updated, _} ->
135
            ok;
×
136
        _ ->
137
            {error, db_failure}
×
138
    end.
139

140
-spec get_users_with_data(binary(), binary()) -> {ok, [binary()]} | {error, any()}.
141
get_users_with_data(LServer, NS) ->
142
    case ejabberd_sql:sql_query(
×
143
           LServer,
144
           ?SQL("select @(username)s from private_storage"
×
145
                " where namespace=%(NS)s and %(LServer)H")) of
146
            {selected, Value} ->
147
            {ok, Value};
×
148
        _ ->
149
            {error, db_failure}
×
150
    end.
151

152
-spec count_users_with_data(binary(), binary()) -> {ok, integer()} | {error, any()}.
153
count_users_with_data(LServer, NS) ->
154
    case ejabberd_sql:sql_query(
×
155
           LServer,
156
           ?SQL("select @(count(*))d from private_storage"
×
157
                " where namespace=%(NS)s and %(LServer)H")) of
158
            {selected, Value} ->
159
            {ok, Value};
×
160
        _ ->
161
            {error, db_failure}
×
162
    end.
163

164
export(_Server) ->
165
    [{private_storage,
×
166
      fun(Host, #private_storage{usns = {LUser, LServer, XMLNS},
167
                                 xml = Data})
168
            when LServer == Host ->
169
              SData = fxml:element_to_binary(Data),
×
170
              [?SQL("delete from private_storage where"
×
171
                    " username=%(LUser)s and %(LServer)H and namespace=%(XMLNS)s;"),
172
               ?SQL_INSERT(
×
173
                  "private_storage",
174
                  ["username=%(LUser)s",
175
                   "server_host=%(LServer)s",
176
                   "namespace=%(XMLNS)s",
177
                   "data=%(SData)s"])];
178
         (_Host, _R) ->
179
              []
×
180
      end}].
181

182
import(_, _, _) ->
183
    ok.
×
184

185
%%%===================================================================
186
%%% Internal functions
187
%%%===================================================================
188
parse_element(LUser, LServer, XML) ->
UNCOV
189
    case fxml_stream:parse_element(XML) of
21✔
190
        El when is_record(El, xmlel) ->
UNCOV
191
            {ok, El};
21✔
192
        _ ->
193
            ?ERROR_MSG("Malformed XML element in SQL table "
×
194
                       "'private_storage' for user ~ts@~ts: ~ts",
195
                       [LUser, LServer, XML]),
×
196
            error
×
197
    end.
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