add class TunnelActive to wg_func works

This commit is contained in:
2024-08-18 23:23:43 +02:00
parent 5606ce15b9
commit 213032252a
3 changed files with 67 additions and 36 deletions

View File

@ -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: