diff --git a/ChangeLog b/ChangeLog index b0f23021e..274171a67 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,21 @@ * src/ejabberd_c2s.erl: Remove comment for an already done TODO. + * src/web/ejabberd_web_admin.erl, src/web/ejabberd_web_admin.hrl: + Many exmpp related fixes. Fix a bug when displaying users lists, + if we can't access the 'offline_msg' mnesia table (using mod_offline_odbc). + This fix should be temporal, we should find a better way to manage this + situation. The webadmin is usable again. + + * src/web/ejabberd_http.erl: Language must be in binary() format. + + * src/translate.erl: Remove a debug call to io:format/2. + + * src/ejabberd_sm.erl, src/mod_configure.erl, src/mod_disco.erl: + ejabberd_sm:get_user_resources/2 returns resources as binary(). + + * src/ejabberd_sm.erl: Bugfix in get_user_info/3. + 2009-02-13 Christophe Romain * src/ejabberd_auth.erl: prevent from calling diff --git a/src/ejabberd_sm.erl b/src/ejabberd_sm.erl index 9f22b2ba4..ff857fc5c 100644 --- a/src/ejabberd_sm.erl +++ b/src/ejabberd_sm.erl @@ -154,7 +154,7 @@ get_user_resources(User, Server) {'EXIT', _Reason} -> []; Ss -> - [binary_to_list(element(3, S#session.usr)) || S <- clean_session_list(Ss)] + [element(3, S#session.usr) || S <- clean_session_list(Ss)] end. get_user_ip(JID) when ?IS_JID(JID) -> @@ -176,9 +176,9 @@ get_user_info(User, Server, Resource) LUser = exmpp_stringprep:nodeprep(User), LServer = exmpp_stringprep:nameprep(Server), LResource = exmpp_stringprep:resourceprep(Resource), - USR = {list_to_binary(LUser), - list_to_binary(LServer), - list_to_binary(LResource)}, + USR = {LUser, + LServer, + LResource}, case mnesia:dirty_index_read(session, USR, #session.usr) of [] -> offline; diff --git a/src/mod_configure.erl b/src/mod_configure.erl index 490e60858..ed5f7bdf9 100644 --- a/src/mod_configure.erl +++ b/src/mod_configure.erl @@ -287,7 +287,7 @@ get_sm_items(Acc, From, To, Node, Lang) -> {allow, ""} -> Nodes = [?NODEJID(To, "Configuration", <<"config">>), ?NODEJID(To, "User Management", <<"user">>)], - {result, Items ++ Nodes ++ get_user_resources(To)}; + {result, Items ++ Nodes ++ [binary_to_list(R) || R <- get_user_resources(To)]}; {allow, "config"} -> {result, []}; {_, "config"} -> diff --git a/src/mod_disco.erl b/src/mod_disco.erl index 345a56ff7..b548464eb 100644 --- a/src/mod_disco.erl +++ b/src/mod_disco.erl @@ -324,7 +324,7 @@ get_sm_items(Acc, From, To, <<>>, _Lang) -> empty -> [] end, Items1 = case {LFrom, LSFrom} of - {LTo, LSTo} -> get_user_resources(To); + {LTo, LSTo} -> [binary_to_list(R) || R <- get_user_resources(To)]; _ -> [] end, {result, Items ++ Items1}; diff --git a/src/translate.erl b/src/translate.erl index 8929ccd06..9a823c5cd 100644 --- a/src/translate.erl +++ b/src/translate.erl @@ -105,7 +105,6 @@ load_file(Lang, File) -> end. translate(Lang, Msg) -> - io:format("translate(~p, ~p) ~n",[Lang, Msg]), LLang = ascii_tolower(Lang), case ets:lookup(translations, {LLang, Msg}) of [{_, Trans}] -> diff --git a/src/web/ejabberd_http.erl b/src/web/ejabberd_http.erl index 1a1546bfd..14fa5054f 100644 --- a/src/web/ejabberd_http.erl +++ b/src/web/ejabberd_http.erl @@ -51,7 +51,7 @@ request_auth, request_keepalive, request_content_length, - request_lang = "en", + request_lang = <<"en">>, %% XXX bard: request handlers are configured in %% ejabberd.cfg under the HTTP service. For example, %% to have the module test_web handle requests with @@ -548,9 +548,9 @@ make_text_output(State, Status, Headers, Data) when is_binary(Data) -> parse_lang(Langs) -> case string:tokens(Langs, ",; ") of [First | _] -> - First; + list_to_binary(First); [] -> - "en" + <<"en">> end. % Code below is taken (with some modifications) from the yaws webserver, which diff --git a/src/web/ejabberd_web_admin.erl b/src/web/ejabberd_web_admin.erl index ef68160d5..c870cef56 100644 --- a/src/web/ejabberd_web_admin.erl +++ b/src/web/ejabberd_web_admin.erl @@ -975,7 +975,7 @@ process_admin(Host, #request{lang = Lang} = Request) -> global -> {webadmin_page_main, [Request]}; Host -> {webadmin_page_host, [Host, Request]} end, - case ejabberd_hooks:run_fold(Hook, Host, [], Opts) of + case ejabberd_hooks:run_fold(Hook, list_to_binary(Host), [], Opts) of [] -> setelement(1, make_xhtml([?XC('h1', "Not Found")], Host, Lang), 404); Res -> make_xhtml(Res, Host, Lang) end. @@ -1291,7 +1291,7 @@ list_vhosts(Lang) -> lists:map( fun(Host) -> OnlineUsers = - length(ejabberd_sm:get_vh_session_list(Host)), + length(ejabberd_sm:get_vh_session_list(list_to_binary(Host))), RegisteredUsers = ejabberd_auth:get_vh_registered_users_number(Host), ?XE('tr', @@ -1400,13 +1400,20 @@ list_given_users(Users, Prefix, Lang, URLFunc) -> ?XE('tbody', lists:map( fun(_SU = {Server, User}) -> - US = {User, Server}, - QueueLen = length(mnesia:dirty_read({offline_msg, US})), - FQueueLen = [?AC(URLFunc({users_queue, Prefix, - User, Server}), - integer_to_list(QueueLen))], + ServerB = list_to_binary(Server), + UserB = list_to_binary(User), + US = {UserB, ServerB}, + FQueueLen = try + QueueLen = length(mnesia:dirty_read({offline_msg, US})), + [?AC(URLFunc({users_queue, Prefix, + User, Server}), + integer_to_list(QueueLen))] + catch + _:_ -> [#xmlcdata{cdata = <<"Can't access the offline messages storage.">>}] + end, + FLast = - case ejabberd_sm:get_user_resources(User, Server) of + case ejabberd_sm:get_user_resources(UserB, ServerB) of [] -> case mnesia:dirty_read({last_activity, US}) of [] -> @@ -1464,7 +1471,7 @@ get_stats(global, Lang) -> ])]; get_stats(Host, Lang) -> - OnlineUsers = length(ejabberd_sm:get_vh_session_list(Host)), + OnlineUsers = length(ejabberd_sm:get_vh_session_list(list_to_binary(Host))), RegisteredUsers = ejabberd_auth:get_vh_registered_users_number(Host), [?XAE('table', [], [?XE('tbody', @@ -1477,20 +1484,22 @@ get_stats(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(list_to_binary(Host))], SUsers = lists:usort(Users), lists:flatmap( fun({_S, U} = SU) -> - [?AC("../user/" ++ ejabberd_http:url_encode(U) ++ "/", + [?AC("../user/" ++ ejabberd_http:url_encode(binary_to_list(U)) ++ "/", su_to_list(SU)), ?BR] end, SUsers). user_info(User, Server, Query, Lang) -> + UserB = list_to_binary(User), + ServerB = list_to_binary(Server), LServer = exmpp_stringprep:nameprep(Server), US = {exmpp_stringprep:nodeprep(User), LServer}, Res = user_parse_query(User, Server, Query), - Resources = ejabberd_sm:get_user_resources(User, Server), + Resources = ejabberd_sm:get_user_resources(UserB, ServerB), FResources = case Resources of [] -> @@ -1499,7 +1508,7 @@ user_info(User, Server, Query, Lang) -> [?XE('ul', lists:map(fun(R) -> FIP = case ejabberd_sm:get_user_info( - User, Server, R) of + UserB, ServerB, R) of offline -> ""; [{node, Node}, {conn, Conn}, {ip, {IP, Port}}] -> @@ -1518,13 +1527,13 @@ user_info(User, Server, Query, Lang) -> ++ "#" ++ atom_to_list(Node) ++ ")" end, - ?LI([?C(R ++ FIP)]) + ?LI([?C(binary_to_list(R) ++ FIP)]) end, lists:sort(Resources)))] end, Password = ejabberd_auth:get_password_s(User, Server), FPassword = [?INPUT("password", "password", Password), ?C(" "), ?INPUTT("submit", "chpassword", "Change Password")], - UserItems = ejabberd_hooks:run_fold(webadmin_user, LServer, [], + UserItems = ejabberd_hooks:run_fold(webadmin_user, list_to_binary(LServer), [], [User, Server, Lang]), [?XC('h1', ?T("User ") ++ us_to_list(US))] ++ case Res of @@ -1562,7 +1571,7 @@ user_parse_query1("removeuser", User, Server, _Query) -> ejabberd_auth:remove_user(User, Server), ok; user_parse_query1(Action, User, Server, Query) -> - case ejabberd_hooks:run_fold(webadmin_user_parse_query, Server, [], [Action, User, Server, Query]) of + case ejabberd_hooks:run_fold(webadmin_user_parse_query, list_to_binary(Server), [], [Action, User, Server, Query]) of [] -> nothing; Res -> Res end. @@ -1972,7 +1981,7 @@ get_node(Host, Node, NPath, Query, Lang) -> global -> {webadmin_page_node, [Node, NPath, Query, Lang]}; Host -> {webadmin_page_hostnode, [Host, Node, NPath, Query, Lang]} end, - case ejabberd_hooks:run_fold(Hook, Host, [], Opts) of + case ejabberd_hooks:run_fold(Hook, list_to_binary(Host), [], Opts) of [] -> [?XC('h1', "Not Found")]; Res -> Res end. @@ -2135,7 +2144,7 @@ node_ports_to_xhtml(Ports, Lang) -> ?XE('td', [?INPUTS("text", "ipnew", "0.0.0.0", "15")]), ?XE('td', [?INPUTS("text", "modulenew", "", "15")]), ?XE('td', [?TEXTAREA("optsnew", "2", "35", "[]")]), - ?XAE('td', [{"colspan", "2"}], + ?XAE('td', [?XMLATTR("colspan", "2")], [?INPUTT("submit", "addnew", "Add New")]) ] )] @@ -2237,7 +2246,7 @@ node_modules_to_xhtml(Modules, Lang) -> [?XE('tr', [?XE('td', [?INPUT("text", "modulenew", "")]), ?XE('td', [?TEXTAREA("optsnew", "2", "40", "[]")]), - ?XAE('td', [{"colspan", "2"}], + ?XAE('td', [?XMLATTR("colspan", "2")], [?INPUTT("submit", "start", "Start")]) ] )] @@ -2399,9 +2408,9 @@ make_server_menu(HostMenu, NodeMenu, Lang) -> get_menu_items_hook({hostnode, Host}, Lang) -> - ejabberd_hooks:run_fold(webadmin_menu_hostnode, Host, [], [Host, Lang]); + ejabberd_hooks:run_fold(webadmin_menu_hostnode, list_to_binary(Host), [], [Host, Lang]); get_menu_items_hook({host, Host}, Lang) -> - ejabberd_hooks:run_fold(webadmin_menu_host, Host, [], [Host, Lang]); + ejabberd_hooks:run_fold(webadmin_menu_host, list_to_binary(Host), [], [Host, Lang]); get_menu_items_hook(node, Lang) -> ejabberd_hooks:run_fold(webadmin_menu_node, [], [Lang]); get_menu_items_hook(server, Lang) -> diff --git a/src/web/ejabberd_web_admin.hrl b/src/web/ejabberd_web_admin.hrl index b896e693e..6f822f2f6 100644 --- a/src/web/ejabberd_web_admin.hrl +++ b/src/web/ejabberd_web_admin.hrl @@ -34,42 +34,42 @@ -define(XACT(Name, Attrs, Text), ?XAC(Name, Attrs, ?T(Text))). -define(LI(Els), ?XE('li', Els)). --define(A(URL, Els), ?XAE('a', [#xmlattr{name = 'href', value = URL}], Els)). +-define(A(URL, Els), ?XAE('a', [exmpp_xml:attribute('href', URL)], Els)). -define(AC(URL, Text), ?A(URL, [?C(Text)])). -define(ACT(URL, Text), ?AC(URL, ?T(Text))). -define(P, ?X('p')). -define(BR, ?X('br')). -define(INPUT(Type, Name, Value), - ?XA('input', [#xmlattr{name = 'type', value = Type}, - #xmlattr{name = 'name', value = Name}, - #xmlattr{name = 'value', value = Value}])). + ?XA('input', [exmpp_xml:attribute('type', Type), + exmpp_xml:attribute('name', Name), + exmpp_xml:attribute('value', Value)])). -define(INPUTT(Type, Name, Value), ?INPUT(Type, Name, ?T(Value))). -define(INPUTS(Type, Name, Value, Size), - ?XA('input', [#xmlattr{name = 'type', value = Type}, - #xmlattr{name = 'name', value = Name}, - #xmlattr{name = 'value', value = Value}, - #xmlattr{name = 'size', value = Size}])). + ?XA('input', [exmpp_xml:attribute('type', Type), + exmpp_xml:attribute('name', Name), + exmpp_xml:attribute('value', Value), + exmpp_xml:attribute('size', Size)])). -define(INPUTST(Type, Name, Value, Size), ?INPUT(Type, Name, ?T(Value), Size)). -define(ACLINPUT(Text), ?XE('td', [?INPUT("text", "value" ++ ID, Text)])). -define(TEXTAREA(Name, Rows, Cols, Value), - ?XAC('textarea', [#xmlattr{name = 'name', value = list_to_binary(Name)}, - #xmlattr{name = 'rows', value = list_to_binary(Rows)}, - #xmlattr{name = 'cols', value = list_to_binary(Cols)}], + ?XAC('textarea', [exmpp_xml:attribute('name', list_to_binary(Name)), + exmpp_xml:attribute('rows', list_to_binary(Rows)), + exmpp_xml:attribute('cols', list_to_binary(Cols))], Value)). %% Build an xmlelement for result --define(XRES(Text), ?XAC('p', [#xmlattr{name = 'class', value = <<"result">>}], Text)). +-define(XRES(Text), ?XAC('p', [exmpp_xml:attribute('class', <<"result">>)], Text)). -define(XREST(Text), ?XRES(?T(Text))). %% Guide Link -define(GL(Ref, Title), ?XAE('div', - [#xmlattr{name = 'class', value = <<"guidelink">>}], + [exmpp_xml:attribute('class', <<"guidelink">>)], [?XAE('a', - [#xmlattr{name = 'href', value = list_to_binary("/admin/doc/guide.html#"++ Ref)}, - #xmlattr{name = 'target', value = <<"_blank">>}], + [exmpp_xml:attribute('href', list_to_binary("/admin/doc/guide.html#"++ Ref)), + exmpp_xml:attribute('target', <<"_blank">>)], [?C("[Guide: " ++ Title ++ "]")]) ])).