From 13e8c857ce68e8beb320b88af1349fc6f6ed96a1 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Sun, 23 Aug 2015 17:58:26 +0200 Subject: [PATCH] mod_http_upload: Change defaults Change the default settings so that mod_http_upload should work out of the box. --- mod_http_upload/README.txt | 5 +- mod_http_upload/conf/mod_http_upload.yml | 7 +-- mod_http_upload/src/mod_http_upload.erl | 61 ++++++++++-------------- 3 files changed, 29 insertions(+), 44 deletions(-) diff --git a/mod_http_upload/README.txt b/mod_http_upload/README.txt index f5a7919..9a300d6 100644 --- a/mod_http_upload/README.txt +++ b/mod_http_upload/README.txt @@ -42,6 +42,7 @@ following to your ejabberd.yml file: # [...] mod_http_upload: docroot: "/home/xmpp/upload" + put_url: "https://@HOST@:5443" The configurable mod_http_upload options are: @@ -79,14 +80,14 @@ The configurable mod_http_upload options are: mod_http_upload. Otherwise, a SHA-1 hash of the user's bare JID is included instead. -- docroot (default: 'undefined') +- docroot (default: "@HOME@/upload") Uploaded files are stored below the directory specified (as an absolute path) with this option. It is mandatory to specify either this option or the 'service_url' option. The keyword @HOME@ is replaced with the home directory of the user running ejabberd. -- put_url (default: "https://@HOST@:5443") +- put_url (default: "http://@HOST@:5444") This option specifies the initial part of the PUT URLs used for file uploads. The keyword @HOST@ is replaced with the virtual host name. diff --git a/mod_http_upload/conf/mod_http_upload.yml b/mod_http_upload/conf/mod_http_upload.yml index 5ca82b4..2782ee0 100644 --- a/mod_http_upload/conf/mod_http_upload.yml +++ b/mod_http_upload/conf/mod_http_upload.yml @@ -1,12 +1,9 @@ listen: - module: ejabberd_http - port: 5443 - tls: true - certfile: "/etc/ejabberd/example.com.pem" + port: 5444 request_handlers: "": mod_http_upload modules: - mod_http_upload: - docroot: "/home/xmpp/upload" + mod_http_upload: {} diff --git a/mod_http_upload/src/mod_http_upload.erl b/mod_http_upload/src/mod_http_upload.erl index 93cdf06..c77a2b5 100644 --- a/mod_http_upload/src/mod_http_upload.erl +++ b/mod_http_upload/src/mod_http_upload.erl @@ -113,9 +113,9 @@ start(ServerHost, Opts) -> PutURL = gen_mod:get_opt(put_url, Opts, fun(<<"http://", _/binary>> = URL) -> URL; (<<"https://", _/binary>> = URL) -> URL; - (_) -> <<"https://@HOST@">> + (_) -> <<"http://@HOST@">> end, - <<"https://@HOST@">>), + <<"http://@HOST@">>), [_, ProcHost | _] = binary:split(expand_host(PutURL, ServerHost), [<<"http://">>, <<"https://">>, <<":">>, <<"/">>], [global]), @@ -213,12 +213,12 @@ init({ServerHost, Opts}) -> sha1), DocRoot = gen_mod:get_opt(docroot, Opts, fun iolist_to_binary/1, - undefined), + <<"@HOME@/upload">>), PutURL = gen_mod:get_opt(put_url, Opts, fun(<<"http://", _/binary>> = URL) -> URL; (<<"https://", _/binary>> = URL) -> URL end, - <<"https://@HOST@:5443">>), + <<"http://@HOST@:5444">>), GetURL = gen_mod:get_opt(get_url, Opts, fun(<<"http://", _/binary>> = URL) -> URL; (<<"https://", _/binary>> = URL) -> URL @@ -229,13 +229,6 @@ init({ServerHost, Opts}) -> (<<"https://", _/binary>> = URL) -> URL end, undefined), - case {DocRoot, ServiceURL} of - {undefined, undefined} -> - ?ERROR_MSG("A mod_http_upload 'docroot' MUST be specified", []), - erlang:error(configuration_error); - _ -> - ok - end, case ServiceURL of undefined -> ok; @@ -693,32 +686,26 @@ code_to_message(500) -> <<"Internal server error.">>. remove_user(User, Server) -> LUser = jlib:nodeprep(User), LServer = jlib:nameprep(Server), - case gen_mod:get_module_opt(LServer, ?MODULE, docroot, - fun iolist_to_binary/1) of - undefined -> - ok; - DocRoot -> - JIDinURL = gen_mod:get_module_opt(LServer, ?MODULE, jid_in_url, - fun(sha1) -> sha1; - (node) -> node - end, - sha1), - UserStr = make_user_string(<>, - JIDinURL), - UserDir = str:join([expand_home(DocRoot), UserStr], <<$/>>), - case del_tree(UserDir) of - ok -> - ?INFO_MSG("Removed HTTP upload directory of ~s@~s", - [User, Server]); - {error, enoent} -> - ?DEBUG("Found no HTTP upload directory of ~s@~s", - [User, Server]); - {error, Error} -> - ?ERROR_MSG("Cannot remove HTTP upload directory of ~s@~s: ~p", - [User, Server, Error]) - end, - ok - end. + DocRoot = gen_mod:get_module_opt(LServer, ?MODULE, docroot, + fun iolist_to_binary/1, + <<"@HOME@/upload">>), + JIDinURL = gen_mod:get_module_opt(LServer, ?MODULE, jid_in_url, + fun(sha1) -> sha1; + (node) -> node + end, + sha1), + UserStr = make_user_string(<>, JIDinURL), + UserDir = str:join([expand_home(DocRoot), UserStr], <<$/>>), + case del_tree(UserDir) of + ok -> + ?INFO_MSG("Removed HTTP upload directory of ~s@~s", [User, Server]); + {error, enoent} -> + ?DEBUG("Found no HTTP upload directory of ~s@~s", [User, Server]); + {error, Error} -> + ?ERROR_MSG("Cannot remove HTTP upload directory of ~s@~s: ~p", + [User, Server, Error]) + end, + ok. -spec del_tree(file:filename_all()) -> ok | {error, term()}.