Skip to content

Instantly share code, notes, and snippets.

@JamesTheAwesomeDude
Last active June 21, 2018 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesTheAwesomeDude/b845f0f9f06cb0db42918107e9eda18c to your computer and use it in GitHub Desktop.
Save JamesTheAwesomeDude/b845f0f9f06cb0db42918107e9eda18c to your computer and use it in GitHub Desktop.
shell script used as "CGI handler" to use .url files as "hotlinks"
#this does NOT have to be in webroot!
AddType text/x-url url
Action text/x-url /cgi-bin/webroot/relative/path/to/URL.cgi
[InternetShortcut]
URL=https://gist.github.com/b845f0f9f06cb0db42918107e9eda18c
# include this from your main hiawatha.conf, or just put its contents in
CGIHandler = /absolute/path/to/URL.cgi:url
# Don't forget to add "CGIHandler = /absolute/path/to/URL.cgi" to cgi-wrapper.conf if you're using CGIWrapper
#!/bin/sh
while read -r line; do
case "${line}" in
"URL="*|"http"*)
url="${line#"URL="}"
break
;;
esac
done < "${PATH_TRANSLATED="${1}"}"
if [ ! -z "${url}" ]; then
status="302 Found"
content_type="text/x-url"
elif [ -r "${PATH_TRANSLATED}" ]; then
status="200 OK"
content_type="application/x-url"
elif [ -e "${PATH_TRANSLATED}" ]; then
status="403 Access Denied"
fi
exec printf "Status: %s\r\n${content_type+"Content-Type: %s\\r\\n"}${url+"Location: %s\\r\\n"}\r\n"\
"${status?"500 Internal Server Error"}"\
${content_type+"${content_type}"}\
${url:+"${url}"}
exec cat "${PATH_TRANSLATED}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment