Compare commits

..

No commits in common. "b70400b4565d38c8db476fa9f50e550d83cb7e0d" and "e25bc154eae345f835aac8141e3797452ca4e746" have entirely different histories.

3 changed files with 67 additions and 96 deletions

View File

@ -4,7 +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="fix when Filname &gt; 17 first copy file after rename"> <list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="little fixes in Class Import">
<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$/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" /> <change beforePath="$PROJECT_DIR$/wg_func.py" beforeDir="false" afterPath="$PROJECT_DIR$/wg_func.py" afterDir="false" />
@ -211,31 +211,7 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1724416642213</updated> <updated>1724416642213</updated>
</task> </task>
<task id="LOCAL-00016" summary="fix label when laat Tunnel delete and fix Tuple error in delete and Start/Stop when listbox empty"> <option name="localTasksCounter" value="16" />
<option name="closed" value="true" />
<created>1724495688099</created>
<option name="number" value="00016" />
<option name="presentableId" value="LOCAL-00016" />
<option name="project" value="LOCAL" />
<updated>1724495688099</updated>
</task>
<task id="LOCAL-00017" summary="remove a ',' in DNS Name">
<option name="closed" value="true" />
<created>1724576599289</created>
<option name="number" value="00017" />
<option name="presentableId" value="LOCAL-00017" />
<option name="project" value="LOCAL" />
<updated>1724576599289</updated>
</task>
<task id="LOCAL-00018" summary="fix when Filname &gt; 17 first copy file after rename">
<option name="closed" value="true" />
<created>1724593165879</created>
<option name="number" value="00018" />
<option name="presentableId" value="LOCAL-00018" />
<option name="project" value="LOCAL" />
<updated>1724593165879</updated>
</task>
<option name="localTasksCounter" value="19" />
<servers /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
@ -277,9 +253,6 @@
<MESSAGE value="In FrameWidged Class else Block StrVar, this resorts reference and variable assignment together" /> <MESSAGE value="In FrameWidged Class else Block StrVar, this resorts reference and variable assignment together" />
<MESSAGE value="add method init_and_report and label_empty to Class ShowAddress" /> <MESSAGE value="add method init_and_report and label_empty to Class ShowAddress" />
<MESSAGE value="little fixes in Class Import" /> <MESSAGE value="little fixes in Class Import" />
<MESSAGE value="fix label when laat Tunnel delete and fix Tuple error in delete and Start/Stop when listbox empty" /> <option name="LAST_COMMIT_MESSAGE" value="little fixes in Class Import" />
<MESSAGE value="remove a ',' in DNS Name" />
<MESSAGE value="fix when Filname &gt; 17 first copy file after rename" />
<option name="LAST_COMMIT_MESSAGE" value="fix when Filname &gt; 17 first copy file after rename" />
</component> </component>
</project> </project>

96
main.py Executable file → Normal file
View File

