mod_http_upload: Expand @HOME@ and @HOST@ keywords
Replace @HOST@ with the virtual host name if the keyword is specified within the "put_url", "get_url", and/or "service_url" values. Also, replace @HOME@ with the home directory of the user running ejabberd if this keyword is specified within the "docroot" value.
This commit is contained in:
parent
f4950cdc83
commit
6db50940a1
|
@ -83,28 +83,30 @@ The configurable mod_http_upload options are:
|
||||||
|
|
||||||
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 '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: "https://@HOST@:5443")
|
||||||
|
|
||||||
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. Note that @HOST@ can NOT be specified for this option in the
|
uploads. The keyword @HOST@ is replaced with the virtual host name.
|
||||||
configuration file, but the virtual host name is used as part of the URL
|
|
||||||
by default.
|
|
||||||
|
|
||||||
- get_url (default: $put_url)
|
- get_url (default: $put_url)
|
||||||
|
|
||||||
This option specifies the initial part of the GET URLs used for
|
This option specifies the initial part of the GET URLs used for
|
||||||
downloading the files. By default, it is set to the same value as the
|
downloading the files. By default, it is set to the same value as the
|
||||||
'put_url', but you can set it to a different value in order to have the
|
'put_url', but you can set it to a different value in order to have the
|
||||||
files served by a proper HTTP server such as Nginx or Apache.
|
files served by a proper HTTP server such as Nginx or Apache. The keyword
|
||||||
|
@HOST@ is replaced with the virtual host name.
|
||||||
|
|
||||||
- service_url (default: 'undefined')
|
- service_url (default: 'undefined')
|
||||||
|
|
||||||
If a 'service_url' is specified, HTTP upload slot requests are forwarded
|
If a 'service_url' is specified, HTTP upload slot requests are forwarded
|
||||||
to this external service instead of being handled by mod_http_upload
|
to this external service instead of being handled by mod_http_upload
|
||||||
itself. An HTTP GET query such as the following is issued whenever an
|
itself. The keyword @HOST@ is replaced with the virtual host name.
|
||||||
HTTP upload slot request is accepted as per the 'access' rule:
|
|
||||||
|
An HTTP GET query such as the following is issued whenever an HTTP upload
|
||||||
|
slot request is accepted as per the 'access' rule:
|
||||||
|
|
||||||
http://localhost:5444/?jid=juliet%40example.com&size=10240&name=example.jpg
|
http://localhost:5444/?jid=juliet%40example.com&size=10240&name=example.jpg
|
||||||
|
|
||||||
|
|
|
@ -113,10 +113,10 @@ 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://", ServerHost/binary>>
|
(_) -> <<"https://@HOST@">>
|
||||||
end,
|
end,
|
||||||
<<"https://", ServerHost/binary>>),
|
<<"https://@HOST@">>),
|
||||||
[_, ProcHost | _] = binary:split(PutURL,
|
[_, ProcHost | _] = binary:split(expand_host(PutURL, ServerHost),
|
||||||
[<<"http://">>, <<"https://">>,
|
[<<"http://">>, <<"https://">>,
|
||||||
<<":">>, <<"/">>], [global]),
|
<<":">>, <<"/">>], [global]),
|
||||||
Proc = gen_mod:get_module_proc(ProcHost, ?PROCNAME),
|
Proc = gen_mod:get_module_proc(ProcHost, ?PROCNAME),
|
||||||
|
@ -218,7 +218,7 @@ init({ServerHost, Opts}) ->
|
||||||
fun(<<"http://", _/binary>> = URL) -> URL;
|
fun(<<"http://", _/binary>> = URL) -> URL;
|
||||||
(<<"https://", _/binary>> = URL) -> URL
|
(<<"https://", _/binary>> = URL) -> URL
|
||||||
end,
|
end,
|
||||||
<<"https://", ServerHost/binary, ":5443">>),
|
<<"https://@HOST@:5443">>),
|
||||||
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
|
||||||
|
@ -251,10 +251,10 @@ init({ServerHost, Opts}) ->
|
||||||
{ok, #state{server_host = ServerHost, host = Host, name = Name,
|
{ok, #state{server_host = ServerHost, host = Host, name = Name,
|
||||||
access = Access, max_size = MaxSize,
|
access = Access, max_size = MaxSize,
|
||||||
secret_length = SecretLength, jid_in_url = JIDinURL,
|
secret_length = SecretLength, jid_in_url = JIDinURL,
|
||||||
docroot = DocRoot,
|
docroot = expand_home(DocRoot),
|
||||||
put_url = str:strip(PutURL, right, $/),
|
put_url = expand_host(str:strip(PutURL, right, $/), ServerHost),
|
||||||
get_url = str:strip(GetURL, right, $/),
|
get_url = expand_host(str:strip(GetURL, right, $/), ServerHost),
|
||||||
service_url = ServiceURL}}.
|
service_url = expand_host(ServiceURL, ServerHost)}}.
|
||||||
|
|
||||||
-spec handle_call(_, {pid(), _}, state()) -> {noreply, state()}.
|
-spec handle_call(_, {pid(), _}, state()) -> {noreply, state()}.
|
||||||
|
|
||||||
|
@ -596,6 +596,19 @@ 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 =< 35 -> N + 55; % Upper-case character.
|
||||||
map_int_to_char(N) when N =< 61 -> N + 61. % Lower-case character.
|
map_int_to_char(N) when N =< 61 -> N + 61. % Lower-case character.
|
||||||
|
|
||||||
|
-spec expand_home(binary()) -> binary().
|
||||||
|
|
||||||
|
expand_home(Subject) ->
|
||||||
|
{ok, [[Home]]} = init:get_argument(home),
|
||||||
|
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).
|
||||||
|
|
||||||
-spec yield_content_type(binary()) -> binary().
|
-spec yield_content_type(binary()) -> binary().
|
||||||
|
|
||||||
yield_content_type(<<"">>) -> <<"application/octet-stream">>;
|
yield_content_type(<<"">>) -> <<"application/octet-stream">>;
|
||||||
|
@ -692,7 +705,7 @@ remove_user(User, Server) ->
|
||||||
sha1),
|
sha1),
|
||||||
UserStr = make_user_string(<<LUser/binary, $@, LServer/binary>>,
|
UserStr = make_user_string(<<LUser/binary, $@, LServer/binary>>,
|
||||||
JIDinURL),
|
JIDinURL),
|
||||||
UserDir = str:join([DocRoot, UserStr], <<$/>>),
|
UserDir = str:join([expand_home(DocRoot), UserStr], <<$/>>),
|
||||||
case del_tree(UserDir) of
|
case del_tree(UserDir) of
|
||||||
ok ->
|
ok ->
|
||||||
?INFO_MSG("Removed HTTP upload directory of ~s@~s",
|
?INFO_MSG("Removed HTTP upload directory of ~s@~s",
|
||||||
|
|
Loading…
Reference in New Issue