Compare commits
2 Commits
9c5004e92a
...
51e372d68c
Author | SHA1 | Date | |
---|---|---|---|
51e372d68c | |||
6ab9c43c3a |
File diff suppressed because one or more lines are too long
@ -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
10
main.py
@ -3,9 +3,7 @@ import os
|
|||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
|
|
||||||
from wg_func import tl_list, wg_export, wg_import_select, TunnelActiv
|
from wg_func import TunnelActiv, ListTunnels, ImportTunnel, ExportTunnels
|
||||||
|
|
||||||
wg_exp = wg_export()
|
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(tk.Tk):
|
class MainWindow(tk.Tk):
|
||||||
@ -67,7 +65,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 = tl_list()
|
self.tl = ListTunnels.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()
|
||||||
@ -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 = 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=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)
|
self.btn_i.grid(column=0, row=2, padx=15, pady=15)
|
||||||
|
|
||||||
def delete():
|
def delete():
|
||||||
@ -92,6 +90,8 @@ 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)
|
||||||
|
104
wg_func.py
104
wg_func.py
@ -41,46 +41,72 @@ class TunnelActiv:
|
|||||||
return active
|
return active
|
||||||
|
|
||||||
|
|
||||||
def tl_list():
|
class ListTunnels:
|
||||||
wg_s = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
|
@staticmethod
|
||||||
tl = wg_s[::3] # tl = Tunnel list # Show of 4.Element in list
|
def tl_list():
|
||||||
return tl
|
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:
|
||||||
try:
|
def __init__(self):
|
||||||
filepath = filedialog.askopenfilename(initialdir=os.environ['HOME'], title="Select Wireguard config File",
|
self.wg_switch = None
|
||||||
filetypes=[("WG config files", "*.conf")])
|
self.btn_stst = None
|
||||||
file = open(filepath, 'r')
|
self.lb_tunnel = None
|
||||||
read = file.read()
|
self.StrVar = None
|
||||||
file.close()
|
self.a = None
|
||||||
pathsplit = filepath.split("/")
|
self.l_box = None
|
||||||
pathsplit1 = pathsplit[-1]
|
|
||||||
if "PrivateKey = " in read and "PublicKey = " in read:
|
def wg_import_select(self):
|
||||||
if len(pathsplit1) > 17:
|
try:
|
||||||
pathsplit = pathsplit1[len(pathsplit1) - 17:]
|
filepath = filedialog.askopenfilename(initialdir=os.environ['HOME'], title="Select Wireguard config File",
|
||||||
os.rename(filepath, os.environ['HOME'] + '/tester/' + str(pathsplit))
|
filetypes=[("WG config files", "*.conf")])
|
||||||
os.system('nmcli connection down ' + str(TunnelActiv.active()))
|
file = open(filepath, 'r')
|
||||||
os.system('nmcli connection import type wireguard file ' + os.environ['HOME'] + '/tester/' +
|
read = file.read()
|
||||||
str(pathsplit))
|
file.close()
|
||||||
os.system('nmcli con mod ' + str(pathsplit[:-5]) + ' connection.autoconnect no')
|
pathsplit = filepath.split("/")
|
||||||
else:
|
pathsplit1 = pathsplit[-1]
|
||||||
subprocess.call('cp ' + str(filepath) + ' ' + os.environ['HOME'] + '/tester/', shell=True)
|
if "PrivateKey = " in read and "PublicKey = " in read:
|
||||||
os.system('nmcli connection down ' + str(TunnelActiv.active()))
|
if len(pathsplit1) > 17:
|
||||||
os.system('nmcli connection import type wireguard file ' + str(filepath))
|
pathsplit = pathsplit1[len(pathsplit1) - 17:]
|
||||||
os.system('nmcli con mod ' + str(pathsplit1[:-5]) + ' connection.autoconnect no')
|
os.rename(filepath, os.environ['HOME'] + '/tester/' + str(pathsplit))
|
||||||
if "PrivateKey = " not in read:
|
os.system('nmcli connection down ' + str(TunnelActiv.active()))
|
||||||
Message()
|
os.system('nmcli connection import type wireguard file ' + os.environ['HOME'] + '/tester/' +
|
||||||
except EOFError:
|
str(pathsplit))
|
||||||
pass
|
os.system('nmcli con mod ' + str(pathsplit[:-5]) + ' connection.autoconnect no')
|
||||||
except TypeError:
|
else:
|
||||||
pass
|
subprocess.call('cp ' + str(filepath) + ' ' + os.environ['HOME'] + '/tester/', shell=True)
|
||||||
|
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:
|
||||||
try:
|
@staticmethod
|
||||||
wg_exp = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
|
def wg_export():
|
||||||
wg_exp = wg_exp[1]
|
try:
|
||||||
return wg_exp
|
wg_exp = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
|
||||||
except IndexError:
|
wg_exp = wg_exp[1]
|
||||||
pass
|
return wg_exp
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user