48 lines
982 B
Bash
48 lines
982 B
Bash
#!/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
|