@ -85,12 +85,12 @@ class FrameWidgets(ttk.Frame):
self.peer.config(font=("Ubuntu", 9)) self.peer.config(font=("Ubuntu", 9))
self.peer.grid(column=0, row=7, sticky="we", padx=130) self.peer.grid(column=0, row=7, sticky="we", padx=130)
# Listbox with Scrollbar # Listbox with Scrollbar
self.scrollbar = ttk.Scrollbar(self) self.scrollbar = tk.Scrollbar(self)
self.l_box = tk.Listbox(self, fg='#606060', selectmode='single') self.l_box = tk.Listbox(self, fg='#606060', selectmode='single')
self.l_box.config(highlightthickness=0, relief='flat') self.l_box.config(highlightthickness=0, relief='flat')
self.scrollbar.config(command=self.l_box.yview) self.scrollbar.config(command=self.l_box.yview)
self.l_box.config(font=("Ubuntu", 12, "bold")) self.l_box.config(font=("Ubuntu", 12, "bold"))
self.l_box.grid(column=1, rowspan=3, row=1) self.l_box.grid(column=1, rowspan=3, row=1, )
# Tunnel List # Tunnel List
self.tl = ListTunnels.tl_list() self.tl = ListTunnels.tl_list()
for tunnels in self.tl: for tunnels in self.tl:
@ -119,26 +119,23 @@ class FrameWidgets(ttk.Frame):
self.btn_i.grid(column=0, row=2, padx=15, pady=15) self.btn_i.grid(column=0, row=2, padx=15, pady=15)
def delete(): def delete():
try: self.select_tunnel = self.l_box.curselection()
self.select_tunnel = self.l_box.curselection() select_tl = self.l_box.get(self.select_tunnel[0])
select_tl = self.l_box.get(self.select_tunnel[0]) os.system('nmcli connection delete ' + str(select_tl))
os.system('nmcli connection delete ' + str(select_tl)) self.l_box.delete(self.select_tunnel[0])
self.l_box.delete(self.select_tunnel[0]) os.remove(os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf')
os.remove(os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf') if self.a != '' and self.a == select_tl:
if self.a != '' and self.a == select_tl: self.StrVar.set(value='')
self.StrVar.set(value='') StartStopBTN.button_start(self)
StartStopBTN.button_start(self) self.l_box.update()
self.l_box.update() # Address Label
# Address Label ShowAddress.label_empty(self)
ShowAddress.label_empty(self) ShowAddress.show_data(self)
except IndexError:
pass
# Button Trash # Button Trash
self.btn_tr = tk.Button(self, image=self.tr_pic, bd=0, command=delete) 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, command=ExportTunnels.wg_export) self.btn_exp = tk.Button(self, image=self.exp_pic, bd=0)
self.btn_exp.grid(column=0, row=4, padx=15, pady=15) self.btn_exp.grid(column=0, row=4, padx=15, pady=15)
# Check Buttons # Check Buttons
self.wg_autostart = tk.Checkbutton(self, text='Autoconnect on PC Start') self.wg_autostart = tk.Checkbutton(self, text='Autoconnect on PC Start')
@ -148,39 +145,36 @@ class FrameWidgets(ttk.Frame):
def wg_switch(self): def wg_switch(self):
self.a = TunnelActiv.active() self.a = TunnelActiv.active()
try: if self.a == '':
if self.a == '': StartStopBTN.button_start(self)
StartStopBTN.button_start(self) self.select_tunnel = self.l_box.curselection()
self.select_tunnel = self.l_box.curselection() select_tl = self.l_box.get(self.select_tunnel[0])
select_tl = self.l_box.get(self.select_tunnel[0]) os.system('nmcli connection up ' + str(select_tl))
os.system('nmcli connection up ' + str(select_tl)) wg_read = os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf'
wg_read = os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf' file = open(wg_read, 'r')
file = open(wg_read, 'r') data = ConToDict.covert_to_dict(file)
data = ConToDict.covert_to_dict(file) # Address Label
# Address Label ShowAddress.init_and_report(self, data)
ShowAddress.init_and_report(self, data) ShowAddress.show_data(self)
ShowAddress.show_data(self) file.close()
file.close() # Button Start/Stop
# Button Start/Stop StartStopBTN.button_stop(self)
StartStopBTN.button_stop(self) self.a = TunnelActiv.active()
self.a = TunnelActiv.active() self.StrVar = tk.StringVar()
self.StrVar = tk.StringVar() self.StrVar.set(self.a)
self.StrVar.set(self.a) GreenLabel.green_show_label(self)
GreenLabel.green_show_label(self) elif self.a != '':
elif self.a != '': # Button Start/Stop
# Button Start/Stop StartStopBTN.button_stop(self)
StartStopBTN.button_stop(self) os.system('nmcli connection down ' + str(self.a))
os.system('nmcli connection down ' + str(self.a)) # Button Start/Stop
# Button Start/Stop StartStopBTN.button_start(self)
StartStopBTN.button_start(self) self.a = TunnelActiv.active()
self.a = TunnelActiv.active() self.StrVar.set('')
self.StrVar.set('') GreenLabel.green_show_label(self)
GreenLabel.green_show_label(self) # Address Label
# Address Label ShowAddress.label_empty(self)
ShowAddress.label_empty(self) ShowAddress.show_data(self)
ShowAddress.show_data(self)
except IndexError:
pass
if __name__ == '__main__': if __name__ == '__main__':

34
wg_func.py Executable file → Normal file
View File

@ -1,7 +1,6 @@
# Wireguard functions for Wire-Py # Wireguard functions for Wire-Py
import os import os
import shutil import subprocess
import tarfile
from tkinter import filedialog from tkinter import filedialog
import tkinter as tk import tkinter as tk
@ -47,6 +46,7 @@ class GreenLabel(tk.Tk):
class StartStopBTN(tk.Tk): class StartStopBTN(tk.Tk):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.tl = None
self.wg_switch = None self.wg_switch = None
self.btn_stst = None self.btn_stst = None
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')
@ -58,9 +58,17 @@ class StartStopBTN(tk.Tk):
self.rowconfigure(0, weight=1) self.rowconfigure(0, weight=1)
def button_start(self): def button_start(self):
self.btn_stst = tk.Button(self, image=self.wg_vpn_start, bd=0, command=self.wg_switch) self.tl = ListTunnels.tl_list()
self.btn_stst.grid(column=0, row=1, padx=15, pady=10, sticky="s") print(len(self.tl))
self.rowconfigure(0, weight=1) if len(self.tl) == 0:
self.btn_stst = tk.Button(self, image=self.wg_vpn_start, bd=0, command=self.wg_switch)
self.btn_stst.config(state=tk.DISABLED)
self.btn_stst.grid(column=0, row=1, padx=15, pady=10, sticky="s")
self.rowconfigure(0, weight=1)
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=10, sticky="s")
self.rowconfigure(0, weight=1)
class ConToDict: class ConToDict:
@ -88,12 +96,9 @@ class ConToDict:
finaldict = {} finaldict = {}
for elements in newlist: for elements in newlist:
finaldict[elements[0]] = elements[1] finaldict[elements[0]] = elements[1]
# end... result a Dictionary # end... result a Dictionary
address = finaldict['Address'] address = finaldict['Address']
dns = finaldict['DNS'] dns = finaldict['DNS']
if ',' in dns:
dns = dns[:-1]
endpoint = finaldict['Endpoint'] endpoint = finaldict['Endpoint']
return address, dns, endpoint return address, dns, endpoint
@ -183,15 +188,14 @@ class ImportTunnel:
pathsplit1 = pathsplit[-1] pathsplit1 = pathsplit[-1]
if "PrivateKey = " in read and "PublicKey = " in read: if "PrivateKey = " in read and "PublicKey = " in read:
if len(pathsplit1) > 17: if len(pathsplit1) > 17:
p1 = shutil.copy(filepath, os.environ['HOME'] + '/tester/')
pathsplit = pathsplit1[len(pathsplit1) - 17:] pathsplit = pathsplit1[len(pathsplit1) - 17:]
os.rename(p1, os.environ['HOME'] + '/tester/' + str(pathsplit)) os.rename(filepath, os.environ['HOME'] + '/tester/' + str(pathsplit))
if self.a != '': if self.a != '':
os.system('nmcli connection down ' + str(TunnelActiv.active())) os.system('nmcli connection down ' + str(TunnelActiv.active()))
os.system('nmcli connection import type wireguard file ' + os.environ['HOME'] + '/tester/' + os.system('nmcli connection import type wireguard file ' + os.environ['HOME'] + '/tester/' +
str(pathsplit)) str(pathsplit))
else: else:
shutil.copy(filepath, os.environ['HOME'] + '/tester/') subprocess.call('cp ' + str(filepath) + ' ' + os.environ['HOME'] + '/tester/', shell=True)
if self.a != '': if self.a != '':
os.system('nmcli connection down ' + str(TunnelActiv.active())) os.system('nmcli connection down ' + str(TunnelActiv.active()))
os.system('nmcli connection import type wireguard file ' + str(filepath)) os.system('nmcli connection import type wireguard file ' + str(filepath))
@ -226,8 +230,8 @@ class ExportTunnels:
@staticmethod @staticmethod
def wg_export(): def wg_export():
try: try:
wg_tar = os.environ['HOME'] + '/datetime' wg_exp = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
p_to_conf = os.environ['HOME'] + '/tester' wg_exp = wg_exp[1]
shutil.make_archive(wg_tar, 'zip', p_to_conf) return wg_exp
except TypeError: except IndexError:
pass pass