summaryrefslogtreecommitdiff
path: root/src/safety/reports
diff options
context:
space:
mode:
Diffstat (limited to 'src/safety/reports')
-rwxr-xr-xsrc/safety/reports47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/safety/reports b/src/safety/reports
new file mode 100755
index 0000000..e9dd9fa
--- /dev/null
+++ b/src/safety/reports
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+render_redirect() {
+ declare -i i=$1
+ cat <<EOF
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>Redirect</title>
+</head>
+<body>
+ <script>
+ window.history.go(-$i);
+ </script>
+</body>
+</html>
+EOF
+}
+
+post() {
+ local dir="$(dirname -- "$0")"
+ file="$(mktemp -- "$dir/reports.d/$(date +%Y-%m-%dT%H:%M:%S)-XXXXXXXXXX")"
+ cat > "$file"
+ printf -- '%s\r\n' \
+ 'Status: 201 Created' \
+ 'Content-Type: text/html; charset=utf-8' \
+ "Location: ${SCRIPT_NAME}/redirect" \
+ ''
+ render_redirect 2
+}
+
+main() {
+ pwd
+ if [[ "$REQUEST_METHOD" == POST ]]; then
+ post
+ elif [[ "$REQUEST_METHOD" == GET ]] && [[ "$PATH_INFO" = */redirect ]]; then
+ render_redirect 2
+ else
+ printf -- '%s\r\n' \
+ 'Status: 403 Forbidden' \
+ ''
+ render_redirect 1
+ fi
+}
+
+main "$@"