Remove open file function, add Show Address Labels with tk.StrVar when remove a not active Tunnel Labels of Active Tunnel removed!

This commit is contained in:
2024-08-23 02:00:24 +02:00
parent 2601b7b0ce
commit 357cae2d2a
3 changed files with 112 additions and 50 deletions

View File

@ -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):
@ -51,11 +53,13 @@ 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.btn_stst.grid(column=0, row=1, padx=15, pady=10, sticky="s")
self.rowconfigure(0, weight=1)
class ConToDict:
@ -70,7 +74,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 +87,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 +106,33 @@ 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 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 +143,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
@ -156,7 +186,14 @@ 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)
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])
ShowAddress.show_data(self)
file.close()
if "PrivateKey = " not in read:
Message()