diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index bc3fea4..d5d1042 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,7 +4,11 @@
-
+
+
+
+
+
@@ -117,7 +121,15 @@
1724013210356
-
+
+
+ 1724013251954
+
+
+
+ 1724013251954
+
+
@@ -125,7 +137,19 @@
@@ -136,6 +160,7 @@
-
+
+
\ No newline at end of file
diff --git a/main.py b/main.py
index 27a4a47..0632394 100644
--- a/main.py
+++ b/main.py
@@ -2,10 +2,10 @@
import os
import tkinter as tk
from tkinter import ttk
-from wg_func import active, tl_list, wg_export, wg_import_select
+
+from wg_func import tl_list, wg_export, wg_import_select, TunnelActiv
wg_exp = wg_export()
-a = active()
class MainWindow(tk.Tk):
@@ -44,13 +44,17 @@ class FrameWidgets(ttk.Frame):
self.exp_pic = tk.PhotoImage(file=r'icons/wg-export-48.png')
self.warning_pic = tk.PhotoImage(file=r'icons/warning_64.png')
+ # Show active Tunnel
+ self.a = TunnelActiv.active()
+
# Show active Label
self.select_tunnel = None
self.lb = tk.Label(self, text='Active:')
self.lb.config(font=("Ubuntu", 11, "bold"))
self.lb.grid(column=2, row=1, padx=10, pady=5, sticky="e")
+
# Label to Show active Tunnel
- self.StrVar = tk.StringVar(value=a)
+ self.StrVar = tk.StringVar(value=self.a)
self.lb_tunnel = tk.Label(self, textvariable=self.StrVar, fg='green')
self.lb_tunnel.config(font=("Ubuntu", 11, "bold"))
@@ -69,7 +73,7 @@ class FrameWidgets(ttk.Frame):
self.l_box.update()
self.l_box.select_set(0) # Later add, for first Item Auto select
# Button Vpn
- if a != '':
+ if self.a != '':
self.btn_stst = tk.Button(self, image=self.wg_vpn_stop, bd=0, command=self.wg_switch)
self.btn_stst.grid(column=0, row=1, padx=15, pady=15, sticky="s")
else:
@@ -84,46 +88,49 @@ class FrameWidgets(ttk.Frame):
select_tl = self.l_box.get(self.select_tunnel[0])
os.system('nmcli connection delete ' + str(select_tl))
self.l_box.delete(self.select_tunnel[0])
- if a != '':
+ if self.a != '':
self.StrVar.set(value='')
self.btn_stst = tk.Button(self, image=self.wg_vpn_start, bd=0, command=self.wg_switch)
self.btn_stst.grid(column=0, row=1, padx=15, pady=15, sticky="s")
- # Button Trash
+ # Button Trash
self.btn_tr = tk.Button(self, image=self.tr_pic, bd=0, command=delete)
self.btn_tr.grid(column=0, row=3, padx=15, pady=15)
# Button Export
self.btn_exp = tk.Button(self, image=self.exp_pic, bd=0)
self.btn_exp.grid(column=0, row=4, padx=15, pady=15)
+ # Check Buttons
self.wg_autostart = tk.Checkbutton(self, text='Autoconnect on PC Start')
self.wg_autostart.grid(column=1, rowspan=3, row=3)
self.wg_update = tk.Checkbutton(self, text='Search automatically for\nWire-Py updates')
self.wg_update.grid(column=1, rowspan=3, row=4)
def wg_switch(self):
- global a
- if a == '':
- # Button Start/Stop
+ self.a = TunnelActiv.active()
+ if self.a == '':
+
self.select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(self.select_tunnel[0])
os.system('nmcli connection up ' + str(select_tl))
- self.btn_stst = tk.Button(self, image=self.wg_vpn_stop, bd=0, command=self.wg_switch)
- self.btn_stst.grid(column=0, row=1, padx=15, pady=15, sticky="s")
- a = active()
- self.StrVar = tk.StringVar()
- self.StrVar.set(a)
- self.lb_tunnel = tk.Label(self, textvariable=self.StrVar, fg='green')
- self.lb_tunnel.config(font=("Ubuntu", 11, "bold"))
- self.lb_tunnel.grid(column=3, row=1, sticky="w")
- elif a != '':
# Button Start/Stop
self.btn_stst = tk.Button(self, image=self.wg_vpn_stop, bd=0, command=self.wg_switch)
self.btn_stst.grid(column=0, row=1, padx=15, pady=15, sticky="s")
- os.system('nmcli connection down ' + str(a))
+ self.a = TunnelActiv.active()
+ self.StrVar = tk.StringVar()
+ self.StrVar.set(self.a)
+ self.lb_tunnel = tk.Label(self, textvariable=self.StrVar, fg='green')
+ self.lb_tunnel.config(font=("Ubuntu", 11, "bold"))
+ self.lb_tunnel.grid(column=3, row=1, sticky="w")
+ elif self.a != '':
+ # Button Start/Stop
+ self.btn_stst = tk.Button(self, image=self.wg_vpn_stop, bd=0, command=self.wg_switch)
+ self.btn_stst.grid(column=0, row=1, padx=15, pady=15, sticky="s")
+ os.system('nmcli connection down ' + str(self.a))
+ # Button Start/Stop
self.btn_stst = tk.Button(self, image=self.wg_vpn_start, bd=0, command=self.wg_switch)
self.btn_stst.grid(column=0, row=1, padx=15, pady=15, sticky="s")
- a = active()
+ self.a = TunnelActiv.active()
self.StrVar = tk.StringVar()
self.StrVar.set(value=' ')
self.lb_tunnel = tk.Label(self, textvariable=self.StrVar, fg='green')
diff --git a/wg_func.py b/wg_func.py
index e3beaa6..b8ed246 100644
--- a/wg_func.py
+++ b/wg_func.py
@@ -29,17 +29,16 @@ class Message(tk.Tk):
self.button.grid(column=0, row=1)
-def active(): # Shows the active tunnel
- a = os.popen('nmcli con show --active | grep -iPo "(.*)(wireguard)"').read().split()
- if not a:
- a = ''
- return a
- else:
- a = a[0]
- return a
+class TunnelActiv:
+ @staticmethod
+ def active(): # Shows the active tunnel
+ active = os.popen('nmcli con show --active | grep -iPo "(.*)(wireguard)"').read().split()
+ if not active:
+ active = ''
+ else:
+ active = active[0]
-
-a = active()
+ return active
def tl_list():
@@ -61,13 +60,13 @@ def wg_import_select():
if len(pathsplit1) > 17:
pathsplit = pathsplit1[len(pathsplit1) - 17:]
os.rename(filepath, os.environ['HOME'] + '/tester/' + str(pathsplit))
- os.system('nmcli connection down ' + str(a))
+ os.system('nmcli connection down ' + str(TunnelActiv.active()))
os.system('nmcli connection import type wireguard file ' + os.environ['HOME'] + '/tester/' +
str(pathsplit))
os.system('nmcli con mod ' + str(pathsplit[:-5]) + ' connection.autoconnect no')
else:
subprocess.call('cp ' + str(filepath) + ' ' + os.environ['HOME'] + '/tester/', shell=True)
- os.system('nmcli connection down ' + str(a))
+ os.system('nmcli connection down ' + str(TunnelActiv.active()))
os.system('nmcli connection import type wireguard file ' + str(filepath))
os.system('nmcli con mod ' + str(pathsplit1[:-5]) + ' connection.autoconnect no')
if "PrivateKey = " not in read: