wg_import_select in wg_func.py extended
This commit is contained in:
40
wg_func.py
40
wg_func.py
@ -1,12 +1,38 @@
|
||||
# Wireguard functions for Wire-Py
|
||||
import os
|
||||
import subprocess
|
||||
from tkinter import filedialog
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
|
||||
|
||||
def wg_import_select():
|
||||
try:
|
||||
filepath = filedialog.askopenfilename(initialdir=os.environ['HOME'], title="Select Wireguard config File",
|
||||
filetypes=[("WG config files", "*.conf")])
|
||||
file = open(filepath, 'r')
|
||||
read = file.read()
|
||||
file.close()
|
||||
pathsplit = filepath.split("/")
|
||||
pathsplit = pathsplit[-1]
|
||||
|
||||
if "PrivateKey = " in read and "PublicKey = " in read:
|
||||
subprocess.call('cp ' + str(filepath) + ' /etc/wg_nmcli/', shell=True)
|
||||
os.system('nmcli connection import type wireguard file ' + str(filepath))
|
||||
os.system('nmcli con mod ' + str(pathsplit[:-5]) + ' connection.autoconnect no')
|
||||
else:
|
||||
messagebox.showwarning(title="conf error", message=" Oh... no valid Wireguard File!\nPlease select a "
|
||||
"valid Wireguard File ")
|
||||
except EOFError:
|
||||
pass
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
|
||||
def active(): # Shows the active tunnel
|
||||
a = os.popen('nmcli connection show --active | grep -iPo "(.*)(wireguard)"').read().split()
|
||||
a = os.popen('nmcli con show --active | grep -iPo "(.*)(wireguard)"').read().split()
|
||||
if not a:
|
||||
a = ''
|
||||
|
||||
return a
|
||||
else:
|
||||
a = a[0]
|
||||
@ -14,7 +40,15 @@ def active(): # Shows the active tunnel
|
||||
|
||||
|
||||
def tl_list():
|
||||
wg_s = os.popen('nmcli connection show | grep -iPo "(.*)(wireguard)"').read().split()
|
||||
wg_s = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
|
||||
tl = wg_s[::3] # tl = Tunnelliste # Hiermit wird jedes 4. Element der Liste gezeigt
|
||||
return tl
|
||||
|
||||
|
||||
def wg_export():
|
||||
try:
|
||||
wg_exp = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
|
||||
wg_exp = wg_exp[1]
|
||||
return wg_exp
|
||||
except IndexError:
|
||||
pass
|
||||
|
Reference in New Issue
Block a user