From: cat æscling <11325618-aescling@users.noreply.gitlab.com> Date: Mon, 31 Jul 2023 20:10:34 +0000 (-0400) Subject: Add optional HTTP to HTTPS redirection script X-Git-Tag: v1.0.0~6 X-Git-Url: https://awoo.directory/?a=commitdiff_plain;h=37091406369fd9dd1f8d0e66b583739115bc29b7;p=httpd-execline.git Add optional HTTP to HTTPS redirection script --- 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 -- " + +
+ +this website uses https
+ +\n" + } + # hack + s6-sleep -m 500 +} + http-error-response.execline + 500 + "internal server error" + "(i/o error? timeout?)"