• 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

51.11
/src/mod_announce_sql.erl
1
%%%-------------------------------------------------------------------
2
%%% File    : mod_announce_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_announce_sql).
26

27
-behaviour(mod_announce).
28

29

30
%% API
31
-export([init/2, set_motd_users/2, set_motd/2, delete_motd/1,
32
         get_motd/1, is_motd_user/2, set_motd_user/2, import/3,
33
         export/1]).
34
-export([sql_schemas/0]).
35

36
-include_lib("xmpp/include/xmpp.hrl").
37
-include("mod_announce.hrl").
38
-include("ejabberd_sql_pt.hrl").
39
-include("logger.hrl").
40

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

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

64
set_motd_users(LServer, USRs) ->
UNCOV
65
    F = fun() ->
7✔
UNCOV
66
                lists:foreach(
7✔
67
                  fun({U, _S, _R}) ->
UNCOV
68
                          ?SQL_UPSERT_T(
14✔
69
                             "motd",
70
                             ["!username=%(U)s",
71
                              "!server_host=%(LServer)s",
72
                              "xml=''"])
73
                  end, USRs)
74
        end,
UNCOV
75
    transaction(LServer, F).
7✔
76

77
set_motd(LServer, Packet) ->
UNCOV
78
    XML = fxml:element_to_binary(Packet),
7✔
UNCOV
79
    F = fun() ->
7✔
UNCOV
80
                ?SQL_UPSERT_T(
7✔
81
                   "motd",
82
                   ["!username=''",
83
                    "!server_host=%(LServer)s",
84
                    "xml=%(XML)s"])
85
        end,
UNCOV
86
    transaction(LServer, F).
7✔
87

88
delete_motd(LServer) ->
UNCOV
89
    F = fun() ->
7✔
UNCOV
90
                ejabberd_sql:sql_query_t(
7✔
UNCOV
91
                  ?SQL("delete from motd where %(LServer)H"))
7✔
92
        end,
UNCOV
93
    transaction(LServer, F).
7✔
94

95
get_motd(LServer) ->
UNCOV
96
    case catch ejabberd_sql:sql_query(
7✔
97
                 LServer,
UNCOV
98
                 ?SQL("select @(xml)s from motd"
7✔
99
                      " where username='' and %(LServer)H")) of
100
        {selected, [{XML}]} ->
101
            parse_element(XML);
×
102
        {selected, []} ->
UNCOV
103
            error;
7✔
104
        _ ->
105
            {error, db_failure}
×
106
    end.
107

108
is_motd_user(LUser, LServer) ->
UNCOV
109
    case catch ejabberd_sql:sql_query(
7✔
110
                 LServer,
UNCOV
111
                 ?SQL("select @(username)s from motd"
7✔
112
                      " where username=%(LUser)s and %(LServer)H")) of
113
        {selected, [_|_]} ->
UNCOV
114
            {ok, true};
7✔
115
        {selected, []} ->
116
            {ok, false};
×
117
        _ ->
118
            {error, db_failure}
×
119
    end.
120

121
set_motd_user(LUser, LServer) ->
122
    F = fun() ->
×
123
                ?SQL_UPSERT_T(
×
124
                   "motd",
125
                   ["!username=%(LUser)s",
126
                    "!server_host=%(LServer)s",
127
                    "xml=''"])
128
        end,
129
    transaction(LServer, F).
×
130

131
export(_Server) ->
132
    [{motd,
×
133
      fun(Host, #motd{server = LServer, packet = El})
134
            when LServer == Host ->
135
              XML = fxml:element_to_binary(El),
×
136
              [?SQL("delete from motd where username='' and %(LServer)H;"),
×
137
               ?SQL_INSERT(
×
138
                  "motd",
139
                  ["username=''",
140
                   "server_host=%(LServer)s",
141
                   "xml=%(XML)s"])];
142
         (_Host, _R) ->
143
              []
×
144
      end},
145
     {motd_users,
146
      fun(Host, #motd_users{us = {LUser, LServer}})
147
            when LServer == Host, LUser /= <<"">> ->
148
              [?SQL("delete from motd where username=%(LUser)s and %(LServer)H;"),
×
149
               ?SQL_INSERT(
×
150
                  "motd",
151
                  ["username=%(LUser)s",
152
                   "server_host=%(LServer)s",
153
                   "xml=''"])];
154
         (_Host, _R) ->
155
              []
×
156
      end}].
157

158
import(_, _, _) ->
159
    ok.
×
160

161
%%%===================================================================
162
%%% Internal functions
163
%%%===================================================================
164
transaction(LServer, F) ->
UNCOV
165
    case ejabberd_sql:sql_transaction(LServer, F) of
21✔
UNCOV
166
        {atomic, _} -> ok;
21✔
167
        _ -> {error, db_failure}
×
168
    end.
169

170
parse_element(XML) ->
171
    case fxml_stream:parse_element(XML) of
×
172
        El when is_record(El, xmlel) ->
173
            {ok, El};
×
174
        _ ->
175
            ?ERROR_MSG("Malformed XML element in SQL table "
×
176
                       "'motd' for username='': ~ts", [XML]),
×
177
            {error, db_failure}
×
178
    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

© 2026 Coveralls, Inc