little fixes a " " to ' '

This commit is contained in:
Désiré Werner Menrath 2024-08-31 17:50:42 +02:00
parent e5d86f1f90
commit b82bd6d9e7
3 changed files with 59 additions and 44 deletions

View File

@ -4,7 +4,7 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="import datetime for datetime in zip_name a export Tunnel"> <list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="columnconfigure on all widgets set">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <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$/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" /> <change beforePath="$PROJECT_DIR$/wg_func.py" beforeDir="false" afterPath="$PROJECT_DIR$/wg_func.py" afterDir="false" />
@ -243,7 +243,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1724610514658</updated> <updated>1724610514658</updated>
</task> </task>
<option name="localTasksCounter" value="20" /> <task id="LOCAL-00020" summary="columnconfigure on all widgets set">
<option name="closed" value="true" />
<created>1724778892233</created>
<option name="number" value="00020" />
<option name="presentableId" value="LOCAL-00020" />
<option name="project" value="LOCAL" />
<updated>1724778892233</updated>
</task>
<option name="localTasksCounter" value="21" />
<servers /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
@ -289,6 +297,7 @@
<MESSAGE value="remove a ',' in DNS Name" /> <MESSAGE value="remove a ',' in DNS Name" />
<MESSAGE value="fix when Filname &gt; 17 first copy file after rename" /> <MESSAGE value="fix when Filname &gt; 17 first copy file after rename" />
<MESSAGE value="add export Tunnel as zip" /> <MESSAGE value="add export Tunnel as zip" />
<option name="LAST_COMMIT_MESSAGE" value="add export Tunnel as zip" /> <MESSAGE value="columnconfigure on all widgets set" />
<option name="LAST_COMMIT_MESSAGE" value="columnconfigure on all widgets set" />
</component> </component>
</project> </project>

26
main.py
View File

@ -6,7 +6,7 @@ from tkinter import ttk
from wg_func import (TunnelActiv, ListTunnels, ImportTunnel, ConToDict, GreenLabel, StartStopBTN, ShowAddress, from wg_func import (TunnelActiv, ListTunnels, ImportTunnel, ConToDict, GreenLabel, StartStopBTN, ShowAddress,
ExportTunnels) ExportTunnels)
fontcolor = '#4011a7' font_color = '#4011a7'
class MainWindow(tk.Tk): class MainWindow(tk.Tk):
@ -71,23 +71,23 @@ class FrameWidgets(ttk.Frame):
# Show active Label # Show active Label
self.select_tunnel = None self.select_tunnel = None
self.lb = tk.Label(self, text='Active: ') self.lb = tk.Label(self, text='Active: ')
self.lb.config(font=("Ubuntu", 11, "bold")) self.lb.config(font=('Ubuntu', 11, 'bold'))
self.lb.grid(column=2, row=1, padx=15, sticky="w") self.lb.grid(column=2, row=1, padx=15, sticky='w')
self.columnconfigure(2, weight=1) self.columnconfigure(2, weight=1)
self.rowconfigure(1, weight=1) self.rowconfigure(1, weight=1)
# Label to Show active Tunnel # Label to Show active Tunnel
self.StrVar = tk.StringVar(value=self.a) self.StrVar = tk.StringVar(value=self.a)
GreenLabel.green_show_label(self) GreenLabel.green_show_label(self)
# Interface Label # Interface Label
self.interface = tk.Label(self.lb_frame, text='Interface', fg=fontcolor) self.interface = tk.Label(self.lb_frame, text='Interface', fg=font_color)
self.interface.grid(column=0, row=4, sticky="we", padx=120) self.interface.grid(column=0, row=4, sticky='we', padx=120)
self.interface.config(font=("Ubuntu", 9)) self.interface.config(font=('Ubuntu', 9))
self.columnconfigure(0, weight=1) self.columnconfigure(0, weight=1)
self.rowconfigure(4, weight=1) self.rowconfigure(4, weight=1)
# Peer Label # Peer Label
self.peer = tk.Label(self.lb_frame2, text='Peer', fg=fontcolor) self.peer = tk.Label(self.lb_frame2, text='Peer', fg=font_color)
self.peer.config(font=("Ubuntu", 9)) self.peer.config(font=('Ubuntu', 9))
self.peer.grid(column=0, row=7, sticky="we", padx=130) self.peer.grid(column=0, row=7, sticky='we', padx=130)
self.columnconfigure(0, weight=1) self.columnconfigure(0, weight=1)
self.rowconfigure(7, weight=1) self.rowconfigure(7, weight=1)
# Listbox with Scrollbar # Listbox with Scrollbar
@ -95,7 +95,7 @@ class FrameWidgets(ttk.Frame):
self.l_box = tk.Listbox(self, fg='#606060', selectmode='single') self.l_box = tk.Listbox(self, fg='#606060', selectmode='single')
self.l_box.config(highlightthickness=0, relief='flat') self.l_box.config(highlightthickness=0, relief='flat')
self.scrollbar.config(command=self.l_box.yview) self.scrollbar.config(command=self.l_box.yview)
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.columnconfigure(1, weight=1) self.columnconfigure(1, weight=1)
self.rowconfigure(1, weight=1) self.rowconfigure(1, weight=1)
@ -154,9 +154,15 @@ class FrameWidgets(ttk.Frame):
self.btn_exp.grid(column=0, row=4, padx=15, pady=15) self.btn_exp.grid(column=0, row=4, padx=15, pady=15)
self.columnconfigure(0, weight=1) self.columnconfigure(0, weight=1)
self.rowconfigure(4, weight=1) self.rowconfigure(4, weight=1)
# Button Rename
self.btn_rename = ttk.Button(self, text='Rename')
self.btn_rename.grid(column=2, row=4, padx=20, pady=15, sticky='e')
self.columnconfigure(3, weight=1)
self.rowconfigure(4, weight=1)
# Check Buttons # Check Buttons
self.wg_autostart = tk.Checkbutton(self, text='Autoconnect on PC Start') self.wg_autostart = tk.Checkbutton(self, text='Autoconnect on PC Start')
self.wg_autostart.grid(column=1, rowspan=3, row=3) self.wg_autostart.grid(column=1, rowspan=3, row=3)
self.columnconfigure(1, weight=1) self.columnconfigure(1, weight=1)
self.rowconfigure(3, weight=1) self.rowconfigure(3, weight=1)
self.wg_update = tk.Checkbutton(self, text='Search automatically for\nWire-Py updates') self.wg_update = tk.Checkbutton(self, text='Search automatically for\nWire-Py updates')

