#!/bin/bash # # script for... # * intercepting vieracast http requests, # * acquiring the content to a local mirror, # * and redirecting/intercepting requests so that the content can be modified # # developed from http://customvieracast.blogspot.com/2010/05/setting-up-development-environment.html # by Paul Mansfield # # this script is fired up as a background process by squid, and each request is fed on STDIN; # http://www.squid-cache.org/Doc/config/url_rewrite_program/ # # place this script into /usr/lib/squid and add the following into /etc/squid/squid.conf like so: # url_rewrite_program /usr/lib/squid/mirror_and_redirect.sh # only mangle requests from your viera TV VIERADEVICE='127.0.0.1/a0520' # where acquired content is stored VIERADIR='/srv/www/htdocs/viera/' # the URL to access the stored content VIERAHTTP='http://localhost/viera' # the user agent of a viera TV, which is necessary to fool the vieracast web servers into giving us content VIERAAGENT='**********************************************************************************************************************************************************************************************************************==' # misc log files MIRRORLOG='/var/log/squid/mirror_and_redirect.log' SLURPLOG='/var/log/squid/slurping.log' # main loop - listens for URL requests from squid while read url client slash fqdn rest do DDD=`date +%Y%m%d-%H%M%S` echo "$DDD url '$url' client '$client' VIERADEVICE '$VIERADEVICE'" >> $MIRRORLOG if [ "$client" = "$VIERADEVICE" ] ; then DDD=`date +%Y%m%d-%H%M%S` filename=`echo $url | sed 's^http://^^g' | sed 's^?.*^^g'` echo "$DDD url '$url' client '$client' filename '$filename'" >> $MIRRORLOG if [ -f $VIERADIR/$filename ]; then # We found a matching local file to replace, so log the redirect and redirect to it echo "$DDD R $VIERAHTTP/$filename" >> $MIRRORLOG echo "$VIERAHTTP/$filename" else # No matching local file, so log the URL, slurp up the content with viera's useragent, and don't modify the URL. echo "$DDD S $url" >> $MIRRORLOG wget --no-proxy --directory-prefix $VIERADIR -a $SLURPLOG -t 1 -nc -xU "$VIERAAGENT" $url echo "" fi else echo "$DDD I" >> $MIRRORLOG echo "" fi done # end of mirror_and_redirect.sh