25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-28 16:34:13 +01:00

* src/web/: Updated

SVN Revision: 208
This commit is contained in:
Alexey Shchepin 2004-03-04 20:56:32 +00:00
parent 0f95685c05
commit 5696c848a6
4 changed files with 106 additions and 42 deletions

View File

@ -1,3 +1,7 @@
2004-03-04 Alexey Shchepin <alexey@sevcom.net>
* src/web/: Updated
2004-03-03 Alexey Shchepin <alexey@sevcom.net> 2004-03-03 Alexey Shchepin <alexey@sevcom.net>
* src/web/: Minor update * src/web/: Minor update

View File

@ -17,6 +17,7 @@
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("jlib.hrl"). -include("jlib.hrl").
-include("ejabberd_http.hrl").
-record(state, {sockmod, -record(state, {sockmod,
socket, socket,
@ -81,20 +82,29 @@ receive_headers(State) ->
end. end.
process_request(#state{request_method = 'GET',
request_path = {abs_path, Path},
request_auth = undefined}) ->
make_xhtml_output(
401,
[{"WWW-Authenticate", "basic realm=\"ejabberd\""}],
ejabberd_web:make_xhtml([{xmlelement, "h1", [],
[{xmlcdata, "401 Unauthorized"}]}]));
process_request(#state{request_method = 'GET', process_request(#state{request_method = 'GET',
request_path = {abs_path, Path}, request_path = {abs_path, Path},
request_auth = {User, Pass}}) -> request_auth = Auth}) ->
case ejabberd_auth:check_password(User, Pass) of User = case Auth of
true -> {U, P} ->
case ejabberd_auth:check_password(U, P) of
true ->
U;
false ->
unauthorized
end;
_ ->
undefined
end,
case User of
unauthorized ->
make_xhtml_output(
401,
[{"WWW-Authenticate", "basic realm=\"ejabberd\""}],
ejabberd_web:make_xhtml([{xmlelement, "h1", [],
[{xmlcdata, "401 Unauthorized"}]}]));
_ ->
case (catch url_decode_q_split(Path)) of case (catch url_decode_q_split(Path)) of
{'EXIT', _} -> {'EXIT', _} ->
process_request(false); process_request(false);
@ -102,30 +112,45 @@ process_request(#state{request_method = 'GET',
LQuery = parse_urlencoded(Query), LQuery = parse_urlencoded(Query),
?INFO_MSG("path: ~p, query: ~p~n", [NPath, LQuery]), ?INFO_MSG("path: ~p, query: ~p~n", [NPath, LQuery]),
LPath = string:tokens(NPath, "/"), LPath = string:tokens(NPath, "/"),
case ejabberd_web:process_get(User, LPath, LQuery, "") of Request = #request{method = 'GET',
path = LPath,
q = LQuery,
user = User},
case ejabberd_web:process_get(Request) of
El when element(1, El) == xmlelement -> El when element(1, El) == xmlelement ->
make_xhtml_output(200, [], El); make_xhtml_output(200, [], El);
{Status, Headers, El} -> {Status, Headers, El} ->
make_xhtml_output(Status, Headers, El) make_xhtml_output(Status, Headers, El)
end end
end; end
_ ->
make_xhtml_output(
401,
[{"WWW-Authenticate", "basic realm=\"ejabberd\""}],
ejabberd_web:make_xhtml([{xmlelement, "h1", [],
[{xmlcdata, "401 Unauthorized"}]}]))
end; end;
process_request(#state{request_method = 'POST', process_request(#state{request_method = 'POST',
request_path = {abs_path, Path}, request_path = {abs_path, Path},
request_auth = {User, Pass}, request_auth = Auth,
request_content_length = Len, request_content_length = Len,
sockmod = SockMod, sockmod = SockMod,
socket = Socket} = State) when is_integer(Len) -> socket = Socket} = State) when is_integer(Len) ->
case ejabberd_auth:check_password(User, Pass) of User = case Auth of
true -> {U, P} ->
case SockMod of case ejabberd_auth:check_password(U, P) of
true ->
U;
false ->
unauthorized
end;
_ ->
undefined
end,
case User of
unauthorized ->
make_xhtml_output(
401,
[{"WWW-Authenticate", "basic realm=\"ejabberd\""}],
ejabberd_web:make_xhtml([{xmlelement, "h1", [],
[{xmlcdata, "401 Unauthorized"}]}]));
_ ->
case SockMod of
gen_tcp -> gen_tcp ->
inet:setopts(Socket, [{packet, 0}]); inet:setopts(Socket, [{packet, 0}]);
ssl -> ssl ->
@ -141,19 +166,18 @@ process_request(#state{request_method = 'POST',
LPath = string:tokens(NPath, "/"), LPath = string:tokens(NPath, "/"),
LQuery = parse_urlencoded(Data), LQuery = parse_urlencoded(Data),
?INFO_MSG("client query: ~p~n", [LQuery]), ?INFO_MSG("client query: ~p~n", [LQuery]),
case ejabberd_web:process_get(User, LPath, LQuery, "") of Request = #request{method = 'POST',
path = LPath,
q = LQuery,
user = User,
data = Data},
case ejabberd_web:process_get(Request) of
El when element(1, El) == xmlelement -> El when element(1, El) == xmlelement ->
make_xhtml_output(200, [], El); make_xhtml_output(200, [], El);
{Status, Headers, El} -> {Status, Headers, El} ->
make_xhtml_output(Status, Headers, El) make_xhtml_output(Status, Headers, El)
end end
end; end
_ ->
make_xhtml_output(
401,
[{"WWW-Authenticate", "basic realm=\"ejabberd\""}],
ejabberd_web:make_xhtml([{xmlelement, "h1", [],
[{xmlcdata, "401 Unauthorized"}]}]))
end; end;
process_request(State) -> process_request(State) ->

