From 34bf2a5dbd57714a2b0a83efa9a934383554d761 Mon Sep 17 00:00:00 2001 From: Corewala Date: Tue, 17 Nov 2020 14:55:16 -0500 Subject: [PATCH] Added YAML variable storage and updated README --- README.md | 7 +++++-- smother.py | 32 +++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3a7c87e..8929b48 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,11 @@ # Smother -A simple gtk application for managing a VPN killswitch using ufw. +A simple gtk application for managing an OpenVPN killswitch using ufw. ## Build Smother -**Required:** `nuitka3`, `python3`, `gtk3` , `ufw`, `gksu` +**Required:** + - **Build:** `python3`, `nuitka3`, `PyYAML` + + - **Runtime:** `gtk3` , `ufw`, `gksu` ```sh git clone https://github.com/Corewala/Smother.git diff --git a/smother.py b/smother.py index 5aecec9..1eb7a60 100644 --- a/smother.py +++ b/smother.py @@ -1,7 +1,8 @@ import gi import os -from gi.repository import Gtk +import yaml gi.require_version('Gtk', '3.0') +from gi.repository import Gtk class Smother(Gtk.Window): @@ -10,8 +11,14 @@ def __init__(self): Gtk.Window.set_resizable(self, False); self.set_border_width(10) - vbox = Gtk.Box(orientation = Gtk.Orientation.VERTICAL, spacing = 20) - self.add(vbox) + # get config file + self.configPath = os.path.join(os.environ['HOME'], ".config/smother.yaml") + if not os.path.exists(self.configPath): + os.system("echo \'enabled: false\' > ~/.config/smother.yaml") + self.config = yaml.safe_load(open(self.configPath, "r+")) + + box = Gtk.Box(orientation = Gtk.Orientation.VERTICAL, spacing = 20) + self.add(box) stack = Gtk.Stack() stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT) @@ -27,14 +34,29 @@ def __init__(self): stack_switcher = Gtk.StackSwitcher() stack_switcher.set_stack(stack) - vbox.pack_start(stack_switcher, True, True, 0) - vbox.pack_start(stack, True, True, 0) + box.pack_start(stack_switcher, True, True, 0) + box.pack_start(stack, True, True, 0) + + if self.config["enabled"]: + self.killbutton.set_sensitive(False) + self.unkillbutton.set_sensitive(True) + else: + self.killbutton.set_sensitive(True) + self.unkillbutton.set_sensitive(False) def on_enable_clicked(self, widget): os.system("gksu bash -c \'/usr/bin/ufw default deny incoming \n /usr/bin/ufw default deny outgoing \n sudo ufw allow out on tun0 from any to any\'") + self.killbutton.set_sensitive(False) + self.unkillbutton.set_sensitive(True) + self.config["enabled"] = True + yaml.safe_dump(self.config, open(self.configPath, "r+")) def on_disable_clicked(self, widget): os.system("gksu bash -c \'/usr/bin/ufw --force reset \n /usr/bin/ufw enable \n /usr/bin/rm /etc/ufw/*.rules.* \n /usr/bin/ufw default deny incoming \n /usr/bin/ufw default allow outgoing\'") + self.killbutton.set_sensitive(True) + self.unkillbutton.set_sensitive(False) + self.config["enabled"] = False + yaml.safe_dump(self.config, open(self.configPath, "r+")) win = Smother() win.connect("destroy", Gtk.main_quit)