mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-20 17:27:00 +01:00
* src/mod_service_log.erl: Bugfix (thanks to Badlop)
* src/jd2ejd.erl: Use mod_vcard_odbc if it is loaded (thanks to Tomasz Sterna) * src/ejabberd_sm.erl: Added a few ejabberdctl commands * src/ejabberd_ctl.erl: New interface for command registration SVN Revision: 507
This commit is contained in:
parent
904300ce04
commit
0234b83be4
13
ChangeLog
13
ChangeLog
@ -1,3 +1,16 @@
|
||||
2006-02-15 Alexey Shchepin <alexey@sevcom.net>
|
||||
|
||||
* src/mod_service_log.erl: Bugfix (thanks to Badlop)
|
||||
|
||||
* src/jd2ejd.erl: Use mod_vcard_odbc if it is loaded (thanks to
|
||||
Tomasz Sterna)
|
||||
|
||||
2006-02-14 Alexey Shchepin <alexey@sevcom.net>
|
||||
|
||||
* src/ejabberd_sm.erl: Added a few ejabberdctl commands
|
||||
|
||||
* src/ejabberd_ctl.erl: New interface for command registration
|
||||
|
||||
2006-02-13 Alexey Shchepin <alexey@sevcom.net>
|
||||
|
||||
* src/ejabberd_ctl.erl: Partially rewritten
|
||||
|
@ -10,7 +10,9 @@
|
||||
-author('alexey@sevcom.net').
|
||||
|
||||
-export([start/0,
|
||||
process/1]).
|
||||
process/1,
|
||||
register_commands/3,
|
||||
unregister_commands/3]).
|
||||
|
||||
-include("ejabberd_ctl.hrl").
|
||||
|
||||
@ -20,7 +22,7 @@ start() ->
|
||||
Node = list_to_atom(SNode),
|
||||
Status = case rpc:call(Node, ?MODULE, process, [Args]) of
|
||||
{badrpc, Reason} ->
|
||||
io:format("RPC call failed on the node ~p: ~p~n",
|
||||
io:format("RPC failed on the node ~p: ~p~n",
|
||||
[Node, Reason]),
|
||||
?STATUS_BADRPC;
|
||||
S ->
|
||||
@ -163,37 +165,76 @@ process(["delete-expired-messages"]) ->
|
||||
mod_offline:remove_expired_messages(),
|
||||
?STATUS_SUCCESS;
|
||||
|
||||
process(_Args) ->
|
||||
process(Args) ->
|
||||
case ejabberd_hooks:run_fold(
|
||||
ejabberd_ctl_process,
|
||||
false,
|
||||
[Args]) of
|
||||
false ->
|
||||
print_usage(),
|
||||
?STATUS_USAGE.
|
||||
|
||||
?STATUS_USAGE;
|
||||
Status ->
|
||||
Status
|
||||
end.
|
||||
|
||||
|
||||
print_usage() ->
|
||||
catch ets:new(ejabberd_ctl_cmds, [named_table, ordered_set, public]),
|
||||
CmdDescs =
|
||||
[{"status", "get ejabberd status"},
|
||||
{"stop", "stop ejabberd"},
|
||||
{"restart", "restart ejabberd"},
|
||||
{"reopen-log", "reopen log file"},
|
||||
{"register user server password", "register a user"},
|
||||
{"unregister user server", "unregister a user"},
|
||||
{"backup file", "store a database backup to file"},
|
||||
{"restore file", "restore a database backup from file"},
|
||||
{"install-fallback file", "install a database fallback from file"},
|
||||
{"dump file", "dump a database to a text file"},
|
||||
{"load file", "restore a database from a text file"},
|
||||
{"import-file file", "import user data from jabberd 1.4 spool file"},
|
||||
{"import-dir dir", "import user data from jabberd 1.4 spool directory"},
|
||||
{"registered-users", "list all registered users"},
|
||||
{"delete-expired-messages", "delete expired offline messages from database"}] ++
|
||||
ets:tab2list(ejabberd_ctl_cmds),
|
||||
MaxCmdLen =
|
||||
lists:max(lists:map(
|
||||
fun({Cmd, _Desc}) ->
|
||||
length(Cmd)
|
||||
end, CmdDescs)),
|
||||
NewLine = io_lib:format("~n", []),
|
||||
FmtCmdDescs =
|
||||
lists:map(
|
||||
fun({Cmd, Desc}) ->
|
||||
[" ", Cmd, string:chars($\s, MaxCmdLen - length(Cmd) + 1),
|
||||
Desc, NewLine]
|
||||
end, CmdDescs),
|
||||
io:format(
|
||||
"Usage: ejabberdctl node command~n"
|
||||
"~n"
|
||||
"Available commands:~n"
|
||||
" status\t\t\tget ejabberd status~n"
|
||||
" stop\t\t\t\tstop ejabberd~n"
|
||||
" restart\t\t\trestart ejabberd~n"
|
||||
" reopen-log\t\t\treopen log file~n"
|
||||
" register user server password\tregister a user~n"
|
||||
" unregister user server\tunregister a user~n"
|
||||
" backup file\t\t\tstore a database backup to file~n"
|
||||
" restore file\t\t\trestore a database backup from file~n"
|
||||
" install-fallback file\t\tinstall a database fallback from file~n"
|
||||
" dump file\t\t\tdump a database to a text file~n"
|
||||
" load file\t\t\trestore a database from a text file~n"
|
||||
" import-file file\t\timport user data from jabberd 1.4 spool file~n"
|
||||
" import-dir dir\t\timport user data from jabberd 1.4 spool directory~n"
|
||||
" registered-users\t\tlist all registered users~n"
|
||||
" delete-expired-messages\tdelete expired offline messages from database~n"
|
||||
++ FmtCmdDescs ++
|
||||
"~n"
|
||||
"Example:~n"
|
||||
" ejabberdctl ejabberd@host restart~n"
|
||||
).
|
||||
|
||||
register_commands(CmdDescs, Module, Function) ->
|
||||
catch ets:new(ejabberd_ctl_cmds, [named_table, ordered_set, public]),
|
||||
ets:insert(ejabberd_ctl_cmds, CmdDescs),
|
||||
ejabberd_hooks:add(ejabberd_ctl_process,
|
||||
Module, Function, 50),
|
||||
ok.
|
||||
|
||||
unregister_commands(CmdDescs, Module, Function) ->
|
||||
catch ets:new(ejabberd_ctl_cmds, [named_table, ordered_set, public]),
|
||||
lists:foreach(fun(CmdDesc) ->
|
||||
ets:delete_object(ejabberd_ctl_cmds, CmdDesc)
|
||||
end, CmdDescs),
|
||||
ejabberd_hooks:delete(ejabberd_ctl_process,
|
||||
Module, Function, 50),
|
||||
ok.
|
||||
|
||||
dump_to_textfile(File) ->
|
||||
dump_to_textfile(mnesia:system_info(is_running), file:open(File, write)).
|
||||
dump_to_textfile(yes, {ok, F}) ->
|
||||
|
@ -27,7 +27,8 @@
|
||||
get_vh_session_list/1,
|
||||
register_iq_handler/4,
|
||||
register_iq_handler/5,
|
||||
unregister_iq_handler/2
|
||||
unregister_iq_handler/2,
|
||||
ctl_process/2
|
||||
]).
|
||||
|
||||
%% gen_server callbacks
|
||||
@ -36,6 +37,7 @@
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("jlib.hrl").
|
||||
-include("ejabberd_ctl.hrl").
|
||||
|
||||
-record(session, {sid, usr, us, priority}).
|
||||
-record(state, {}).
|
||||
@ -164,6 +166,11 @@ init([]) ->
|
||||
ejabberd_hooks:add(remove_user, Host,
|
||||
ejabberd_sm, disconnect_removed_user, 100)
|
||||
end, ?MYHOSTS),
|
||||
ejabberd_ctl:register_commands(
|
||||
[{"connected-users", "list all established sessions"},
|
||||
{"connected-users-number", "print a number of established sessions"},
|
||||
{"user-resources user server", "print user's connected resources"}],
|
||||
?MODULE, ctl_process),
|
||||
{ok, #state{}}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
@ -522,6 +529,27 @@ process_iq(From, To, Packet) ->
|
||||
end.
|
||||
|
||||
|
||||
ctl_process(_Val, ["connected-users"]) ->
|
||||
USRs = dirty_get_sessions_list(),
|
||||
NewLine = io_lib:format("~n", []),
|
||||
SUSRs = lists:sort(USRs),
|
||||
FUSRs = lists:map(fun({U, S, R}) -> [U, $@, S, $/, R, NewLine] end, SUSRs),
|
||||
io:format("~s", [FUSRs]),
|
||||
?STATUS_SUCCESS;
|
||||
ctl_process(_Val, ["connected-users-number"]) ->
|
||||
N = length(dirty_get_sessions_list()),
|
||||
io:format("~p~n", [N]),
|
||||
?STATUS_SUCCESS;
|
||||
ctl_process(_Val, ["user-resources", User, Server]) ->
|
||||
Resources = get_user_resources(User, Server),
|
||||
NewLine = io_lib:format("~n", []),
|
||||
SResources = lists:sort(Resources),
|
||||
FResources = lists:map(fun(R) -> [R, NewLine] end, SResources),
|
||||
io:format("~s", [FResources]),
|
||||
?STATUS_SUCCESS;
|
||||
ctl_process(Val, _Args) ->
|
||||
Val.
|
||||
|
||||
|
||||
update_tables() ->
|
||||
case catch mnesia:table_info(session, attributes) of
|
||||
|
@ -134,10 +134,19 @@ xdb_data(User, Server, {xmlelement, _Name, Attrs, _Els} = El) ->
|
||||
end,
|
||||
ok;
|
||||
?NS_VCARD ->
|
||||
case lists:member(mod_vcard_odbc,
|
||||
gen_mod:loaded_modules(LServer)) of
|
||||
true ->
|
||||
catch mod_vcard_odbc:process_sm_iq(
|
||||
From,
|
||||
jlib:make_jid("", Server, ""),
|
||||
#iq{type = set, xmlns = ?NS_VCARD, sub_el = El});
|
||||
false ->
|
||||
catch mod_vcard:process_sm_iq(
|
||||
From,
|
||||
jlib:make_jid("", Server, ""),
|
||||
#iq{type = set, xmlns = ?NS_VCARD, sub_el = El}),
|
||||
#iq{type = set, xmlns = ?NS_VCARD, sub_el = El})
|
||||
end,
|
||||
ok;
|
||||
"jabber:x:offline" ->
|
||||
process_offline(Server, From, El),
|
||||
|
@ -34,14 +34,13 @@ stop(Host) ->
|
||||
ok.
|
||||
|
||||
log_user_send(From, To, Packet) ->
|
||||
log_packet(From, To, Packet).
|
||||
log_packet(From, To, Packet, From#jid.lserver).
|
||||
|
||||
log_user_receive(_JID, From, To, Packet) ->
|
||||
log_packet(From, To, Packet).
|
||||
log_packet(From, To, Packet, To#jid.lserver).
|
||||
|
||||
|
||||
log_packet(From, To, {xmlelement, Name, Attrs, Els}) ->
|
||||
Host = From#jid.lserver,
|
||||
log_packet(From, To, {xmlelement, Name, Attrs, Els}, Host) ->
|
||||
Loggers = gen_mod:get_module_opt(Host, ?MODULE, loggers, []),
|
||||
ServerJID = #jid{user = "", server = Host, resource = "",
|
||||
luser = "", lserver = Host, lresource = ""},
|
||||
|
Loading…
Reference in New Issue
Block a user