From 37091406369fd9dd1f8d0e66b583739115bc29b7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?cat=20=C3=A6scling?= <11325618-aescling@users.noreply.gitlab.com> Date: Mon, 31 Jul 2023 16:10:34 -0400 Subject: [PATCH] Add optional HTTP to HTTPS redirection script --- visible-to-httpd/binaries/redirect.execline | 76 +++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 visible-to-httpd/binaries/redirect.execline diff --git a/visible-to-httpd/binaries/redirect.execline b/visible-to-httpd/binaries/redirect.execline new file mode 100644 index 0000000..dff964c --- /dev/null +++ b/visible-to-httpd/binaries/redirect.execline @@ -0,0 +1,76 @@ +#!/command/execlineb -WP + +importas -i httpd_execline_jail_directory httpd_execline_jail_directory + +export PATH /binaries +chroot ${httpd_execline_jail_directory} +s6-applyuidgid -U -z + +export program_name redirect.execline + +# see end of script: handle crashes cleanly +if -X -n -t { + http-start-line-parse.execline + multisubstitute { + importas -i -u method http_start_line_parse_method + importas -i requested_resource http_start_line_parse_resource + } + ifelse -n { eltest \${method} =~ HEAD|GET } + { + http-error-response.execline + 501 + "method not implemented" + "unsupported method: \""${method}\" + } + + http-header-parse.execline + supported-hostname-test.execline + importas -i hostname http_header_parse_host + + fdclose 0 + + foreground { + log.execline + "info:" + "client request:" + "for \""${hostname}\"":" + \"${method}\" + \"${requested_resource}\"":" + "redirecting" + } + + # TODO: file length in bytes: SHOULD be provided + backtick -E -n Date { date -u "+%a, %d %b %Y %T GMT" } + backtick -E -n Location { s6-echo -n -- "https://"${hostname}${requested_resource} } + if { + s6-echo -n -- "HTTP/1.1 301 moved permanently\r +Location: "${Location}"\r +Content-Type: "application/xhtml+xml; charset=utf-8"\r +Date: "${Date}"\r +" } + if -t { eltest \${method} = GET } + if { + s6-echo -n -- " + + + + moved permanently + + +

moved permanently

+

this website uses https

+ +\n" + } + # hack + s6-sleep -m 500 +} + http-error-response.execline + 500 + "internal server error" + "(i/o error? timeout?)" -- 2.47.3