On 21-Apr-2010, at 15:03, Michael Taboada (AI5HF) wrote:
>
> Hi,
> I have a script to unban a user from denyhosts, but every time I run it it
> either unbans everyone, or unbans many of the people, even though I told it
> to only unban one ip address.
> If anyone could write a revised script, that would be great.
This is what I wrote:
#!/bin/sh
VERSION='1.1'
# Unlist an IP address from denyhosts
case $1 in
'')
echo "undenyhosts $VERSION"
echo "Usage: undenyhosts <ipaddress>"
;;
*)
# Set to path to startup script
# Commonly /etc/init.d/denyhosts
#RCDENY='/etc/init.d/denyhosts'
RCDENY='/usr/local/etc/rc.d/denyhosts'
# Set to path to data dir
# Commonly /var/lib/denyhosts
#BEDENY='/var/lib/denyhosts'
BEDENY='/usr/local/share/denyhosts/data/'
# Set to the full path to the hosts.deny file
# Commonly /etc/hosts.deny
#DENY='/etc/hosts.deny'
DENY='/etc/hosts.deniedssh'
# Is the IP address actually listed in denyhosts?
ISDENY=`grep $1 $DENY`
if [ "$ISDENY" ]; then
# Stop denyhosts, redirect errors and output to /dev/null
$RCDENY stop > /dev/null 2>&1
echo "Purging $1 from $BEDENY, leaving .bak file"
sed -i .bak "/$1/d" $BEDENY/users*
sed -i .bak "/$1/d" $BEDENY/hosts*
sed -i .bak "/$1/d" $BEDENY/sync*
echo "Purging $1 from $DENY, leaving .bak file"
sed -i .bak "/$1/d" $DENY
# Restart denyhosts. Don't redirect output so that
# any problems restarting it will cause an alert
$RCDENY start
else
echo "$1 is not listed in $DENY"
fi
esac
--
Chefet, Chefet, thought Dios. Maker of rings, weaver of metal. Now he's out of
our heads, and see how his nails grow into claws... --Pyramids
------------------------------------------------------------------------------
_______________________________________________
Denyhosts-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/denyhosts-user