]> granicus.if.org Git - ejabberd/commitdiff
mod_http_upload: Also expand @HOST@ in 'docroot'
authorHolger Weiss <holger@zedat.fu-berlin.de>
Sat, 20 Feb 2016 19:13:30 +0000 (20:13 +0100)
committerHolger Weiss <holger@zedat.fu-berlin.de>
Sat, 20 Feb 2016 19:13:30 +0000 (20:13 +0100)
In some environments, it might be desirable to use separate document
roots for each virtual host.

src/mod_http_upload.erl
src/mod_http_upload_quota.erl

index 24cf8aaf13b6e314363f5ebdef2e8f6922431644..d360ac195c0376467567f0e0d10c0e8f634519e5 100644 (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]);
index db0b4aa4caf16267830d21f468ccaa288397590d..a5ae0c3cc0141fc6046b387388cf2704caa9a155 100644 (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()}.