Compare commits
4 Commits
42e2608854
...
ae32cc9e74
Author | SHA1 | Date | |
---|---|---|---|
ae32cc9e74 | |||
5606ce15b9 | |||
b84b783fa0 | |||
0c48966d47 |
@ -4,11 +4,7 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<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="add class Frame and class Massage, delete funktion go 100%, add resize window" />
|
||||||
<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="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
@ -46,7 +42,7 @@
|
|||||||
"Python.main.executor": "Run",
|
"Python.main.executor": "Run",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"git-widget-placeholder": "wire-py-reformat-14-08-2024",
|
"git-widget-placeholder": "wire-py-reformat-14-08-2024",
|
||||||
"last_opened_file_path": "/home/punix/Pyapps/wire-py"
|
"last_opened_file_path": "/home/punix/Downloads/tkinter-bitcoin_price_converter_objectoriented(1).py"
|
||||||
}
|
}
|
||||||
}</component>
|
}</component>
|
||||||
<component name="RunManager">
|
<component name="RunManager">
|
||||||
@ -105,7 +101,23 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1723666477079</updated>
|
<updated>1723666477079</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="3" />
|
<task id="LOCAL-00003" summary="wg_import_select in wg_func.py extended">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1723847456806</created>
|
||||||
|
<option name="number" value="00003" />
|
||||||
|
<option name="presentableId" value="LOCAL-00003" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1723847456806</updated>
|
||||||
|
</task>
|
||||||
|
<task id="LOCAL-00004" summary="add class Frame and class Massage, delete funktion go 100%, add resize window">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1724013210356</created>
|
||||||
|
<option name="number" value="00004" />
|
||||||
|
<option name="presentableId" value="LOCAL-00004" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1724013210356</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="5" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="Vcs.Log.Tabs.Properties">
|
<component name="Vcs.Log.Tabs.Properties">
|
||||||
@ -122,6 +134,8 @@
|
|||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
|
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
|
||||||
<MESSAGE value="Tunnel Start and Stop Work" />
|
<MESSAGE value="Tunnel Start and Stop Work" />
|
||||||
<option name="LAST_COMMIT_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" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
BIN
icons/warning_128.png
Normal file
BIN
icons/warning_128.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.7 KiB |
BIN
icons/warning_256.png
Normal file
BIN
icons/warning_256.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
BIN
icons/warning_32.png
Normal file
BIN
icons/warning_32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
icons/warning_64.png
Normal file
BIN
icons/warning_64.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
34
main.py
34
main.py
@ -2,27 +2,23 @@
|
|||||||
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, tl_list, wg_export, wg_import_select
|
||||||
|
|
||||||
wg_exp = wg_export()
|
wg_exp = wg_export()
|
||||||
|
|
||||||
|
|
||||||
color_default = '#d3ebff'
|
|
||||||
color_dark = '#2e2e2e'
|
|
||||||
a = active()
|
a = active()
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(tk.Tk):
|
class MainWindow(tk.Tk):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.select_tunnel = None
|
|
||||||
self.switch_on = None
|
self.switch_on = None
|
||||||
self.switch_off = None
|
self.switch_off = None
|
||||||
self.x_width = 600
|
self.x_width = 600
|
||||||
self.y_height = 350
|
self.y_height = 350
|
||||||
self.monitor_center_x = self.winfo_screenwidth() / 2 - (self.x_width / 2)
|
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.monitor_center_y = self.winfo_screenheight() / 2 - (self.y_height / 2)
|
||||||
|
self.resizable(width=False, height=False)
|
||||||
self.lb_tunnel = None
|
self.lb_tunnel = None
|
||||||
self.title('Wire-Py')
|
self.title('Wire-Py')
|
||||||
self.configure()
|
self.configure()
|
||||||
@ -32,6 +28,13 @@ class MainWindow(tk.Tk):
|
|||||||
# Set it as the window icon.
|
# Set it as the window icon.
|
||||||
self.iconphoto(True, self.wg_icon)
|
self.iconphoto(True, self.wg_icon)
|
||||||
|
|
||||||
|
FrameWidgets(self).grid()
|
||||||
|
|
||||||
|
|
||||||
|
class FrameWidgets(ttk.Frame):
|
||||||
|
def __init__(self, container, **kwargs):
|
||||||
|
super().__init__(container, **kwargs)
|
||||||
|
|
||||||
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')
|
||||||
self.wgi_on = tk.PhotoImage(file=r'icons/wire-switch-on-48.png')
|
self.wgi_on = tk.PhotoImage(file=r'icons/wire-switch-on-48.png')
|
||||||
@ -39,8 +42,10 @@ class MainWindow(tk.Tk):
|
|||||||
self.imp_pic = tk.PhotoImage(file=r'icons/wg-import.png')
|
self.imp_pic = tk.PhotoImage(file=r'icons/wg-import.png')
|
||||||
self.tr_pic = tk.PhotoImage(file=r'icons/wg-trash-48.png')
|
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.exp_pic = tk.PhotoImage(file=r'icons/wg-export-48.png')
|
||||||
|
self.warning_pic = tk.PhotoImage(file=r'icons/warning_64.png')
|
||||||
|
|
||||||
# Show active Label
|
# Show active Label
|
||||||
|
self.select_tunnel = None
|
||||||
self.lb = tk.Label(self, text='Active:')
|
self.lb = tk.Label(self, text='Active:')
|
||||||
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")
|
||||||
@ -73,8 +78,19 @@ class MainWindow(tk.Tk):
|
|||||||
# Button Import
|
# Button Import
|
||||||
self.btn_i = tk.Button(self, image=self.imp_pic, bd=0, command=wg_import_select)
|
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
|
|
||||||
self.btn_tr = tk.Button(self, image=self.tr_pic, bd=0)
|
def delete():
|
||||||
|
self.select_tunnel = self.l_box.curselection()
|
||||||
|
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 != '':
|
||||||
|
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")
|
||||||
|
|
||||||
|
# Button Trash
|
||||||
|
self.btn_tr = tk.Button(self, image=self.tr_pic, bd=0, command=delete)
|
||||||
self.btn_tr.grid(column=0, row=3, padx=15, pady=15)
|
self.btn_tr.grid(column=0, row=3, padx=15, pady=15)
|
||||||
# Button Export
|
# Button Export
|
||||||
self.btn_exp = tk.Button(self, image=self.exp_pic, bd=0)
|
self.btn_exp = tk.Button(self, image=self.exp_pic, bd=0)
|
||||||
@ -109,7 +125,7 @@ class MainWindow(tk.Tk):
|
|||||||
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()
|
||||||
self.StrVar = tk.StringVar()
|
self.StrVar = tk.StringVar()
|
||||||
self.StrVar.set(' ')
|
self.StrVar.set(value=' ')
|
||||||
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")
|
||||||
|
77
wg_func.py
77
wg_func.py
@ -3,30 +3,30 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
from tkinter import filedialog
|
from tkinter import filedialog
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from tkinter import messagebox
|
|
||||||
|
|
||||||
|
|
||||||
def wg_import_select():
|
class Message(tk.Tk):
|
||||||
try:
|
def __init__(self, *args, **kwargs):
|
||||||
filepath = filedialog.askopenfilename(initialdir=os.environ['HOME'], title="Select Wireguard config File",
|
super().__init__(*args, **kwargs)
|
||||||
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:
|
self.warning_pic = None
|
||||||
subprocess.call('cp ' + str(filepath) + ' /etc/wg_nmcli/', shell=True)
|
self.x_width = 300
|
||||||
os.system('nmcli connection import type wireguard file ' + str(filepath))
|
self.y_height = 120
|
||||||
os.system('nmcli con mod ' + str(pathsplit[:-5]) + ' connection.autoconnect no')
|
self.monitor_center_x = self.winfo_screenwidth() / 2 - (self.x_width / 2)
|
||||||
else:
|
self.monitor_center_y = self.winfo_screenheight() / 2 - (self.y_height / 2)
|
||||||
messagebox.showwarning(title="conf error", message=" Oh... no valid Wireguard File!\nPlease select a "
|
self.resizable(width=False, height=False)
|
||||||
"valid Wireguard File ")
|
self.title('Import error!')
|
||||||
except EOFError:
|
self.configure()
|
||||||
pass
|
self.geometry('%dx%d+%d+%d' % (self.x_width, self.y_height, self.monitor_center_x, self.monitor_center_y))
|
||||||
except TypeError:
|
self.columnconfigure(0, weight=1)
|
||||||
pass
|
|
||||||
|
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)
|
||||||
|
self.button.config(padx=15, pady=5)
|
||||||
|
self.button.grid(column=0, row=1)
|
||||||
|
|
||||||
|
|
||||||
def active(): # Shows the active tunnel
|
def active(): # Shows the active tunnel
|
||||||
@ -39,12 +39,45 @@ def active(): # Shows the active tunnel
|
|||||||
return a
|
return a
|
||||||
|
|
||||||
|
|
||||||
|
a = active()
|
||||||
|
|
||||||
|
|
||||||
def tl_list():
|
def tl_list():
|
||||||
wg_s = os.popen('nmcli con 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 = Tunnel list # Show of 4.Element in list
|
||||||
return tl
|
return tl
|
||||||
|
|
||||||
|
|
||||||
|
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("/")
|
||||||
|
pathsplit1 = pathsplit[-1]
|
||||||
|
if "PrivateKey = " in read and "PublicKey = " in read:
|
||||||
|
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 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 import type wireguard file ' + str(filepath))
|
||||||
|
os.system('nmcli con mod ' + str(pathsplit1[:-5]) + ' connection.autoconnect no')
|
||||||
|
if "PrivateKey = " not in read:
|
||||||
|
Message()
|
||||||
|
except EOFError:
|
||||||
|
pass
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def wg_export():
|
def wg_export():
|
||||||
try:
|
try:
|
||||||
wg_exp = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
|
wg_exp = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
|
||||||
|
Loading…
Reference in New Issue
Block a user