add file dict_to_address for
address a active Tunnel. Label green pack in Class. add Class to convert fileoutput as String to Dictionary
This commit is contained in:
parent
999fe7be84
commit
70793075e9
@ -4,7 +4,8 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="add class ListTunnels and class ImportTunnel, and add class ExportTunnels (ExportTunnels no finish)">
|
||||
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="add Label Interface and Peer to new FrameWidget one and two. when import Tunnel then add to list works and remove of list when Tunnel delete.(with Label active on and off) add to class and methods open a avtive Tunnel when Wire-Py open, when import and start a Tunnel">
|
||||
<change afterPath="$PROJECT_DIR$/dict_to_address" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/wg_func.py" beforeDir="false" afterPath="$PROJECT_DIR$/wg_func.py" afterDir="false" />
|
||||
@ -40,16 +41,16 @@
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"ASKED_ADD_EXTERNAL_FILES": "true",
|
||||
"Python.main.executor": "Run",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"git-widget-placeholder": "main",
|
||||
"last_opened_file_path": "/home/punix/Downloads/tkinter-bitcoin_price_converter_objectoriented(1).py",
|
||||
"settings.editor.selected.configurable": "preferences.lookFeel"
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"ASKED_ADD_EXTERNAL_FILES": "true",
|
||||
"Python.main.executor": "Run",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"git-widget-placeholder": "main",
|
||||
"last_opened_file_path": "/home/punix/Pyapps/wire-py",
|
||||
"settings.editor.selected.configurable": "preferences.lookFeel"
|
||||
}
|
||||
}]]></component>
|
||||
}</component>
|
||||
<component name="RunManager">
|
||||
<configuration name="main" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
|
||||
<module name="wire-py" />
|
||||
@ -138,7 +139,15 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1724048994613</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="7" />
|
||||
<task id="LOCAL-00007" summary="add Label Interface and Peer to new FrameWidget one and two. when import Tunnel then add to list works and remove of list when Tunnel delete.(with Label active on and off) add to class and methods open a avtive Tunnel when Wire-Py open, when import and start a Tunnel">
|
||||
<option name="closed" value="true" />
|
||||
<created>1724102937260</created>
|
||||
<option name="number" value="00007" />
|
||||
<option name="presentableId" value="LOCAL-00007" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1724102937260</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="8" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
@ -171,6 +180,7 @@
|
||||
<MESSAGE value="add class Frame and class Massage, delete funktion go 100%, add resize window" />
|
||||
<MESSAGE value="add class Frame and class Massage, delete funktion go 100%, add resize window, add warning pic" />
|
||||
<MESSAGE value="add class ListTunnels and class ImportTunnel, and add class ExportTunnels (ExportTunnels no finish)" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="add class ListTunnels and class ImportTunnel, and add class ExportTunnels (ExportTunnels no finish)" />
|
||||
<MESSAGE value="add Label Interface and Peer to new FrameWidget one and two. when import Tunnel then add to list works and remove of list when Tunnel delete.(with Label active on and off) add to class and methods open a avtive Tunnel when Wire-Py open, when import and start a Tunnel" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="add Label Interface and Peer to new FrameWidget one and two. when import Tunnel then add to list works and remove of list when Tunnel delete.(with Label active on and off) add to class and methods open a avtive Tunnel when Wire-Py open, when import and start a Tunnel" />
|
||||
</component>
|
||||
</project>
|
3
dict_to_address
Normal file
3
dict_to_address
Normal file
@ -0,0 +1,3 @@
|
||||
192.168.178.158/24
|
||||
192.168.178.1,
|
||||
rj2cexasg9b9oydd.myfritz.net:54775
|
42
main.py
42
main.py
@ -3,7 +3,8 @@ import os
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
|
||||
from wg_func import TunnelActiv, ListTunnels, ImportTunnel, ExportTunnels
|
||||
from wg_func import (TunnelActiv, ListTunnels, ImportTunnel,
|
||||
ConToDict, GreenLabel, ExportTunnels)
|
||||
|
||||
|
||||
class MainWindow(tk.Tk):
|
||||
@ -17,7 +18,6 @@ class MainWindow(tk.Tk):
|
||||
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()
|
||||
self.geometry('%dx%d+%d+%d' % (self.x_width, self.y_height, self.monitor_center_x, self.monitor_center_y))
|
||||
@ -33,6 +33,7 @@ class FrameWidgets(ttk.Frame):
|
||||
def __init__(self, container, **kwargs):
|
||||
super().__init__(container, **kwargs)
|
||||
|
||||
self.lb_tunnel = None
|
||||
self.wg_read = None
|
||||
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')
|
||||
@ -59,17 +60,29 @@ class FrameWidgets(ttk.Frame):
|
||||
|
||||
# Label to Show active Tunnel
|
||||
self.StrVar = tk.StringVar(value=self.a)
|
||||
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")
|
||||
GreenLabel.green_show_label(self)
|
||||
|
||||
# Label Interface and Peers
|
||||
# Interface Label
|
||||
self.interface = tk.Label(self.lb_frame, text='Interface')
|
||||
self.interface.grid(column=0, row=4, sticky="n", padx=10)
|
||||
self.interface.config(font=("Ubuntu", 9))
|
||||
# Address Label
|
||||
self.address = tk.Label(self.lb_frame, text='address')
|
||||
self.address.grid(column=0, row=5, sticky="n", padx=10)
|
||||
self.address.config(font=("Ubuntu", 9))
|
||||
# DNS Label
|
||||
self.dns = tk.Label(self.lb_frame, text='dns')
|
||||
self.dns.grid(column=0, row=6, sticky="n", padx=10)
|
||||
self.dns.config(font=("Ubuntu", 9))
|
||||
# Peer Label
|
||||
self.peer = tk.Label(self.lb_frame2, text='Peer')
|
||||
self.peer.config(font=("Ubuntu", 9))
|
||||
self.peer.grid(column=0, row=5, sticky="n", padx=10)
|
||||
self.peer.grid(column=0, row=7, sticky="n", padx=10)
|
||||
# Endpoint Label
|
||||
self.endpoint = tk.Label(self.lb_frame2, text='Endpoint')
|
||||
self.endpoint.config(font=("Ubuntu", 9))
|
||||
self.endpoint.grid(column=0, row=8, sticky="n", padx=10)
|
||||
|
||||
self.scrollbar = tk.Scrollbar(self)
|
||||
self.l_box = tk.Listbox(self, fg='#606060', selectmode='single')
|
||||
self.l_box.config(highlightthickness=0, relief='flat')
|
||||
@ -88,9 +101,8 @@ class FrameWidgets(ttk.Frame):
|
||||
self.btn_stst.grid(column=0, row=1, padx=15, pady=15, sticky="s")
|
||||
wg_read = os.environ['HOME'] + '/tester/' + str(self.a) + '.conf'
|
||||
file = open(wg_read, 'r')
|
||||
read = file.read()
|
||||
ConToDict.covert_to_dict(file)
|
||||
file.close()
|
||||
print(read)
|
||||
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=15, sticky="s")
|
||||
@ -132,19 +144,15 @@ 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')
|
||||
read = file.read()
|
||||
ConToDict.covert_to_dict(file)
|
||||
file.close()
|
||||
print(read)
|
||||
|
||||
# Button Start/Stop
|
||||
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.a = TunnelActiv.active()
|
||||
self.StrVar = tk.StringVar()
|
||||
self.StrVar.set(self.a)
|
||||
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")
|
||||
GreenLabel.green_show_label(self)
|
||||
elif self.a != '':
|
||||
# Button Start/Stop
|
||||
self.btn_stst = tk.Button(self, image=self.wg_vpn_stop, bd=0, command=self.wg_switch)
|
||||
@ -156,9 +164,7 @@ class FrameWidgets(ttk.Frame):
|
||||
self.a = TunnelActiv.active()
|
||||
self.StrVar = tk.StringVar()
|
||||
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")
|
||||
GreenLabel.green_show_label(self)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
53
wg_func.py
53
wg_func.py
@ -1,7 +1,7 @@
|
||||
# Wireguard functions for Wire-Py
|
||||
import os
|
||||
import subprocess
|
||||
from tkinter import filedialog
|
||||
from tkinter import filedialog, ttk
|
||||
import tkinter as tk
|
||||
|
||||
|
||||
@ -29,6 +29,54 @@ class Message(tk.Tk):
|
||||
self.button.grid(column=0, row=1)
|
||||
|
||||
|
||||
class GreenLabel(tk.Tk):
|
||||
def __init__(self, container, **kwargs):
|
||||
super().__init__(container, **kwargs)
|
||||
self.StrVar = None
|
||||
self.lb_tunnel = None
|
||||
|
||||
def green_show_label(self):
|
||||
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")
|
||||
|
||||
|
||||
class ConToDict:
|
||||
@classmethod
|
||||
def covert_to_dict(cls, file):
|
||||
dictlist = []
|
||||
for lines in file.readlines():
|
||||
lineplit = lines.split()
|
||||
dictlist = dictlist + lineplit
|
||||
dictlist.remove('[Interface]')
|
||||
dictlist.remove('[Peer]')
|
||||
for items in dictlist:
|
||||
if items == '=':
|
||||
dictlist.remove(items)
|
||||
for i in dictlist:
|
||||
a = [dictlist[0], dictlist[1]]
|
||||
b = [dictlist[2], dictlist[3]]
|
||||
c = [dictlist[4], dictlist[5]]
|
||||
d = [dictlist[6], dictlist[7]]
|
||||
e = [dictlist[8], dictlist[9]]
|
||||
f = [dictlist[10], dictlist[11]]
|
||||
g = [dictlist[12], dictlist[13]]
|
||||
h = [dictlist[14], dictlist[15]]
|
||||
newlist = [a, b, c, d, e, f, g, h]
|
||||
finaldict = {}
|
||||
for elements in newlist:
|
||||
finaldict[elements[0]] = elements[1]
|
||||
|
||||
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()
|
||||
|
||||
|
||||
class TunnelActiv:
|
||||
@staticmethod
|
||||
def active(): # Shows the active tunnel
|
||||
@ -94,9 +142,8 @@ class ImportTunnel:
|
||||
self.btn_stst.grid(column=0, row=1, padx=15, pady=15, sticky="s")
|
||||
wg_read = os.environ['HOME'] + '/tester/' + str(self.a) + '.conf'
|
||||
file = open(wg_read, 'r')
|
||||
read = file.read()
|
||||
ConToDict.covert_to_dict(file)
|
||||
file.close()
|
||||
print(read)
|
||||
if "PrivateKey = " not in read:
|
||||
Message()
|
||||
except EOFError:
|
||||
|
Loading…
Reference in New Issue
Block a user