Last active
June 21, 2018 19:32
-
-
Save James-E-A/b845f0f9f06cb0db42918107e9eda18c to your computer and use it in GitHub Desktop.
shell script used as "CGI handler" to use .url files as "hotlinks"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[InternetShortcut] | |
URL=https://gist.github.com/b845f0f9f06cb0db42918107e9eda18c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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