mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-26 16:26:24 +01:00
0b4539caa1
polling and admin interface * src/web/ejabberd_web.erl: Likewise * src/ejabberd.cfg.example: Updated * src/web/ejabberd_web_admin.erl: Updated * doc/guide.tex: Updated SVN Revision: 236
84 lines
2.4 KiB
Erlang
84 lines
2.4 KiB
Erlang
%%%----------------------------------------------------------------------
|
|
%%% File : ejabberd_web.erl
|
|
%%% Author : Alexey Shchepin <alexey@sevcom.net>
|
|
%%% Purpose :
|
|
%%% Created : 28 Feb 2004 by Alexey Shchepin <alexey@sevcom.net>
|
|
%%% Id : $Id$
|
|
%%%----------------------------------------------------------------------
|
|
|
|
-module(ejabberd_web).
|
|
-author('alexey@sevcom.net').
|
|
-vsn('$Revision$ ').
|
|
|
|
%% External exports
|
|
-export([make_xhtml/1,
|
|
process_get/2]).
|
|
|
|
-include("ejabberd.hrl").
|
|
-include("jlib.hrl").
|
|
-include("ejabberd_http.hrl").
|
|
|
|
|
|
make_xhtml(Els) ->
|
|
{xmlelement, "html", [{"xmlns", "http://www.w3.org/1999/xhtml"},
|
|
{"xml:lang", "en"},
|
|
{"lang", "en"}],
|
|
[{xmlelement, "head", [],
|
|
[{xmlelement, "meta", [{"http-equiv", "Content-Type"},
|
|
{"content", "text/html; charset=utf-8"}], []}]},
|
|
{xmlelement, "body", [], Els}
|
|
]}.
|
|
|
|
|
|
-define(X(Name), {xmlelement, Name, [], []}).
|
|
-define(XA(Name, Attrs), {xmlelement, Name, Attrs, []}).
|
|
-define(XE(Name, Els), {xmlelement, Name, [], Els}).
|
|
-define(XAE(Name, Attrs, Els), {xmlelement, Name, Attrs, Els}).
|
|
-define(C(Text), {xmlcdata, Text}).
|
|
-define(XC(Name, Text), ?XE(Name, [?C(Text)])).
|
|
-define(XAC(Name, Attrs, Text), ?XAE(Name, Attrs, [?C(Text)])).
|
|
|
|
-define(LI(Els), ?XE("li", Els)).
|
|
-define(A(URL, Els), ?XAE("a", [{"href", URL}], Els)).
|
|
-define(AC(URL, Text), ?A(URL, [?C(Text)])).
|
|
-define(P, ?X("p")).
|
|
-define(BR, ?X("br")).
|
|
-define(INPUT(Type, Name, Value),
|
|
?XA("input", [{"type", Type},
|
|
{"name", Name},
|
|
{"value", Value}])).
|
|
|
|
|
|
process_get({_, true},
|
|
#request{user = User,
|
|
path = ["admin" | RPath],
|
|
q = Query,
|
|
lang = Lang} = Request) ->
|
|
if
|
|
User /= undefined ->
|
|
case acl:match_rule(configure, jlib:make_jid(User, ?MYNAME, "")) of
|
|
deny ->
|
|
{401, [], make_xhtml([?XC("h1", "Not Allowed")])};
|
|
allow ->
|
|
ejabberd_web_admin:process_admin(
|
|
Request#request{path = RPath})
|
|
end;
|
|
true ->
|
|
{401,
|
|
[{"WWW-Authenticate", "basic realm=\"ejabberd\""}],
|
|
ejabberd_web:make_xhtml([{xmlelement, "h1", [],
|
|
[{xmlcdata, "401 Unauthorized"}]}])}
|
|
end;
|
|
|
|
process_get({true, _},
|
|
#request{user = User,
|
|
path = ["http-poll" | RPath],
|
|
q = Query,
|
|
lang = Lang} = Request) ->
|
|
ejabberd_http_poll:process_request(Request#request{path = RPath});
|
|
|
|
process_get(_, _Request) ->
|
|
{404, [], make_xhtml([?XC("h1", "Not found")])}.
|
|
|
|
|