diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 40e434d..0f1311c 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,8 +4,9 @@
-
+
+
@@ -509,7 +510,23 @@
1727018233930
-
+
+
+ 1727028762875
+
+
+
+ 1727028762875
+
+
+
+ 1727028915701
+
+
+
+ 1727028915701
+
+
@@ -550,8 +567,6 @@
-
-
@@ -575,29 +590,31 @@
-
+
+
+
file://$PROJECT_DIR$/wg_func.py
- 135
+ 137
file://$PROJECT_DIR$/wg_func.py
- 194
+ 196
file://$PROJECT_DIR$/wg_func.py
- 72
+ 74
file://$PROJECT_DIR$/wg_func.py
- 343
+ 348
diff --git a/wg_func.py b/wg_func.py
index 2215267..1f69ec5 100755
--- a/wg_func.py
+++ b/wg_func.py
@@ -14,7 +14,7 @@ path_to_file = Path('/etc/wire_py/wg_py')
_u = Path.read_text(Path('/tmp/_u'))
-def msg_window(img_w, img_i, w_title, w_txt):
+def msg_window(img_w, img_i, w_title, w_txt, x, y):
"""
Function for different message windows for the user. with 4 arguments to be passed.
To create messages with your own images, icons, and titles. As an alternative to Python Messagebox.
@@ -23,11 +23,13 @@ def msg_window(img_w, img_i, w_title, w_txt):
img_i = Image for Icon
w_title = Windows Title
w_txt = Text for Tk Window
+ x = Window width
+ y = Window height
"""
msg = tk.Toplevel()
msg.resizable(width=False, height=False)
- msg.x_width = 340
- msg.y_height = 140
+ msg.x_width = x
+ msg.y_height = y
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)
@@ -242,14 +244,15 @@ class ImportTunnel:
if len(pre_key) != 0:
with open('/etc/wire_py/.keys', 'r') as readfile:
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)
+ x = 340 # width
+ y = 140 # height
+ msg_window(iw, ii, wt, msg_t, x, y)
else:
with open('/etc/wire_py/.keys', 'a') as keyfile:
keyfile.write(pre_key + '\r')
@@ -292,12 +295,14 @@ class ImportTunnel:
os.chmod(str(wg_read), 0o600)
if 'PrivateKey = ' not in read:
- """img_w, img_i, w_title, w_txt hand over"""
+ """img_w, img_i, w_title, w_txt x, y 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)
+ x = 340 # width
+ y = 140 # height
+ msg_window(iw, ii, wt, msg_t, x, y)
except EOFError:
pass
except TypeError:
@@ -398,14 +403,18 @@ class ExportTunnels:
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)
+ x = 340 # width
+ y = 140 # height
+ msg_window(iw, ii, wt, msg_t, x, y)
else:
"""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)
+ x = 340 # width
+ y = 140 # height
+ msg_window(iw, ii, wt, msg_t, x, y)
except TypeError:
pass
diff --git a/wg_main.py b/wg_main.py
index 253e82b..8655c08 100755
--- a/wg_main.py
+++ b/wg_main.py
@@ -7,7 +7,7 @@ from pathlib import Path
from tkinter import ttk
from wg_func import (TunnelActiv, ListTunnels, ImportTunnel, ConToDict, GreenLabel, StartStopBTN, ShowAddress,
- FileHandle, ExportTunnels, OnOff)
+ FileHandle, ExportTunnels, OnOff, msg_window)
font_color = '#4011a7'
@@ -191,7 +191,14 @@ class FrameWidgets(ttk.Frame):
self.enp.set('')
return select_tl
except IndexError:
- pass
+ """img_w, img_i, w_title, w_txt x, y hand over"""
+ iw = r'/usr/share/icons/wp-icons/64/info.png'
+ ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
+ wt = 'Renaming not possible'
+ msg_t = 'Please select a tunnel from the list.'
+ x = 340 # width
+ y = 140 # height
+ msg_window(iw, ii, wt, msg_t, x, y)
# Button Trash
self.btn_tr = tk.Button(self.lb_frame_btn_lbox, image=self.tr_pic, bd=0, command=delete)
@@ -208,31 +215,69 @@ class FrameWidgets(ttk.Frame):
self.lb_rename.config(state='disable')
def tl_rename():
- try:
- self.select_tunnel = self.l_box.curselection()
- select_tl = self.l_box.get(self.select_tunnel[0])
- # nmcli connection modify old connection.id iphone
- check_call(['nmcli', 'connection', 'modify', select_tl, 'connection.id', self.lb_rename.get()])
- source = Path('/etc/wire_py') / str(select_tl + '.conf')
- destination = source.with_name(str(self.lb_rename.get() + '.conf'))
- source.replace(destination)
- self.l_box.delete(self.select_tunnel[0])
- self.l_box.insert("end", self.lb_rename.get())
- self.l_box.update()
- new_a_connect = self.lb_rename.get()
- self.lb_rename.delete(0, tk.END)
- if self.a != '' and self.a == select_tl:
- self.a = TunnelActiv.active()
- self.StrVar.set(value=self.a)
- if Path.is_file(Path('/etc/wire_py/wg_py')):
- path_to_file = Path('/etc/wire_py') / 'wg_py'
- a_con = Path.read_text(path_to_file)
- if select_tl == a_con:
- self.autoconnect_var.set(value=new_a_connect)
- Path.write_text(path_to_file, new_a_connect)
- return select_tl
- except IndexError:
- pass
+
+ if len(self.lb_rename.get()) > 12:
+ """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_msg.png'
+ wt = 'Renaming not possible'
+ msg_t = 'The new name may contain only 12 characters.'
+ x = 420 # width
+ y = 140 # height
+ msg_window(iw, ii, wt, msg_t, x, y)
+
+ elif len(self.lb_rename.get()) == 0:
+ """img_w, img_i, w_title, w_txt x, y hand over"""
+ iw = r'/usr/share/icons/wp-icons/64/info.png'
+ ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
+ wt = 'Renaming not possible'
+ msg_t = 'At least one character must be entered.'
+ x = 380 # width
+ y = 140 # height
+ msg_window(iw, ii, wt, msg_t, x, y)
+
+ elif ' ' in self.lb_rename.get():
+ """img_w, img_i, w_title, w_txt x, y hand over"""
+ iw = r'/usr/share/icons/wp-icons/64/info.png'
+ ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
+ wt = 'Renaming not possible'
+ msg_t = 'Please do not use blanks.'
+ x = 280 # width
+ y = 140 # height
+ msg_window(iw, ii, wt, msg_t, x, y)
+ else:
+ try:
+ self.select_tunnel = self.l_box.curselection()
+ select_tl = self.l_box.get(self.select_tunnel[0])
+ # nmcli connection modify old connection.id iphone
+ check_call(['nmcli', 'connection', 'modify', select_tl, 'connection.id', self.lb_rename.get()])
+ source = Path('/etc/wire_py') / str(select_tl + '.conf')
+ destination = source.with_name(str(self.lb_rename.get() + '.conf'))
+ source.replace(destination)
+ self.l_box.delete(self.select_tunnel[0])
+ self.l_box.insert("end", self.lb_rename.get())
+ self.l_box.update()
+ new_a_connect = self.lb_rename.get()
+ self.lb_rename.delete(0, tk.END)
+ if self.a != '' and self.a == select_tl:
+ self.a = TunnelActiv.active()
+ self.StrVar.set(value=self.a)
+ if Path.is_file(Path('/etc/wire_py/wg_py')):
+ path_to_file = Path('/etc/wire_py') / 'wg_py'
+ a_con = Path.read_text(path_to_file)
+ if select_tl == a_con:
+ self.autoconnect_var.set(value=new_a_connect)
+ Path.write_text(path_to_file, new_a_connect)
+ return select_tl
+ except IndexError:
+ """img_w, img_i, w_title, w_txt x, y hand over"""
+ iw = r'/usr/share/icons/wp-icons/64/info.png'
+ ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
+ wt = 'Renaming not possible'
+ msg_t = 'Please select a tunnel from the list.'
+ x = 340 # width
+ y = 140 # height
+ msg_window(iw, ii, wt, msg_t, x, y)
# Button Rename
self.btn_rename = ttk.Button(self, text='Rename', state='disable', command=tl_rename)
@@ -292,7 +337,14 @@ class FrameWidgets(ttk.Frame):
self.enp.set('')
ShowAddress.show_data(self)
except IndexError:
- pass
+ """img_w, img_i, w_title, w_txt x, y hand over"""
+ iw = r'/usr/share/icons/wp-icons/64/info.png'
+ ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
+ wt = 'Renaming not possible'
+ msg_t = 'Please select a tunnel from the list.'
+ x = 340 # width
+ y = 140 # height
+ msg_window(iw, ii, wt, msg_t, x, y)
if __name__ == '__main__':