Squid redirector: различия между версиями

Материал из noname.com.ua
Перейти к навигацииПерейти к поиску
(Новая: =Squid Redirector= Вспомнил как шутил, и решил записать, что бы не забыть. <PRE> url_rewrite_program /usr/local/redirector/redirector.sh </PR...)
 
Строка 5: Строка 5:
 
<PRE>
 
<PRE>
 
url_rewrite_program /usr/local/redirector/redirector.sh
 
url_rewrite_program /usr/local/redirector/redirector.sh
  +
</PRE>
  +
  +
<PRE>
  +
#!/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
 
</PRE>
 
</PRE>

Версия 11:01, 1 апреля 2011

Squid Redirector

Вспомнил как шутил, и решил записать, что бы не забыть.

url_rewrite_program /usr/local/redirector/redirector.sh
#!/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