stopforumspam bash to .htaccess
ອັນນີ້ແມ່ນລຸງ ກ໋ອບຂອງໄທບ້ານມາໄວ້ຊື່ໆ ເດີ້ ກັນ ລືມ
#!/bin/bash
cd /tmp
wget http://www.stopforumspam.com/downloads/bannedips.zip
unzip bannedips.zip
rm /tmp/.htaccess
cat bannedips.csv | awk '{print "deny from " $1}' RS="," >> /tmp/.htaccess
cat /tmp/.htaccess >> /home/laozaa/public_html/.htaccess
replace the cat line with this if youre using nginx and includes
rm /etc/nginx/blacklist.conf
cat bannedips.csv | awk '{print "deny " $1 ";"}' RS="," >> /etc/nginx/blacklist.conf
killall -HUP nginx
ອັນນີ້ແມ່ນເກັບລົງໃນ Mysql
-
CREATE TABLE IF NOT EXISTS `stopforumspam` (
`ip` varchar(32) NOT NULL,
`id` int(32) NOT NULL auto_increment,
`time` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `ip` (`ip`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=287040 ;
##IMPORTER SCRIPT
#!/bin/bash
wget http://www.stopforumspam.com/downloads/bannedips.zip
unzip ./bannedips.zip >>/dev/null
rm newips.csv
sed ‘s/,/\n/g’ bannedips.csv > newips.csv
P=password
D=database
U=user
mysql -u$U -p$P -D$D<<< ‘TRUNCATE stopforumspam ; ‘
mysql -u$U -p$P -D$D<<< ‘ LOAD DATA LOCAL INFILE “./newips.csv” INTO TABLE stopforumspam FIELDS TERMINATED BY “,” OPTIONALLY ENCLOSED BY “””” LINES TERMINATED BY “\n” (ip);’
##BASH
//PHP
$ip=$_SERVER[‘REMOTE_ADDR’];
$result = dbquery(“SELECT * FROM stopforumspam WHERE ip='”.$ip.“‘”); //php-fusion query
$numrows = dbrows($result); //php-fusion query
echo $numrows; //php-fusion query
if($numrows==“1”)
{
file_put_contents(‘ips.txt’, $ip . “\n“, FILE_APPEND);
die(”);
// EXEC IPTABLES BAN $ip
//FAIL2BAN FOR VSERVERS
}
//PHP
//CRONJOB SCRIPT TO BAN
#!/bin/bash
sort -u PATHtoDOMAIN1/ips.txt|uniq > neuips.txt
”> PATHtoDOMAIN1/ips.txt
#DOMAIN2 ETC..
sort -u PATHtoDOMAIN2/ips.txt|uniq >> neuips.txt
”> PATHtoDOMAIN2/ips.txt/ips.txt
URLFILE=neuips.txt
for i in `cat $URLFILE`; do
iptables -A INPUT -s $i -j DROP
done