I set it up by using a php file + shell file + cronjob
Now I easily open a public website address "mydomain.com/whatis.php" and it automatically whitelist my IP.
"whatis.php" PHP file code :
<?php
echo file_put_contents("/tmp/iplog",$_SERVER["REMOTE_ADDR"]);
?>
"/script/ip" Shell file code :
#!/bin/bash
i=1
while [ $i -le 10 ]
do
status=`cat /tmp/iplog`
if [ "$status" != "0" ]; then
echo $status >> /etc/csf/csf.allow
echo $status >> /etc/csf/csf.ignore
# echo "allow from $status" >> /home/DOMAIN/public_html/admin/.htaccess
echo "0" > /tmp/iplog
`/etc/csf/csf.pl -r > /tmp/csf.log`
fi
sleep 5
(( i++ ))
done
* * * * * /script/ip
Note : I tried to run `csf -r` to reset CSF firewall in shell script but it didn't work ! I don't know why. I found here that we should use `/etc/csf/csf.pl -r` instead. Thanks to that guy !!
No comments:
Post a Comment