Добавить paranoia-shutdown.sh
This commit is contained in:
47
paranoia-shutdown.sh
Normal file
47
paranoia-shutdown.sh
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
allowIp=$2
|
||||||
|
pidFile="/var/run/paranoia-shutdown.pid"
|
||||||
|
|
||||||
|
start(){
|
||||||
|
|
||||||
|
echo $$ > "$pidFile"
|
||||||
|
|
||||||
|
tail -f -n0 /var/log/auth.log | while read string
|
||||||
|
do
|
||||||
|
if echo "$string" | grep "Accepted password for"
|
||||||
|
then
|
||||||
|
ip=$(echo "$string" | grep -o -E '([0-9]{1,3}[\.]){3}[0-9]{1,3}')
|
||||||
|
|
||||||
|
if [ "$ip" != "$allowIp" ]
|
||||||
|
then
|
||||||
|
logger "Alert!!! Alert!!! Alert!!! Login from not confirmed ip $ip. Faster shutdown!"
|
||||||
|
systemctl poweroff
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
stop(){
|
||||||
|
|
||||||
|
kill $(cat "$pidFile")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
start;;
|
||||||
|
|
||||||
|
stop)
|
||||||
|
stop;;
|
||||||
|
|
||||||
|
restart)
|
||||||
|
stop
|
||||||
|
sleep 3
|
||||||
|
start
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
|
||||||
|
echo $"Usage: $0 {start|stop|restart}"
|
||||||
|
exit 3
|
||||||
|
esac
|
||||||
Reference in New Issue
Block a user