Compare commits

...

2 Commits

5 changed files with 150 additions and 44 deletions

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,4 @@
<changelist name="Uncommitted_changes_before_Checkout_at_19_08_24,_06_49_[Changes]" date="1724042999949" recycled="false" toDelete="true">
<option name="PATH" value="$PROJECT_DIR$/.idea/shelf/Uncommitted_changes_before_Checkout_at_19_08_24,_06_49_[Changes]/shelved.patch" />
<option name="DESCRIPTION" value="Uncommitted changes before Checkout at 19.08.24, 06:49 [Changes]" />
</changelist>

10
main.py
View File

@ -3,9 +3,7 @@ import os
import tkinter as tk
from tkinter import ttk
from wg_func import tl_list, wg_export, wg_import_select, TunnelActiv
wg_exp = wg_export()
from wg_func import TunnelActiv, ListTunnels, ImportTunnel, ExportTunnels
class MainWindow(tk.Tk):
@ -67,7 +65,7 @@ class FrameWidgets(ttk.Frame):
self.l_box.config(font=("Ubuntu", 12, "bold"))
self.l_box.grid(column=1, rowspan=3, row=1, )
self.tl = tl_list()
self.tl = ListTunnels.tl_list()
for tunnels in self.tl:
self.l_box.insert("end", tunnels)
self.l_box.update()
@ -80,7 +78,7 @@ class FrameWidgets(ttk.Frame):
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 Import
self.btn_i = tk.Button(self, image=self.imp_pic, bd=0, command=wg_import_select)
self.btn_i = tk.Button(self, image=self.imp_pic, bd=0, command=lambda: ImportTunnel.wg_import_select(self))
self.btn_i.grid(column=0, row=2, padx=15, pady=15)
def delete():
@ -92,6 +90,8 @@ class FrameWidgets(ttk.Frame):
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")
self.l_box.update()
self.l_box.select_set(0)
# Button Trash
self.btn_tr = tk.Button(self, image=self.tr_pic, bd=0, command=delete)

View File

@ -41,13 +41,24 @@ class TunnelActiv:
return active
def tl_list():
class ListTunnels:
@staticmethod
def tl_list():
wg_s = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
tl = wg_s[::3] # tl = Tunnel list # Show of 4.Element in list
return tl
def wg_import_select():
class ImportTunnel:
def __init__(self):
self.wg_switch = None
self.btn_stst = None
self.lb_tunnel = None
self.StrVar = None
self.a = None
self.l_box = None
def wg_import_select(self):
try:
filepath = filedialog.askopenfilename(initialdir=os.environ['HOME'], title="Select Wireguard config File",
filetypes=[("WG config files", "*.conf")])
@ -69,15 +80,30 @@ def wg_import_select():
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')
self.StrVar.set(value=' ')
self.a = TunnelActiv.active()
self.l_box.insert(0, self.a)
self.l_box.update()
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")
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")
if "PrivateKey = " not in read:
Message()
except EOFError:
pass
except TypeError:
pass
except FileNotFoundError:
pass
def wg_export():
class ExportTunnels:
@staticmethod
def wg_export():
try:
wg_exp = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
wg_exp = wg_exp[1]