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:
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.

View File

@ -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: {}

View File

@ -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 ->
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(<<LUser/binary, $@, LServer/binary>>,
JIDinURL),
UserStr = make_user_string(<<LUser/binary, $@, LServer/binary>>, 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]);
?INFO_MSG("Removed HTTP upload directory of ~s@~s", [User, Server]);
{error, enoent} ->
?DEBUG("Found no HTTP upload directory of ~s@~s",
[User, Server]);
?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.
ok.
-spec del_tree(file:filename_all()) -> ok | {error, term()}.