From b75fb79677a90fd1885eb43c98158910da940ff5 Mon Sep 17 00:00:00 2001 From: Alexey Shchepin Date: Sun, 21 Mar 2004 20:27:09 +0000 Subject: [PATCH] * (all): Updated win32 stuff (thanks to Sergei Golovan) * src/web/ejabberd_web.erl: Added interface for access rules configuration SVN Revision: 221 --- ChangeLog | 7 ++ doc/guide.tex | 11 +- src/Makefile.win32 | 42 +++++++- src/eldap/Makefile.win32 | 24 +++++ src/expat_erl.c | 1 + src/mod_irc/Makefile.win32 | 6 +- src/mod_irc/iconv_erl.c | 1 + src/mod_muc/Makefile.win32 | 2 +- src/mod_pubsub/Makefile.win32 | 2 +- src/stringprep/Makefile.win32 | 4 +- src/stringprep/stringprep_drv.c | 1 + src/web/Makefile.win32 | 24 +++++ src/web/ejabberd_web.erl | 185 ++++++++++++++++++++++++-------- 13 files changed, 253 insertions(+), 57 deletions(-) create mode 100644 src/eldap/Makefile.win32 create mode 100644 src/web/Makefile.win32 diff --git a/ChangeLog b/ChangeLog index d53329461..0de59dd95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-03-21 Alexey Shchepin + + * (all): Updated win32 stuff (thanks to Sergei Golovan) + + * src/web/ejabberd_web.erl: Added interface for access rules + configuration + 2004-03-20 Alexey Shchepin * doc/guide.tex: Updated diff --git a/doc/guide.tex b/doc/guide.tex index 2d552d6db..a9ba8d3cc 100644 --- a/doc/guide.tex +++ b/doc/guide.tex @@ -127,14 +127,17 @@ To compile \ejabberd{} in MS Windows environment, you will need the following packages: \begin{itemize} \item MS Visual C++~6.0 Compiler -\item \footahref{http://www.erlang.org/download/otp_win32_R8B-2.exe}{Erlang - emulator version~5.1.2} +\item \footahref{http://www.erlang.org/download/otp_win32_R9C-0.exe}{Erlang emulator version~5.3} \item \footahref{http://prdownloads.sourceforge.net/expat/expat_win32bin_1_95_6.exe?download}{Expat~1.95.6} -\item \footahref{http://prdownloads.sourceforge.net/gnuwin32/libiconv-1.8-1-lib.exe?download}{Iconv~1.8} (optional) +\item +\footahref{http://prdownloads.sourceforge.net/gnuwin32/libiconv-1.8-1-bin.exe?download}{Iconv~1.8 +binaries} and +\footahref{http://prdownloads.sourceforge.net/gnuwin32/libiconv-1.8-1-lib.exe?download}{Iconv~1.8 +development libraries} +(optional) \end{itemize} - \subsection{Obtaining} \label{sec:obtaining} diff --git a/src/Makefile.win32 b/src/Makefile.win32 index fdf9a1324..dff7f2151 100644 --- a/src/Makefile.win32 +++ b/src/Makefile.win32 @@ -3,10 +3,29 @@ include Makefile.inc EXPAT_DIR="c:\progra~1\expat-1.95.6" -ALL : expat_erl.dll +ALL : expat_erl.dll compile-beam all-recursive + +all-recursive : + cd eldap + nmake -nologo -f Makefile.win32 + cd ..\mod_irc + nmake -nologo -f Makefile.win32 + cd ..\mod_muc + nmake -nologo -f Makefile.win32 + cd ..\mod_pubsub + nmake -nologo -f Makefile.win32 + cd ..\stringprep + nmake -nologo -f Makefile.win32 + cd ..\web + nmake -nologo -f Makefile.win32 + cd .. + +compile-beam : erl -s make all report -noinput -s erlang halt -CLEAN : +CLEAN : clean-recursive clean-local + +clean-local : -@erase expat_erl.obj -@erase vc60.idb -@erase expat_erl.dll @@ -15,8 +34,23 @@ CLEAN : -@erase expat_erl.pch -@erase *.beam +clean-recursive : + cd eldap + nmake -nologo -f Makefile.win32 clean + cd ..\mod_irc + nmake -nologo -f Makefile.win32 clean + cd ..\mod_muc + nmake -nologo -f Makefile.win32 clean + cd ..\mod_pubsub + nmake -nologo -f Makefile.win32 clean + cd ..\stringprep + nmake -nologo -f Makefile.win32 clean + cd ..\web + nmake -nologo -f Makefile.win32 clean + cd .. + CPP=cl.exe -CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "$(ERLANG_DIR)\usr\include" /I "$(EI_DIR)\include" /I "$(EXPAT_DIR)\source\lib" /D "WIN32" /D "NDEBUG" /D "_USRDLL" /D "_MBCS" /Fpexpat_erl.pch /YX /FD /c +CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "$(ERLANG_DIR)\usr\include" /I "$(EI_DIR)\include" /I "$(EXPAT_DIR)\source\lib" /D "__WIN32__" /D "WIN32" /D "NDEBUG" /D "_USRDLL" /D "_MBCS" /Fpexpat_erl.pch /YX /FD /c .c.obj:: $(CPP) @<< @@ -24,7 +58,7 @@ CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "$(ERLANG_DIR)\usr\include" /I "$(EI_DIR)\in << LINK32=link.exe -LINK32_FLAGS=kernel32.lib "$(ERLANG_DIR)\usr\lib\erl_dll.lib" "$(EI_DIR)\lib\ei.lib" "$(EI_DIR)\lib\erl_interface.lib" "$(EXPAT_DIR)\libs\libexpat.lib" /nologo /subsystem:console /dll /pdb:none /machine:I386 /out:expat_erl.dll +LINK32_FLAGS=kernel32.lib "$(EI_DIR)\lib\ei.lib" "$(EI_DIR)\lib\erl_interface.lib" "$(EXPAT_DIR)\libs\libexpat.lib" /nologo /subsystem:console /dll /pdb:none /machine:I386 /out:expat_erl.dll /nodefaultlib:libcmt LINK32_OBJS=expat_erl.obj expat_erl.dll : $(LINK32_OBJS) diff --git a/src/eldap/Makefile.win32 b/src/eldap/Makefile.win32 new file mode 100644 index 000000000..bcffb01c7 --- /dev/null +++ b/src/eldap/Makefile.win32 @@ -0,0 +1,24 @@ + +include ..\Makefile.inc + +OUTDIR = .. +EFLAGS = -I .. -pz .. + +OBJS = \ + $(OUTDIR)\eldap.beam \ + $(OUTDIR)\ELDAPv3.beam + +ALL : $(OBJS) + +CLEAN : + -@erase ELDAPv3.asn1db ELDAPv3.erl ELDAPv3.hrl + -@erase $(OBJS) + +ELDAPv3.erl : ELDAPv3.asn + erlc -bber_bin -W $(EFLAGS) ELDAPv3.asn + +$(OUTDIR)\eldap.beam : eldap.erl ELDAPv3.erl + erlc -W $(EFLAGS) -o $(OUTDIR) eldap.erl + +$(OUTDIR)\ELDAPv3.beam : ELDAPv3.erl + erlc -W $(EFLAGS) -o $(OUTDIR) ELDAPv3.erl diff --git a/src/expat_erl.c b/src/expat_erl.c index 82be23073..237295a93 100644 --- a/src/expat_erl.c +++ b/src/expat_erl.c @@ -1,6 +1,7 @@ /* $Id$ */ #include +#include #include #include #include diff --git a/src/mod_irc/Makefile.win32 b/src/mod_irc/Makefile.win32 index 515f5432a..c87bb2869 100644 --- a/src/mod_irc/Makefile.win32 +++ b/src/mod_irc/Makefile.win32 @@ -20,7 +20,7 @@ CLEAN : -@erase iconv_erl.obj -@erase iconv_erl.pch -@erase vc60.idb - -@erase *.beam + -@erase $(OBJS) $(OUTDIR)\iconv.beam : iconv.erl erlc -W $(EFLAGS) -o $(OUTDIR) iconv.erl @@ -32,7 +32,7 @@ $(OUTDIR)\mod_irc_connection.beam : mod_irc_connection.erl erlc -W $(EFLAGS) -o $(OUTDIR) mod_irc_connection.erl CPP=cl.exe -CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "$(ERLANG_DIR)\usr\include" /I "$(EI_DIR)\include" /I "$(GNUWIN_DIR)\include" /D "WIN32" /D "NDEBUG" /D "_USRDLL" /D "_MBCS" /Fpiconv_erl.pch /YX /FD /c +CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "$(ERLANG_DIR)\usr\include" /I "$(EI_DIR)\include" /I "$(GNUWIN_DIR)\include" /D "__WIN32__" /D "WIN32" /D "NDEBUG" /D "_USRDLL" /D "_MBCS" /Fpiconv_erl.pch /YX /FD /c .c.obj:: $(CPP) @<< @@ -40,7 +40,7 @@ CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "$(ERLANG_DIR)\usr\include" /I "$(EI_DIR)\in << LINK32=link.exe -LINK32_FLAGS=kernel32.lib "$(ERLANG_DIR)\usr\lib\erl_dll.lib" "$(EI_DIR)\lib\ei.lib" "$(EI_DIR)\lib\erl_interface.lib" "$(GNUWIN_DIR)\lib\libiconv.lib" /nologo /subsystem:console /dll /pdb:none /machine:I386 /out:$(OUTDIR)\iconv_erl.dll +LINK32_FLAGS=kernel32.lib "$(EI_DIR)\lib\ei.lib" "$(EI_DIR)\lib\erl_interface.lib" "$(GNUWIN_DIR)\lib\libiconv.lib" /nologo /subsystem:console /dll /pdb:none /machine:I386 /out:$(OUTDIR)\iconv_erl.dll /nodefaultlib:libcmt LINK32_OBJS=iconv_erl.obj $(OUTDIR)\iconv_erl.dll : $(LINK32_OBJS) diff --git a/src/mod_irc/iconv_erl.c b/src/mod_irc/iconv_erl.c index de9914184..923f5cc6f 100644 --- a/src/mod_irc/iconv_erl.c +++ b/src/mod_irc/iconv_erl.c @@ -1,6 +1,7 @@ /* $Id$ */ #include +#include #include #include #include diff --git a/src/mod_muc/Makefile.win32 b/src/mod_muc/Makefile.win32 index 790032e88..67e6c430e 100644 --- a/src/mod_muc/Makefile.win32 +++ b/src/mod_muc/Makefile.win32 @@ -11,7 +11,7 @@ OBJS = \ ALL : $(OBJS) CLEAN : - -@erase *.beam + -@erase $(OBJS) $(OUTDIR)\mod_muc.beam : mod_muc.erl erlc -W $(EFLAGS) -o $(OUTDIR) mod_muc.erl diff --git a/src/mod_pubsub/Makefile.win32 b/src/mod_pubsub/Makefile.win32 index f2421f5a5..bb44dd778 100644 --- a/src/mod_pubsub/Makefile.win32 +++ b/src/mod_pubsub/Makefile.win32 @@ -10,7 +10,7 @@ OBJS = \ ALL : $(OBJS) CLEAN : - -@erase *.beam + -@erase $(OBJS) $(OUTDIR)\mod_pubsub.beam : mod_pubsub.erl erlc -W $(EFLAGS) -o $(OUTDIR) mod_pubsub.erl diff --git a/src/stringprep/Makefile.win32 b/src/stringprep/Makefile.win32 index 5339e3d2e..4f46efda2 100644 --- a/src/stringprep/Makefile.win32 +++ b/src/stringprep/Makefile.win32 @@ -19,7 +19,7 @@ $(OUTDIR)\stringprep.beam : stringprep.erl erlc -W $(EFLAGS) -o $(OUTDIR) stringprep.erl CPP=cl.exe -CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "$(ERLANG_DIR)\usr\include" /I "$(EI_DIR)\include" /D "WIN32" /D "NDEBUG" /D "_USRDLL" /D "_MBCS" /Fpstringprep_drv.pch /YX /FD /c +CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "$(ERLANG_DIR)\usr\include" /I "$(EI_DIR)\include" /D "__WIN32__" /D "WIN32" /D "NDEBUG" /D "_USRDLL" /D "_MBCS" /Fpstringprep_drv.pch /YX /FD /c .c.obj:: $(CPP) @<< @@ -27,7 +27,7 @@ CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "$(ERLANG_DIR)\usr\include" /I "$(EI_DIR)\in << LINK32=link.exe -LINK32_FLAGS=kernel32.lib "$(ERLANG_DIR)\usr\lib\erl_dll.lib" "$(EI_DIR)\lib\ei.lib" "$(EI_DIR)\lib\erl_interface.lib" /nologo /subsystem:console /dll /pdb:none /machine:I386 /out:$(OUTDIR)\stringprep_drv.dll +LINK32_FLAGS=kernel32.lib "$(EI_DIR)\lib\ei.lib" "$(EI_DIR)\lib\erl_interface.lib" /nologo /subsystem:console /dll /pdb:none /machine:I386 /out:$(OUTDIR)\stringprep_drv.dll /nodefaultlib:libcmt LINK32_OBJS=stringprep_drv.obj diff --git a/src/stringprep/stringprep_drv.c b/src/stringprep/stringprep_drv.c index 13aba69bc..2ae83be80 100644 --- a/src/stringprep/stringprep_drv.c +++ b/src/stringprep/stringprep_drv.c @@ -1,6 +1,7 @@ /* $Id$ */ #include +#include #include #include diff --git a/src/web/Makefile.win32 b/src/web/Makefile.win32 new file mode 100644 index 000000000..f9ee493ee --- /dev/null +++ b/src/web/Makefile.win32 @@ -0,0 +1,24 @@ + +include ..\Makefile.inc + +OUTDIR = .. +EFLAGS = -I .. -pz .. + +OBJS = \ + $(OUTDIR)\ejabberd_http.beam \ + $(OUTDIR)\ejabberd_web.beam \ + $(OUTDIR)\ejabberd_http_poll.beam + +ALL : $(OBJS) + +CLEAN : + -@erase $(OBJS) + +$(OUTDIR)\ejabberd_http.beam : ejabberd_http.erl + erlc -W $(EFLAGS) -o $(OUTDIR) ejabberd_http.erl + +$(OUTDIR)\ejabberd_web.beam : ejabberd_web.erl + erlc -W $(EFLAGS) -o $(OUTDIR) ejabberd_web.erl + +$(OUTDIR)\ejabberd_http_poll.beam : ejabberd_http_poll.erl + erlc -W $(EFLAGS) -o $(OUTDIR) ejabberd_http_poll.erl diff --git a/src/web/ejabberd_web.erl b/src/web/ejabberd_web.erl index d532f78f4..ca89952da 100644 --- a/src/web/ejabberd_web.erl +++ b/src/web/ejabberd_web.erl @@ -43,7 +43,10 @@ make_xhtml(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(#request{user = User, @@ -130,7 +133,7 @@ process_admin(#request{user = User, {"cols", "80"}], ACLs), ?BR, - ?XA("input", [{"type", "submit"}]) + ?INPUT("submit", "", "") ]) ]); @@ -168,13 +171,9 @@ process_admin(#request{method = Method, [?XAE("form", [{"method", "post"}], [acls_to_xhtml(ACLs), ?BR, - ?XA("input", [{"type", "submit"}, - {"name", "delete"}, - {"value", "Delete Selected"}]), + ?INPUT("submit", "delete", "Delete Selected"), ?C(" "), - ?XA("input", [{"type", "submit"}, - {"name", "submit"}, - {"value", "Submit"}]) + ?INPUT("submit", "submit", "Submit") ]) ]); @@ -241,17 +240,27 @@ process_admin(#request{user = User, {"cols", "80"}], Access), ?BR, - ?XA("input", [{"type", "submit"}]) + ?INPUT("submit", "", "") ]) ]); process_admin(#request{method = Method, - user = User, - path = ["access"], - q = Query, - lang = Lang} = Request) -> + user = User, + path = ["access"], + q = Query, + lang = Lang} = Request) -> ?INFO_MSG("query: ~p", [Query]), - Res = nothing, + Res = case Method of + 'POST' -> + case catch access_parse_query(Query) of + {'EXIT', _} -> + error; + ok -> + ok + end; + _ -> + nothing + end, AccessRules = ets:select(config, [{{config, {access, '$1'}, '$2'}, @@ -266,9 +275,47 @@ process_admin(#request{method = Method, [?XAE("form", [{"method", "post"}], [access_rules_to_xhtml(AccessRules), ?BR, - ?XA("input", [{"type", "submit"}, - {"name", "delete"}, - {"value", "Delete Selected"}]) + ?INPUT("submit", "delete", "Delete Selected") + ]) + ]); + +process_admin(#request{method = Method, + user = User, + path = ["access", SName], + q = Query, + lang = Lang} = Request) -> + ?INFO_MSG("query: ~p", [Query]), + Name = list_to_atom(SName), + Res = case lists:keysearch("rules", 1, Query) of + {value, {_, String}} -> + case parse_access_rule(String) of + {ok, Rs} -> + ejabberd_config:add_global_option( + {access, Name}, Rs), + ok; + _ -> + error + end; + _ -> + nothing + end, + Rules = case ejabberd_config:get_global_option({access, Name}) of + undefined -> + []; + Rs1 -> + Rs1 + end, + make_xhtml([?XC("h1", + "ejabberd access rule '" ++ SName ++ "' configuration")] ++ + case Res of + ok -> [?C("submited"), ?P]; + error -> [?C("bad format"), ?P]; + nothing -> [] + end ++ + [?XAE("form", [{"method", "post"}], + [access_rule_to_xhtml(Rules), + ?BR, + ?INPUT("submit", "submit", "") ]) ]); @@ -306,28 +353,20 @@ acls_to_xhtml(ACLs) -> SName = atom_to_list(Name), ID = term_to_id(ACL), ?XE("tr", - [?XE("td", - [?XA("input", [{"type", "checkbox"}, - {"name", "selected"}, - {"value", ID}])]), + [?XE("td", [?INPUT("checkbox", "selected", ID)]), ?XC("td", SName)] ++ acl_spec_to_xhtml(ID, Spec) ) end, ACLs) ++ [?XE("tr", [?X("td"), - ?XE("td", - [?XA("input", [{"type", "text"}, - {"name", "namenew"}, - {"value", ""}])] - )] ++ + ?XE("td", [?INPUT("text", "namenew", "")]) + ] ++ acl_spec_to_xhtml("new", {user, ""}) )] )]). --define(ACLINPUT(Text), ?XE("td", [?XA("input", [{"type", "text"}, - {"name", "value" ++ ID}, - {"value", Text}])])). +-define(ACLINPUT(Text), ?XE("td", [?INPUT("text", "value" ++ ID, Text)])). acl_spec_to_text({user, U}) -> {user, U}; @@ -445,10 +484,7 @@ access_rules_to_xhtml(AccessRules) -> SName = atom_to_list(Name), ID = term_to_id(Access), ?XE("tr", - [?XE("td", - [?XA("input", [{"type", "checkbox"}, - {"name", "selected"}, - {"value", ID}])]), + [?XE("td", [?INPUT("checkbox", "selected", ID)]), ?XE("td", [?AC(SName ++ "/", SName)]), ?XC("td", term_to_string(Rules)) ] @@ -456,19 +492,84 @@ access_rules_to_xhtml(AccessRules) -> end, AccessRules) ++ [?XE("tr", [?X("td"), - ?XE("td", - [?XA("input", [{"type", "text"}, - {"name", "namenew"}, - {"value", ""}])] - ), - ?XE("td", - [?XA("input", [{"type", "submit"}, - {"name", "addnew"}, - {"value", "Add New"}])]) + ?XE("td", [?INPUT("text", "namenew", "")]), + ?XE("td", [?INPUT("submit", "addnew", "Add New")]) ] )] )]). +access_parse_query(Query) -> + AccessRules = + ets:select(config, + [{{config, {access, '$1'}, '$2'}, + [], + [{{access, '$1', '$2'}}]}]), + case lists:keysearch("addnew", 1, Query) of + {value, _} -> + access_parse_addnew(AccessRules, Query); + _ -> + case lists:keysearch("delete", 1, Query) of + {value, _} -> + access_parse_delete(AccessRules, Query) + end + end. + +access_parse_addnew(AccessRules, Query) -> + case lists:keysearch("namenew", 1, Query) of + {value, {_, String}} when String /= "" -> + Name = list_to_atom(String), + ejabberd_config:add_global_option({access, Name}, []), + ok + end. + +access_parse_delete(AccessRules, Query) -> + lists:foreach( + fun({access, Name, _Rules} = AccessRule) -> + ID = term_to_id(AccessRule), + case lists:member({"selected", ID}, Query) of + true -> + mnesia:transaction( + fun() -> + mnesia:delete({config, {access, Name}}) + end); + _ -> + ok + end + end, AccessRules), + ok. + + + + +access_rule_to_xhtml(Rules) -> + Text = lists:flatmap( + fun({Access, ACL} = Rule) -> + SAccess = atom_to_list(Access), + SACL = atom_to_list(ACL), + SAccess ++ "\t" ++ SACL ++ "\n" + end, Rules), + ?XAC("textarea", [{"name", "rules"}, + {"rows", "16"}, + {"cols", "80"}], + Text). + +parse_access_rule(Text) -> + Strings = string:tokens(Text, "\r\n"), + case catch lists:flatmap( + fun(String) -> + case string:tokens(String, "\s\t") of + [Access, ACL] -> + [{list_to_atom(Access), list_to_atom(ACL)}]; + [] -> + [] + end + end, Strings) of + {'EXIT', _Reason} -> + error; + Rs -> + {ok, Rs} + end. +