#!/usr/local/bin/ksh
#################################################################################
# Modifications 01/07/03 - Lists are getting duplications due to the lack of a #
# uniq command. Command added. Also adding lines to detect the #
# presence of entries already made. - rmorten #
# 03/22/03 - Forced upgrade (hardware problems on the old cliff) #
# caused us to re-install squid. Directory differences are only #
# the first of many changes that will most likely made. - rmorten #
# 06/24/04 - Poofed /home/bin with a renegade script with some #
# references to bad tmp files. Made a change for a second time #
# to allow 5 part site names. Other changes are lost for good #
# unless I can remember what they were... - rmorten #
#################################################################################
CONFDIR=/usr/local/squid/etc
LOGDIR=$CONFDIR/logs
ALLOWSITE=$CONFDIR/squid.allowlist.sites
ALLOWDOMAIN=$CONFDIR/squid.allowlist.domain
ALLOWIP=$CONFDIR/squid.allowlist.ip
TMP=/tmp/tmpfile.$LOGNAME.$$
BOOT=/home/rmorten/Bin/squidboot
SERIAL=`date '+%y%m%d%H%M%S'`
USAGE="I need at least one domain or site name or IP address to allow:\n\nallow search.x.com\t<- site example\nx.com\t\t\t<- domain example\n1.2.3.4\t\t\t<- IP example"

if [ $# -lt 1 ]
then
echo $USAGE
exit
fi

for x in $*
do
echo $x | awk ' /^[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?$/ {print $1}' >> $TMP.ip
echo $x | awk ' /^[(\-)aA-zZ0-9]+\.[(\-)aA-zZ0-9]+$/ {print "." $1}' | sed 's/\.\./\./g'>> $TMP.domain
echo $x | awk ' /^[(\-)aA-zZ0-9]+\.[(\-)aA-zZ0-9]+\.([(\-)aA-zZ0-9]+)?\.?([(\-)aA-zZ0-9]+)?\.?([(\-)aA-zZ0-9]+)?$/ {print $1}' | awk ' $0 !~ /^[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?$/ {print $1}' >> $TMP.site
done

if [ -s $TMP.site ]
then
cat $TMP.site > $LOGDIR/allow.site.$SERIAL
for site in `cat $TMP.site`
do
grep $site $ALLOWSITE > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo "WARNING: SITE NOT ADDED! $site already found in $ALLOWSITE."
else
echo "$site added"
fi
done
cat $ALLOWSITE >> $TMP.site
cat $TMP.site | sort | uniq > $ALLOWSITE
fi

if [ -s $TMP.domain ]
then
cat $TMP.domain > $LOGDIR/allow.domain.$SERIAL
for domain in `cat $TMP.domain`
do
grep $domain $ALLOWDOMAIN > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo "WARNING: DOMAIN NOT ADDED! $domain already found in $ALLOWDOMAIN."
else
echo "$domain added"
fi
done
cat $ALLOWDOMAIN >> $TMP.domain
cat $TMP.domain | sort | uniq > $ALLOWDOMAIN
fi

if [ -s $TMP.ip ]
then
cat $TMP.ip > $LOGDIR/allow.ip.$SERIAL
for ip in `cat $TMP.ip`
do
grep $ip $ALLOWIP > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo "WARNING: IP NOT ADDED! $ip already found in $ALLOWIP."
else
echo "$ip added"
fi
done
cat $ALLOWIP >> $TMP.ip
cat $TMP.ip | sort -n | uniq > $ALLOWIP
fi

SITECOUNT=`cat $ALLOWSITE | wc -l | awk '{print $1}'`
DOMAINCOUNT=`cat $ALLOWDOMAIN | wc -l | awk '{print $1}'`
IPCOUNT=`cat $ALLOWIP | wc -l | awk '{print $1}'`
echo "\nIP Addresses allowed: \t$IPCOUNT"
echo "Sites allowed: \t$SITECOUNT"
echo "Domains allowed: \t$DOMAINCOUNT\n" 

$BOOT

# Cleanup
rm -fr $TMP*

 

  • Expect the best and be prepared for the worst.

  • It is the service that counts, the product can be found anywhere...

[Under Construction]This website will always be under construction...
The information contained within this website is confidential and only to be used in conjunction with the employment of Richard C. Mortensen.  All other use is unauthorized.
Send mail to webmaster@can-be-scanned.com with questions or comments about this web site.
Copyright © 2000 PR Enterprises, Inc.
Last modified: June 09, 2000