mod_http_upload: Also expand @HOST@ in 'docroot'

In some environments, it might be desirable to use separate document
roots for each virtual host.
This commit is contained in:
Holger Weiss 2016-02-20 20:13:30 +01:00
parent b971449f12
commit 44f581c3b5
2 changed files with 15 additions and 11 deletions

View File

@ -86,7 +86,8 @@
%% Utility functions.
-export([get_proc_name/2,
expand_home/1]).
expand_home/1,
expand_host/2]).
-include("ejabberd.hrl").
-include("ejabberd_http.hrl").
@ -274,6 +275,7 @@ init({ServerHost, Opts}) ->
fun(B) when is_boolean(B) -> B end,
true),
DocRoot1 = expand_home(str:strip(DocRoot, right, $/)),
DocRoot2 = expand_host(DocRoot1, ServerHost),
case ServiceURL of
undefined ->
ok;
@ -290,7 +292,7 @@ init({ServerHost, Opts}) ->
undefined ->
ok;
Mode ->
file:change_mode(DocRoot1, Mode)
file:change_mode(DocRoot2, Mode)
end,
case Thumbnail of
true ->
@ -310,7 +312,7 @@ init({ServerHost, Opts}) ->
secret_length = SecretLength, jid_in_url = JIDinURL,
file_mode = FileMode, dir_mode = DirMode,
thumbnail = Thumbnail,
docroot = DocRoot1,
docroot = DocRoot2,
put_url = expand_host(str:strip(PutURL, right, $/), ServerHost),
get_url = expand_host(str:strip(GetURL, right, $/), ServerHost),
service_url = ServiceURL}}.
@ -510,6 +512,12 @@ expand_home(Subject) ->
Parts = binary:split(Subject, <<"@HOME@">>, [global]),
str:join(Parts, list_to_binary(Home)).
-spec expand_host(binary(), binary()) -> binary().
expand_host(Subject, Host) ->
Parts = binary:split(Subject, <<"@HOST@">>, [global]),
str:join(Parts, Host).
%%--------------------------------------------------------------------
%% Internal functions.
%%--------------------------------------------------------------------
@ -738,12 +746,6 @@ map_int_to_char(N) when N =< 9 -> N + 48; % Digit.
map_int_to_char(N) when N =< 35 -> N + 55; % Upper-case character.
map_int_to_char(N) when N =< 61 -> N + 61. % Lower-case character.
-spec expand_host(binary(), binary()) -> binary().
expand_host(Subject, Host) ->
Parts = binary:split(Subject, <<"@HOST@">>, [global]),
str:join(Parts, Host).
-spec yield_content_type(binary()) -> binary().
yield_content_type(<<"">>) -> ?DEFAULT_CONTENT_TYPE;
@ -975,8 +977,9 @@ remove_user(User, Server) ->
(node) -> node
end,
sha1),
DocRoot1 = expand_host(expand_home(DocRoot), ServerHost),
UserStr = make_user_string(jid:make(User, Server, <<"">>), JIDinURL),
UserDir = str:join([expand_home(DocRoot), UserStr], <<$/>>),
UserDir = str:join([DocRoot1, UserStr], <<$/>>),
case del_tree(UserDir) of
ok ->
?INFO_MSG("Removed HTTP upload directory of ~s@~s", [User, Server]);

View File

@ -132,6 +132,7 @@ init({ServerHost, Opts}) ->
fun iolist_to_binary/1,
<<"@HOME@/upload">>),
DocRoot2 = mod_http_upload:expand_home(str:strip(DocRoot1, right, $/)),
DocRoot3 = mod_http_upload:expand_host(DocRoot2, ServerHost),
Timers = if MaxDays == infinity -> [];
true ->
{ok, T1} = timer:send_after(?INITIAL_TIMEOUT, sweep),
@ -144,7 +145,7 @@ init({ServerHost, Opts}) ->
access_soft_quota = AccessSoftQuota,
access_hard_quota = AccessHardQuota,
max_days = MaxDays,
docroot = DocRoot2,
docroot = DocRoot3,
timers = Timers}}.
-spec handle_call(_, {pid(), _}, state()) -> {noreply, state()}.