View File

@ -5,7 +5,7 @@ from datetime import datetime
from tkinter import filedialog from tkinter import filedialog
import tkinter as tk import tkinter as tk
fontcolor = '#4011a7' font_color = '#4011a7'
class Message(tk.Tk): class Message(tk.Tk):
@ -25,9 +25,9 @@ class Message(tk.Tk):
self.label = tk.Label(self, image=self.warning_pic, self.label = tk.Label(self, image=self.warning_pic,
text='Oh... no valid Wireguard File!\nPlease select a valid Wireguard File') text='Oh... no valid Wireguard File!\nPlease select a valid Wireguard File')
self.label.config(font=("Ubuntu", 11), padx=15, pady=15) self.label.config(font=('Ubuntu', 11), padx=15, pady=15)
self.label.grid(column=0, row=0) self.label.grid(column=0, row=0)
self.button = tk.Button(self, text="OK", command=self.destroy) self.button = tk.Button(self, text='OK', command=self.destroy)
self.button.config(padx=15, pady=5) self.button.config(padx=15, pady=5)
self.button.grid(column=0, row=1) self.button.grid(column=0, row=1)
@ -40,7 +40,7 @@ class GreenLabel(tk.Tk):
def green_show_label(self): def green_show_label(self):
self.lb_tunnel = tk.Label(self, textvariable=self.StrVar, fg='green') self.lb_tunnel = tk.Label(self, textvariable=self.StrVar, fg='green')
self.lb_tunnel.config(font=("Ubuntu", 11, "bold")) self.lb_tunnel.config(font=('Ubuntu', 11, 'bold'))
self.lb_tunnel.grid(column=2, padx=10, row=1) self.lb_tunnel.grid(column=2, padx=10, row=1)
self.columnconfigure(2, weight=1) self.columnconfigure(2, weight=1)
self.rowconfigure(1, weight=1) self.rowconfigure(1, weight=1)
@ -72,14 +72,14 @@ class ConToDict:
def covert_to_dict(cls, file): def covert_to_dict(cls, file):
dictlist = [] dictlist = []
for lines in file.readlines(): for lines in file.readlines():
lineplit = lines.split() line_plit = lines.split()
dictlist = dictlist + lineplit dictlist = dictlist + line_plit
dictlist.remove('[Interface]') dictlist.remove('[Interface]')
dictlist.remove('[Peer]') dictlist.remove('[Peer]')
for items in dictlist: for items in dictlist:
if items == '=': if items == '=':
dictlist.remove(items) dictlist.remove(items)
for i in dictlist: # Here is the beginning (Loop) of convert List to Dictionary for _ in dictlist: # Here is the beginning (Loop) of convert List to Dictionary
a = [dictlist[0], dictlist[1]] a = [dictlist[0], dictlist[1]]
b = [dictlist[2], dictlist[3]] b = [dictlist[2], dictlist[3]]
c = [dictlist[4], dictlist[5]] c = [dictlist[4], dictlist[5]]
@ -88,17 +88,17 @@ class ConToDict:
f = [dictlist[10], dictlist[11]] f = [dictlist[10], dictlist[11]]
g = [dictlist[12], dictlist[13]] g = [dictlist[12], dictlist[13]]
h = [dictlist[14], dictlist[15]] h = [dictlist[14], dictlist[15]]
newlist = [a, b, c, d, e, f, g, h] new_list = [a, b, c, d, e, f, g, h]
finaldict = {} final_dict = {}
for elements in newlist: for elements in new_list:
finaldict[elements[0]] = elements[1] final_dict[elements[0]] = elements[1]
# end... result a Dictionary # end... result a Dictionary
address = finaldict['Address'] address = final_dict['Address']
dns = finaldict['DNS'] dns = final_dict['DNS']
if ',' in dns: if ',' in dns:
dns = dns[:-1] dns = dns[:-1]
endpoint = finaldict['Endpoint'] endpoint = final_dict['Endpoint']
return address, dns, endpoint return address, dns, endpoint
@ -143,16 +143,16 @@ class ShowAddress(tk.Tk):
def show_data(self): def show_data(self):
# Address Label # Address Label
self.address = tk.Label(self.lb_frame, textvariable=self.add, fg='blue') self.address = tk.Label(self.lb_frame, textvariable=self.add, fg='blue')
self.address.grid(column=0, row=5, sticky="w", padx=10) self.address.grid(column=0, row=5, sticky='w', padx=10)
self.address.config(font=("Ubuntu", 9)) self.address.config(font=('Ubuntu', 9))
# DNS Label # DNS Label
self.dns = tk.Label(self.lb_frame, textvariable=self.DNS, fg='blue') self.dns = tk.Label(self.lb_frame, textvariable=self.DNS, fg='blue')
self.dns.grid(column=0, row=6, sticky="w", padx=10, pady=3) self.dns.grid(column=0, row=6, sticky='w', padx=10, pady=3)
self.dns.config(font=("Ubuntu", 9)) self.dns.config(font=('Ubuntu', 9))
# Endpoint Label # Endpoint Label
self.endpoint = tk.Label(self.lb_frame2, textvariable=self.enp, fg='blue') self.endpoint = tk.Label(self.lb_frame2, textvariable=self.enp, fg='blue')
self.endpoint.grid(column=0, row=8, sticky="w", padx=10, pady=5) self.endpoint.grid(column=0, row=8, sticky='w', padx=10, pady=5)
self.endpoint.config(font=("Ubuntu", 9)) self.endpoint.config(font=('Ubuntu', 9))
class ListTunnels: class ListTunnels:
@ -178,22 +178,22 @@ class ImportTunnel:
def wg_import_select(self): def wg_import_select(self):
try: try:
filepath = filedialog.askopenfilename(initialdir=os.environ['HOME'], title="Select Wireguard config File", filepath = filedialog.askopenfilename(initialdir=os.environ['HOME'], title='Select Wireguard config File',
filetypes=[("WG config files", "*.conf")]) filetypes=[('WG config files', '*.conf')])
file = open(filepath, 'r') file = open(filepath, 'r')
read = file.read() read = file.read()
file.close() file.close()
pathsplit = filepath.split("/") path_split = filepath.split('/')
pathsplit1 = pathsplit[-1] path_split1 = path_split[-1]
if "PrivateKey = " in read and "PublicKey = " in read: if 'PrivateKey = ' in read and 'PublicKey = ' in read:
if len(pathsplit1) > 17: if len(path_split1) > 17:
p1 = shutil.copy(filepath, os.environ['HOME'] + '/tester/') p1 = shutil.copy(filepath, os.environ['HOME'] + '/tester/')
pathsplit = pathsplit1[len(pathsplit1) - 17:] path_split = path_split1[len(path_split1) - 17:]
os.rename(p1, os.environ['HOME'] + '/tester/' + str(pathsplit)) os.rename(p1, os.environ['HOME'] + '/tester/' + str(path_split))
if self.a != '': if self.a != '':
os.system('nmcli connection down ' + str(TunnelActiv.active())) os.system('nmcli connection down ' + str(TunnelActiv.active()))
os.system('nmcli connection import type wireguard file ' + os.environ['HOME'] + '/tester/' + os.system('nmcli connection import type wireguard file ' + os.environ['HOME'] + '/tester/' +
str(pathsplit)) str(path_split))
else: else:
shutil.copy(filepath, os.environ['HOME'] + '/tester/') shutil.copy(filepath, os.environ['HOME'] + '/tester/')
if self.a != '': if self.a != '':
@ -216,7 +216,7 @@ class ImportTunnel:
ShowAddress.show_data(self) ShowAddress.show_data(self)
file.close() file.close()
os.system('nmcli con mod ' + str(self.a) + ' connection.autoconnect no') os.system('nmcli con mod ' + str(self.a) + ' connection.autoconnect no')
if "PrivateKey = " not in read: if 'PrivateKey = ' not in read:
Message() Message()
except EOFError: except EOFError:
pass pass
@ -230,7 +230,7 @@ class ExportTunnels:
@staticmethod @staticmethod
def wg_export(): def wg_export():
now_time = datetime.now() now_time = datetime.now()
now_datetime = now_time.strftime('/wg-exp-' + "%m-%d-%Y" + '-' + "%H:%M") now_datetime = now_time.strftime('/wg-exp-' + '%m-%d-%Y' + '-' + '%H:%M')
tl = ListTunnels.tl_list() tl = ListTunnels.tl_list()
try: try:
if len(tl) != 0: if len(tl) != 0: