diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 57987ad..7bb3b3b 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,7 +4,7 @@
-
+
@@ -486,7 +486,15 @@
1726915238475
-
+
+
+ 1726959423800
+
+
+
+ 1726959423800
+
+
@@ -527,7 +535,6 @@
-
@@ -552,6 +559,7 @@
-
+
+
\ No newline at end of file
diff --git a/wg_func.py b/wg_func.py
index c0a35d1..aca793e 100755
--- a/wg_func.py
+++ b/wg_func.py
@@ -14,78 +14,34 @@ path_to_file = Path('/etc/wire_py/wg_py')
_u = Path.read_text(Path('/tmp/_u'))
-def msg_window():
+def msg_window(img_w, img_i, w_title, w_txt):
+ """
+ img_w = Image for Tk Window
+ img_i = Image for Icon
+ w_title = Windows Title
+ w_txt = Text for Tk Window
+ """
msg = tk.Toplevel()
msg.resizable(width=False, height=False)
msg.x_width = 340
msg.y_height = 140
- msg.title('Import error!')
+ msg.title(w_title)
msg.monitor_center_x = msg.winfo_screenwidth() / 2 - (msg.x_width / 2)
msg.monitor_center_y = msg.winfo_screenheight() / 2 - (msg.y_height / 2)
msg.geometry('%dx%d+%d+%d' % (msg.x_width, msg.y_height, msg.monitor_center_x, msg.monitor_center_y))
msg.columnconfigure(0, weight=1)
msg.configure(pady=20)
- msg.warning = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/64/error.png')
- msg.i_warning = tk.Label(msg, image=msg.warning)
- msg.i_warning.grid(column=0, row=0)
- label = tk.Label(msg, text='Oh... no valid Wireguard File!\nPlease select a valid Wireguard File')
+ msg.img = tk.PhotoImage(file=img_w)
+ msg.i_window = tk.Label(msg, image=msg.img)
+ msg.i_window.grid(column=0, row=0)
+ label = tk.Label(msg, text=w_txt)
label.config(font=('Ubuntu', 11), padx=15, pady=15)
label.grid(column=1, row=0)
button = tk.Button(msg, text='OK', command=msg.destroy)
button.config(padx=15, pady=5)
button.grid(column=0, columnspan=2, row=1)
- wg_icon_2 = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_msg.png')
- msg.iconphoto(True, wg_icon_2)
- msg.winfo_toplevel()
-
-
-def msg_exp_successful_window():
- msg = tk.Toplevel()
- msg.resizable(width=False, height=False)
- msg.x_width = 340
- msg.y_height = 140
- msg.title('Import error!')
- msg.monitor_center_x = msg.winfo_screenwidth() / 2 - (msg.x_width / 2)
- msg.monitor_center_y = msg.winfo_screenheight() / 2 - (msg.y_height / 2)
- msg.geometry('%dx%d+%d+%d' % (msg.x_width, msg.y_height, msg.monitor_center_x, msg.monitor_center_y))
- msg.columnconfigure(0, weight=1)
- msg.configure(pady=20)
- msg.warning = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/64/info.png')
- msg.i_warning = tk.Label(msg, image=msg.warning)
- msg.i_warning.grid(column=0, row=0)
- label = tk.Label(msg, text='Your zip file is in home directory')
- label.config(font=('Ubuntu', 11), padx=15, pady=15)
- label.grid(column=1, row=0)
- button = tk.Button(msg, text='OK', command=msg.destroy)
- button.config(padx=15, pady=5)
- button.grid(column=0, columnspan=2, row=1)
- wg_icon_2 = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_vpn.png')
- msg.iconphoto(True, wg_icon_2)
- msg.winfo_toplevel()
-
-
-def msg_exp_fail_window():
- msg = tk.Toplevel()
- msg.resizable(width=False, height=False)
- msg.x_width = 340
- msg.y_height = 140
- msg.title('Export error!')
- msg.monitor_center_x = msg.winfo_screenwidth() / 2 - (msg.x_width / 2)
- msg.monitor_center_y = msg.winfo_screenheight() / 2 - (msg.y_height / 2)
- msg.geometry('%dx%d+%d+%d' % (msg.x_width, msg.y_height, msg.monitor_center_x, msg.monitor_center_y))
- msg.columnconfigure(0, weight=1)
- msg.configure(pady=20)
- msg.warning = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/64/error.png')
- msg.i_warning = tk.Label(msg, image=msg.warning)
- msg.i_warning.grid(column=0, row=0)
- label = tk.Label(msg, text='Export failed! Please try again')
- label.config(font=('Ubuntu', 11), padx=15, pady=15)
- label.grid(column=1, row=0)
- button = tk.Button(msg, text='OK', command=msg.destroy)
- button.config(padx=15, pady=5)
- button.grid(column=0, columnspan=2, row=1)
- wg_icon_2 = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_msg.png')
- msg.iconphoto(True, wg_icon_2)
+ img_i = tk.PhotoImage(file=img_i)
+ msg.iconphoto(True, img_i)
msg.winfo_toplevel()
@@ -250,14 +206,20 @@ class ImportTunnel:
with open(filepath, 'r') as file:
key = ConToDict.covert_to_dict(file)
pre_key = key[3]
- print(type(pre_key))
if len(pre_key) != 0:
with open('/etc/wire_py/.keys', 'r') as readfile:
- if pre_key in readfile:
- print('Tunnel already available! Please use another file for import')
+ p_key = readfile.readlines()
+ print(p_key)
+ if pre_key in p_key or pre_key + '\n' in p_key:
+ """img_w, img_i, w_title, w_txt hand over"""
+ iw = r'/usr/share/icons/wp-icons/64/error.png'
+ ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
+ wt = 'Import Error'
+ msg_t = 'Tunnel already available!\nPlease use another file for import'
+ msg_window(iw, ii, wt, msg_t)
else:
with open('/etc/wire_py/.keys', 'a') as keyfile:
- keyfile.write('\r\n' + pre_key)
+ keyfile.write(pre_key + '\r')
if len(path_split1) > 17:
p1 = shutil.copy(filepath, Path('/etc/wire_py/'))
path_split = path_split1[len(path_split1) - 17:]
@@ -297,7 +259,12 @@ class ImportTunnel:
os.chmod(str(wg_read), 0o600)
if 'PrivateKey = ' not in read:
- msg_window()
+ """img_w, img_i, w_title, w_txt hand over"""
+ iw = r'/usr/share/icons/wp-icons/64/error.png'
+ ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
+ wt = 'Import Error'
+ msg_t = 'Oh... no valid Wireguard File!\nPlease select a valid Wireguard File'
+ msg_window(iw, ii, wt, msg_t)
except EOFError:
pass
except TypeError:
@@ -379,9 +346,19 @@ class ExportTunnels:
os.chown(wg_tar + '.zip', 1000, 1000)
with zipfile.ZipFile((wg_tar + '.zip'), 'r') as zf:
if len(zf.namelist()) != 0:
- msg_exp_successful_window()
+ """img_w, img_i, w_title, w_txt hand over"""
+ iw = r'/usr/share/icons/wp-icons/64/info.png'
+ ii = r'/usr/share/icons/wp-icons/48/wg_vpn.png'
+ wt = 'Import Error'
+ msg_t = 'Your zip file is in home directory'
+ msg_window(iw, ii, wt, msg_t)
else:
- msg_exp_fail_window()
+ """img_w, img_i, w_title, w_txt hand over"""
+ iw = r'/usr/share/icons/wp-icons/64/error.png'
+ ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
+ wt = 'Export error'
+ msg_t = 'Export failed! Please try again'
+ msg_window(iw, ii, wt, msg_t)
except TypeError:
pass
diff --git a/wg_main.py b/wg_main.py
index 170c0c5..7837dbc 100755
--- a/wg_main.py
+++ b/wg_main.py
@@ -160,7 +160,6 @@ class FrameWidgets(ttk.Frame):
with open('/etc/wire_py/' + select_tl + '.conf', 'r+') as file2:
key = ConToDict.covert_to_dict(file2)
pre_key = key[3]
- print(pre_key)
check_call(['nmcli', 'connection', 'delete', select_tl])
self.l_box.delete(self.select_tunnel[0])
if Path.is_file(Path('/etc/wire_py/wg_py')):