diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index d15774a..7aa4bb7 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,9 +4,8 @@
-
+
-
@@ -164,7 +163,55 @@
1724237471056
-
+
+
+ 1724272761629
+
+
+
+ 1724272761629
+
+
+
+ 1724371229008
+
+
+
+ 1724371229008
+
+
+
+ 1724400463791
+
+
+
+ 1724400463791
+
+
+
+ 1724401340512
+
+
+
+ 1724401340512
+
+
+
+ 1724410630021
+
+
+
+ 1724410630021
+
+
+
+ 1724416642213
+
+
+
+ 1724416642213
+
+
@@ -200,6 +247,12 @@
-
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dict_to_address b/dict_to_address
deleted file mode 100644
index 2a74fd9..0000000
--- a/dict_to_address
+++ /dev/null
@@ -1,3 +0,0 @@
-192.168.178.158/24
-192.168.178.1,
-rj2cexasg9b9oydd.myfritz.net:54775
diff --git a/main.py b/main.py
index 61a3201..9a5e9dd 100644
--- a/main.py
+++ b/main.py
@@ -3,8 +3,10 @@ import os
import tkinter as tk
from tkinter import ttk
-from wg_func import (TunnelActiv, ListTunnels, ImportTunnel,
- ConToDict, GreenLabel, StartStopBTN, ExportTunnels)
+from wg_func import (TunnelActiv, ListTunnels, ImportTunnel, ConToDict, GreenLabel, StartStopBTN, ShowAddress,
+ ExportTunnels)
+
+fontcolor = '#4011a7'
class MainWindow(tk.Tk):
@@ -24,7 +26,6 @@ class MainWindow(tk.Tk):
self.columnconfigure(2, weight=1)
self.rowconfigure(0, weight=1)
self.style = ttk.Style(self)
- print(self.style.theme_names())
self.style.theme_use('clam')
# Load the image file from disk.
self.wg_icon = tk.PhotoImage(file=r'icons/wg-vpn-48.png')
@@ -38,6 +39,11 @@ class FrameWidgets(ttk.Frame):
def __init__(self, container, **kwargs):
super().__init__(container, **kwargs)
+ self.enp = None
+ self.DNS = None
+ self.add = None
+ self.data = None
+ self.peer = None
self.lb_tunnel = None
self.wg_read = None
self.wg_vpn_start = tk.PhotoImage(file=r'icons/wg-vpn-start-48.png')
@@ -50,13 +56,13 @@ class FrameWidgets(ttk.Frame):
# Show active Tunnel
self.a = TunnelActiv.active()
- # Label 2
+ # Label Frame 1
self.lb_frame = ttk.Frame(self)
self.lb_frame.configure(relief='solid')
self.lb_frame.grid(column=2, row=2, sticky='snew', padx=20, pady=5)
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
-
+ # Label Frame 2
self.lb_frame2 = ttk.Frame(self)
self.lb_frame2.configure(relief='solid')
self.lb_frame2.grid(column=2, row=3, sticky='snew', padx=20, pady=5)
@@ -67,60 +73,47 @@ class FrameWidgets(ttk.Frame):
self.lb = tk.Label(self, text='Active: ')
self.lb.config(font=("Ubuntu", 11, "bold"))
self.lb.grid(column=2, row=1, padx=15, sticky="w")
-
# Label to Show active Tunnel
self.StrVar = tk.StringVar(value=self.a)
GreenLabel.green_show_label(self)
-
- datafile = open('dict_to_address', 'r')
- address = datafile.readline()
- dns = datafile.readline()
- endpoint = datafile.readline()
- datafile.close()
- print(address, dns, endpoint)
# Interface Label
- self.interface = tk.Label(self.lb_frame, text='Interface')
+ self.interface = tk.Label(self.lb_frame, text='Interface', fg=fontcolor)
self.interface.grid(column=0, row=4, sticky="we", padx=120)
self.interface.config(font=("Ubuntu", 9))
- self.rowconfigure(0, weight=1)
- # Address Label
- self.address = tk.Label(self.lb_frame, text='Address: ' + address)
- 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, text='DNS: ' + dns)
- self.dns.grid(column=0, row=6, sticky="w", padx=10, pady=5)
- self.dns.config(font=("Ubuntu", 9))
# Peer Label
- self.peer = tk.Label(self.lb_frame2, text='Peer')
+ self.peer = tk.Label(self.lb_frame2, text='Peer', fg=fontcolor)
self.peer.config(font=("Ubuntu", 9))
self.peer.grid(column=0, row=7, sticky="we", padx=130)
- # Endpoint Label
- self.endpoint = tk.Label(self.lb_frame2, text='Endpoint: ' + endpoint)
- self.endpoint.grid(column=0, row=8, sticky="w", padx=10, pady=5)
- self.endpoint.config(font=("Ubuntu", 9))
-
+ # Listbox with Scrollbar
self.scrollbar = tk.Scrollbar(self)
self.l_box = tk.Listbox(self, fg='#606060', selectmode='single')
self.l_box.config(highlightthickness=0, relief='flat')
self.scrollbar.config(command=self.l_box.yview)
self.l_box.config(font=("Ubuntu", 12, "bold"))
self.l_box.grid(column=1, rowspan=3, row=1, )
-
+ # Tunnel List
self.tl = ListTunnels.tl_list()
for tunnels in self.tl:
self.l_box.insert("end", tunnels)
self.l_box.update()
-
# Button Vpn
if self.a != '':
StartStopBTN.button_stop(self)
wg_read = os.environ['HOME'] + '/tester/' + str(self.a) + '.conf'
file = open(wg_read, 'r')
- ConToDict.covert_to_dict(file)
+ data = ConToDict.covert_to_dict(file)
+ # Address Label
+ ShowAddress.init_and_report(self, data)
+ ShowAddress.show_data(self)
file.close()
else:
StartStopBTN.button_start(self)
+ # Address Label
+ self.add = tk.StringVar()
+ self.DNS = tk.StringVar()
+ self.enp = tk.StringVar()
+ ShowAddress.label_empty(self)
+ ShowAddress.show_data(self)
# Button Import
self.btn_i = tk.Button(self, image=self.imp_pic, bd=0, command=lambda: ImportTunnel.wg_import_select(self))
self.btn_i.grid(column=0, row=2, padx=15, pady=15)
@@ -131,18 +124,19 @@ class FrameWidgets(ttk.Frame):
os.system('nmcli connection delete ' + str(select_tl))
self.l_box.delete(self.select_tunnel[0])
os.remove(os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf')
- if self.a != '':
+ if self.a != '' and self.a == select_tl:
self.StrVar.set(value='')
StartStopBTN.button_start(self)
self.l_box.update()
-
+ # Address Label
+ ShowAddress.label_empty(self)
+ ShowAddress.show_data(self)
# 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)
self.btn_exp.grid(column=0, row=4, padx=15, pady=15)
-
# Check Buttons
self.wg_autostart = tk.Checkbutton(self, text='Autoconnect on PC Start')
self.wg_autostart.grid(column=1, rowspan=3, row=3)
@@ -158,7 +152,10 @@ class FrameWidgets(ttk.Frame):
os.system('nmcli connection up ' + str(select_tl))
wg_read = os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf'
file = open(wg_read, 'r')
- ConToDict.covert_to_dict(file)
+ data = ConToDict.covert_to_dict(file)
+ # Address Label
+ ShowAddress.init_and_report(self, data)
+ ShowAddress.show_data(self)
file.close()
# Button Start/Stop
StartStopBTN.button_stop(self)
@@ -173,9 +170,11 @@ class FrameWidgets(ttk.Frame):
# Button Start/Stop
StartStopBTN.button_start(self)
self.a = TunnelActiv.active()
- self.StrVar = tk.StringVar()
- self.StrVar.set(value=' ')
+ self.StrVar.set('')
GreenLabel.green_show_label(self)
+ # Address Label
+ ShowAddress.label_empty(self)
+ ShowAddress.show_data(self)
if __name__ == '__main__':
diff --git a/wg_func.py b/wg_func.py
index 7b1b5f5..4a8289d 100644
--- a/wg_func.py
+++ b/wg_func.py
@@ -1,9 +1,11 @@
# Wireguard functions for Wire-Py
import os
import subprocess
-from tkinter import filedialog, ttk
+from tkinter import filedialog
import tkinter as tk
+fontcolor = '#4011a7'
+
class Message(tk.Tk):
def __init__(self, *args, **kwargs):
@@ -44,6 +46,7 @@ class GreenLabel(tk.Tk):
class StartStopBTN(tk.Tk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
+ self.tl = None
self.wg_switch = None
self.btn_stst = None
self.wg_vpn_start = tk.PhotoImage(file=r'icons/wg-vpn-start-48.png')
@@ -51,11 +54,21 @@ class StartStopBTN(tk.Tk):
def button_stop(self):
self.btn_stst = tk.Button(self, image=self.wg_vpn_stop, bd=0, command=self.wg_switch)
- self.btn_stst.grid(column=0, row=1, padx=15, pady=15, sticky="s")
+ self.btn_stst.grid(column=0, row=1, padx=15, pady=10, sticky="s")
+ self.rowconfigure(0, weight=1)
def button_start(self):
- 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")
+ self.tl = ListTunnels.tl_list()
+ print(len(self.tl))
+ if len(self.tl) == 0:
+ self.btn_stst = tk.Button(self, image=self.wg_vpn_start, bd=0, command=self.wg_switch)
+ self.btn_stst.config(state=tk.DISABLED)
+ self.btn_stst.grid(column=0, row=1, padx=15, pady=10, sticky="s")
+ self.rowconfigure(0, weight=1)
+ else:
+ 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=10, sticky="s")
+ self.rowconfigure(0, weight=1)
class ConToDict:
@@ -70,7 +83,7 @@ class ConToDict:
for items in dictlist:
if items == '=':
dictlist.remove(items)
- for i in dictlist:
+ for i 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]]
@@ -83,15 +96,11 @@ class ConToDict:
finaldict = {}
for elements in newlist:
finaldict[elements[0]] = elements[1]
-
+ # end... result a Dictionary
address = finaldict['Address']
dns = finaldict['DNS']
endpoint = finaldict['Endpoint']
- with open('dict_to_address', 'w+') as data:
- data.write(address + '\n')
- data.write(dns + '\n')
- data.write(endpoint + '\n')
- data.close()
+ return address, dns, endpoint
class TunnelActiv:
@@ -106,6 +115,47 @@ class TunnelActiv:
return active
+class ShowAddress(tk.Tk):
+ def __init__(self, container, **kwargs):
+ super().__init__(container, **kwargs)
+ self.lb_frame2 = None
+ self.lb_frame = None
+ self.endpoint = None
+ self.dns = None
+ self.address = None
+ self.enp = None
+ self.DNS = None
+ self.add = None
+
+ def init_and_report(self, data=None):
+ # Address Label
+ self.add = tk.StringVar()
+ self.add.set('Address: ' + data[0])
+ self.DNS = tk.StringVar()
+ self.DNS.set(' DNS: ' + data[1])
+ self.enp = tk.StringVar()
+ self.enp.set('Endpoint: ' + data[2])
+
+ def label_empty(self):
+ self.add.set('')
+ self.DNS.set('')
+ self.enp.set('')
+
+ 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))
+ # 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))
+ # 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))
+
+
class ListTunnels:
@staticmethod
def tl_list():
@@ -116,6 +166,9 @@ class ListTunnels:
class ImportTunnel:
def __init__(self):
+ self.enp = None
+ self.DNS = None
+ self.add = None
self.select_tunnel = None
self.wg_switch = None
self.btn_stst = None
@@ -137,16 +190,17 @@ class ImportTunnel:
if len(pathsplit1) > 17:
pathsplit = pathsplit1[len(pathsplit1) - 17:]
os.rename(filepath, os.environ['HOME'] + '/tester/' + str(pathsplit))
- os.system('nmcli connection down ' + str(TunnelActiv.active()))
+ 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))
- 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(TunnelActiv.active()))
+ if self.a != '':
+ os.system('nmcli connection down ' + str(TunnelActiv.active()))
os.system('nmcli connection import type wireguard file ' + str(filepath))
- os.system('nmcli con mod ' + str(pathsplit1[:-5]) + ' connection.autoconnect no')
- self.StrVar.set(value=' ')
+
+ self.StrVar.set('')
self.a = TunnelActiv.active()
self.l_box.insert(0, self.a)
self.l_box.update()
@@ -156,8 +210,12 @@ class ImportTunnel:
StartStopBTN.button_stop(self)
wg_read = os.environ['HOME'] + '/tester/' + str(self.a) + '.conf'
file = open(wg_read, 'r')
- ConToDict.covert_to_dict(file)
+ data = ConToDict.covert_to_dict(file)
+ # Address Label
+ ShowAddress.init_and_report(self, data)
+ ShowAddress.show_data(self)
file.close()
+ os.system('nmcli con mod ' + str(self.a) + ' connection.autoconnect no')
if "PrivateKey = " not in read:
Message()
except EOFError: