From 22dbd1fa4b0cc5eab1cb59c9efce67095e50c9ab Mon Sep 17 00:00:00 2001 From: Jay Ta'ala Date: Mon, 8 Apr 2019 07:18:34 +1000 Subject: [PATCH] Switched to single script which can enable, disable, or -t option. Removed previously written on/off scripts. --- vpnkillswitch | 46 ++++++++++++++++++++++++++++++++++++++++++++++ vpnkillswitch-off | 11 ----------- vpnkillswitch-on | 20 -------------------- 3 files changed, 46 insertions(+), 31 deletions(-) create mode 100755 vpnkillswitch delete mode 100755 vpnkillswitch-off delete mode 100755 vpnkillswitch-on diff --git a/vpnkillswitch b/vpnkillswitch new file mode 100755 index 0000000..b28f685 --- /dev/null +++ b/vpnkillswitch @@ -0,0 +1,46 @@ +#!/bin/bash + +# process arguments +while getopts ":edt:" opt; do + case ${opt} in + e) + # ENABLE KILLSWITCH + # Default policies + sudo /usr/bin/ufw default deny incoming + sudo /usr/bin/ufw default deny outgoing + + # Openvpn interface (adjust interface accordingly to your configuration) + sudo /usr/bin/ufw allow out on tun0 + + # Openvpn (adjust port accordingly to your vpn setup) + sudo /usr/bin/ufw allow out to any port 1194 + ;; + d) + # DISABLE KILLSWITCH + sudo /usr/bin/ufw --force reset + sudo /usr/bin/ufw enable + + # delete backUP rules from reset + sudo /usr/bin/rm /etc/ufw/*.rules.* + + # reset to defaults and enable + sudo /usr/bin/ufw default deny incoming + sudo /usr/bin/ufw default allow outgoing + ;; + t) + # ADD OUTGOING RULE + echo "allow outgoing traffic to $OPTARG" + sudo /usr/bin/ufw allow out to $OPTARG + ;; + esac +done + +if (( $OPTIND == 1 )); then + echo " " + echo -e "Please provide at least one of the following options:\n -e" + echo " enable killswitch" + echo " -d" + echo " disable killswitch" + echo " -t [CIDR]" + echo -e " open outgoing ufw rule to a specific CIDR (ip address or range)\n" +fi diff --git a/vpnkillswitch-off b/vpnkillswitch-off deleted file mode 100755 index 657a22c..0000000 --- a/vpnkillswitch-off +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -sudo /usr/bin/ufw --force reset -sudo /usr/bin/ufw enable - -# delete back rules from reset -sudo /usr/bin/rm /etc/ufw/*.rules.* - -# reset to defaults and enable -sudo /usr/bin/ufw default deny incoming -sudo /usr/bin/ufw default allow outgoing diff --git a/vpnkillswitch-on b/vpnkillswitch-on deleted file mode 100755 index dd8dc12..0000000 --- a/vpnkillswitch-on +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -# Default policies -sudo /usr/bin/ufw default deny incoming -sudo /usr/bin/ufw default deny outgoing - -# Openvpn interface (adjust interface accordingly to your configuration) -sudo /usr/bin/ufw allow out on tun0 - -# Openvpn (adjust port accordingly to your vpn setup) -sudo /usr/bin/ufw allow out to any port 1194 - -# process arguments -while getopts "t:" opt; do - case ${opt} in - t) - echo "allow outgoing traffic to $OPTARG" - sudo /usr/bin/ufw allow out to $OPTARG;; - esac -done -- GitLab