Compare commits

..

13 Commits

Author SHA1 Message Date
4c89488950 Merge pull request 'wire-py-reformat-14-09-2024' (#14) from wire-py-reformat-14-09-2024 into main
Reviewed-on: https://git.ilunix.de/punix/Wire-Py/pulls/14
2024-09-14 23:31:00 +02:00
d1a822fff0 little fixes, add msg_window()
function for Messagebox to show a tk.Toplevel()
replace var = open() with:
with open() as var:
and remove by classes (tk.tk) and super()
2024-09-14 23:25:48 +02:00
8fa6e6374f little fixes a labels when stop and start, installer first functions works 2024-09-10 20:06:33 +02:00
35406026f0 little fixes replace os.system with check_call
first steps in install Script add wg_start.service file
2024-09-08 20:31:46 +02:00
c0ae2d2b75 Merge pull request 'wire-py-reformat-14-08-2024' (#13) from wire-py-reformat-14-08-2024 into main
Reviewed-on: https://git.ilunix.de/punix/Wire-Py/pulls/13
2024-09-05 22:22:00 +02:00
e4774abf19 Merge pull request 'fixes on empty Listbox now is disable and now works autoconnect label with read and write, delete works now with read and write' (#12) from wire-py-reformat-14-08-2024 into main
Reviewed-on: https://git.ilunix.de/punix/Wire-Py/pulls/12
2024-09-04 20:55:51 +02:00
7b1e543428 Merge pull request 'add if question and add autoconnect, autoconnect_var to class Filehandle in box_set no finish!' (#11) from wire-py-reformat-14-08-2024 into main
Reviewed-on: https://git.ilunix.de/punix/Wire-Py/pulls/11
2024-09-04 09:20:05 +02:00
6f83fc7162 Merge pull request 'wire-py-reformat-14-08-2024' (#10) from wire-py-reformat-14-08-2024 into main
Reviewed-on: https://git.ilunix.de/punix/Wire-Py/pulls/10
2024-09-04 06:26:30 +02:00
b70400b456 Merge pull request 'wire-py-reformat-14-08-2024' (#9) from wire-py-reformat-14-08-2024 into main
Reviewed-on: https://git.ilunix.de/punix/Wire-Py/pulls/9
2024-08-25 20:32:05 +02:00
e25bc154ea Merge pull request 'wire-py-reformat-14-08-2024' (#8) from wire-py-reformat-14-08-2024 into main
Reviewed-on: https://git.ilunix.de/punix/Wire-Py/pulls/8
2024-08-23 18:00:19 +02:00
7aa3cd75fe Merge pull request 'Set Style to Clam' (#7) from wire-py-reformat-14-08-2024 into main
Reviewed-on: https://git.ilunix.de/punix/Wire-Py/pulls/7
2024-08-21 22:52:27 +02:00
0b9eec8d1d Merge pull request 'add Class StartStopBTN to wg_func.py' (#6) from wire-py-reformat-14-08-2024 into main
Reviewed-on: https://git.ilunix.de/punix/Wire-Py/pulls/6
2024-08-21 12:52:51 +02:00
b9083d4698 Merge pull request 'add file dict_to_address for' (#5) from wire-py-reformat-14-08-2024 into main
Reviewed-on: https://git.ilunix.de/punix/Wire-Py/pulls/5
2024-08-21 12:00:18 +02:00
6 changed files with 212 additions and 110 deletions

View File

@ -4,13 +4,16 @@
<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="little fixes"> <list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="little fixes a labels when stop and start, installer first functions works">
<change afterPath="$PROJECT_DIR$/start_wg.py" afterDir="false" /> <change afterPath="$PROJECT_DIR$/message.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/wg_py" afterDir="false" /> <change afterPath="$PROJECT_DIR$/test.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/test2.py" afterDir="false" />
<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$/install.py" beforeDir="false" afterPath="$PROJECT_DIR$/install.py" 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$/start_wg.py" beforeDir="false" afterPath="$PROJECT_DIR$/start_wg.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" />
<change beforePath="$PROJECT_DIR$/wg_py.xml" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/wg_py" beforeDir="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" />
@ -47,7 +50,10 @@
<component name="PropertiesComponent">{ <component name="PropertiesComponent">{
&quot;keyToString&quot;: { &quot;keyToString&quot;: {
&quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;, &quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;,
&quot;Python.INSTALL.executor&quot;: &quot;Run&quot;,
&quot;Python.install.executor&quot;: &quot;Run&quot;,
&quot;Python.main.executor&quot;: &quot;Run&quot;, &quot;Python.main.executor&quot;: &quot;Run&quot;,
&quot;Python.messagebox.executor&quot;: &quot;Run&quot;,
&quot;Python.start_wg.executor&quot;: &quot;Run&quot;, &quot;Python.start_wg.executor&quot;: &quot;Run&quot;,
&quot;Python.wg_func.executor&quot;: &quot;Run&quot;, &quot;Python.wg_func.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
@ -331,10 +337,39 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1725639633873</updated> <updated>1725639633873</updated>
</task> </task>
<option name="localTasksCounter" value="27" /> <task id="LOCAL-00027" summary="little fixes">
<option name="closed" value="true" />
<created>1725746027132</created>
<option name="number" value="00027" />
<option name="presentableId" value="LOCAL-00027" />
<option name="project" value="LOCAL" />
<updated>1725746027132</updated>
</task>
<task id="LOCAL-00028" summary="little fixes replace os.system with check_call&#10;first steps in install Script add wg_start.service file">
<option name="closed" value="true" />
<created>1725820337669</created>
<option name="number" value="00028" />
<option name="presentableId" value="LOCAL-00028" />
<option name="project" value="LOCAL" />
<updated>1725820337669</updated>
</task>
<task id="LOCAL-00029" summary="little fixes a labels when stop and start, installer first functions works">
<option name="closed" value="true" />
<created>1725991610908</created>
<option name="number" value="00029" />
<option name="presentableId" value="LOCAL-00029" />
<option name="project" value="LOCAL" />
<updated>1725991610908</updated>
</task>
<option name="localTasksCounter" value="30" />
<servers /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
<option name="OPEN_GENERIC_TABS">
<map>
<entry key="f9756e7d-0c5c-4b84-84e4-660314c46ea4" value="TOOL_WINDOW" />
</map>
</option>
<option name="TAB_STATES"> <option name="TAB_STATES">
<map> <map>
<entry key="MAIN"> <entry key="MAIN">
@ -354,13 +389,16 @@
</State> </State>
</value> </value>
</entry> </entry>
<entry key="f9756e7d-0c5c-4b84-84e4-660314c46ea4">
<value>
<State />
</value>
</entry>
</map> </map>
</option> </option>
</component> </component>
<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="wg_import_select in wg_func.py extended" />
<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" />
<MESSAGE value="add class Frame and class Massage, delete funktion go 100%, add resize window, add warning pic" /> <MESSAGE value="add class Frame and class Massage, delete funktion go 100%, add resize window, add warning pic" />
<MESSAGE value="add class ListTunnels and class ImportTunnel, and add class ExportTunnels (ExportTunnels no finish)" /> <MESSAGE value="add class ListTunnels and class ImportTunnel, and add class ExportTunnels (ExportTunnels no finish)" />
@ -384,6 +422,8 @@
<MESSAGE value="fixes on empty Listbox now is disable and now works autoconnect label with read and write, delete works now with read and write" /> <MESSAGE value="fixes on empty Listbox now is disable and now works autoconnect label with read and write, delete works now with read and write" />
<MESSAGE value="add Frame widget 3&#10;for Buttons and Listbox with Scrollbar.&#10;all Widgets new format&#10;delete works now of disable checkbox when Listbox empty (part two)" /> <MESSAGE value="add Frame widget 3&#10;for Buttons and Listbox with Scrollbar.&#10;all Widgets new format&#10;delete works now of disable checkbox when Listbox empty (part two)" />
<MESSAGE value="little fixes" /> <MESSAGE value="little fixes" />
<option name="LAST_COMMIT_MESSAGE" value="little fixes" /> <MESSAGE value="little fixes replace os.system with check_call&#10;first steps in install Script add wg_start.service file" />
<MESSAGE value="little fixes a labels when stop and start, installer first functions works" />
<option name="LAST_COMMIT_MESSAGE" value="little fixes a labels when stop and start, installer first functions works" />
</component> </component>
</project> </project>

34
install.py Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/python3
from pathlib import Path
from getpass import getpass
# for services file in /lib/systemd/system/
config_path = Path.home() / ".config" / "wire_py" / "wg_py"
start_file = f'''\
#!/usr/bin/python3
from subprocess import check_call
path_to_file = {str(config_path)!r}
with open(path_to_file, 'r') as file:
*_, line = file
a_con = line[5:]
check_call(['nmcli', 'connection', 'up', a_con])
'''
Path("start_wg.py").write_text(start_file)
config_path.parent.mkdir(exist_ok=True)
if not Path.exists(config_path):
config_path.write_text("false")
# Prompt the user for the sudo password
#sudo_password = getpass('Enter sudo password: ')
#def cp_files():
# Define the command to run the Python script with sudo
#command = ['sudo', '-S', 'python3', 'script.py']
# Run the command as a subprocess, passing the sudo password
#subprocess.run(command, input=sudo_password.encode(), check=True)

38
main.py
View File

@ -1,8 +1,9 @@
#!/usr/bin/python3 #!/usr/bin/python3
import os import os
import tkinter as tk import tkinter as tk
from subprocess import check_call
from tkinter import ttk from tkinter import ttk
from pathlib import Path
from wg_func import (TunnelActiv, ListTunnels, ImportTunnel, ConToDict, GreenLabel, StartStopBTN, ShowAddress, from wg_func import (TunnelActiv, ListTunnels, ImportTunnel, ConToDict, GreenLabel, StartStopBTN, ShowAddress,
FileHandle, ExportTunnels, OnOff) FileHandle, ExportTunnels, OnOff)
@ -126,13 +127,12 @@ class FrameWidgets(ttk.Frame):
# Button Vpn # Button Vpn
if self.a != '': if self.a != '':
StartStopBTN.button_stop(self) StartStopBTN.button_stop(self)
wg_read = os.environ['HOME'] + '/tester/' + str(self.a) + '.conf' wg_read = Path.home() / 'tester/' / str(self.a + '.conf')
file = open(wg_read, 'r') with open(wg_read, 'r') as file:
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()
else: else:
StartStopBTN.button_start(self) StartStopBTN.button_start(self)
# Address Label # Address Label
@ -151,21 +151,32 @@ class FrameWidgets(ttk.Frame):
try: 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)) check_call(['nmcli', 'connection', 'delete', 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(Path.home() / 'tester/' / str(select_tl + '.conf'))
path_to_file = Path.home() / '.config/wire_py/wg_py'
with open(path_to_file, 'r') as file2:
for line in file2.readlines():
a_con = line[5:]
if select_tl == a_con:
self.selected_option.set(0)
self.autoconnect_var.set('no Autoconnect')
# for disable checkbox when Listbox empty # for disable checkbox when Listbox empty
tl = ListTunnels.tl_list() tl = ListTunnels.tl_list()
if len(tl) == 0: if len(tl) == 0:
self.wg_autostart.configure(state='disabled') self.wg_autostart.configure(state='disabled')
with open(path_to_file, 'w') as file2:
file2.write('false')
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) self.add.set('')
self.DNS.set('')
self.enp.set('')
return select_tl return select_tl
except IndexError: except IndexError:
@ -209,14 +220,13 @@ class FrameWidgets(ttk.Frame):
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)) check_call(['nmcli', 'connection', 'up', select_tl])
wg_read = os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf' wg_read = Path.home() / 'tester/' / str(select_tl + '.conf')
file = open(wg_read, 'r') with open(wg_read, 'r') as file:
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()
# Button Start/Stop # Button Start/Stop
StartStopBTN.button_stop(self) StartStopBTN.button_stop(self)
self.a = TunnelActiv.active() self.a = TunnelActiv.active()
@ -226,14 +236,16 @@ class FrameWidgets(ttk.Frame):
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)) check_call(['nmcli', 'connection', 'down', 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) self.add.set('')
self.DNS.set('')
self.enp.set('')
ShowAddress.show_data(self) ShowAddress.show_data(self)
except IndexError: except IndexError:
pass pass

View File

@ -1,12 +1,9 @@
#!/usr/bin/python3 #!/usr/bin/python3
from subprocess import check_call from subprocess import check_call
from pathlib import Path
home = Path.home() path_to_file = '/home/punix/.config/wire_py/wg_py'
path_to_file = home / 'Pyapps/wire-py/wg_py'
with open(path_to_file, 'r') as file: with open(path_to_file, 'r') as file:
for line in file.readlines(): *_, line = file
a_con = line[5:] a_con = line[5:]
check_call(['nmcli', 'connection', 'up', a_con]) check_call(['nmcli', 'connection', 'up', a_con])

View File

@ -4,37 +4,40 @@ import shutil
from datetime import datetime from datetime import datetime
from tkinter import filedialog, ttk from tkinter import filedialog, ttk
import tkinter as tk import tkinter as tk
from pathlib import Path
from subprocess import check_call
font_color = '#4011a7' font_color = '#4011a7'
path_to_file = Path.home() / '.config/wire_py/wg_py'
class Message(tk.Tk): def msg_window():
def __init__(self, *args, **kwargs): msg = tk.Toplevel()
super().__init__(*args, **kwargs) msg.resizable(width=False, height=False)
msg.x_width = 340
self.warning_pic = None msg.y_height = 140
self.x_width = 300 msg.title('Import error!')
self.y_height = 120 msg.monitor_center_x = msg.winfo_screenwidth() / 2 - (msg.x_width / 2)
self.monitor_center_x = self.winfo_screenwidth() / 2 - (self.x_width / 2) msg.monitor_center_y = msg.winfo_screenheight() / 2 - (msg.y_height / 2)
self.monitor_center_y = self.winfo_screenheight() / 2 - (self.y_height / 2) msg.geometry('%dx%d+%d+%d' % (msg.x_width, msg.y_height, msg.monitor_center_x, msg.monitor_center_y))
self.resizable(width=False, height=False) msg.columnconfigure(0, weight=1)
self.title('Import error!') msg.configure(pady=20)
self.configure() msg.warning = tk.PhotoImage(file=r'icons/warning_64.png')
self.geometry('%dx%d+%d+%d' % (self.x_width, self.y_height, self.monitor_center_x, self.monitor_center_y)) msg.i_warning = tk.Label(msg, image=msg.warning)
self.columnconfigure(0, weight=1) msg.i_warning.grid(column=0, row=0)
label = tk.Label(msg, text='Oh... no valid Wireguard File!\nPlease select a valid Wireguard File')
self.label = tk.Label(self, image=self.warning_pic, label.config(font=('Ubuntu', 11), padx=15, pady=15)
text='Oh... no valid Wireguard File!\nPlease select a valid Wireguard File') label.grid(column=1, row=0)
self.label.config(font=('Ubuntu', 11), padx=15, pady=15) button = tk.Button(msg, text='OK', command=msg.destroy)
self.label.grid(column=0, row=0) button.config(padx=15, pady=5)
self.button = tk.Button(self, text='OK', command=self.destroy) button.grid(column=0, columnspan=2, row=1)
self.button.config(padx=15, pady=5) wg_icon_2 = tk.PhotoImage(file=r'icons/wg-stop.png')
self.button.grid(column=0, row=1) msg.iconphoto(True, wg_icon_2)
msg.winfo_toplevel()
class GreenLabel(tk.Tk): class GreenLabel:
def __init__(self, container, **kwargs): def __init__(self):
super().__init__(container, **kwargs)
self.StrVar = None self.StrVar = None
self.lb_tunnel = None self.lb_tunnel = None
@ -45,10 +48,15 @@ class GreenLabel(tk.Tk):
self.columnconfigure(2, weight=1) self.columnconfigure(2, weight=1)
self.rowconfigure(0, weight=1) self.rowconfigure(0, weight=1)
def columnconfigure(self, param, weight):
pass
class StartStopBTN(tk.Tk): def rowconfigure(self, param, weight):
def __init__(self, *args, **kwargs): pass
super().__init__(*args, **kwargs)
class StartStopBTN:
def __init__(self):
self.lb_frame_btn_lbox = None self.lb_frame_btn_lbox = None
self.wg_switch = None self.wg_switch = None
self.btn_stst = None self.btn_stst = None
@ -111,9 +119,8 @@ class TunnelActiv:
return active return active
class ShowAddress(tk.Tk): class ShowAddress:
def __init__(self, container, **kwargs): def __init__(self):
super().__init__(container, **kwargs)
self.lb_frame2 = None self.lb_frame2 = None
self.lb_frame = None self.lb_frame = None
self.endpoint = None self.endpoint = None
@ -161,10 +168,9 @@ class ListTunnels:
class ImportTunnel: class ImportTunnel:
def __init__(self): def __init__(self):
self.enp = None
self.DNS = None
self.add = None
self.select_tunnel = None self.select_tunnel = None
self.wg_switch = None self.wg_switch = None
self.btn_stst = None self.btn_stst = None
@ -175,27 +181,30 @@ class ImportTunnel:
def wg_import_select(self): def wg_import_select(self):
try: try:
filepath = filedialog.askopenfilename(initialdir=os.environ['HOME'], title='Select Wireguard config File', filepath = filedialog.askopenfilename(initialdir=Path.home(), title='Select Wireguard config File',
filetypes=[('WG config files', '*.conf')]) filetypes=[('WG config files', '*.conf')], )
file = open(filepath, 'r') with open(filepath, 'r') as file:
read = file.read() read = file.read()
file.close()
path_split = filepath.split('/') path_split = filepath.split('/')
path_split1 = path_split[-1] path_split1 = path_split[-1]
self.a = TunnelActiv.active()
if 'PrivateKey = ' in read and 'PublicKey = ' in read: if 'PrivateKey = ' in read and 'PublicKey = ' in read:
if len(path_split1) > 17: if len(path_split1) > 17:
p1 = shutil.copy(filepath, os.environ['HOME'] + '/tester/') p1 = shutil.copy(filepath, Path.home() / 'tester/')
path_split = path_split1[len(path_split1) - 17:] path_split = path_split1[len(path_split1) - 17:]
os.rename(p1, os.environ['HOME'] + '/tester/' + str(path_split)) os.rename(p1, Path.home() / 'tester/' / str(path_split))
if self.a != '': if self.a != '':
os.system('nmcli connection down ' + str(TunnelActiv.active())) check_call(['nmcli', 'connection', 'down', TunnelActiv.active()])
os.system('nmcli connection import type wireguard file ' + os.environ['HOME'] + '/tester/' + ShowAddress.label_empty(self)
str(path_split)) check_call(['nmcli', 'connection', 'import', 'type', 'wireguard', 'file', Path.home() / 'tester' /
path_split])
else: else:
shutil.copy(filepath, os.environ['HOME'] + '/tester/') shutil.copy(filepath, Path.home() / 'tester/')
if self.a != '': if self.a != '':
os.system('nmcli connection down ' + str(TunnelActiv.active())) check_call(['nmcli', 'connection', 'down', TunnelActiv.active()])
os.system('nmcli connection import type wireguard file ' + str(filepath)) ShowAddress.label_empty(self)
check_call(['nmcli', 'connection', 'import', 'type', 'wireguard', 'file', filepath])
self.StrVar.set('') self.StrVar.set('')
self.a = TunnelActiv.active() self.a = TunnelActiv.active()
@ -205,16 +214,15 @@ class ImportTunnel:
self.StrVar.set(self.a) self.StrVar.set(self.a)
GreenLabel.green_show_label(self) GreenLabel.green_show_label(self)
StartStopBTN.button_stop(self) StartStopBTN.button_stop(self)
wg_read = os.environ['HOME'] + '/tester/' + str(self.a) + '.conf' wg_read = Path.home() / 'tester/' / str(self.a + '.conf')
file = open(wg_read, 'r') with open(wg_read, 'r') as file:
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() check_call(['nmcli', 'con', 'mod', self.a, 'connection.autoconnect', 'no'])
os.system('nmcli con mod ' + str(self.a) + ' connection.autoconnect no')
if 'PrivateKey = ' not in read: if 'PrivateKey = ' not in read:
Message() msg_window()
except EOFError: except EOFError:
pass pass
except TypeError: except TypeError:
@ -234,19 +242,20 @@ class FileHandle:
self.tl = None self.tl = None
self.selected_option = None self.selected_option = None
self.l_box = None self.l_box = None
self.select_tunnel = None
def box_set(self): def box_set(self):
try: try:
self.select_tunnel = self.l_box.curselection() select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(self.select_tunnel[0]) select_tl = self.l_box.get(select_tunnel[0])
if self.selected_option.get() == 0: if self.selected_option.get() == 0:
off = open('wg_py', 'w') with open(path_to_file, 'w') as off:
off.close() off.write('false ' + '\n')
tl = ListTunnels.tl_list()
if len(tl) == 0:
self.wg_autostart.configure(state='disabled')
if self.selected_option.get() >= 1: if self.selected_option.get() >= 1:
set_on = open('wg_py', 'w') with open(path_to_file, 'w') as set_on:
set_on.write(select_tl) set_on.write('true ' + select_tl)
set_on.close()
except IndexError: except IndexError:
self.selected_option.set(1) self.selected_option.set(1)
@ -254,26 +263,26 @@ class FileHandle:
OnOff.on_off(self) OnOff.on_off(self)
class OnOff(tk.Tk, FileHandle): class OnOff:
def __init__(self, container, **kwargs): def __init__(self):
super().__init__(container, **kwargs) self.wg_autostart = None
self.selected_option = None
self.auto_con = None
self.autoconnect = None
self.autoconnect_var = None
self.lb_frame_buttons = None self.lb_frame_buttons = None
def on_off(self): def on_off(self):
a_connect = {} with open(path_to_file, 'r') as file:
on_or_off = open('wg_py', 'r') for line in file.readlines():
for line in on_or_off.readlines(): a_connect = line
line_splitted = line.split()
a_connect[line_splitted[0]] = line_splitted[1]
if 'true' in a_connect: if 'true' in a_connect:
self.selected_option.set(1) self.selected_option.set(1)
self.autoconnect_var.set('') self.autoconnect_var.set('')
self.auto_con = a_connect['true'] self.auto_con = a_connect[5:]
else: else:
self.wg_autostart.configure(state='disabled') self.wg_autostart.configure(state='disabled')
self.auto_con = 'no Autoconnect' self.auto_con = 'no Autoconnect'
on_or_off.close()
self.autoconnect_var = tk.StringVar() self.autoconnect_var = tk.StringVar()
self.autoconnect_var.set(self.auto_con) self.autoconnect_var.set(self.auto_con)
@ -286,12 +295,12 @@ class ExportTunnels:
@staticmethod @staticmethod
def wg_export(): def wg_export():
now_time = datetime.now() now_time = datetime.now()
now_datetime = now_time.strftime('/wg-exp-' + '%m-%d-%Y' + '-' + '%H:%M') now_datetime = now_time.strftime('wg-exp-' + '%m-%d-%Y' + '-' + '%H:%M')
tl = ListTunnels.tl_list() tl = ListTunnels.tl_list()
try: try:
if len(tl) != 0: if len(tl) != 0:
wg_tar = os.environ['HOME'] + now_datetime wg_tar = Path.home() / now_datetime
p_to_conf = os.environ['HOME'] + '/tester' p_to_conf = Path.home() / 'tester/'
shutil.make_archive(wg_tar, 'zip', p_to_conf) shutil.make_archive(wg_tar, 'zip', p_to_conf)
#if zip_full != 0: #if zip_full != 0:
#print('Export erfolgraeich') #print('Export erfolgraeich')

10
wg_start.service Normal file
View File

@ -0,0 +1,10 @@
[Unit]
Description=Automatic Tunnel Start
After=network-online.target
[Service]
Type=oneshot
ExecStartPre=/bin/sleep 3
ExecStart=/bin/start_wg.py
[Install]
WantedBy=multi-user.target