blob: e9dd9fa16ced6b1447821ee4825f37890e0e78ae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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 "$@"
|