17
src/web/ejabberd_http.hrl Normal file
View File

@ -0,0 +1,17 @@
%%%----------------------------------------------------------------------
%%% File : ejabberd_http.hrl
%%% Author : Alexey Shchepin <alexey@sevcom.net>
%%% Purpose :
%%% Created : 4 Mar 2004 by Alexey Shchepin <alexey@sevcom.net>
%%% Id : $Id$
%%%----------------------------------------------------------------------
-record(request, {method,
path,
q = [],
user,
lang = "",
data = ""
}).

View File

@ -12,10 +12,11 @@
%% External exports %% External exports
-export([make_xhtml/1, -export([make_xhtml/1,
process_get/4]). process_get/1]).
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("jlib.hrl"). -include("jlib.hrl").
-include("ejabberd_http.hrl").
make_xhtml(Els) -> make_xhtml(Els) ->
@ -44,20 +45,35 @@ make_xhtml(Els) ->
-define(BR, ?X("br")). -define(BR, ?X("br")).
process_get(User, ["config" | RPath], Query, Lang) ->
case acl:match_rule(configure, jlib:make_jid(User, ?MYNAME, "")) of process_get(#request{user = User,
deny -> path = ["config" | RPath],
{401, [], make_xhtml([?XC("h1", "Not Allowed")])}; q = Query,
allow -> lang = Lang} = Request) ->
process_config(User, RPath, Query, Lang) if
User /= undefined ->
case acl:match_rule(configure, jlib:make_jid(User, ?MYNAME, "")) of
deny ->
{401, [], make_xhtml([?XC("h1", "Not Allowed")])};
allow ->
process_config(Request#request{path = RPath})
end;
true ->
{401,
[{"WWW-Authenticate", "basic realm=\"ejabberd\""}],
ejabberd_web:make_xhtml([{xmlelement, "h1", [],
[{xmlcdata, "401 Unauthorized"}]}])}
end; end;
process_get(User, Path, Query, Lang) -> process_get(_Request) ->
{404, [], make_xhtml([?XC("h1", "Not found")])}. {404, [], make_xhtml([?XC("h1", "Not found")])}.
process_config(User, [], Query, Lang) -> process_config(#request{user = User,
path = [],
q = Query,
lang = Lang} = Request) ->
make_xhtml([?XC("h1", "ejabberd configuration"), make_xhtml([?XC("h1", "ejabberd configuration"),
?XE("ul", ?XE("ul",
[?LI([?AC("acls/", "Access Control Lists")]), [?LI([?AC("acls/", "Access Control Lists")]),
@ -67,7 +83,10 @@ process_config(User, [], Query, Lang) ->
]) ])
]); ]);
process_config(User, ["acls"], Query, Lang) -> process_config(#request{user = User,
path = ["acls"],
q = Query,
lang = Lang} = Request) ->
case acl:match_rule(configure, jlib:make_jid(User, ?MYNAME, "")) of case acl:match_rule(configure, jlib:make_jid(User, ?MYNAME, "")) of
deny -> deny ->
{401, [], make_xhtml([?XC("h1", "Not Allowed")])}; {401, [], make_xhtml([?XC("h1", "Not Allowed")])};
@ -111,7 +130,7 @@ process_config(User, ["acls"], Query, Lang) ->
]) ])
end; end;
process_config(User, Path, Query, Lang) -> process_config(_Request) ->
{404, [], make_xhtml([?XC("h1", "Not found")])}. {404, [], make_xhtml([?XC("h1", "Not found")])}.