Skip to content

Commit

Permalink
Added YAML variable storage and updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
Corewala committed Nov 17, 2020
1 parent 3d6a3f7 commit 34bf2a5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
32 changes: 27 additions & 5 deletions smother.py
Original file line number Diff line number Diff line change
@@ -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):

Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 34bf2a5

Please sign in to comment.