2004-03-02 22:16:55 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : ejabberd_web.erl
|
2007-12-24 14:57:53 +01:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2007-06-27 13:05:14 +02:00
|
|
|
%%% Purpose :
|
2013-03-14 10:33:02 +01:00
|
|
|
%%% Purpose :
|
2007-12-24 14:57:53 +01:00
|
|
|
%%% Created : 28 Feb 2004 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2019-01-08 22:53:27 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2019 ProcessOne
|
2007-12-24 14:57:53 +01:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
2009-01-12 15:44:42 +01:00
|
|
|
%%%
|
2014-02-22 11:27:40 +01:00
|
|
|
%%% You should have received a copy of the GNU General Public License along
|
|
|
|
%%% with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-12-24 14:57:53 +01:00
|
|
|
%%%
|
2004-03-02 22:16:55 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(ejabberd_web).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2007-12-24 14:57:53 +01:00
|
|
|
-author('alexey@process-one.net').
|
2004-03-02 22:16:55 +01:00
|
|
|
|
|
|
|
%% External exports
|
2013-03-14 10:33:02 +01:00
|
|
|
-export([make_xhtml/1, make_xhtml/2, error/1]).
|
2004-03-02 22:16:55 +01:00
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
-include("logger.hrl").
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2016-07-30 17:37:57 +02:00
|
|
|
-include("xmpp.hrl").
|
2004-03-02 22:16:55 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-include("ejabberd_http.hrl").
|
2004-03-02 22:16:55 +01:00
|
|
|
|
2007-01-25 06:53:58 +01:00
|
|
|
%% XXX bard: there are variants of make_xhtml in ejabberd_http and
|
|
|
|
%% ejabberd_web_admin. It might be a good idea to centralize it here
|
|
|
|
%% and also create an ejabberd_web.hrl file holding the macros, so
|
|
|
|
%% that third parties can use ejabberd_web as an "utility" library.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
make_xhtml(Els) -> make_xhtml([], Els).
|
2008-05-31 20:21:43 +02:00
|
|
|
|
|
|
|
make_xhtml(HeadEls, Els) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
#xmlel{name = <<"html">>,
|
|
|
|
attrs =
|
|
|
|
[{<<"xmlns">>, <<"http://www.w3.org/1999/xhtml">>},
|
|
|
|
{<<"xml:lang">>, <<"en">>}, {<<"lang">>, <<"en">>}],
|
|
|
|
children =
|
|
|
|
[#xmlel{name = <<"head">>, attrs = [],
|
|
|
|
children =
|
|
|
|
[#xmlel{name = <<"meta">>,
|
|
|
|
attrs =
|
|
|
|
[{<<"http-equiv">>, <<"Content-Type">>},
|
|
|
|
{<<"content">>,
|
|
|
|
<<"text/html; charset=utf-8">>}],
|
|
|
|
children = []}
|
|
|
|
| HeadEls]},
|
|
|
|
#xmlel{name = <<"body">>, attrs = [], children = Els}]}.
|
|
|
|
|
|
|
|
-define(X(Name),
|
|
|
|
#xmlel{name = Name, attrs = [], children = []}).
|
|
|
|
|
|
|
|
-define(XA(Name, Attrs),
|
|
|
|
#xmlel{name = Name, attrs = Attrs, children = []}).
|
|
|
|
|
|
|
|
-define(XE(Name, Els),
|
|
|
|
#xmlel{name = Name, attrs = [], children = Els}).
|
|
|
|
|
|
|
|
-define(XAE(Name, Attrs, Els),
|
|
|
|
#xmlel{name = Name, attrs = Attrs, children = Els}).
|
|
|
|
|
2004-03-02 22:16:55 +01:00
|
|
|
-define(C(Text), {xmlcdata, Text}).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2004-03-02 22:16:55 +01:00
|
|
|
-define(XC(Name, Text), ?XE(Name, [?C(Text)])).
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-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)).
|
|
|
|
|
2004-03-02 22:16:55 +01:00
|
|
|
-define(AC(URL, Text), ?A(URL, [?C(Text)])).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
|
|
|
-define(P, ?X(<<"p">>)).
|
|
|
|
|
|
|
|
-define(BR, ?X(<<"br">>)).
|
|
|
|
|
2004-03-21 21:27:09 +01:00
|
|
|
-define(INPUT(Type, Name, Value),
|
2013-03-14 10:33:02 +01:00
|
|
|
?XA(<<"input">>,
|
|
|
|
[{<<"type">>, Type}, {<<"name">>, Name},
|
|
|
|
{<<"value">>, Value}])).
|
2004-03-03 22:07:27 +01:00
|
|
|
|
2007-01-25 06:53:58 +01:00
|
|
|
error(not_found) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{404, [],
|
|
|
|
make_xhtml([?XC(<<"h1">>, <<"404 Not Found">>)])};
|
2007-06-27 13:05:14 +02:00
|
|
|
error(not_allowed) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{401, [],
|
|
|
|
make_xhtml([?XC(<<"h1">>, <<"401 Unauthorized">>)])}.
|