aboutsummaryrefslogtreecommitdiffstats
path: root/baseline/ufw-allow-mosh
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2021-05-14 18:14:50 +0000
committerterminaldweller <thabogre@gmail.com>2021-05-14 18:14:50 +0000
commit6e528248414e330c9e25e81596ab47b8b8a5b701 (patch)
treee1aa41a7f3198eeac187e6177ec7d4a33db229d3 /baseline/ufw-allow-mosh
downloadscripts-master.tar.gz
scripts-master.zip
first commitmaster
Diffstat (limited to 'baseline/ufw-allow-mosh')
-rwxr-xr-xbaseline/ufw-allow-mosh31
1 files changed, 31 insertions, 0 deletions
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