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
This commit is contained in:
Désiré Werner Menrath 2024-08-19 23:28:53 +02:00
parent 6ab9c43c3a
commit 999fe7be84
3 changed files with 58 additions and 19 deletions

View File

@ -4,7 +4,7 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="add class Frame and class Massage, delete funktion go 100%, add resize window, add warning pic">
<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)">
<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,15 +40,16 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;,
&quot;Python.main.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;wire-py-reformat-14-08-2024&quot;,
&quot;last_opened_file_path&quot;: &quot;/home/punix/Downloads/tkinter-bitcoin_price_converter_objectoriented(1).py&quot;
<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>
}]]></component>
<component name="RunManager">
<configuration name="main" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="wire-py" />
@ -129,7 +130,15 @@
<option name="project" value="LOCAL" />
<updated>1724013251954</updated>
</task>
<option name="localTasksCounter" value="6" />
<task id="LOCAL-00006" summary="add class ListTunnels and class ImportTunnel, and add class ExportTunnels (ExportTunnels no finish)">
<option name="closed" value="true" />
<created>1724048994613</created>
<option name="number" value="00006" />
<option name="presentableId" value="LOCAL-00006" />
<option name="project" value="LOCAL" />
<updated>1724048994613</updated>
</task>
<option name="localTasksCounter" value="7" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -161,6 +170,7 @@
<MESSAGE value="wg_import_select in wg_func.py extended" />
<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" />
<option name="LAST_COMMIT_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)" />
</component>
</project>

35
main.py
View File

@ -33,6 +33,7 @@ class FrameWidgets(ttk.Frame):
def __init__(self, container, **kwargs):
super().__init__(container, **kwargs)
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')
self.wgi_on = tk.PhotoImage(file=r'icons/wire-switch-on-48.png')
@ -41,23 +42,34 @@ class FrameWidgets(ttk.Frame):
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 Tunnel
self.a = TunnelActiv.active()
# Label 2
self.lb_frame = ttk.Frame(self)
self.lb_frame.configure(relief='solid')
self.lb_frame.grid(column=2, row=2, sticky='n', padx=10)
self.lb_frame2 = ttk.Frame(self)
self.lb_frame2.configure(relief='solid')
self.lb_frame2.grid(column=2, row=3, sticky='nw', padx=10)
# 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")
self.lb.grid(column=2, row=1, padx=5, sticky="we")
# 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")
# Label Interface and Peers
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))
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.scrollbar = tk.Scrollbar(self)
self.l_box = tk.Listbox(self, fg='#606060', selectmode='single')
self.l_box.config(highlightthickness=0, relief='flat')
@ -69,11 +81,16 @@ class FrameWidgets(ttk.Frame):
for tunnels in self.tl:
self.l_box.insert("end", tunnels)
self.l_box.update()
self.l_box.select_set(0) # Later add, for first Item Auto select
# Button Vpn
if self.a != '':
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")
wg_read = os.environ['HOME'] + '/tester/' + str(self.a) + '.conf'
file = open(wg_read, 'r')
read = file.read()
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")
@ -86,12 +103,12 @@ class FrameWidgets(ttk.Frame):
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])
os.remove(os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf')
if self.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")
self.l_box.update()
self.l_box.select_set(0)
# Button Trash
self.btn_tr = tk.Button(self, image=self.tr_pic, bd=0, command=delete)
@ -113,6 +130,12 @@ class FrameWidgets(ttk.Frame):
self.select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(self.select_tunnel[0])
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()
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")

View File

@ -20,8 +20,8 @@ class Message(tk.Tk):
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 = 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)
@ -51,6 +51,7 @@ class ListTunnels:
class ImportTunnel:
def __init__(self):
self.select_tunnel = None
self.wg_switch = None
self.btn_stst = None
self.lb_tunnel = None
@ -91,6 +92,11 @@ class ImportTunnel:
self.lb_tunnel.grid(column=3, row=1, sticky="w")
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")
wg_read = os.environ['HOME'] + '/tester/' + str(self.a) + '.conf'
file = open(wg_read, 'r')
read = file.read()
file.close()
print(read)
if "PrivateKey = " not in read:
Message()
except EOFError: