./ct_report/coverage/service_admin_extra_last.COVER.html

1 %%%-------------------------------------------------------------------
2 %%% File : service_admin_extra_last.erl
3 %%% Author : Badlop <badlop@process-one.net>, Piotr Nosek <piotr.nosek@erlang-solutions.com>
4 %%% Purpose : Contributed administrative functions and commands
5 %%% Created : 10 Aug 2008 by Badlop <badlop@process-one.net>
6 %%%
7 %%%
8 %%% ejabberd, Copyright (C) 2002-2008 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
21 %%% along with this program; if not, write to the Free Software
22 %%% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 %%%
24 %%%-------------------------------------------------------------------
25
26 -module(service_admin_extra_last).
27 -author('badlop@process-one.net').
28
29 -export([
30 commands/0,
31 set_last/4
32 ]).
33
34 -ignore_xref([commands/0, set_last/4]).
35
36 -include("mongoose.hrl").
37 -include("ejabberd_commands.hrl").
38 -include("mod_roster.hrl").
39 -include("jlib.hrl").
40 -include_lib("exml/include/exml.hrl").
41
42 %%%
43 %%% Register commands
44 %%%
45
46 -spec commands() -> [ejabberd_commands:cmd(), ...].
47 commands() ->
48 164 [
49 #ejabberd_commands{name = set_last, tags = [last],
50 desc = "Set last activity information",
51 longdesc = "Timestamp is the seconds since"
52 "1970-01-01 00:00:00 UTC, for example: date +%s",
53 module = ?MODULE, function = set_last,
54 args = [{user, binary}, {host, binary},
55 {timestamp, integer}, {status, binary}],
56 result = {res, restuple}}
57 ].
58
59 %%%
60 %%% Last Activity
61 %%%
62
63 -spec set_last(jid:user(), jid:server(), _, _) -> {Res, string()} when
64 Res :: ok | user_does_not_exist.
65 set_last(User, Server, Timestamp, Status) ->
66 1 JID = jid:make(User, Server, <<>>),
67 1 case ejabberd_auth:does_user_exist(JID) of
68 true ->
69 1 {ok, HostType} = mongoose_domain_api:get_host_type(JID#jid.lserver),
70 1 mod_last:store_last_info(HostType, JID#jid.luser, JID#jid.lserver, Timestamp, Status),
71 1 {ok, io_lib:format("Last activity for user ~s is set as ~B with status ~s",
72 [jid:to_binary(JID), Timestamp, Status])};
73 false ->
74
:-(
String = io_lib:format("User ~s@~s does not exist", [User, Server]),
75
:-(
{user_does_not_exist, String}
76 end.
Line Hits Source