Skip to content

Instantly share code, notes, and snippets.

Created August 10, 2014 10:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/9774aea9b6d603f9afec to your computer and use it in GitHub Desktop.
Save anonymous/9774aea9b6d603f9afec to your computer and use it in GitHub Desktop.
rss_proxy.cgi
#!/bin/bash
PATH="/mnt/data/www/temp_rss/"
DATE=/bin/date
STAT=/usr/bin/stat
SED=/bin/sed
TOUCH=/usr/bin/touch
EXECPATH="/mnt/data/www/rss_proxy"
TERM=""
if [ -z "$QUERY_STRING" ] || [[ $QUERY_STRING == url* ]]
then
echo "Content-type: text/html; charset=UTF-8"
echo
echo "<html><head></head><body>"
echo "<h3>Hi, and welcome to the fanfiction.net story RSS proxy! </h3>"
echo "<form action=\"rss_proxy.cgi\" method=\"get\">&raquo;&nbsp; fanfiction.net URL:"
echo "<input type=\"text\" name=\"url\" style=\"width: 50%; \" />"
echo "<input type=\"submit\" value=\"Submit\"></form><br>"
TERM="yes"
fi
if [[ $QUERY_STRING == url* ]]
then
echo "Paste this link into your RSS reader: "
LINK=$(echo $QUERY_STRING |/bin/sed -e "s@.*%2Fs%2F@@" -e "s@%2F.*@@")
LINK="http://feephome.no-ip.org/~feep/rss_proxy.cgi?$LINK"
echo "<a href=\"$LINK\">$LINK</a>"
fi
if [ ! -z $TERM ]
then
echo "</body></html>"
exit 0
fi
# echo "<html><head></head><body>"
# echo $QUERY_STRING
# echo "</body></html>"
# exit 0
FN="$PATH${QUERY_STRING/&*/}"
if [ -e "$FN" ]
then
AGE=$(($($DATE +%s) - $($STAT -c %Y "$FN")))
if [ "$AGE" -gt "$((60*15))" -o "$AGE" -lt "0" ]
then
# only regen if older than 15min
# first, force only one regen at a time
$TOUCH "$FN"
FID=$(echo "$QUERY_STRING" |/usr/bin/md5sum |/usr/bin/cut -d " " -f1)
/usr/bin/flock --nb /tmp/$FID -c "$EXECPATH $QUERY_STRING >/dev/null"
fi
else
# always regen
FID=$(echo "$QUERY_STRING" |/usr/bin/md5sum |/usr/bin/cut -d " " -f1)
/usr/bin/flock --nb /tmp/$FID -c "$EXECPATH $QUERY_STRING >/dev/null"
fi
echo "Content-type: application/rss+xml; charset=UTF-8"
echo
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
echo "<rss version=\"2.0\">"
/bin/cat "$FN" |$SED -e "s@m.fanfiction@fanfiction@"
echo "</rss>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment