mod_http_upload: Change defaults

Change the default settings so that mod_http_upload should work out of
the box.
This commit is contained in:
Holger Weiss 2015-08-23 17:58:26 +02:00
parent 6db50940a1
commit 13e8c857ce
3 changed files with 29 additions and 44 deletions

View File

@ -42,6 +42,7 @@ following to your ejabberd.yml file:
# [...] # [...]
mod_http_upload: mod_http_upload:
docroot: "/home/xmpp/upload" docroot: "/home/xmpp/upload"
put_url: "https://@HOST@:5443"
The configurable mod_http_upload options are: 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 mod_http_upload. Otherwise, a SHA-1 hash of the user's bare JID is
included instead. included instead.
- docroot (default: 'undefined') - docroot (default: "@HOME@/upload")
Uploaded files are stored below the directory specified (as an absolute Uploaded files are stored below the directory specified (as an absolute
path) with this option. It is mandatory to specify either this option or 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 the 'service_url' option. The keyword @HOME@ is replaced with the home
directory of the user running ejabberd. 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 This option specifies the initial part of the PUT URLs used for file
uploads. The keyword @HOST@ is replaced with the virtual host name. uploads. The keyword @HOST@ is replaced with the virtual host name.

View File

@ -1,12 +1,9 @@
listen: listen:
- -
module: ejabberd_http module: ejabberd_http
port: 5443 port: 5444
tls: true
certfile: "/etc/ejabberd/example.com.pem"
request_handlers: request_handlers:
"": mod_http_upload "": mod_http_upload
modules: modules:
mod_http_upload: mod_http_upload: {}
docroot: "/home/xmpp/upload"

View File

@ -113,9 +113,9 @@ start(ServerHost, Opts) ->
PutURL = gen_mod:get_opt(put_url, Opts, PutURL = gen_mod:get_opt(put_url, Opts,
fun(<<"http://", _/binary>> = URL) -> URL; fun(<<"http://", _/binary>> = URL) -> URL;
(<<"https://", _/binary>> = URL) -> URL; (<<"https://", _/binary>> = URL) -> URL;
(_) -> <<"https://@HOST@">> (_) -> <<"http://@HOST@">>
end, end,
<<"https://@HOST@">>), <<"http://@HOST@">>),
[_, ProcHost | _] = binary:split(expand_host(PutURL, ServerHost), [_, ProcHost | _] = binary:split(expand_host(PutURL, ServerHost),
[<<"http://">>, <<"https://">>, [<<"http://">>, <<"https://">>,
<<":">>, <<"/">>], [global]), <<":">>, <<"/">>], [global]),
@ -213,12 +213,12 @@ init({ServerHost, Opts}) ->
sha1), sha1),
DocRoot = gen_mod:get_opt(docroot, Opts, DocRoot = gen_mod:get_opt(docroot, Opts,
fun iolist_to_binary/1, fun iolist_to_binary/1,
undefined), <<"@HOME@/upload">>),
PutURL = gen_mod:get_opt(put_url, Opts, PutURL = gen_mod:get_opt(put_url, Opts,
fun(<<"http://", _/binary>> = URL) -> URL; fun(<<"http://", _/binary>> = URL) -> URL;
(<<"https://", _/binary>> = URL) -> URL (<<"https://", _/binary>> = URL) -> URL
end, end,
<<"https://@HOST@:5443">>), <<"http://@HOST@:5444">>),
GetURL = gen_mod:get_opt(get_url, Opts, GetURL = gen_mod:get_opt(get_url, Opts,
fun(<<"http://", _/binary>> = URL) -> URL; fun(<<"http://", _/binary>> = URL) -> URL;
(<<"https://", _/binary>> = URL) -> URL (<<"https://", _/binary>> = URL) -> URL
@ -229,13 +229,6 @@ init({ServerHost, Opts}) ->
(<<"https://", _/binary>> = URL) -> URL (<<"https://", _/binary>> = URL) -> URL
end, end,
undefined), 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 case ServiceURL of
undefined -> undefined ->
ok; ok;
@ -693,32 +686,26 @@ code_to_message(500) -> <<"Internal server error.">>.
remove_user(User, Server) -> remove_user(User, Server) ->
LUser = jlib:nodeprep(User), LUser = jlib:nodeprep(User),
LServer = jlib:nameprep(Server), LServer = jlib:nameprep(Server),
case gen_mod:get_module_opt(LServer, ?MODULE, docroot, DocRoot = gen_mod:get_module_opt(LServer, ?MODULE, docroot,
fun iolist_to_binary/1) of fun iolist_to_binary/1,
undefined -> <<"@HOME@/upload">>),
ok; JIDinURL = gen_mod:get_module_opt(LServer, ?MODULE, jid_in_url,
DocRoot -> fun(sha1) -> sha1;
JIDinURL = gen_mod:get_module_opt(LServer, ?MODULE, jid_in_url, (node) -> node
fun(sha1) -> sha1; end,
(node) -> node sha1),
end, UserStr = make_user_string(<<LUser/binary, $@, LServer/binary>>, JIDinURL),
sha1), UserDir = str:join([expand_home(DocRoot), UserStr], <<$/>>),
UserStr = make_user_string(<<LUser/binary, $@, LServer/binary>>, case del_tree(UserDir) of
JIDinURL), ok ->
UserDir = str:join([expand_home(DocRoot), UserStr], <<$/>>), ?INFO_MSG("Removed HTTP upload directory of ~s@~s", [User, Server]);
case del_tree(UserDir) of {error, enoent} ->
ok -> ?DEBUG("Found no HTTP upload directory of ~s@~s", [User, Server]);
?INFO_MSG("Removed HTTP upload directory of ~s@~s", {error, Error} ->
[User, Server]); ?ERROR_MSG("Cannot remove HTTP upload directory of ~s@~s: ~p",
{error, enoent} -> [User, Server, Error])
?DEBUG("Found no HTTP upload directory of ~s@~s", end,
[User, Server]); ok.
{error, Error} ->
?ERROR_MSG("Cannot remove HTTP upload directory of ~s@~s: ~p",
[User, Server, Error])
end,
ok
end.
-spec del_tree(file:filename_all()) -> ok | {error, term()}. -spec del_tree(file:filename_all()) -> ok | {error, term()}.