From 6e528248414e330c9e25e81596ab47b8b8a5b701 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Fri, 14 May 2021 22:44:50 +0430 Subject: first commit --- baseline/ufw-allow-mosh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 baseline/ufw-allow-mosh (limited to 'baseline/ufw-allow-mosh') diff --git a/baseline/ufw-allow-mosh b/baseline/ufw-allow-mosh new file mode 100755 index 0000000..3f696ca --- /dev/null +++ b/baseline/ufw-allow-mosh @@ -0,0 +1,31 @@ +#!/bin/bash +# ripped off from here:https://stephenreescarter.net/mosh-and-ufw-without-1000-open-ports/ +# add entry in sudoers: my-awesome-user ALL:(ALL:ALL) NOPASSWD: /usr/local/bin/ufw-allow-mosh +# then add this in zshrc: sudo /usr/local/bin/ufw-allow-mosh + +# Load active ports +PORTS=`lsof -i | grep mosh-serv | cut -f2 -d":"` +STATUS=`sudo ufw status` + +# Add Rules for new ports +for PORT in $PORTS; do + + echo $STATUS | grep "$PORT/udp" > /dev/null + if [ $? -gt 0 ]; then + echo "Allowing new port $PORT" + sudo ufw allow $PORT/udp > /dev/null + fi +done + +# Remove closed ports +PORTS=`sudo ufw status | grep "^60.../udp" | cut -f1 -d"/" | sort | uniq` +OPEN=`lsof -i | grep mosh-serv` + +for PORT in $PORTS; do + + echo $OPEN | grep $PORT > /dev/null + if [ $? -gt 0 ]; then + echo "Removing closed port $PORT." + sudo ufw delete allow $PORT/udp > /dev/null + fi +done -- cgit v1.2.3