wire-py-reformat-14-08-2024 #1

Merged
punix merged 3 commits from wire-py-reformat-14-08-2024 into main 2024-08-18 22:39:19 +02:00
3 changed files with 52 additions and 28 deletions
Showing only changes of commit 0c48966d47 - Show all commits

View File

@ -4,7 +4,7 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="Tunnel Start and Stop Work">
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="wg_import_select in wg_func.py extended">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/wg_func.py" beforeDir="false" afterPath="$PROJECT_DIR$/wg_func.py" afterDir="false" />
@ -105,7 +105,15 @@
<option name="project" value="LOCAL" />
<updated>1723666477079</updated>
</task>
<option name="localTasksCounter" value="3" />
<task id="LOCAL-00003" summary="wg_import_select in wg_func.py extended">
<option name="closed" value="true" />
<created>1723847456806</created>
<option name="number" value="00003" />
<option name="presentableId" value="LOCAL-00003" />
<option name="project" value="LOCAL" />
<updated>1723847456806</updated>
</task>
<option name="localTasksCounter" value="4" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -122,6 +130,7 @@
<component name="VcsManagerConfiguration">
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<MESSAGE value="Tunnel Start and Stop Work" />
<option name="LAST_COMMIT_MESSAGE" value="Tunnel Start and Stop Work" />
<MESSAGE value="wg_import_select in wg_func.py extended" />
<option name="LAST_COMMIT_MESSAGE" value="wg_import_select in wg_func.py extended" />
</component>
</project>

View File

@ -1,8 +1,6 @@
#!/usr/bin/python3
import os
import tkinter as tk
from tkinter import ttk
from tkinter import filedialog
from wg_func import active, tl_list, wg_export, wg_import_select
wg_exp = wg_export()

View File

@ -6,29 +6,6 @@ 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 con show --active | grep -iPo "(.*)(wireguard)"').read().split()
if not a:
@ -39,6 +16,46 @@ def active(): # Shows the active tunnel
return a
a = active()
def tl_list():
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_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("/")
pathsplit1 = pathsplit[-1]
if "PrivateKey = " in read and "PublicKey = " in read:
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 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 import type wireguard file ' + str(filepath))
os.system('nmcli con mod ' + str(pathsplit1[:-5]) + ' connection.autoconnect no')
if "PrivateKey = " not in read:
messagebox.showwarning(title="conf error", message=" Oh... no valid Wireguard File!\nPlease select a "
"valid Wireguard File ")
except EOFError:
pass
except TypeError:
pass
def tl_list():
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