summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexey Shchepin <alexey@process-one.net>2004-03-12 15:15:17 +0000
committerAlexey Shchepin <alexey@process-one.net>2004-03-12 15:15:17 +0000
commita2b2d08ddc99a902ba2ebf2e5cfa2c7a46b3f795 (patch)
treed93004df2a4080887d793820da1b028aa72a688c /src
parent* src/configure.ac: Updated (diff)
* src/web/ejabberd_web.erl: Experiments with web-interface
SVN Revision: 214
Diffstat (limited to 'src')
-rw-r--r--src/web/ejabberd_web.erl115
1 files changed, 80 insertions, 35 deletions
diff --git a/src/web/ejabberd_web.erl b/src/web/ejabberd_web.erl
index 548b0bf1..55a43f9c 100644
--- a/src/web/ejabberd_web.erl
+++ b/src/web/ejabberd_web.erl
@@ -93,22 +93,15 @@ process_config(#request{user = User,
path = ["acls"],
q = Query,
lang = Lang} = Request) ->
- case acl:match_rule(configure, jlib:make_jid(User, ?MYNAME, "")) of
- deny ->
- {401, [], make_xhtml([?XC("h1", "Not Allowed")])};
- allow ->
- Res = case lists:keysearch("acls", 1, Query) of
- {value, {_, String}} ->
- case erl_scan:string(String) of
- {ok, Tokens, _} ->
- case erl_parse:parse_term(Tokens) of
- {ok, NewACLs} ->
- case acl:add_list(NewACLs, true) of
- ok ->
- ok;
- _ ->
- error
- end;
+ Res = case lists:keysearch("acls", 1, Query) of
+ {value, {_, String}} ->
+ case erl_scan:string(String) of
+ {ok, Tokens, _} ->
+ case erl_parse:parse_term(Tokens) of
+ {ok, NewACLs} ->
+ case acl:add_list(NewACLs, true) of
+ ok ->
+ ok;
_ ->
error
end;
@@ -116,28 +109,80 @@ process_config(#request{user = User,
error
end;
_ ->
- nothing
- end,
- ACLs = lists:flatten(io_lib:format("~p.", [ets:tab2list(acl)])),
- make_xhtml([?XC("h1", "ejabberd ACLs configuration")] ++
- case Res of
- ok -> [?C("submited"), ?P];
- error -> [?C("bad format"), ?P];
- nothing -> []
- end ++
- [?XAE("form", [{"method", "post"}],
- [?XAC("textarea", [{"name", "acls"},
- {"rows", "16"},
- {"cols", "80"}],
- ACLs),
- ?BR,
- ?XA("input", [{"type", "submit"}])
- ])
- ])
- end;
+ error
+ end;
+ _ ->
+ nothing
+ end,
+ ACLs = lists:flatten(io_lib:format("~p.", [ets:tab2list(acl)])),
+ make_xhtml([?XC("h1", "ejabberd ACLs configuration")] ++
+ case Res of
+ ok -> [?C("submited"), ?P];
+ error -> [?C("bad format"), ?P];
+ nothing -> []
+ end ++
+ [?XAE("form", [{"method", "post"}],
+ [?XAC("textarea", [{"name", "acls"},
+ {"rows", "16"},
+ {"cols", "80"}],
+ ACLs),
+ ?BR,
+ ?XA("input", [{"type", "submit"}])
+ ])
+ ]);
+
+process_config(#request{user = User,
+ path = ["acls2"],
+ q = Query,
+ lang = Lang} = Request) ->
+ ACLs = ets:tab2list(acl),
+ make_xhtml([?XC("h1", "ejabberd ACLs configuration")] ++
+ [?XAE("form", [{"method", "post"}],
+ [acls_to_xhtml(ACLs),
+ ?BR,
+ ?XA("input", [{"type", "submit"}])
+ ])
+ ]);
process_config(_Request) ->
{404, [], make_xhtml([?XC("h1", "Not found")])}.
+acls_to_xhtml(ACLs) ->
+ ?XAE("table", [],
+ [?XE("tbody",
+ lists:map(
+ fun({acl, Name, Spec}) ->
+ ?XE("tr",
+ [?XC("td", atom_to_list(Name))] ++
+ acl_spec_to_xhtml(Spec)
+ )
+ end, ACLs)
+ )]).
+
+-define(ACLINPUT(Text), ?XE("td", [?XA("input", [{"type", "text"},
+ {"name", ""},
+ {"value", Text}])])).
+
+acl_spec_to_xhtml({user, U}) ->
+ [acl_spec_select(user), ?ACLINPUT(U)];
+
+acl_spec_to_xhtml(Spec) ->
+ [acl_spec_select(raw),
+ ?ACLINPUT(lists:flatten(io_lib:format("~p.", [Spec])))
+ ].
+
+acl_spec_select(Opt) ->
+ ?XE("td",
+ [?XAE("select", [{"name", ""}],
+ lists:map(
+ fun(O) ->
+ Sel = if
+ O == Opt -> [{"selected", "selected"}];
+ true -> []
+ end,
+ ?XAC("option",
+ Sel ++ [{"value", atom_to_list(O)}],
+ atom_to_list(O))
+ end, [all, user, server, raw]))]).