#!/bin/csh -f # USAGE: preposition [recur-depth [host policy:local/domain/any]] # # Copyright (c) 1999-2000 # by iMimic Networking, Inc., Houston, Texas # # This software is furnished under a license and may be used and copied only # in accordance with the terms of such license and with the inclusion of the # above copyright notice. This software or any other copies thereof may not # be provided or otherwise made available to any other person. No title to # or ownership of the software is hereby transferred. # # $Id: preposition,v 1.1.1.1 2003/02/21 16:47:37 lmwang Exp $ # onintr cleanup setenv PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:${PATH} if ($#argv < 2) then exit 1 endif set rule = $1 shift set proxdir = "/usr/local/prox" set proxconf = "${proxdir}/etc/prox.conf" set useragent = 'DataReactor Core (iMimic Networking, Inc.)' set rundir = /www/log/TMP/RULE${rule} set quota = "50m" set lockfile = ${rundir}/LOCK.PREPOSITION.${rule} set timeout = 300 set retrytime = 30 if (-e ${proxconf}) then set port = `awk 'BEGIN {port = 3128} $1 ~ /^[pP][oO][rR][tT]$/ {port = $2} END {print port}' ${proxconf}` else set port = 3128 endif setenv http_proxy "http://127.0.0.1:${port}/" setenv ftp_proxy "http://127.0.0.1:${port}/" setenv WGETRC /usr/local/prox/etc/wgetrc if ($#argv == 0) then exit 1 endif set url = "$1" shift set recurargs = "" if ($#argv > 0) then set recurlevel = "$1" shift # Make sure that it is a positive number # 0 in 'wget' means infinite, but we want it to mean no recursion expr ${recurlevel} / ${recurlevel} >& /dev/null if (! $status) then set recurargs = ( --recursive --level=${recurlevel} ) endif endif set domainargs = "" # default to local-only if ($#argv > 0) then set domainpolicy = "$1" if (x"$domainpolicy" =~ x[Dd][Oo][Mm][Aa][Ii][Nn]) then set domainargs = ( --span-hosts --domains=`awk -v x="$url" 'END {x = x "/"; x = substr(x,index(x,".")+1); print substr(x,1,index(x,"/")-1)}' < /dev/null` ) else if (x"$domainpolicy" =~ x[Aa][Nn][Yy] || x"$domainpolicy" =~ x[Rr][Ee][Mm][Oo][Tt][Ee]) then set domainargs = "--span-hosts" endif endif set retry mkdir -p ${rundir} && chmod 777 ${rundir} >& /dev/null cd ${rundir} >& /dev/null if ($status || ! -w ${rundir}) then exit 1 endif ln -s /dev/null ${lockfile} >& /dev/null && unset retry while ($?retry) @ timeout -= ${retrytime} if ($timeout < 0) then exit 1 endif sleep ${retrytime} ln -s /dev/null ${lockfile} >& /dev/null && unset retry end wget --no-directories --quota=${quota} "--user-agent=${useragent}" --save-headers --delete-after "--header=Cache-Control: max-age=0" --server-response --no-parent --no-host-lookup ${recurargs} ${domainargs} ${url} >& /dev/null cleanup: rm -rf ${lockfile} ${rundir} >& /dev/null exit 0