diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 7a35cc4..bc3fea4 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,11 +4,7 @@
-
-
-
-
-
+
@@ -46,7 +42,7 @@
"Python.main.executor": "Run",
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "wire-py-reformat-14-08-2024",
- "last_opened_file_path": "/home/punix/Pyapps/wire-py"
+ "last_opened_file_path": "/home/punix/Downloads/tkinter-bitcoin_price_converter_objectoriented(1).py"
}
}
@@ -105,7 +101,23 @@
1723666477079
-
+
+
+ 1723847456806
+
+
+
+ 1723847456806
+
+
+
+ 1724013210356
+
+
+
+ 1724013210356
+
+
@@ -122,6 +134,8 @@
-
+
+
+
\ No newline at end of file
diff --git a/icons/warning_128.png b/icons/warning_128.png
new file mode 100644
index 0000000..ae580f8
Binary files /dev/null and b/icons/warning_128.png differ
diff --git a/icons/warning_256.png b/icons/warning_256.png
new file mode 100644
index 0000000..7734e3a
Binary files /dev/null and b/icons/warning_256.png differ
diff --git a/icons/warning_32.png b/icons/warning_32.png
new file mode 100644
index 0000000..e695c2c
Binary files /dev/null and b/icons/warning_32.png differ
diff --git a/icons/warning_64.png b/icons/warning_64.png
new file mode 100644
index 0000000..5ac3858
Binary files /dev/null and b/icons/warning_64.png differ
diff --git a/main.py b/main.py
index 1ec5b80..27a4a47 100644
--- a/main.py
+++ b/main.py
@@ -2,27 +2,23 @@
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()
-
-
-color_default = '#d3ebff'
-color_dark = '#2e2e2e'
a = active()
class MainWindow(tk.Tk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
- self.select_tunnel = None
+
self.switch_on = None
self.switch_off = None
self.x_width = 600
self.y_height = 350
self.monitor_center_x = self.winfo_screenwidth() / 2 - (self.x_width / 2)
self.monitor_center_y = self.winfo_screenheight() / 2 - (self.y_height / 2)
+ self.resizable(width=False, height=False)
self.lb_tunnel = None
self.title('Wire-Py')
self.configure()
@@ -32,6 +28,13 @@ class MainWindow(tk.Tk):
# Set it as the window icon.
self.iconphoto(True, self.wg_icon)
+ FrameWidgets(self).grid()
+
+
+class FrameWidgets(ttk.Frame):
+ def __init__(self, container, **kwargs):
+ super().__init__(container, **kwargs)
+
self.wg_vpn_start = tk.PhotoImage(file=r'icons/wg-vpn-start-48.png')
self.wg_vpn_stop = tk.PhotoImage(file=r'icons/wg-vpn-stop-48.png')
self.wgi_on = tk.PhotoImage(file=r'icons/wire-switch-on-48.png')
@@ -39,8 +42,10 @@ class MainWindow(tk.Tk):
self.imp_pic = tk.PhotoImage(file=r'icons/wg-import.png')
self.tr_pic = tk.PhotoImage(file=r'icons/wg-trash-48.png')
self.exp_pic = tk.PhotoImage(file=r'icons/wg-export-48.png')
+ self.warning_pic = tk.PhotoImage(file=r'icons/warning_64.png')
# Show active Label
+ self.select_tunnel = None
self.lb = tk.Label(self, text='Active:')
self.lb.config(font=("Ubuntu", 11, "bold"))
self.lb.grid(column=2, row=1, padx=10, pady=5, sticky="e")
@@ -73,8 +78,19 @@ class MainWindow(tk.Tk):
# Button Import
self.btn_i = tk.Button(self, image=self.imp_pic, bd=0, command=wg_import_select)
self.btn_i.grid(column=0, row=2, padx=15, pady=15)
- # Button Trash
- self.btn_tr = tk.Button(self, image=self.tr_pic, bd=0)
+
+ def delete():
+ self.select_tunnel = self.l_box.curselection()
+ select_tl = self.l_box.get(self.select_tunnel[0])
+ os.system('nmcli connection delete ' + str(select_tl))
+ self.l_box.delete(self.select_tunnel[0])
+ if a != '':
+ self.StrVar.set(value='')
+ self.btn_stst = tk.Button(self, image=self.wg_vpn_start, bd=0, command=self.wg_switch)
+ self.btn_stst.grid(column=0, row=1, padx=15, pady=15, sticky="s")
+
+ # Button Trash
+ self.btn_tr = tk.Button(self, image=self.tr_pic, bd=0, command=delete)
self.btn_tr.grid(column=0, row=3, padx=15, pady=15)
# Button Export
self.btn_exp = tk.Button(self, image=self.exp_pic, bd=0)
@@ -109,7 +125,7 @@ class MainWindow(tk.Tk):
self.btn_stst.grid(column=0, row=1, padx=15, pady=15, sticky="s")
a = active()
self.StrVar = tk.StringVar()
- self.StrVar.set(' ')
+ self.StrVar.set(value=' ')
self.lb_tunnel = tk.Label(self, textvariable=self.StrVar, fg='green')
self.lb_tunnel.config(font=("Ubuntu", 11, "bold"))
self.lb_tunnel.grid(column=3, row=1, sticky="w")
diff --git a/wg_func.py b/wg_func.py
index 98aecd3..e3beaa6 100644
--- a/wg_func.py
+++ b/wg_func.py
@@ -3,30 +3,30 @@ import os
import subprocess
from tkinter import filedialog
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]
+class Message(tk.Tk):
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
- 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
+ self.warning_pic = None
+ self.x_width = 300
+ self.y_height = 120
+ self.monitor_center_x = self.winfo_screenwidth() / 2 - (self.x_width / 2)
+ self.monitor_center_y = self.winfo_screenheight() / 2 - (self.y_height / 2)
+ self.resizable(width=False, height=False)
+ self.title('Import error!')
+ self.configure()
+ self.geometry('%dx%d+%d+%d' % (self.x_width, self.y_height, self.monitor_center_x, self.monitor_center_y))
+ self.columnconfigure(0, weight=1)
+
+ 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.grid(column=0, row=0)
+ self.button = tk.Button(self, text="OK", command=self.destroy)
+ self.button.config(padx=15, pady=5)
+ self.button.grid(column=0, row=1)
def active(): # Shows the active tunnel
@@ -39,12 +39,45 @@ 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
+ tl = wg_s[::3] # tl = Tunnel list # Show of 4.Element in list
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:
+ Message()
+ except EOFError:
+ pass
+ except TypeError:
+ pass
+
+
def wg_export():
try:
wg_exp = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()