Compare commits

..

No commits in common. "ae32cc9e7487a7760229ce856359e79e9bfa63a7" and "42e260885476fb5bc59506e3158f2b541c82bee4" have entirely different histories.

7 changed files with 39 additions and 102 deletions

View File

@ -4,7 +4,11 @@
<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="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="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$/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" />
@ -42,7 +46,7 @@
&quot;Python.main.executor&quot;: &quot;Run&quot;, &quot;Python.main.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;wire-py-reformat-14-08-2024&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; &quot;last_opened_file_path&quot;: &quot;/home/punix/Pyapps/wire-py&quot;
} }
}</component> }</component>
<component name="RunManager"> <component name="RunManager">
@ -101,23 +105,7 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1723666477079</updated> <updated>1723666477079</updated>
</task> </task>
<task id="LOCAL-00003" summary="wg_import_select in wg_func.py extended"> <option name="localTasksCounter" value="3" />
<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">
@ -134,8 +122,6 @@
<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" />
<MESSAGE value="wg_import_select in wg_func.py extended" /> <option name="LAST_COMMIT_MESSAGE" value="Tunnel Start and Stop Work" />
<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>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

34
main.py
View File

@ -2,23 +2,27 @@
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()
@ -28,13 +32,6 @@ 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')
@ -42,10 +39,8 @@ class FrameWidgets(ttk.Frame):
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")
@ -78,19 +73,8 @@ class FrameWidgets(ttk.Frame):
# 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
def delete(): self.btn_tr = tk.Button(self, image=self.tr_pic, bd=0)
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)
@ -125,7 +109,7 @@ class FrameWidgets(ttk.Frame):
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(value=' ') self.StrVar.set(' ')
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")

View File

@ -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
class Message(tk.Tk): def wg_import_select():
def __init__(self, *args, **kwargs): try:
super().__init__(*args, **kwargs) 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]
self.warning_pic = None if "PrivateKey = " in read and "PublicKey = " in read:
self.x_width = 300 subprocess.call('cp ' + str(filepath) + ' /etc/wg_nmcli/', shell=True)
self.y_height = 120 os.system('nmcli connection import type wireguard file ' + str(filepath))
self.monitor_center_x = self.winfo_screenwidth() / 2 - (self.x_width / 2) os.system('nmcli con mod ' + str(pathsplit[:-5]) + ' connection.autoconnect no')
self.monitor_center_y = self.winfo_screenheight() / 2 - (self.y_height / 2) else:
self.resizable(width=False, height=False) messagebox.showwarning(title="conf error", message=" Oh... no valid Wireguard File!\nPlease select a "
self.title('Import error!') "valid Wireguard File ")
self.configure() except EOFError:
self.geometry('%dx%d+%d+%d' % (self.x_width, self.y_height, self.monitor_center_x, self.monitor_center_y)) pass
self.columnconfigure(0, weight=1) except TypeError:
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,45 +39,12 @@ 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 = Tunnel list # Show of 4.Element in list tl = wg_s[::3] # tl = Tunnelliste # Hiermit wird jedes 4. Element der Liste gezeigt
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()