wg_import_select in wg_func.py extended
This commit is contained in:
parent
7b5821a686
commit
42e2608854
28
.idea/workspace.xml
generated
28
.idea/workspace.xml
generated
@ -6,6 +6,8 @@
|
|||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="Tunnel Start and Stop Work">
|
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="Tunnel Start and Stop Work">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@ -38,15 +40,15 @@
|
|||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent">{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"ASKED_ADD_EXTERNAL_FILES": "true",
|
"ASKED_ADD_EXTERNAL_FILES": "true",
|
||||||
"Python.main.executor": "Run",
|
"Python.main.executor": "Run",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"git-widget-placeholder": "main",
|
"git-widget-placeholder": "wire-py-reformat-14-08-2024",
|
||||||
"last_opened_file_path": "/home/punix/Pyapps/wire-py"
|
"last_opened_file_path": "/home/punix/Pyapps/wire-py"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="RunManager">
|
<component name="RunManager">
|
||||||
<configuration name="main" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
|
<configuration name="main" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
|
||||||
<module name="wire-py" />
|
<module name="wire-py" />
|
||||||
@ -95,7 +97,15 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1723666001005</updated>
|
<updated>1723666001005</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="2" />
|
<task id="LOCAL-00002" summary="Tunnel Start and Stop Work">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1723666477079</created>
|
||||||
|
<option name="number" value="00002" />
|
||||||
|
<option name="presentableId" value="LOCAL-00002" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1723666477079</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="3" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="Vcs.Log.Tabs.Properties">
|
<component name="Vcs.Log.Tabs.Properties">
|
||||||
|
32
main.py
32
main.py
@ -2,12 +2,11 @@
|
|||||||
import os
|
import os
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
|
from tkinter import filedialog
|
||||||
|
from wg_func import active, tl_list, wg_export, wg_import_select
|
||||||
|
|
||||||
from wg_func import active
|
wg_exp = wg_export()
|
||||||
|
|
||||||
from wg_func import tl_list
|
|
||||||
|
|
||||||
path = '/~/.config/wg_nmcli/'
|
|
||||||
|
|
||||||
color_default = '#d3ebff'
|
color_default = '#d3ebff'
|
||||||
color_dark = '#2e2e2e'
|
color_dark = '#2e2e2e'
|
||||||
@ -29,9 +28,9 @@ class MainWindow(tk.Tk):
|
|||||||
self.configure()
|
self.configure()
|
||||||
self.geometry('%dx%d+%d+%d' % (self.x_width, self.y_height, self.monitor_center_x, self.monitor_center_y))
|
self.geometry('%dx%d+%d+%d' % (self.x_width, self.y_height, self.monitor_center_x, self.monitor_center_y))
|
||||||
# Load the image file from disk.
|
# Load the image file from disk.
|
||||||
wg_icon = tk.PhotoImage(file=r'icons/wg-vpn-48.png')
|
self.wg_icon = tk.PhotoImage(file=r'icons/wg-vpn-48.png')
|
||||||
# Set it as the window icon.
|
# Set it as the window icon.
|
||||||
self.iconphoto(True, wg_icon)
|
self.iconphoto(True, self.wg_icon)
|
||||||
|
|
||||||
self.wg_vpn_start = tk.PhotoImage(file=r'icons/wg-vpn-start-48.png')
|
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.wg_vpn_stop = tk.PhotoImage(file=r'icons/wg-vpn-stop-48.png')
|
||||||
@ -46,9 +45,9 @@ class MainWindow(tk.Tk):
|
|||||||
self.lb.config(font=("Ubuntu", 11, "bold"))
|
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=10, pady=5, sticky="e")
|
||||||
# Label to Show active Tunnel
|
# Label to Show active Tunnel
|
||||||
self.StrVar = tk.StringVar()
|
self.StrVar = tk.StringVar(value=a)
|
||||||
self.StrVar.set(a)
|
|
||||||
self.lb_tunnel = tk.Label(self, textvariable=self.StrVar, fg='green')
|
self.lb_tunnel = tk.Label(self, textvariable=self.StrVar, fg='green')
|
||||||
|
|
||||||
self.lb_tunnel.config(font=("Ubuntu", 11, "bold"))
|
self.lb_tunnel.config(font=("Ubuntu", 11, "bold"))
|
||||||
self.lb_tunnel.grid(column=3, row=1, sticky="w")
|
self.lb_tunnel.grid(column=3, row=1, sticky="w")
|
||||||
|
|
||||||
@ -68,12 +67,11 @@ class MainWindow(tk.Tk):
|
|||||||
if a != '':
|
if a != '':
|
||||||
self.btn_stst = tk.Button(self, image=self.wg_vpn_stop, bd=0, command=self.wg_switch)
|
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=15, sticky="s")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.btn_stst = tk.Button(self, image=self.wg_vpn_start, bd=0, command=self.wg_switch)
|
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=15, sticky="s")
|
||||||
# Button Import
|
# Button Import
|
||||||
self.btn_i = tk.Button(self, image=self.imp_pic, bd=0)
|
self.btn_i = tk.Button(self, image=self.imp_pic, bd=0, command=wg_import_select)
|
||||||
self.btn_i.grid(column=0, row=2, padx=15, pady=15)
|
self.btn_i.grid(column=0, row=2, padx=15, pady=15)
|
||||||
# Button Trash
|
# Button Trash
|
||||||
self.btn_tr = tk.Button(self, image=self.tr_pic, bd=0)
|
self.btn_tr = tk.Button(self, image=self.tr_pic, bd=0)
|
||||||
@ -97,8 +95,11 @@ class MainWindow(tk.Tk):
|
|||||||
self.btn_stst = tk.Button(self, image=self.wg_vpn_stop, bd=0, command=self.wg_switch)
|
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=15, sticky="s")
|
||||||
a = active()
|
a = active()
|
||||||
StrVar = tk.StringVar()
|
self.StrVar = tk.StringVar()
|
||||||
return StrVar.set(a)
|
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 != '':
|
elif a != '':
|
||||||
# Button Start/Stop
|
# Button Start/Stop
|
||||||
self.btn_stst = tk.Button(self, image=self.wg_vpn_stop, bd=0, command=self.wg_switch)
|
self.btn_stst = tk.Button(self, image=self.wg_vpn_stop, bd=0, command=self.wg_switch)
|
||||||
@ -106,7 +107,12 @@ class MainWindow(tk.Tk):
|
|||||||
os.system('nmcli connection down ' + str(a))
|
os.system('nmcli connection down ' + str(a))
|
||||||
self.btn_stst = tk.Button(self, image=self.wg_vpn_start, bd=0, command=self.wg_switch)
|
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=15, sticky="s")
|
||||||
a = ''
|
a = active()
|
||||||
|
self.StrVar = tk.StringVar()
|
||||||
|
self.StrVar.set(' ')
|
||||||
|
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")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
40
wg_func.py
40
wg_func.py
@ -1,12 +1,38 @@
|
|||||||
# Wireguard functions for Wire-Py
|
# Wireguard functions for Wire-Py
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
|
from tkinter import filedialog
|
||||||
|
import tkinter as tk
|
||||||
|
from tkinter import messagebox
|
||||||
|
|
||||||
|
|
||||||
|
def wg_import_select():
|
||||||
|
try:
|
||||||
|
filepath = filedialog.askopenfilename(initialdir=os.environ['HOME'], title="Select Wireguard config File",
|
||||||
|
filetypes=[("WG config files", "*.conf")])
|
||||||
|
file = open(filepath, 'r')
|
||||||
|
read = file.read()
|
||||||
|
file.close()
|
||||||
|
pathsplit = filepath.split("/")
|
||||||
|
pathsplit = pathsplit[-1]
|
||||||
|
|
||||||
|
if "PrivateKey = " in read and "PublicKey = " in read:
|
||||||
|
subprocess.call('cp ' + str(filepath) + ' /etc/wg_nmcli/', shell=True)
|
||||||
|
os.system('nmcli connection import type wireguard file ' + str(filepath))
|
||||||
|
os.system('nmcli con mod ' + str(pathsplit[:-5]) + ' connection.autoconnect no')
|
||||||
|
else:
|
||||||
|
messagebox.showwarning(title="conf error", message=" Oh... no valid Wireguard File!\nPlease select a "
|
||||||
|
"valid Wireguard File ")
|
||||||
|
except EOFError:
|
||||||
|
pass
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def active(): # Shows the active tunnel
|
def active(): # Shows the active tunnel
|
||||||
a = os.popen('nmcli connection show --active | grep -iPo "(.*)(wireguard)"').read().split()
|
a = os.popen('nmcli con show --active | grep -iPo "(.*)(wireguard)"').read().split()
|
||||||
if not a:
|
if not a:
|
||||||
a = ''
|
a = ''
|
||||||
|
|
||||||
return a
|
return a
|
||||||
else:
|
else:
|
||||||
a = a[0]
|
a = a[0]
|
||||||
@ -14,7 +40,15 @@ def active(): # Shows the active tunnel
|
|||||||
|
|
||||||
|
|
||||||
def tl_list():
|
def tl_list():
|
||||||
wg_s = os.popen('nmcli connection show | grep -iPo "(.*)(wireguard)"').read().split()
|
wg_s = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
|
||||||
tl = wg_s[::3] # tl = Tunnelliste # Hiermit wird jedes 4. Element der Liste gezeigt
|
tl = wg_s[::3] # tl = Tunnelliste # Hiermit wird jedes 4. Element der Liste gezeigt
|
||||||
return tl
|
return tl
|
||||||
|
|
||||||
|
|
||||||
|
def wg_export():
|
||||||
|
try:
|
||||||
|
wg_exp = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
|
||||||
|
wg_exp = wg_exp[1]
|
||||||
|
return wg_exp
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user