diff --git a/Makefile.in b/Makefile.in index c6202950f..c9b0e9650 100644 --- a/Makefile.in +++ b/Makefile.in @@ -324,7 +324,7 @@ BINARIES=$(DEPSDIR)/epam/priv/bin/epam $(DEPSDIR)/eimp/priv/bin/eimp $(DEPSDIR)/ DEPS_FILES_FILTERED=$(filter-out $(BINARIES) $(DEPSDIR)/elixir/ebin/elixir.app,$(DEPS_FILES)) DEPS_DIRS=$(sort $(DEPSDIR)/ $(foreach DEP,$(DEPS),$(DEPSDIR)/$(DEP)/) $(dir $(DEPS_FILES))) -MAIN_FILES=$(filter-out %/configure.beam,$(call FILES_WILDCARD,$(EBINDIR)/*.beam $(EBINDIR)/*.app priv/msgs/*.msg priv/css/*.css priv/img/*.png priv/js/*.js priv/lib/* priv/mod_invites/* priv/mod_invites/static/* priv/mod_invites/static/bootstrap4/css/bootstrap.min.css priv/mod_invites/static/bootstrap4/js/bootstrap.min.js priv/mod_invites/static/jquery/jquery.min.js \ +MAIN_FILES=$(filter-out %/configure.beam,$(call FILES_WILDCARD,$(EBINDIR)/*.beam $(EBINDIR)/*.app priv/msgs/*.msg priv/css/*.css priv/img/*.png priv/js/*.js priv/lib/* priv/mod_invites/* priv/mod_invites/static/* priv/mod_invites/static/bootstrap/css/bootstrap.min.css priv/mod_invites/static/bootstrap/js/bootstrap.min.js priv/mod_invites/static/jquery/jquery.min.js \ priv/mod_invites/static/logos/* include/*.hrl COPYING)) MAIN_DIRS=$(sort $(dir $(MAIN_FILES)) priv/bin priv/sql priv/lua priv/mod_invites) diff --git a/src/ejabberd_http.erl b/src/ejabberd_http.erl index ca0d24780..6af2e7762 100644 --- a/src/ejabberd_http.erl +++ b/src/ejabberd_http.erl @@ -33,7 +33,7 @@ accept/1, receive_headers/1, recv_file/2, listen_opt_type/1, listen_options/0, apply_custom_headers/2]). --export([get_url/4, get_auto_url/2, get_auto_urls/2, find_handler_port_path/2]). +-export([get_url/4, get_auto_url/2, get_auto_urls/2, find_handler_port_path/2, url_decode_q_split_normalize/1]). -export([init/3]). -deprecate({get_auto_url, 2}). diff --git a/src/mod_invites_http.erl b/src/mod_invites_http.erl index 3cebd6f14..11677f993 100644 --- a/src/mod_invites_http.erl +++ b/src/mod_invites_http.erl @@ -66,6 +66,14 @@ %% @format-begin landing_page(Host, Invite) -> + case landing_page_tmpl(Host) of + <<>> -> + <<>>; + Tmpl -> + render_landing_page_url(Tmpl, Host, Invite) + end. + +landing_page_tmpl(Host) -> case mod_invites_opt:landing_page(Host) of none -> <<>>; @@ -75,12 +83,12 @@ landing_page(Host, Invite) -> ?WARNING_MSG("'auto' URL configured for mod_invites but no request_handler found in your ~s listeners configuration.", [Host]), <<>>; - AutoURL0 -> - AutoURL = misc:expand_keyword(<<"@HOST@">>, AutoURL0, Host), - render_landing_page_url(<>, Host, Invite) + AutoURL -> + ExpandedAutoURL = misc:expand_keyword(<<"@HOST@">>, AutoURL, Host), + <> end; Tmpl -> - render_landing_page_url(Tmpl, Host, Invite) + Tmpl end. render_landing_page_url(Tmpl, Host, Invite) -> @@ -116,7 +124,7 @@ process([Token | _] = LocalPath, #request{host = Host, lang = Lang} = Request) - process_valid_token(LocalPath, Request, Invite) end; false -> - ?NOT_FOUND(render(Host, Lang, <<"invite_invalid.html">>, ctx(Request, LocalPath))) + ?NOT_FOUND(render(Host, Lang, <<"invite_invalid.html">>, ctx(Request, LocalPath, Token))) catch _:not_found -> ?NOT_FOUND; @@ -227,7 +235,7 @@ process_register_post(Invite, render_bad_request(Host, Invite, <<"register_error.html">>, - [{message, Msg} | ctx(Request, LocalPath)]) + [{message, Msg} | ctx(Request, LocalPath, Token)]) end end catch @@ -330,20 +338,29 @@ app_ctx(Host, AppID, Lang, Ctx) -> ctx(#request{host = Host, path = Path, lang = Lang}, - LocalPath) -> + LocalPath, + Token) -> + OriginalPath = case landing_page_tmpl(Host) of + <<>> -> + Path; + Tmpl -> + Url = render_url(Tmpl, [{invite, [{token, Token}]}, {host, Host}]), + #{path := OPath} = uri_string:parse(Url), + {LPath, _Q} = ejabberd_http:url_decode_q_split_normalize(OPath), + LPath + end, Base = iolist_to_binary(uri_string:normalize( - lists:join(<<"/">>, Path -- LocalPath))), + lists:join(<<"/">>, OriginalPath -- LocalPath))), SiteName = mod_invites_opt:site_name(Host), - [{base, Base}, ?STATIC_CTX, ?SITE_NAME_CTX(SiteName), ?LANG(Lang)]. - + [{base, Base}, ?STATIC_CTX, ?SITE_NAME_CTX(SiteName), ?LANG(Lang)]; ctx(Invite, #request{host = Host} = Request, LocalPath) -> [{invite, invite_to_proplist(Invite)}, {uri, mod_invites:token_uri(Invite)}, {domain, Host}, {token, Invite#invite_token.token}, {registration_url, <<(Invite#invite_token.token)/binary, "/", ?REGISTRATION/binary>>} - | ctx(Request, LocalPath)]. + | ctx(Request, LocalPath, Invite#invite_token.token)]. apps_json(Host, Lang, Ctx) -> AppsBins = render(Host, Lang, <<"apps.json">>, Ctx),