 |

 |
|
 |
| |
08-05-2005, 10:57 AM
|
#22
|
Country: 
|
oops, i didn't explain it right. when i kill it manually with its pid it works, but when i try to kill it with the init script, e.g. /etc/init.d/peerguardnf stop, which is a killall call, something gets broken - but not always. i also tried it with a renamed script, so that it cannot kill itself, didn't help. it seems the only way for me to kill it in a clean way is doing it manually with the pid. strange situation. unfortunately pg seems to have a startup routine that spawns the real pg process, so one cannot use a pid file, right?
|
|
|
|
| |
08-23-2005, 04:34 AM
|
#23
|
Country: 
|
scripts I'm using...
Improved from JFM's suggestions before, here's what I'm using for an update script...
Most notably, it only downloads new blocklists when they're updated,
so it doen't waste bandwidth needlessly, and doesn't hurt blocklist.org
much to check.
It also only restarts peerguardian if an update took place, which leaves the
computer unprotected for a minimal amount of time and doesn't slam the
processor unnecessarily on weak firewall boxes.
Code:
#!/bin/sh
#
# Copyright (C) 2005 /meth/usr
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# peerguardianupdate
# Make sure PG_ETC points to the directory where
# you want to put your downloaded blocklists.
# Remove the lists you don't want to download and
# use from BLOCKLISTS.
PG_ETC=/etc/peerguardian/
BLOCKLISTS="ads edu gov p2p spy"
endscript () {
date +"------------ "%F" "%X" "%Z" End PeerGuardian update"
exit $1
}
date +"------------ "%F" "%X" "%Z" Begin PeerGuardian update"
cd "$PG_ETC"
UPDATED=""
for i in $BLOCKLISTS ; do
TIMESTAMP=0
if [ -e $i.p2b.gz ] ; then
TIMESTAMP=`stat --format=%y $i.p2b.gz`
echo "File $i.p2b.gz last updated $TIMESTAMP"
TIMESTAMP=`stat --format=%Y $i.p2b.gz`
fi
wget -N http://blocklist.org/$i.p2b.gz
if [ `stat --format=%Y $i.p2b.gz` -gt $TIMESTAMP ] ; then
UPDATED=$i
fi
done
# if none of the blockfiles were updated,
# then just exit
if [ -z $UPDATED ] ; then
echo "No blocklists needed updating."
endscript 0
fi
rm -f *.p2p > /dev/null 2>&1
for i in $BLOCKLISTS ; do
gunzip -c $i.p2b.gz > $i.p2b
peerguardnf -n $i.p2b
rm $i.p2b
BLOCKLISTSCAT="$BLOCKLISTSCAT $i.p2b.p2p"
done
cat $BLOCKLISTSCAT | peerguardnf -f merged.p2b.p2p
for i in $BLOCKLISTS ; do
rm $i.p2b.p2p
done
# uncomment below to unblock Yahoo! Mail and whatever else needs unblocking here
#grep -v -i "yahoo\!" merged.p2b.p2p | grep -v -i "spite media" | grep -v "Trendstep Ltd" > merged.p2b.p2p.tmp
#mv merged.p2b.p2p.tmp merged.p2b.p2p
/usr/local/bin/restartpg
endscript 0
I put it in fcrontab to run a minute after startup and every 6 hours.
It also outputs to a log file:
Code:
# Refresh PeerGuardian's blocklist
@first(1) 6h peerguardianupdate >> /path/to/your/peerguardianupdate.log 2>&1
and the restart script (adjust paths as necessary):
Code:
#!/bin/sh
#
# Copyright (C) 2005 /meth/usr
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
PG_CONF=/etc/peerguardian.conf
PG_LOG=/var/log/peerguardian.log
killall peerguardnf > /dev/null 2>&1
sleep 4
peerguardnf -h -m -d -c "$PG_CONF" -l "$PG_LOG"
sleep 1
# change iptables rules from defaults to ones that work on a firewall
iptables -D CUSTOMFORWARD -j PEERGUARDFORWARD > /dev/null 2>&1
iptables --flush PEERGUARDFORWARD > /dev/null 2>&1
iptables --delete-chain PEERGUARDFORWARD > /dev/null 2>&1
iptables --new PEERGUARDFORWARD
iptables -D INPUT -j QUEUE
iptables -D OUTPUT -j QUEUE
iptables -A PEERGUARDFORWARD -j QUEUE
iptables -A CUSTOMFORWARD -j PEERGUARDFORWARD
exit 0
...the restart script is written for using peerguardian on a dedicated firewall.
Use the restart script from an rc file to get it up and running at system startup.
Then everything works fully automated (as it should  )
enjoy!
|
|
|
|
| |
09-08-2005, 10:38 AM
|
#29
|
Country: 
|
Script and installation instructions
I took /meth/usr's script, had some days of learning how some things work and made a script for easy handling PeerGuardian. Since all this took me much time, i will tell you how i install it and get it working automatically on my Debian machine.
I think that's usefull for newbies.
jre
Features:
- This script only downloads new blocklists (traffic saving)
- has three options: start, stop and restart
- allows to easily manage, what blocklists are downloaded
- allows to have unblocked IPs
- makes a backup of the old blocklist
- makes a backup of the log file and starts a new one, so the log stays small
- ...
- and is very easy to handle because it's just one file
Installation:
Save the script-text as a file called peerguardian.sh
In the console change to the directory where you have just saved the file and type (as root):
Code:
cp peerguardian.sh /usr/local/bin
mkdir /etc/peerguardian
In debian this way the ownership and file permissions are set to "-rwxr-xr-x 1 root staff" (It's important that the script is executable(x), you can do this with chmod)
You can now handle PeerGuardian by just typing (as root) in a console one of the following commands:
Code:
peerguardian.sh start
IF there are updates for the blocklists available they are updated, the old blocklist and the log-file are backuped and PeerGuardian is started.
Code:
peerguardian.sh restart
If there are updates for the blocklists available they are updated, the old blocklist and the log-file are backuped, old PeerGuardian processes are killed and after 4 seconds PeerGuardian is started again.
Code:
peerguardian.sh stop
PeerGuardian is stopped.
To automatically start PeerGuardian at bootup type the following (as root in the console):
Code:
ln -s /usr/local/bin/peerguardian.sh /etc/init.d/peerguardian.sh
ln -s /etc/init.d/peerguardian.sh /etc/rc0.d/K20peerguardian.sh
ln -s /etc/init.d/peerguardian.sh /etc/rc2.d/S95peerguardian.sh
ln -s /etc/init.d/peerguardian.sh /etc/rc3.d/S95peerguardian.sh
ln -s /etc/init.d/peerguardian.sh /etc/rc4.d/S95peerguardian.sh
ln -s /etc/init.d/peerguardian.sh /etc/rc5.d/S95peerguardian.sh
ln -s /etc/init.d/peerguardian.sh /etc/rc6.d/K20peerguardian.sh
To automatically update the already running PeerGuardian use cron. In my example it updates everyday at 4:37 AM. Type as root in the console:
Now you're in an editor, insert here the next two lines (one line text and one free line) and save the file:
Code:
37 4 * * * /usr/local/bin/peerguardian.sh update
And here is the Script:
Code:
#!/bin/sh
# Update new blocklists and start/stop/restart PeerGuardian
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# testdescription
#
# Make sure PG_ETC points to the directory where
# you want to put your downloaded blocklists.
# Remove the lists you don't want to download and
# use from BLOCKLISTS.
PG_ETC=/etc/peerguardian/
BLOCKLISTS="ads p2p spy phishing bogon"
#BLOCKLISTS="ads edu gov p2p spy phishing bogon"
PG_CONF=/etc/PG.conf
PG_LOG=/var/log/PG.log
PG_LIST=/etc/p2p.p2b.p2p
endscript () {
date +"------------ "%F" "%X" "%Z" End PeerGuardian Script"
exit $1
}
date +"------------ "%F" "%X" "%Z" Begin PeerGuardian $1"
case "$1" in
'start')
cd "$PG_ETC"
# check if blockfiles were updated:
UPDATED=""
for i in $BLOCKLISTS ; do
TIMESTAMP=0
if [ -e $i.p2b.gz ] ; then
TIMESTAMP=`stat --format=%y $i.p2b.gz`
echo "File $i.p2b.gz last updated $TIMESTAMP"
TIMESTAMP=`stat --format=%Y $i.p2b.gz`
fi
wget -N http://blocklist.org/$i.p2b.gz
if [ `stat --format=%Y $i.p2b.gz` -gt $TIMESTAMP ] ; then
UPDATED=$i
fi
done
# if none of the blockfiles were updated:
if [ -z $UPDATED ] ; then
echo "No blocklists needed updating."
echo "Starting PeerGuardian"
mv $PG_LOG $PG_LOG.backup
peerguardnf -h -m -d -c "$PG_CONF" -l "$PG_LOG"
endscript 0
fi
# if any blockfiles were updated:
rm -f *.p2p > /dev/null 2>&1
for i in $BLOCKLISTS ; do
gunzip -c $i.p2b.gz > $i.p2b
peerguardnf -n $i.p2b
rm $i.p2b
BLOCKLISTSCAT="$BLOCKLISTSCAT $i.p2b.p2p"
done
cat $BLOCKLISTSCAT | peerguardnf -f merged.p2b.p2p
for i in $BLOCKLISTS ; do
rm $i.p2b.p2p
done
# uncomment below to unblock Yahoo! Mail and whatever
# else needs unblocking here. Do this also in the
# restart section.
#grep -v -i "yahoo\!" merged.p2b.p2p | grep -v -i "spite media" | grep -v "Trendstep Ltd" > merged.p2b.p2p.tmp
#mv merged.p2b.p2p.tmp merged.p2b.p2p
mv $PG_LIST $PG_LIST.backup
mv merged.p2b.p2p $PG_LIST
mv $PG_LOG $PG_LOG.backup
echo "Starting PeerGuardian"
peerguardnf -h -m -d -c "$PG_CONF" -l "$PG_LOG"
endscript 0
;;
'stop')
echo "Stopping PeerGuardian"
killall peerguardnf > /dev/null 2>&1
endscript 0
;;
'restart')
cd "$PG_ETC"
# check if blockfiles were updated:
UPDATED=""
for i in $BLOCKLISTS ; do
TIMESTAMP=0
if [ -e $i.p2b.gz ] ; then
TIMESTAMP=`stat --format=%y $i.p2b.gz`
echo "File $i.p2b.gz last updated $TIMESTAMP"
TIMESTAMP=`stat --format=%Y $i.p2b.gz`
fi
wget -N http://blocklist.org/$i.p2b.gz
if [ `stat --format=%Y $i.p2b.gz` -gt $TIMESTAMP ] ; then
UPDATED=$i
fi
done
# if none of the blockfiles were updated:
if [ -z $UPDATED ] ; then
echo "No blocklists needed updating."
echo "Stopping PeerGuardian"
killall peerguardnf > /dev/null 2>&1
mv $PG_LOG $PG_LOG.backup
sleep 4
echo "Starting PeerGuardian"
peerguardnf -h -m -d -c "$PG_CONF" -l "$PG_LOG"
fi
# if any blockfiles were updated:
rm -f *.p2p > /dev/null 2>&1
for i in $BLOCKLISTS ; do
gunzip -c $i.p2b.gz > $i.p2b
peerguardnf -n $i.p2b
rm $i.p2b
BLOCKLISTSCAT="$BLOCKLISTSCAT $i.p2b.p2p"
done
cat $BLOCKLISTSCAT | peerguardnf -f merged.p2b.p2p
for i in $BLOCKLISTS ; do
rm $i.p2b.p2p
done
# uncomment below to unblock Yahoo! Mail and whatever
# else needs unblocking here. Do this also in the
# restart section.
#grep -v -i "yahoo\!" merged.p2b.p2p | grep -v -i "spite media" | grep -v "Trendstep Ltd" > merged.p2b.p2p.tmp
#mv merged.p2b.p2p.tmp merged.p2b.p2p
echo "Stopping PeerGuardian"
killall peerguardnf > /dev/null 2>&1
mv $PG_LIST $PG_LIST.backup
mv merged.p2b.p2p $PG_LIST
mv $PG_LOG $PG_LOG.backup
sleep 4
echo "Starting PeerGuardian"
peerguardnf -h -m -d -c "$PG_CONF" -l "$PG_LOG"
endscript 0
;;
*)
echo "Usage: $0 { start | stop | restart }"
;;
esac
exit 0
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 09:18 AM.
 |
|
 |
|
 |