Squid redirector
Материал из noname.com.ua
Версия от 15:43, 28 сентября 2012; Sirmax (обсуждение | вклад)
Squid Redirector
Вспомнил как шутил, и решил записать, что бы не забыть.
iptables
-A PREROUTING -s 10.0.192.0/24 -m tcp -p tcp --dport 80 -j REDIRECT --to-port 13128
squid
http_port 127.0.0.1:13128 transparent http_port 10.0.192.254:13128 transparent http_port 172.16.49.65:3128 url_rewrite_program /usr/local/redirector/redirector.sh url_rewrite_children 100
redirect script
#!/bin/bash #$|=1; #$count = 0; #$pid = $$; LOG='/tmp/redir.log' WGET='/usr/bin/wget' BASENAME='/usr/bin/basename' MOGRIFY='/usr/bin/mogrify' HTTP_ROOT="/var/www/localhost/htdocs" NEW_URL_BASE="http://127.0.0.1" #URL <SP> client_ip "/" fqdn <SP> user <SP> method [<SP> kvpairs]<NL> COUNT=0 while read L do # echo L=~~~""$L"~~~", COUNT=$COUNT >> $LOG # echo $L >> $LOG URL=`echo $L | awk '{ print $1 }'` IP=`echo $L | awk '{ print $2}'` FQDN=`echo $L | awk '{ print $3 }'` USER=`echo $L | awk '{ print $4 }'` METHOD=`echo $L | awk '{ print $5 }'` OTHER=`echo $L | awk '{ print $6 }'` # echo URL="~~~"$URL"~~~" >> $LOG # echo RES=$URL $IP $FQDN $USER $METHOD $OTHER >> $LOG if echo $URL | egrep "png$|jpeg$|gif$|jpg$" >/dev/null 2>/dev/null then # echo REWRITE IT >> $LOG # Выяснить расширение файла EXT=` $BASENAME $URL | awk '{print a[split($1,a,".")];}'` # echo $WGET -q -O ${HTTP_ROOT}/$$"_"${COUNT}.${EXT} ${URL} >> $LOG $WGET -q -O ${HTTP_ROOT}/$$"_"${COUNT}.${EXT} ${URL} # Тут вставить выбор фильтра # $MOGRIFY -blur 4 ${HTTP_ROOT}/$$"_"${COUNT}.${EXT} $MOGRIFY -blur 4 ${HTTP_ROOT}/$$"_"${COUNT}.${EXT} # $MOGRIFY -flip ${HTTP_ROOT}/$$"_"${COUNT}.${EXT} # echo $MOGRIFY -flip ${HTTP_ROOT}/$$"_"${COUNT}.${EXT} >> $LOG NEW_URL=`echo ${NEW_URL_BASE}/$$"_"${COUNT}.${EXT}` echo $NEW_URL # echo "NEW_URL=~~~"$NEW_URL"~~~" >> $LOG else # echo "NEW_URL=URL~~~"$URL"~~~" >> $LOG echo $URL fi let COUNT=COUNT+1 done exit