Skip to content

Commit

Permalink
Buttons now use threading to prevent app from freezing due to ufw bei…
Browse files Browse the repository at this point in the history
…ng slow. Also, notifications for when your VPN drops are a thing now.
  • Loading branch information
Corewala committed Jan 6, 2021
1 parent f7f7d86 commit e12a8a5
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 33 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
3 changes: 3 additions & 0 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<img width="180" src="https://raw.githubusercontent.com/Corewala/Smother/c4b2f5b87048a58b6f9fa70552a331d8a71ce6f4/smother.svg" />

# Smother
[![forthebadge](https://forthebadge.com/images/badges/made-with-python.svg)](https://forthebadge.com)
[![forthebadge](https://forthebadge.com/images/badges/powered-by-electricity.svg)](https://forthebadge.com)

A simple gtk application for managing an OpenVPN killswitch using ufw.

## Build Smother
Expand Down
10 changes: 0 additions & 10 deletions build.sh

This file was deleted.

56 changes: 40 additions & 16 deletions install.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,32 +1,52 @@
if ! command -v ufw &> /dev/null; then
printf "Please make sure that ufw is properly installed\n"
exit
fi
printf "Please select\n";
printf "1: Install or update Smother\n";
if command -v smother &> /dev/null; then
printf "1: Update Smother\n"
else
printf "1: Install Smother\n"
fi
printf "2: Uninstall Smother\n";
printf "> ";

#Repeat only if the user hasn't entered an integer...
while ! [[ $selection =~ ^[1-2]+$ ]];
#Repeat only if the user hasn't entered an integer
while ! [[ $selection =~ ^[1-2]+$ ]];
do
read selection;
#if the entered value was not an integer, show this
if ! [[ $selection =~ ^[1-2]+$ ]]; then
sleep 1;
printf "$(tput setaf 9)Please try again$(tput sgr0)\n";
printf "1: Install or update Smother\n";
if command -v smother &> /dev/null; then
printf "1: Update Smother\n"
else
printf "1: Install Smother\n"
fi
printf "2: Uninstall Smother\n";
printf "> ";
fi
done

case $selection in
1)
#Install
sudo systemctl enable ufw &> /dev/null
sudo ufw enable &> /dev/null
mkdir ~/.local/bin &> /dev/null
mkdir ~/.local/share/applications &> /dev/null
mkdir ~/.icons &> /dev/null
cp build/smother ~/.local/bin
cp build/Smother.desktop ~/.local/share/applications
cp smother.svg ~/.icons
rm ~/.local/bin/smother &> /dev/null
rm ~/.local/share/applications/Smother.desktop &> /dev/null
rm ~/.icons/smother.svg &> /dev/null
cp smother.py ~/.local/bin/smother &> /dev/null
cp smother.desktop ~/.local/share/applications/smother.desktop &> /dev/null
cp smother.svg ~/.icons/smother.svg &> /dev/null
if command -v smother &> /dev/null; then
printf "Successfully installed Smother\n"
elif test -f ~/.local/bin/smother; then
printf "Successfully installed Smother\nPlease make sure that ~/.local/bin is in your PATH\n"
else
printf "Smother was not installed\n"
fi
;;

2)
Expand All @@ -36,12 +56,16 @@ case $selection in
sudo /usr/bin/rm /etc/ufw/*.rules.* &> /dev/null
sudo /usr/bin/ufw default deny incoming &> /dev/null
sudo /usr/bin/ufw default allow outgoing &> /dev/null
rm ~/.local/bin/smother
rm ~/.local/share/applications/Smother.desktop
rm /.icons/smother.svg
rm ~/.local/bin/smother &> /dev/null
rm ~/.local/share/applications/smother.desktop &> /dev/null
rm ~/.icons/smother.svg &> /dev/null
if ! test -f ~/.local/bin/smother; then
printf "Successfully uninstalled Smother\n"
else
printf "Smother was not uninstalled\n"
fi
;;

*)
printf "[$(tput setaf 12 && tput blink)INFO$(tput sgr0)] $(tput setaf 12)Exiting script$(tput sgr0)\n";
;;
esac
esac
8 changes: 8 additions & 0 deletions smother.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Desktop Entry]
Type=Application
Name=Smother
Exec=smother
Terminal=false
Icon=smother
Categories=GNOME;Network;
StartupNotify=false
57 changes: 50 additions & 7 deletions smother.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/python3
import gi
import os
import yaml
import time
gi.require_version('Gtk', '3.0')
from threading import Thread
from gi.repository import Gtk

class Smother(Gtk.Window):
Expand Down Expand Up @@ -74,23 +77,63 @@ def on_port_apply(self, widget):
yaml.safe_dump(self.config, open(self.configPath, "r+"))

def on_enable_clicked(self, widget):
print("Enabling killswitch")
Thread(target = self.enable, args = ()).start()

def on_disable_clicked(self, widget):
Thread(target = self.disable, args = ()).start()
print("Disabling killswitch")

def enable(self):
self.killbutton.set_sensitive(False)
if self.config["reconnecting"] and self.config["port"]:
command = "pkexec bash -c \'ufw default deny incoming \n ufw default deny outgoing \n ufw allow out on tun0 from any to any \n ufw allow out " + str(int(self.config["port"])) + "/udp \n ufw allow in " + str(int(self.config["port"])) + "/udp \n ufw allow out 53 \n ufw allow in 53\'"
commandstatus = os.system("pkexec bash -c \'ufw default deny incoming \n ufw default deny outgoing \n ufw allow out on tun0 from any to any \n ufw allow out " + str(int(self.config["port"])) + "/udp \n ufw allow in " + str(int(self.config["port"])) + "/udp \n ufw allow out 53 \n ufw allow in 53\' &> /dev/null")
else:
command = "pkexec bash -c \'ufw default deny incoming \n ufw default deny outgoing \n ufw allow out on tun0 from any to any\'"

if not os.system(command):
self.killbutton.set_sensitive(False)
commandstatus = os.system("pkexec bash -c \'ufw default deny incoming \n ufw default deny outgoing \n ufw allow out on tun0 from any to any\' &> /dev/null")
if not commandstatus:
self.unkillbutton.set_sensitive(True)
self.config["enabled"] = True
yaml.safe_dump(self.config, open(self.configPath, "r+"))
os.system("notify-send 'Smother' 'Killswitch disabled' -i smother")
Thread(target = self.status_check, args = ()).start()
print("Killswitch enabled")
elif commandstatus != 32256:
self.killbutton.set_sensitive(True)
os.system("notify-send 'Smother' 'Failed to enable killswitch' -u critical -i smother")
print("\33[31m" + "Failed to enable killswitch" + "\33[0m")
else:
self.killbutton.set_sensitive(True)
print("\33[33m" + "Request dismissed" + "\33[0m")

def on_disable_clicked(self, widget):
if not os.system("pkexec bash -c \'ufw --force reset \n ufw enable \n rm /etc/ufw/*.rules.* \n ufw default deny incoming \n ufw default allow outgoing\'"):
def disable(self):
self.unkillbutton.set_sensitive(False)
commandstatus = os.system("pkexec bash -c \'ufw --force reset \n ufw enable \n rm /etc/ufw/*.rules.* \n ufw default deny incoming \n ufw default allow outgoing\' &> /dev/null")
if not commandstatus:
self.killbutton.set_sensitive(True)
self.unkillbutton.set_sensitive(False)
self.config["enabled"] = False
yaml.safe_dump(self.config, open(self.configPath, "r+"))
os.system("notify-send 'Smother' 'Killswitch disabled' -i smother")
print("Killswitch disabled")
elif commandstatus != 32256:
self.unkillbutton.set_sensitive(True)
os.system("notify-send 'Smother' 'Failed to disable killswitch' -u critical -i smother")
print("\33[31m" + "Failed to disable killswitch" + "\33[0m")
else:
self.unkillbutton.set_sensitive(True)
print("\33[33m" + "Request dismissed" + "\33[0m")

def status_check(self):
vpnstatus = True
while self.config["enabled"]:
if not os.system("nmcli device status | grep \"tun0\" &> /dev/null"):
vpnstatus = True
else:
if vpnstatus:
os.system("notify-send 'Smother' 'VPN is down' -u critical -i smother")
print("\33[33m" + "VPN is down" + "\33[0m")
vpnstatus = False
time.sleep(1)

win = Smother()
win.connect("destroy", Gtk.main_quit)
Expand Down

0 comments on commit e12a8a5

Please sign in to comment.