little fixes a " " to ' '

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

View File

@ -5,7 +5,7 @@ from datetime import datetime
from tkinter import filedialog
import tkinter as tk
fontcolor = '#4011a7'
font_color = '#4011a7'
class Message(tk.Tk):
@ -25,9 +25,9 @@ class Message(tk.Tk):
self.label = tk.Label(self, image=self.warning_pic,
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.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.grid(column=0, row=1)
@ -40,7 +40,7 @@ class GreenLabel(tk.Tk):
def green_show_label(self):
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.columnconfigure(2, weight=1)
self.rowconfigure(1, weight=1)
@ -72,14 +72,14 @@ class ConToDict:
def covert_to_dict(cls, file):
dictlist = []
for lines in file.readlines():
lineplit = lines.split()
dictlist = dictlist + lineplit
line_plit = lines.split()
dictlist = dictlist + line_plit
dictlist.remove('[Interface]')
dictlist.remove('[Peer]')
for items in dictlist:
if 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]]
b = [dictlist[2], dictlist[3]]
c = [dictlist[4], dictlist[5]]
@ -88,17 +88,17 @@ class ConToDict:
f = [dictlist[10], dictlist[11]]
g = [dictlist[12], dictlist[13]]
h = [dictlist[14], dictlist[15]]
newlist = [a, b, c, d, e, f, g, h]
finaldict = {}
for elements in newlist:
finaldict[elements[0]] = elements[1]
new_list = [a, b, c, d, e, f, g, h]
final_dict = {}
for elements in new_list:
final_dict[elements[0]] = elements[1]
# end... result a Dictionary
address = finaldict['Address']
dns = finaldict['DNS']
address = final_dict['Address']
dns = final_dict['DNS']
if ',' in dns:
dns = dns[:-1]
endpoint = finaldict['Endpoint']
endpoint = final_dict['Endpoint']
return address, dns, endpoint
@ -143,16 +143,16 @@ class ShowAddress(tk.Tk):
def show_data(self):
# Address Label
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.config(font=("Ubuntu", 9))
self.address.grid(column=0, row=5, sticky='w', padx=10)
self.address.config(font=('Ubuntu', 9))
# DNS Label
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.config(font=("Ubuntu", 9))
self.dns.grid(column=0, row=6, sticky='w', padx=10, pady=3)
self.dns.config(font=('Ubuntu', 9))
# Endpoint Label
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.config(font=("Ubuntu", 9))
self.endpoint.grid(column=0, row=8, sticky='w', padx=10, pady=5)
self.endpoint.config(font=('Ubuntu', 9))
class ListTunnels:
@ -178,22 +178,22 @@ class ImportTunnel:
def wg_import_select(self):
try:
filepath = filedialog.askopenfilename(initialdir=os.environ['HOME'], title="Select Wireguard config File",
filetypes=[("WG config files", "*.conf")])
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:
path_split = filepath.split('/')
path_split1 = path_split[-1]
if 'PrivateKey = ' in read and 'PublicKey = ' in read:
if len(path_split1) > 17:
p1 = shutil.copy(filepath, os.environ['HOME'] + '/tester/')
pathsplit = pathsplit1[len(pathsplit1) - 17:]
os.rename(p1, os.environ['HOME'] + '/tester/' + str(pathsplit))
path_split = path_split1[len(path_split1) - 17:]
os.rename(p1, os.environ['HOME'] + '/tester/' + str(path_split))
if self.a != '':
os.system('nmcli connection down ' + str(TunnelActiv.active()))
os.system('nmcli connection import type wireguard file ' + os.environ['HOME'] + '/tester/' +
str(pathsplit))
str(path_split))
else:
shutil.copy(filepath, os.environ['HOME'] + '/tester/')
if self.a != '':
@ -216,7 +216,7 @@ class ImportTunnel:
ShowAddress.show_data(self)
file.close()
os.system('nmcli con mod ' + str(self.a) + ' connection.autoconnect no')
if "PrivateKey = " not in read:
if 'PrivateKey = ' not in read:
Message()
except EOFError:
pass
@ -230,7 +230,7 @@ class ExportTunnels:
@staticmethod
def wg_export():
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()
try:
if len(tl) != 0: