Update mod_muc_log_http to work with ejabberd git master

This commit is contained in:
Badlop 2015-02-02 13:07:12 +01:00
parent edb67df064
commit 2b7bbd9535
2 changed files with 18 additions and 36 deletions

View File

@ -2,9 +2,9 @@
mod_muc_log_http - Serve MUC logs on the web mod_muc_log_http - Serve MUC logs on the web
Homepage: http://ejabberd.jabber.ru/mod_muc_log_http Homepage: http://ejabberd.im/mod_muc_log_http
Author: Badlop Author: Badlop
Requirement: ejabberd SVN r1561, or ejabbed 2.1.0 when released Requirement: ejabberd git master
DESCRIPTION DESCRIPTION
@ -19,34 +19,20 @@ of mod_http_fileserver, customized for log serving.
CONFIGURATION CONFIGURATION
============= =============
If you want to compile this module with Erlang/OTP R11B-3 or older, Sample ejabberd.yml options. The directory to serve is already defined
edit Emakefile and remove this:
{d, 'SSL39'},
Sample ejabberd.cfg options. The directory to serve is already defined
on mod_muc_log. on mod_muc_log.
{listen, listen:
... -
{5280, ejabberd_http, [http_poll, web_admin, port: 5280
{request_handlers, [ module: ejabberd_http
{["pub", "muclogs"], mod_muc_log_http} request_handlers:
] "/pub/muclogs": mod_muc_log_http
}
]
}
...
]}.
{modules, modules:
[ mod_muc_log:
... outdir: "/tmp/muclogs"
{mod_muc_log, [ mod_muc_log_http: {}
{outdir, "/var/www/ejabberdlogs"}
]},
{mod_muc_log_http, []},
...
]}.
USAGE USAGE

View File

@ -26,12 +26,6 @@
-define(PROCNAME, mod_muc_log_http). -define(PROCNAME, mod_muc_log_http).
-ifdef(SSL39).
-define(STRING2LOWER, string).
-else.
-define(STRING2LOWER, httpd_util).
-endif.
% TODO: % TODO:
% - If chatroom is password protected, ask password % - If chatroom is password protected, ask password
% - If chatroom is only for members, ask for username and password % - If chatroom is only for members, ask for username and password
@ -47,10 +41,11 @@
process(LocalPath, Request) -> process(LocalPath, Request) ->
serve(LocalPath, Request). serve(LocalPath, Request).
serve(LocalPath, #request{host = Host} = Request) -> serve(LocalPathBin, #request{host = Host} = Request) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME), Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
Proc ! {get_docroot, self()}, Proc ! {get_docroot, self()},
receive DocRoot -> ok end, receive DocRoot -> ok end,
LocalPath = [binary_to_list(LPB) || LPB <- LocalPathBin],
FileName = filename:join(filename:split(DocRoot) ++ LocalPath), FileName = filename:join(filename:split(DocRoot) ++ LocalPath),
case file:read_file(FileName) of case file:read_file(FileName) of
{ok, FileContents} -> {ok, FileContents} ->
@ -213,7 +208,7 @@ show_dir_listing(DirName, LocalPath) ->
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
content_type(Filename) -> content_type(Filename) ->
case ?STRING2LOWER:to_lower(filename:extension(Filename)) of case string:to_lower(filename:extension(Filename)) of
".jpg" -> "image/jpeg"; ".jpg" -> "image/jpeg";
".jpeg" -> "image/jpeg"; ".jpeg" -> "image/jpeg";
".gif" -> "image/gif"; ".gif" -> "image/gif";
@ -246,8 +241,9 @@ loop(DocRoot) ->
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
start(Host, _Opts) -> start(Host, _Opts) ->
DocRoot = gen_mod:get_module_opt(Host, mod_muc_log, outdir, "www/muc"), DocRootBin = gen_mod:get_module_opt(Host, mod_muc_log, outdir, fun(A) -> A end, <<"www/muc">>),
Proc = gen_mod:get_module_proc(Host, ?PROCNAME), Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
DocRoot = binary_to_list(DocRootBin),
catch register(Proc, spawn(?MODULE, loop, [DocRoot])), catch register(Proc, spawn(?MODULE, loop, [DocRoot])),
ok. ok.