Created
March 13, 2025 19:32
-
-
Save theundefined/32a555e1aa217eea777aea2d22344132 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
command=$1 | |
list=$2 | |
ip=$3 | |
[ -z "$list" ] && list=blokowane | |
if [ $command = "off" ]; then | |
ssh -o PubkeyAcceptedKeyTypes=ssh-rsa -o StrictHostKeyChecking=no IP.ROUTERA -l homeassistant -i /config/.ssh/id_rsa /ip firewall address-list add list=$list address=$ip | |
elif [ $command = "on" ]; then | |
ids=` ssh -o PubkeyAcceptedKeyTypes=ssh-rsa -o StrictHostKeyChecking=no IP.ROUTERA -l homeassistant -i /config/.ssh/id_rsa /ip firewall address-list print |grep $list |grep "$ip " |awk '{print $1}'` | |
for i in $ids; do | |
ssh -o PubkeyAcceptedKeyTypes=ssh-rsa -o StrictHostKeyChecking=no IP.ROUTERA -l homeassistant -i /config/.ssh/id_rsa /ip firewall address-list remove $i | |
done | |
elif [ $command = "test" ]; then | |
cachefile=/tmp/internet_manage.$list.cache | |
if [ `stat -c %Y $cachefile` -le $(( `date +%s` - 30 )) ]; then | |
ssh -o PubkeyAcceptedKeyTypes=ssh-rsa -o StrictHostKeyChecking=no IP.ROUTERA -l homeassistant -i /config/.ssh/id_rsa /ip firewall address-list print |grep $list >$cachefile | |
fi | |
ips=`cat $cachefile |grep "$ip "` | |
if [ "$ips" ]; then | |
exit 1 | |
else | |
exit 0 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment