25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

* src/eldap/eldap.erl: Fix compilation warnings: Part 4 (EJAB-290)

* src/web/ejabberd_web_admin.erl: Likewise

SVN Revision: 1048
This commit is contained in:
Badlop 2007-12-07 01:40:24 +00:00
parent 95c69b0251
commit dd706eea94
3 changed files with 105 additions and 145 deletions

View File

@ -1,5 +1,8 @@
2007-12-07 Badlop <badlop@process-one.net> 2007-12-07 Badlop <badlop@process-one.net>
* src/eldap/eldap.erl: Fix compilation warnings: Part 4 (EJAB-290)
* src/web/ejabberd_web_admin.erl: Likewise
* src/mod_irc/iconv.erl: Fix compilation warnings: 3 (EJAB-290) * src/mod_irc/iconv.erl: Fix compilation warnings: 3 (EJAB-290)
* src/mod_irc/mod_irc.erl: Likewise * src/mod_irc/mod_irc.erl: Likewise
* src/mod_irc/mod_irc_connection.erl: Likewise * src/mod_irc/mod_irc_connection.erl: Likewise

View File

@ -104,7 +104,7 @@ start_link(Name) ->
gen_fsm:start_link({local, Reg_name}, ?MODULE, [], []). gen_fsm:start_link({local, Reg_name}, ?MODULE, [], []).
start_link(Name, Hosts, Port, Rootdn, Passwd) -> start_link(Name, Hosts, Port, Rootdn, Passwd) ->
Log = fun(N, Fmt, Args) -> io:format("---- " ++ Fmt, [Args]) end, Log = fun(_N, Fmt, Args) -> io:format("---- " ++ Fmt, [Args]) end,
Reg_name = list_to_atom("eldap_" ++ Name), Reg_name = list_to_atom("eldap_" ++ Name),
gen_fsm:start_link({local, Reg_name}, ?MODULE, {Hosts, Port, Rootdn, Passwd, Log}, []). gen_fsm:start_link({local, Reg_name}, ?MODULE, {Hosts, Port, Rootdn, Passwd, Log}, []).
@ -299,7 +299,7 @@ parse_search_args([{timeout, Timeout}|T],A) when integer(Timeout) ->
parse_search_args(T,A#eldap_search{timeout = Timeout}); parse_search_args(T,A#eldap_search{timeout = Timeout});
parse_search_args([{limit, Limit}|T],A) when is_integer(Limit) -> parse_search_args([{limit, Limit}|T],A) when is_integer(Limit) ->
parse_search_args(T,A#eldap_search{limit = Limit}); parse_search_args(T,A#eldap_search{limit = Limit});
parse_search_args([H|T],A) -> parse_search_args([H|_],_) ->
throw({error,{unknown_arg, H}}); throw({error,{unknown_arg, H}});
parse_search_args([],A) -> parse_search_args([],A) ->
A. A.
@ -414,11 +414,11 @@ connecting(timeout, S) ->
%% {stop, Reason, NewStateData} | %% {stop, Reason, NewStateData} |
%% {stop, Reason, Reply, NewStateData} %% {stop, Reason, Reply, NewStateData}
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
connecting(Event, From, S) -> connecting(_Event, _From, S) ->
Reply = {error, connecting}, Reply = {error, connecting},
{reply, Reply, connecting, S}. {reply, Reply, connecting, S}.
wait_bind_response(Event, From, S) -> wait_bind_response(_Event, _From, S) ->
Reply = {error, wait_bind_response}, Reply = {error, wait_bind_response},
{reply, Reply, wait_bind_response, S}. {reply, Reply, wait_bind_response, S}.
@ -454,7 +454,7 @@ active_bind(Event, From, S) ->
%% {next_state, NextStateName, NextStateData, Timeout} | %% {next_state, NextStateName, NextStateData, Timeout} |
%% {stop, Reason, NewStateData} %% {stop, Reason, NewStateData}
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
handle_event(close, StateName, S) -> handle_event(close, _StateName, S) ->
gen_tcp:close(S#eldap.fd), gen_tcp:close(S#eldap.fd),
{stop, closed, S}; {stop, closed, S};
@ -471,7 +471,7 @@ handle_event(process_bind_q, active_bind, #eldap{bind_q=Q} = S) ->
{next_state, active, S} {next_state, active, S}
end; end;
handle_event(Event, StateName, S) -> handle_event(_Event, StateName, S) ->
{next_state, StateName, S}. {next_state, StateName, S}.
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
@ -484,15 +484,16 @@ handle_event(Event, StateName, S) ->
%% {stop, Reason, NewStateData} | %% {stop, Reason, NewStateData} |
%% {stop, Reason, Reply, NewStateData} %% {stop, Reason, Reply, NewStateData}
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
handle_sync_event({debug_level, N}, From, StateName, S) -> handle_sync_event({debug_level, N}, _From, StateName, S) ->
{reply, ok, StateName, S#eldap{debug_level = N}}; {reply, ok, StateName, S#eldap{debug_level = N}};
handle_sync_event(Event, From, StateName, S) -> handle_sync_event(_Event, _From, StateName, S) ->
{reply, {StateName, S}, StateName, S}; {reply, {StateName, S}, StateName, S}.
handle_sync_event(Event, From, StateName, S) -> %% TODO: Check this clause, because it never matches:
Reply = ok, %%handle_sync_event(Event, From, StateName, S) ->
{reply, Reply, StateName, S}. %% Reply = ok,
%% {reply, Reply, StateName, S}.
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
%% Func: handle_info/3 %% Func: handle_info/3
@ -504,34 +505,34 @@ handle_sync_event(Event, From, StateName, S) ->
%% %%
%% Packets arriving in various states %% Packets arriving in various states
%% %%
handle_info({tcp, Socket, Data}, connecting, S) -> handle_info({tcp, _Socket, Data}, connecting, S) ->
log1("eldap. tcp packet received when disconnected!~n~p~n", [Data], S), log1("eldap. tcp packet received when disconnected!~n~p~n", [Data], S),
{next_state, connecting, S}; {next_state, connecting, S};
handle_info({tcp, Socket, Data}, wait_bind_response, S) -> handle_info({tcp, _Socket, Data}, wait_bind_response, S) ->
cancel_timer(S#eldap.bind_timer), cancel_timer(S#eldap.bind_timer),
case catch recvd_wait_bind_response(Data, S) of case catch recvd_wait_bind_response(Data, S) of
bound -> {next_state, active, S}; bound -> {next_state, active, S};
{fail_bind, Reason} -> close_and_retry(S), {fail_bind, _Reason} -> close_and_retry(S),
{next_state, connecting, S#eldap{fd = null}}; {next_state, connecting, S#eldap{fd = null}};
{'EXIT', Reason} -> close_and_retry(S), {'EXIT', _Reason} -> close_and_retry(S),
{next_state, connecting, S#eldap{fd = null}}; {next_state, connecting, S#eldap{fd = null}};
{error, Reason} -> close_and_retry(S), {error, _Reason} -> close_and_retry(S),
{next_state, connecting, S#eldap{fd = null}} {next_state, connecting, S#eldap{fd = null}}
end; end;
handle_info({tcp, Socket, Data}, StateName, S) handle_info({tcp, _Socket, Data}, StateName, S)
when StateName==active; StateName==active_bind -> when StateName==active; StateName==active_bind ->
case catch recvd_packet(Data, S) of case catch recvd_packet(Data, S) of
{reply, Reply, To, NewS} -> gen_fsm:reply(To, Reply), {reply, Reply, To, NewS} -> gen_fsm:reply(To, Reply),
{next_state, StateName, NewS}; {next_state, StateName, NewS};
{ok, NewS} -> {next_state, StateName, NewS}; {ok, NewS} -> {next_state, StateName, NewS};
{'EXIT', Reason} -> {next_state, StateName, S}; {'EXIT', _Reason} -> {next_state, StateName, S};
{error, Reason} -> {next_state, StateName, S} {error, _Reason} -> {next_state, StateName, S}
end; end;
handle_info({tcp_closed, Socket}, All_fsm_states, S) -> handle_info({tcp_closed, _Socket}, _All_fsm_states, S) ->
F = fun(Id, [{Timer, From, Name}|Res]) -> F = fun(_Id, [{Timer, From, _Name}|_]) ->
gen_fsm:reply(From, {error, tcp_closed}), gen_fsm:reply(From, {error, tcp_closed}),
cancel_timer(Timer) cancel_timer(Timer)
end, end,
@ -540,7 +541,7 @@ handle_info({tcp_closed, Socket}, All_fsm_states, S) ->
{next_state, connecting, S#eldap{fd = null, {next_state, connecting, S#eldap{fd = null,
dict = dict:new(), bind_q=queue:new()}}; dict = dict:new(), bind_q=queue:new()}};
handle_info({tcp_error, Socket, Reason}, Fsm_state, S) -> handle_info({tcp_error, _Socket, Reason}, Fsm_state, S) ->
log1("eldap received tcp_error: ~p~nIn State: ~p~n", [Reason, Fsm_state], S), log1("eldap received tcp_error: ~p~nIn State: ~p~n", [Reason, Fsm_state], S),
{next_state, Fsm_state, S}; {next_state, Fsm_state, S};
%% %%
@ -550,14 +551,14 @@ handle_info({timeout, Timer, {cmd_timeout, Id}}, active, S) ->
case cmd_timeout(Timer, Id, S) of case cmd_timeout(Timer, Id, S) of
{reply, To, Reason, NewS} -> gen_fsm:reply(To, Reason), {reply, To, Reason, NewS} -> gen_fsm:reply(To, Reason),
{next_state, active, NewS}; {next_state, active, NewS};
{error, Reason} -> {next_state, active, S} {error, _Reason} -> {next_state, active, S}
end; end;
handle_info({timeout, retry_connect}, connecting, S) -> handle_info({timeout, retry_connect}, connecting, S) ->
{ok, NextState, NewS} = connect_bind(S), {ok, NextState, NewS} = connect_bind(S),
{next_state, NextState, NewS}; {next_state, NextState, NewS};
handle_info({timeout, Timer, bind_timeout}, wait_bind_response, S) -> handle_info({timeout, _Timer, bind_timeout}, wait_bind_response, S) ->
close_and_retry(S), close_and_retry(S),
{next_state, connecting, S#eldap{fd = null}}; {next_state, connecting, S#eldap{fd = null}};
@ -574,7 +575,7 @@ handle_info(Info, StateName, S) ->
%% Purpose: Shutdown the fsm %% Purpose: Shutdown the fsm
%% Returns: any %% Returns: any
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
terminate(Reason, StateName, StatData) -> terminate(_Reason, _StateName, _StatData) ->
ok. ok.
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
@ -582,7 +583,7 @@ terminate(Reason, StateName, StatData) ->
%% Purpose: Convert process state when code is changed %% Purpose: Convert process state when code is changed
%% Returns: {ok, NewState, NewStateData} %% Returns: {ok, NewState, NewStateData}
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
code_change(OldVsn, StateName, S, Extra) -> code_change(_OldVsn, StateName, S, _Extra) ->
{ok, StateName, S}. {ok, StateName, S}.
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
@ -713,18 +714,18 @@ recvd_packet(Pkt, S) ->
Error -> Error Error -> Error
end. end.
check_reply(#'LDAPResult'{resultCode = success}, From) -> check_reply(#'LDAPResult'{resultCode = success}, _From) ->
ok; ok;
check_reply(#'LDAPResult'{resultCode = Reason}, From) -> check_reply(#'LDAPResult'{resultCode = Reason}, _From) ->
{error, Reason}; {error, Reason};
check_reply(Other, From) -> check_reply(Other, _From) ->
{error, Other}. {error, Other}.
check_bind_reply(#'BindResponse'{resultCode = success}, From) -> check_bind_reply(#'BindResponse'{resultCode = success}, _From) ->
ok; ok;
check_bind_reply(#'BindResponse'{resultCode = Reason}, From) -> check_bind_reply(#'BindResponse'{resultCode = Reason}, _From) ->
{error, Reason}; {error, Reason};
check_bind_reply(Other, From) -> check_bind_reply(Other, _From) ->
{error, Other}. {error, Other}.
get_op_rec(Id, Dict) -> get_op_rec(Id, Dict) ->
@ -781,9 +782,9 @@ cancel_timer(Timer) ->
%%% Sanity check of received packet %%% Sanity check of received packet
check_tag(Data) -> check_tag(Data) ->
case asn1rt_ber_bin:decode_tag(Data) of case asn1rt_ber_bin:decode_tag(Data) of
{Tag, Data1, Rb} -> {_Tag, Data1, _Rb} ->
case asn1rt_ber_bin:decode_length(Data1) of case asn1rt_ber_bin:decode_length(Data1) of
{{Len,Data2}, Rb2} -> ok; {{_Len,_Data2}, _Rb2} -> ok;
_ -> throw({error,decoded_tag_length}) _ -> throw({error,decoded_tag_length})
end; end;
_ -> throw({error,decoded_tag}) _ -> throw({error,decoded_tag})
@ -813,7 +814,7 @@ cmd_timeout(Timer, Id, S) ->
#eldap_search_result{entries = Res1, #eldap_search_result{entries = Res1,
referrals = Ref1}}, referrals = Ref1}},
S#eldap{dict = New_dict}}; S#eldap{dict = New_dict}};
Others -> _ ->
New_dict = dict:erase(Id, Dict), New_dict = dict:erase(Id, Dict),
{reply, From, {error, timeout}, S#eldap{dict = New_dict}} {reply, From, {error, timeout}, S#eldap{dict = New_dict}}
end; end;
@ -857,13 +858,13 @@ connect_bind(S) ->
{ok, wait_bind_response, NewS#eldap{fd = Socket, {ok, wait_bind_response, NewS#eldap{fd = Socket,
host = Host, host = Host,
bind_timer = Timer}}; bind_timer = Timer}};
{error, Reason} -> {error, _Reason} ->
gen_tcp:close(Socket), gen_tcp:close(Socket),
erlang:send_after(?RETRY_TIMEOUT, self(), erlang:send_after(?RETRY_TIMEOUT, self(),
{timeout, retry_connect}), {timeout, retry_connect}),
{ok, connecting, S#eldap{host = Host}} {ok, connecting, S#eldap{host = Host}}
end; end;
{error, Reason} -> {error, _Reason} ->
erlang:send_after(?RETRY_TIMEOUT, self(), erlang:send_after(?RETRY_TIMEOUT, self(),
{timeout, retry_connect}), {timeout, retry_connect}),
{ok, connecting, S#eldap{host = Host}} {ok, connecting, S#eldap{host = Host}}
@ -887,9 +888,9 @@ next_host(Host, Hosts) -> % Find next in turn
next_host(Host, Hosts, Hosts). next_host(Host, Hosts, Hosts).
next_host(Host, [Host], Hosts) -> hd(Hosts); % Wrap back to first next_host(Host, [Host], Hosts) -> hd(Hosts); % Wrap back to first
next_host(Host, [Host|Tail], Hosts) -> hd(Tail); % Take next next_host(Host, [Host|Tail], _Hosts) -> hd(Tail); % Take next
next_host(Host, [], Hosts) -> hd(Hosts); % Never connected before? (shouldn't happen) next_host(_Host, [], Hosts) -> hd(Hosts); % Never connected before? (shouldn't happen)
next_host(Host, [H|T], Hosts) -> next_host(Host, T, Hosts). next_host(Host, [_|T], Hosts) -> next_host(Host, T, Hosts).
%%% -------------------------------------------------------------------- %%% --------------------------------------------------------------------
@ -918,7 +919,7 @@ v_modifications(Mods) ->
v_substr([{Key,Str}|T]) when list(Str),Key==initial;Key==any;Key==final -> v_substr([{Key,Str}|T]) when list(Str),Key==initial;Key==any;Key==final ->
[{Key,Str}|v_substr(T)]; [{Key,Str}|v_substr(T)];
v_substr([H|T]) -> v_substr([H|_]) ->
throw({error,{substring_arg,H}}); throw({error,{substring_arg,H}});
v_substr([]) -> v_substr([]) ->
[]. [].
@ -973,7 +974,7 @@ get_integer(Key, List) ->
case lists:keysearch(Key, 1, List) of case lists:keysearch(Key, 1, List) of
{value, {Key, Value}} when integer(Value) -> {value, {Key, Value}} when integer(Value) ->
Value; Value;
{value, {Key, Value}} -> {value, {Key, _Value}} ->
throw({error, "Bad Value in Config for " ++ atom_to_list(Key)}); throw({error, "Bad Value in Config for " ++ atom_to_list(Key)});
false -> false ->
throw({error, "No Entry in Config for " ++ atom_to_list(Key)}) throw({error, "No Entry in Config for " ++ atom_to_list(Key)})
@ -983,7 +984,7 @@ get_list(Key, List) ->
case lists:keysearch(Key, 1, List) of case lists:keysearch(Key, 1, List) of
{value, {Key, Value}} when list(Value) -> {value, {Key, Value}} when list(Value) ->
Value; Value;
{value, {Key, Value}} -> {value, {Key, _Value}} ->
throw({error, "Bad Value in Config for " ++ atom_to_list(Key)}); throw({error, "Bad Value in Config for " ++ atom_to_list(Key)});
false -> false ->
throw({error, "No Entry in Config for " ++ atom_to_list(Key)}) throw({error, "No Entry in Config for " ++ atom_to_list(Key)})
@ -993,10 +994,10 @@ get_log(Key, List) ->
case lists:keysearch(Key, 1, List) of case lists:keysearch(Key, 1, List) of
{value, {Key, Value}} when function(Value) -> {value, {Key, Value}} when function(Value) ->
Value; Value;
{value, {Key, Else}} -> {value, {Key, _Else}} ->
false; false;
false -> false ->
fun(Level, Format, Args) -> io:format("--- " ++ Format, Args) end fun(_Level, Format, Args) -> io:format("--- " ++ Format, Args) end
end. end.
get_hosts(Key, List) -> get_hosts(Key, List) ->
@ -1009,7 +1010,7 @@ get_hosts(Key, List) ->
({Key1, Value}) when list(Value), ({Key1, Value}) when list(Value),
Key == Key1-> Key == Key1->
Value; Value;
({Else, Value}) -> ({_Else, _Value}) ->
throw({error, "Bad Hostname in config"}) throw({error, "Bad Hostname in config"})
end, List). end, List).

View File

@ -24,9 +24,7 @@
-include("ejabberd_web_admin.hrl"). -include("ejabberd_web_admin.hrl").
process(["server", SHost | RPath], #request{auth = Auth, process(["server", SHost | RPath], #request{auth = Auth} = Request) ->
q = Query,
lang = Lang} = Request) ->
Host = jlib:nameprep(SHost), Host = jlib:nameprep(SHost),
case lists:member(Host, ?MYHOSTS) of case lists:member(Host, ?MYHOSTS) of
true -> true ->
@ -51,9 +49,7 @@ process(["server", SHost | RPath], #request{auth = Auth,
ejabberd_web:error(not_found) ejabberd_web:error(not_found)
end; end;
process(RPath, #request{auth = Auth, process(RPath, #request{auth = Auth} = Request) ->
q = Query,
lang = Lang} = Request) ->
case get_auth(Auth) of case get_auth(Auth) of
{User, Server} -> {User, Server} ->
case acl:match_rule( case acl:match_rule(
@ -584,10 +580,8 @@ logo_fill() ->
"RK5CYII="). "RK5CYII=").
process_admin(global, process_admin(global,
#request{us = US, #request{path = [],
path = [], lang = Lang}) ->
q = Query,
lang = Lang} = Request) ->
MenuItems1 = ejabberd_hooks:run_fold(webadmin_menu_main, [], []), MenuItems1 = ejabberd_hooks:run_fold(webadmin_menu_main, [], []),
MenuItems2 = [?LI([?ACT("/admin/"++MI_uri++"/", MI_name)]) || {MI_uri, MI_name} <- MenuItems1], MenuItems2 = [?LI([?ACT("/admin/"++MI_uri++"/", MI_name)]) || {MI_uri, MI_name} <- MenuItems1],
make_xhtml([?XCT("h1", "Administration"), make_xhtml([?XCT("h1", "Administration"),
@ -604,10 +598,8 @@ process_admin(global,
], global, Lang); ], global, Lang);
process_admin(Host, process_admin(Host,
#request{us = US, #request{path = [],
path = [], lang = Lang}) ->
q = Query,
lang = Lang} = Request) ->
Base = "/admin/server/" ++ Host ++ "/", Base = "/admin/server/" ++ Host ++ "/",
MenuItems1 = ejabberd_hooks:run_fold(webadmin_menu_host, Host, [], [Host]), MenuItems1 = ejabberd_hooks:run_fold(webadmin_menu_host, Host, [], [Host]),
MenuItems2 = [?LI([?ACT(Base ++ MI_uri ++ "/", MI_name)]) || {MI_uri, MI_name} <- MenuItems1], MenuItems2 = [?LI([?ACT(Base ++ MI_uri ++ "/", MI_name)]) || {MI_uri, MI_name} <- MenuItems1],
@ -626,39 +618,22 @@ process_admin(Host,
) )
], Host, Lang); ], Host, Lang);
process_admin(Host, process_admin(Host, #request{path = ["style.css"]}) ->
#request{us = US,
path = ["style.css"],
q = Query,
lang = Lang} = Request) ->
{200, [{"Content-Type", "text/css"}], css(Host)}; {200, [{"Content-Type", "text/css"}], css(Host)};
process_admin(Host, process_admin(_Host, #request{path = ["favicon.ico"]}) ->
#request{us = US,
path = ["favicon.ico"],
q = Query,
lang = Lang} = Request) ->
{200, [{"Content-Type", "image/x-icon"}], favicon()}; {200, [{"Content-Type", "image/x-icon"}], favicon()};
process_admin(Host, process_admin(_Host, #request{path = ["logo.png"]}) ->
#request{us = US,
path = ["logo.png"],
q = Query,
lang = Lang} = Request) ->
{200, [{"Content-Type", "image/png"}], logo()}; {200, [{"Content-Type", "image/png"}], logo()};
process_admin(Host, process_admin(_Host, #request{path = ["logo-fill.png"]}) ->
#request{us = US,
path = ["logo-fill.png"],
q = Query,
lang = Lang} = Request) ->
{200, [{"Content-Type", "image/png"}], logo_fill()}; {200, [{"Content-Type", "image/png"}], logo_fill()};
process_admin(Host, process_admin(Host,
#request{us = US, #request{path = ["acls-raw"],
path = ["acls-raw"],
q = Query, q = Query,
lang = Lang} = Request) -> lang = Lang}) ->
Res = case lists:keysearch("acls", 1, Query) of Res = case lists:keysearch("acls", 1, Query) of
{value, {_, String}} -> {value, {_, String}} ->
case erl_scan:string(String) of case erl_scan:string(String) of
@ -703,10 +678,9 @@ process_admin(Host,
process_admin(Host, process_admin(Host,
#request{method = Method, #request{method = Method,
us = US,
path = ["acls"], path = ["acls"],
q = Query, q = Query,
lang = Lang} = Request) -> lang = Lang}) ->
?DEBUG("query: ~p", [Query]), ?DEBUG("query: ~p", [Query]),
Res = case Method of Res = case Method of
'POST' -> 'POST' ->
@ -746,10 +720,9 @@ process_admin(Host,
], Host, Lang); ], Host, Lang);
process_admin(Host, process_admin(Host,
#request{us = US, #request{path = ["access-raw"],
path = ["access-raw"],
q = Query, q = Query,
lang = Lang} = Request) -> lang = Lang}) ->
SetAccess = SetAccess =
fun(Rs) -> fun(Rs) ->
mnesia:transaction( mnesia:transaction(
@ -816,10 +789,9 @@ process_admin(Host,
process_admin(Host, process_admin(Host,
#request{method = Method, #request{method = Method,
us = US,
path = ["access"], path = ["access"],
q = Query, q = Query,
lang = Lang} = Request) -> lang = Lang}) ->
?DEBUG("query: ~p", [Query]), ?DEBUG("query: ~p", [Query]),
Res = case Method of Res = case Method of
'POST' -> 'POST' ->
@ -852,11 +824,9 @@ process_admin(Host,
], Host, Lang); ], Host, Lang);
process_admin(Host, process_admin(Host,
#request{method = Method, #request{path = ["access", SName],
us = US,
path = ["access", SName],
q = Query, q = Query,
lang = Lang} = Request) -> lang = Lang}) ->
?DEBUG("query: ~p", [Query]), ?DEBUG("query: ~p", [Query]),
Name = list_to_atom(SName), Name = list_to_atom(SName),
Res = case lists:keysearch("rules", 1, Query) of Res = case lists:keysearch("rules", 1, Query) of
@ -893,43 +863,35 @@ process_admin(Host,
], Host, Lang); ], Host, Lang);
process_admin(global, process_admin(global,
#request{us = US, #request{path = ["vhosts"],
path = ["vhosts"], lang = Lang}) ->
q = Query,
lang = Lang} = Request) ->
Res = list_vhosts(Lang), Res = list_vhosts(Lang),
make_xhtml([?XCT("h1", "ejabberd virtual hosts")] ++ Res, global, Lang); make_xhtml([?XCT("h1", "ejabberd virtual hosts")] ++ Res, global, Lang);
process_admin(Host, process_admin(Host,
#request{us = US, #request{path = ["users"],
path = ["users"],
q = Query, q = Query,
lang = Lang} = Request) when is_list(Host) -> lang = Lang}) when is_list(Host) ->
Res = list_users(Host, Query, Lang, fun url_func/1), Res = list_users(Host, Query, Lang, fun url_func/1),
make_xhtml([?XCT("h1", "Users")] ++ Res, Host, Lang); make_xhtml([?XCT("h1", "Users")] ++ Res, Host, Lang);
process_admin(Host, process_admin(Host,
#request{us = US, #request{path = ["users", Diap],
path = ["users", Diap], lang = Lang}) when is_list(Host) ->
q = Query,
lang = Lang} = Request) when is_list(Host) ->
Res = list_users_in_diapason(Host, Diap, Lang, fun url_func/1), Res = list_users_in_diapason(Host, Diap, Lang, fun url_func/1),
make_xhtml([?XCT("h1", "Users")] ++ Res, Host, Lang); make_xhtml([?XCT("h1", "Users")] ++ Res, Host, Lang);
process_admin(Host, process_admin(Host,
#request{us = US, #request{
path = ["online-users"], path = ["online-users"],
q = Query, lang = Lang}) when is_list(Host) ->
lang = Lang} = Request) when is_list(Host) ->
Res = list_online_users(Host, Lang), Res = list_online_users(Host, Lang),
make_xhtml([?XCT("h1", "Online Users")] ++ Res, Host, Lang); make_xhtml([?XCT("h1", "Online Users")] ++ Res, Host, Lang);
process_admin(Host, process_admin(Host,
#request{method = Method, #request{path = ["last-activity"],
us = US,
path = ["last-activity"],
q = Query, q = Query,
lang = Lang} = Request) when is_list(Host) -> lang = Lang}) when is_list(Host) ->
?DEBUG("query: ~p", [Query]), ?DEBUG("query: ~p", [Query]),
Month = case lists:keysearch("period", 1, Query) of Month = case lists:keysearch("period", 1, Query) of
{value, {_, Val}} -> {value, {_, Val}} ->
@ -966,34 +928,28 @@ process_admin(Host,
Res, Host, Lang); Res, Host, Lang);
process_admin(Host, process_admin(Host,
#request{us = US, #request{path = ["stats"],
path = ["stats"], lang = Lang}) ->
q = Query,
lang = Lang} = Request) ->
Res = get_stats(Host, Lang), Res = get_stats(Host, Lang),
make_xhtml([?XCT("h1", "Statistics")] ++ Res, Host, Lang); make_xhtml([?XCT("h1", "Statistics")] ++ Res, Host, Lang);
process_admin(Host, process_admin(Host,
#request{us = US, #request{path = ["user", U],
path = ["user", U],
q = Query, q = Query,
lang = Lang} = Request) -> lang = Lang}) ->
Res = user_info(U, Host, Query, Lang), Res = user_info(U, Host, Query, Lang),
make_xhtml(Res, Host, Lang); make_xhtml(Res, Host, Lang);
process_admin(Host, process_admin(Host,
#request{us = US, #request{path = ["nodes"],
path = ["nodes"], lang = Lang}) ->
q = Query,
lang = Lang} = Request) ->
Res = get_nodes(Lang), Res = get_nodes(Lang),
make_xhtml(Res, Host, Lang); make_xhtml(Res, Host, Lang);
process_admin(Host, process_admin(Host,
#request{us = US, #request{path = ["node", SNode | NPath],
path = ["node", SNode | NPath],
q = Query, q = Query,
lang = Lang} = Request) -> lang = Lang}) ->
case search_running_node(SNode) of case search_running_node(SNode) of
false -> false ->
make_xhtml([?XCT("h1", "Node not found")], Host, Lang); make_xhtml([?XCT("h1", "Node not found")], Host, Lang);
@ -1115,7 +1071,7 @@ acl_parse_submit(ACLs, Query) ->
NewACLs = NewACLs =
lists:map( lists:map(
fun({acl, Name, Spec} = ACL) -> fun({acl, Name, Spec} = ACL) ->
SName = atom_to_list(Name), %%SName = atom_to_list(Name),
ID = term_to_id(ACL), ID = term_to_id(ACL),
case {lists:keysearch("type" ++ ID, 1, Query), case {lists:keysearch("type" ++ ID, 1, Query),
lists:keysearch("value" ++ ID, 1, Query)} of lists:keysearch("value" ++ ID, 1, Query)} of
@ -1176,7 +1132,7 @@ string_to_spec("raw", Val) ->
acl_parse_delete(ACLs, Query) -> acl_parse_delete(ACLs, Query) ->
NewACLs = NewACLs =
lists:filter( lists:filter(
fun({acl, Name, Spec} = ACL) -> fun({acl, _Name, _Spec} = ACL) ->
ID = term_to_id(ACL), ID = term_to_id(ACL),
not lists:member({"selected", ID}, Query) not lists:member({"selected", ID}, Query)
end, ACLs), end, ACLs),
@ -1221,7 +1177,7 @@ access_parse_query(Host, Query) ->
end end
end. end.
access_parse_addnew(AccessRules, Host, Query) -> access_parse_addnew(_AccessRules, Host, Query) ->
case lists:keysearch("namenew", 1, Query) of case lists:keysearch("namenew", 1, Query) of
{value, {_, String}} when String /= "" -> {value, {_, String}} when String /= "" ->
Name = list_to_atom(String), Name = list_to_atom(String),
@ -1250,7 +1206,7 @@ access_parse_delete(AccessRules, Host, Query) ->
access_rule_to_xhtml(Rules) -> access_rule_to_xhtml(Rules) ->
Text = lists:flatmap( Text = lists:flatmap(
fun({Access, ACL} = Rule) -> fun({Access, ACL} = _Rule) ->
SAccess = atom_to_list(Access), SAccess = atom_to_list(Access),
SACL = atom_to_list(ACL), SACL = atom_to_list(ACL),
SAccess ++ "\t" ++ SACL ++ "\n" SAccess ++ "\t" ++ SACL ++ "\n"
@ -1318,7 +1274,7 @@ list_users(Host, Query, Lang, URLFunc) ->
lists:flatmap( lists:flatmap(
fun(K) -> fun(K) ->
L = K + M - 1, L = K + M - 1,
Node = integer_to_list(K) ++ "-" ++ integer_to_list(L), %%Node = integer_to_list(K) ++ "-" ++ integer_to_list(L),
Last = if L < N -> su_to_list(lists:nth(L, SUsers)); Last = if L < N -> su_to_list(lists:nth(L, SUsers));
true -> su_to_list(lists:last(SUsers)) true -> su_to_list(lists:last(SUsers))
end, end,
@ -1397,7 +1353,7 @@ list_given_users(Users, Prefix, Lang, URLFunc) ->
?XCT("td", "Last Activity")])]), ?XCT("td", "Last Activity")])]),
?XE("tbody", ?XE("tbody",
lists:map( lists:map(
fun(SU = {Server, User}) -> fun(_SU = {Server, User}) ->
US = {User, Server}, US = {User, Server},
QueueLen = length(mnesia:dirty_read({offline_msg, US})), QueueLen = length(mnesia:dirty_read({offline_msg, US})),
FQueueLen = [?AC(URLFunc({users_queue, Prefix, FQueueLen = [?AC(URLFunc({users_queue, Prefix,
@ -1475,10 +1431,10 @@ get_stats(Host, Lang) ->
list_online_users(Host, _Lang) -> list_online_users(Host, _Lang) ->
Users = [{S, U} || {U, S, R} <- ejabberd_sm:get_vh_session_list(Host)], Users = [{S, U} || {U, S, _R} <- ejabberd_sm:get_vh_session_list(Host)],
SUsers = lists:usort(Users), SUsers = lists:usort(Users),
lists:flatmap( lists:flatmap(
fun({S, U} = SU) -> fun({_S, U} = SU) ->
[?AC("../user/" ++ ejabberd_http:url_encode(U) ++ "/", [?AC("../user/" ++ ejabberd_http:url_encode(U) ++ "/",
su_to_list(SU)), su_to_list(SU)),
?BR] ?BR]
@ -1696,7 +1652,7 @@ get_node(global, Node, [], Query, Lang) ->
?INPUTT("submit", "stop", "Stop")]) ?INPUTT("submit", "stop", "Stop")])
]; ];
get_node(Host, Node, [], Query, Lang) -> get_node(Host, Node, [], _Query, Lang) ->
MenuItems1 = ejabberd_hooks:run_fold(webadmin_menu_hostnode, Host, [], [Host, Node]), MenuItems1 = ejabberd_hooks:run_fold(webadmin_menu_hostnode, Host, [], [Host, Node]),
MenuItems2 = [?LI([?ACT(MI_uri++"/", MI_name)]) || {MI_uri, MI_name} <- MenuItems1], MenuItems2 = [?LI([?ACT(MI_uri++"/", MI_name)]) || {MI_uri, MI_name} <- MenuItems1],
[?XC("h1", ?T("Node ") ++ atom_to_list(Node)), [?XC("h1", ?T("Node ") ++ atom_to_list(Node)),
@ -1768,7 +1724,7 @@ get_node(global, Node, ["db"], Query, Lang) ->
end; end;
get_node(global, Node, ["backup"], Query, Lang) -> get_node(global, Node, ["backup"], Query, Lang) ->
Res = node_backup_parse_query(Node, Query), _Res = node_backup_parse_query(Node, Query),
[?XC("h1", ?T("Backup of ") ++ atom_to_list(Node)), [?XC("h1", ?T("Backup of ") ++ atom_to_list(Node)),
?XCT("p", "Remark that these options will only backup the builtin Mnesia database. If you are using the ODBC module, you also need to backup your SQL database separately."), ?XCT("p", "Remark that these options will only backup the builtin Mnesia database. If you are using the ODBC module, you also need to backup your SQL database separately."),
?XAE("form", [{"action", ""}, {"method", "post"}], ?XAE("form", [{"action", ""}, {"method", "post"}],
@ -1858,7 +1814,7 @@ get_node(Host, Node, ["modules"], Query, Lang) when is_list(Host) ->
[node_modules_to_xhtml(NewModules, Lang)]) [node_modules_to_xhtml(NewModules, Lang)])
]; ];
get_node(global, Node, ["stats"], Query, Lang) -> get_node(global, Node, ["stats"], _Query, Lang) ->
UpTime = rpc:call(Node, erlang, statistics, [wall_clock]), UpTime = rpc:call(Node, erlang, statistics, [wall_clock]),
UpTimeS = io_lib:format("~.3f", [element(1, UpTime)/1000]), UpTimeS = io_lib:format("~.3f", [element(1, UpTime)/1000]),
CPUTime = rpc:call(Node, erlang, statistics, [runtime]), CPUTime = rpc:call(Node, erlang, statistics, [runtime]),
@ -1904,7 +1860,7 @@ get_node(global, Node, ["update"], Query, Lang) ->
rpc:call(Node, code, purge, [ejabberd_update]), rpc:call(Node, code, purge, [ejabberd_update]),
Res = node_update_parse_query(Node, Query), Res = node_update_parse_query(Node, Query),
rpc:call(Node, code, load_file, [ejabberd_update]), rpc:call(Node, code, load_file, [ejabberd_update]),
{ok, Dir, UpdatedBeams, Script, LowLevelScript, Check} = {ok, _Dir, UpdatedBeams, Script, LowLevelScript, Check} =
rpc:call(Node, ejabberd_update, update_info, []), rpc:call(Node, ejabberd_update, update_info, []),
Mods = Mods =
case UpdatedBeams of case UpdatedBeams of
@ -2071,10 +2027,10 @@ node_ports_to_xhtml(Ports, Lang) ->
])]), ])]),
?XE("tbody", ?XE("tbody",
lists:map( lists:map(
fun({Port, Module, Opts} = E) -> fun({Port, Module, Opts} = _E) ->
SPort = integer_to_list(Port), SPort = integer_to_list(Port),
SModule = atom_to_list(Module), SModule = atom_to_list(Module),
ID = term_to_id(E), %%ID = term_to_id(E),
?XE("tr", ?XE("tr",
[?XC("td", SPort), [?XC("td", SPort),
?XE("td", [?INPUT("text", "module" ++ SPort, ?XE("td", [?INPUT("text", "module" ++ SPort,
@ -2151,9 +2107,9 @@ node_modules_to_xhtml(Modules, Lang) ->
])]), ])]),
?XE("tbody", ?XE("tbody",
lists:map( lists:map(
fun({Module, Opts} = E) -> fun({Module, Opts} = _E) ->
SModule = atom_to_list(Module), SModule = atom_to_list(Module),
ID = term_to_id(E), %%ID = term_to_id(E),
?XE("tr", ?XE("tr",
[?XC("td", SModule), [?XC("td", SModule),
?XE("td", [?INPUTS("text", "opts" ++ SModule, ?XE("td", [?INPUTS("text", "opts" ++ SModule,
@ -2274,8 +2230,8 @@ pretty_print_xml({xmlelement, Name, Attrs, Els}, Prefix) ->
url_func({user_diapason, From, To}) -> url_func({user_diapason, From, To}) ->
integer_to_list(From) ++ "-" ++ integer_to_list(To) ++ "/"; integer_to_list(From) ++ "-" ++ integer_to_list(To) ++ "/";
url_func({users_queue, Prefix, User, Server}) -> url_func({users_queue, Prefix, User, _Server}) ->
Prefix ++ "user/" ++ User ++ "/queue/"; Prefix ++ "user/" ++ User ++ "/queue/";
url_func({user, Prefix, User, Server}) -> url_func({user, Prefix, User, _Server}) ->
Prefix ++ "user/" ++ User ++ "/". Prefix ++ "user/" ++ User ++ "/".