Compare commits

..

No commits in common. "51e372d68c03ef574e21cb7c3b9945e5c3c218cd" and "9c5004e92ab2fd88d3b585ea2de5aa6edc4edbcf" have entirely different histories.

5 changed files with 44 additions and 150 deletions

File diff suppressed because one or more lines are too long

View File

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

View File

@ -41,72 +41,46 @@ class TunnelActiv:
return active return active
class ListTunnels: def tl_list():
@staticmethod wg_s = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
def tl_list(): tl = wg_s[::3] # tl = Tunnel list # Show of 4.Element in list
wg_s = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split() return tl
tl = wg_s[::3] # tl = Tunnel list # Show of 4.Element in list
return tl
class ImportTunnel: def wg_import_select():
def __init__(self): try:
self.wg_switch = None filepath = filedialog.askopenfilename(initialdir=os.environ['HOME'], title="Select Wireguard config File",
self.btn_stst = None filetypes=[("WG config files", "*.conf")])
self.lb_tunnel = None file = open(filepath, 'r')
self.StrVar = None read = file.read()
self.a = None file.close()
self.l_box = None pathsplit = filepath.split("/")
pathsplit1 = pathsplit[-1]
def wg_import_select(self): if "PrivateKey = " in read and "PublicKey = " in read:
try: if len(pathsplit1) > 17:
filepath = filedialog.askopenfilename(initialdir=os.environ['HOME'], title="Select Wireguard config File", pathsplit = pathsplit1[len(pathsplit1) - 17:]
filetypes=[("WG config files", "*.conf")]) os.rename(filepath, os.environ['HOME'] + '/tester/' + str(pathsplit))
file = open(filepath, 'r') os.system('nmcli connection down ' + str(TunnelActiv.active()))
read = file.read() os.system('nmcli connection import type wireguard file ' + os.environ['HOME'] + '/tester/' +
file.close() str(pathsplit))
pathsplit = filepath.split("/") os.system('nmcli con mod ' + str(pathsplit[:-5]) + ' connection.autoconnect no')
pathsplit1 = pathsplit[-1] else:
if "PrivateKey = " in read and "PublicKey = " in read: subprocess.call('cp ' + str(filepath) + ' ' + os.environ['HOME'] + '/tester/', shell=True)
if len(pathsplit1) > 17: os.system('nmcli connection down ' + str(TunnelActiv.active()))
pathsplit = pathsplit1[len(pathsplit1) - 17:] os.system('nmcli connection import type wireguard file ' + str(filepath))
os.rename(filepath, os.environ['HOME'] + '/tester/' + str(pathsplit)) os.system('nmcli con mod ' + str(pathsplit1[:-5]) + ' connection.autoconnect no')
os.system('nmcli connection down ' + str(TunnelActiv.active())) if "PrivateKey = " not in read:
os.system('nmcli connection import type wireguard file ' + os.environ['HOME'] + '/tester/' + Message()
str(pathsplit)) except EOFError:
os.system('nmcli con mod ' + str(pathsplit[:-5]) + ' connection.autoconnect no') pass
else: except TypeError:
subprocess.call('cp ' + str(filepath) + ' ' + os.environ['HOME'] + '/tester/', shell=True) pass
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
class ExportTunnels: def wg_export():
@staticmethod try:
def wg_export(): wg_exp = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
try: wg_exp = wg_exp[1]
wg_exp = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split() return wg_exp
wg_exp = wg_exp[1] except IndexError:
return wg_exp pass
except IndexError:
pass