add class TunnelActive to wg_func works
This commit is contained in:
parent
5606ce15b9
commit
213032252a
33
.idea/workspace.xml
generated
33
.idea/workspace.xml
generated
@ -4,7 +4,11 @@
|
||||
<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" />
|
||||
<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">
|
||||
<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" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
@ -117,7 +121,15 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1724013210356</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="5" />
|
||||
<task id="LOCAL-00005" summary="add class Frame and class Massage, delete funktion go 100%, add resize window, add warning pic">
|
||||
<option name="closed" value="true" />
|
||||
<created>1724013251954</created>
|
||||
<option name="number" value="00005" />
|
||||
<option name="presentableId" value="LOCAL-00005" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1724013251954</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="6" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
@ -125,7 +137,19 @@
|
||||
<map>
|
||||
<entry key="MAIN">
|
||||
<value>
|
||||
<State />
|
||||
<State>
|
||||
<option name="FILTERS">
|
||||
<map>
|
||||
<entry key="branch">
|
||||
<value>
|
||||
<list>
|
||||
<option value="origin/wire-py-reformat-14-08-2024" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</State>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
@ -136,6 +160,7 @@
|
||||
<MESSAGE value="Tunnel Start and Stop Work" />
|
||||
<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" />
|
||||
<option name="LAST_COMMIT_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" />
|
||||
</component>
|
||||
</project>
|
45
main.py
45
main.py
@ -2,10 +2,10 @@
|
||||
import os
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from wg_func import active, tl_list, wg_export, wg_import_select
|
||||
|
||||
from wg_func import tl_list, wg_export, wg_import_select, TunnelActiv
|
||||
|
||||
wg_exp = wg_export()
|
||||
a = active()
|
||||
|
||||
|
||||
class MainWindow(tk.Tk):
|
||||
@ -44,13 +44,17 @@ class FrameWidgets(ttk.Frame):
|
||||
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()
|
||||
|
||||
# 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")
|
||||
|
||||
# Label to Show active Tunnel
|
||||
self.StrVar = tk.StringVar(value=a)
|
||||
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"))
|
||||
@ -69,7 +73,7 @@ class FrameWidgets(ttk.Frame):
|
||||
self.l_box.update()
|
||||
self.l_box.select_set(0) # Later add, for first Item Auto select
|
||||
# Button Vpn
|
||||
if a != '':
|
||||
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")
|
||||
else:
|
||||
@ -84,7 +88,7 @@ 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])
|
||||
if a != '':
|
||||
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")
|
||||
@ -96,34 +100,37 @@ class FrameWidgets(ttk.Frame):
|
||||
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)
|
||||
self.wg_update = tk.Checkbutton(self, text='Search automatically for\nWire-Py updates')
|
||||
self.wg_update.grid(column=1, rowspan=3, row=4)
|
||||
|
||||
def wg_switch(self):
|
||||
global a
|
||||
if a == '':
|
||||
# Button Start/Stop
|
||||
self.a = TunnelActiv.active()
|
||||
if self.a == '':
|
||||
|
||||
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))
|
||||
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")
|
||||
a = active()
|
||||
self.StrVar = tk.StringVar()
|
||||
self.StrVar.set(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")
|
||||
elif a != '':
|
||||
# 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")
|
||||
os.system('nmcli connection down ' + str(a))
|
||||
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")
|
||||
elif self.a != '':
|
||||
# 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")
|
||||
os.system('nmcli connection down ' + str(self.a))
|
||||
# Button Start/Stop
|
||||
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")
|
||||
a = active()
|
||||
self.a = TunnelActiv.active()
|
||||
self.StrVar = tk.StringVar()
|
||||
self.StrVar.set(value=' ')
|
||||
self.lb_tunnel = tk.Label(self, textvariable=self.StrVar, fg='green')
|
||||
|
19
wg_func.py
19
wg_func.py
@ -29,17 +29,16 @@ class Message(tk.Tk):
|
||||
self.button.grid(column=0, row=1)
|
||||
|
||||
|
||||
class TunnelActiv:
|
||||
@staticmethod
|
||||
def active(): # Shows the active tunnel
|
||||
a = os.popen('nmcli con show --active | grep -iPo "(.*)(wireguard)"').read().split()
|
||||
if not a:
|
||||
a = ''
|
||||
return a
|
||||
active = os.popen('nmcli con show --active | grep -iPo "(.*)(wireguard)"').read().split()
|
||||
if not active:
|
||||
active = ''
|
||||
else:
|
||||
a = a[0]
|
||||
return a
|
||||
active = active[0]
|
||||
|
||||
|
||||
a = active()
|
||||
return active
|
||||
|
||||
|
||||
def tl_list():
|
||||
@ -61,13 +60,13 @@ def wg_import_select():
|
||||
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 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(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')
|
||||
if "PrivateKey = " not in read:
|
||||
|
Loading…
x
Reference in New Issue
Block a user