diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 16447c5..0f8ea06 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,11 +4,14 @@
-
+
+
-
-
+
+
+
+
@@ -61,9 +64,10 @@
"Python.wg_main.executor": "Run",
"RunOnceActivity.ShowReadmeOnStart": "true",
"Shell Script.install.executor": "Run",
+ "Shell Script.run_as.executor": "Run",
"git-widget-placeholder": "main",
"last_opened_file_path": "/home/punix/Pyapps/wire-py",
- "settings.editor.selected.configurable": "configurable.group.editor"
+ "settings.editor.selected.configurable": "reference.settingsdialog.IDE.editor.colors"
}
}
@@ -144,38 +148,6 @@
1723279982210
-
-
- 1724401340512
-
-
-
- 1724401340512
-
-
-
- 1724410630021
-
-
-
- 1724410630021
-
-
-
- 1724416642213
-
-
-
- 1724416642213
-
-
-
- 1724495688099
-
-
-
- 1724495688099
-
1724576599289
@@ -536,7 +508,39 @@
1729353898830
-
+
+
+ 1729541504291
+
+
+
+ 1729541504292
+
+
+
+ 1729541561434
+
+
+
+ 1729541561434
+
+
+
+ 1729593628907
+
+
+
+ 1729593628908
+
+
+
+ 1729938941026
+
+
+
+ 1729938941027
+
+
@@ -577,8 +581,6 @@
-
-
@@ -602,20 +604,17 @@
-
+
+
+
- file://$PROJECT_DIR$/wg_func.py
- 341
-
-
-
- file://$PROJECT_DIR$/wg_main.py
- 273
-
+ file://$PROJECT_DIR$/start_wg.py
+ 1
+
diff --git a/Changelog b/Changelog
index 1bfdf2a..8e3b619 100644
--- a/Changelog
+++ b/Changelog
@@ -4,12 +4,29 @@ My standard System: Linux Mint 22 Cinnamon
## [Unreleased]
- os import in wg_func replaced by other methods
- - Guide to menu '?' with pictures
- - In Gitea Readme enter text, images
- - Own filedialog for import
- If Wire-Py already runs, prevent further start
- for loops with lists replaced by List Comprehensions
- - Keeping Classes Together
+ - Update search after start of Wire-Py
+
+
+ ### Added
+27-10-2024
+
+- Add Autoconnect settings to settings.conf
+
+
+ ### Added
+26-10-2024
+
+- Add run_as Bash script and open_gitea.py python script
+- Add Tooltip disable/enable
+- Rename settings to settings.conf for theme, updates and tooltip enable in one file
+
+
+ ### Added
+25-10-2024
+
+- Optimize Class and Tooltip
### Added
diff --git a/install b/install
index 7a967c4..e6af75c 100755
--- a/install
+++ b/install
@@ -7,8 +7,8 @@ BLUE='\033[30;1;34m'
install_file_with(){
clear
sudo apt install python3-tk && \
- sudo cp -u wg_main.py start_wg.py wg_func.py wirepy.py /usr/bin/ && \
- sudo mkdir -p /etc/wire_py && sudo touch /etc/wire_py/.keys && sudo cp -u settings theme /etc/wire_py/ && \
+ sudo cp -u wg_main.py start_wg.py wg_func.py wirepy.py run_as open_gitea.py /usr/bin/ && \
+ sudo mkdir -p /etc/wire_py && sudo touch /etc/wire_py/.keys && sudo cp -u settings.conf /etc/wire_py/ && \
sudo cp -uR wp-icons /usr/share/icons/ && sudo cp -uR TK-Themes /usr/share/ && \
sudo chown -R root:root /etc/wire_py && sudo chmod 755 /etc/wire_py && \
sudo ln -sf /usr/bin/wirepy.py /usr/local/bin/wirepy && \
@@ -21,8 +21,8 @@ install_file_with(){
install_arch_d(){
clear
sudo pacman -S --noconfirm tk python3 python-requests && \
- sudo cp -u wg_main.py start_wg.py wg_func.py wirepy.py /usr/bin/ && \
- sudo mkdir -p /etc/wire_py && sudo touch /etc/wire_py/.keys && sudo cp -u settings theme /etc/wire_py/ && \
+ sudo cp -u wg_main.py start_wg.py wg_func.py wirepy.py run_as open_gitea.py /usr/bin/ && \
+ sudo mkdir -p /etc/wire_py && sudo touch /etc/wire_py/.keys && sudo cp -u settings.conf /etc/wire_py/ && \
sudo cp -uR wp-icons /usr/share/icons/ && sudo cp -uR TK-Themes /usr/share/ && \
sudo chown -R root:root /etc/wire_py && sudo chmod 755 /etc/wire_py && \
sudo ln -sf /usr/bin/wirepy.py /usr/local/bin/wirepy && \
@@ -89,9 +89,9 @@ elif grep -i 'fedora' /etc/os-release > /dev/null 2>&1
if ! which python3-tkinter &> /dev/null
then sudo dnf install python3-tkinter -y
- sudo cp -u wg_main.py start_wg.py wg_func.py wirepy.py /usr/bin/ && \
+ sudo cp -u wg_main.py start_wg.py wg_func.py wirepy.py run_as open_gitea.py /usr/bin/ && \
sudo mkdir -p /etc/wire_py && sudo touch /etc/wire_py/.keys && \
- sudo cp -u settings theme /etc/wire_py/ && \
+ sudo cp -u settings.conf /etc/wire_py/ && \
sudo cp -uR wp-icons /usr/share/icons/ && sudo cp -uR TK-Themes /usr/share/ && \
sudo chown -R root:root /etc/wire_py && sudo chmod 755 /etc/wire_py && \
sudo ln -sf /usr/bin/wirepy.py /usr/local/bin/wirepy && \
@@ -105,9 +105,9 @@ elif grep -i 'suse' /etc/os-release > /dev/null 2>&1
then
if ! which python311-tk &> /dev/null
then sudo zypper install python311-tk
- sudo cp -u wg_main.py start_wg.py wg_func.py wirepy.py /usr/bin/ && \
+ sudo cp -u wg_main.py start_wg.py wg_func.py wirepy.py run_as open_gitea.py /usr/bin/ && \
sudo mkdir -p /etc/wire_py && sudo touch /etc/wire_py/.keys && \
- sudo cp -u settings theme /etc/wire_py/ && \
+ sudo cp -u settings.conf /etc/wire_py/ && \
sudo cp -uR wp-icons /usr/share/icons/ && sudo cp -uR TK-Themes /usr/share/ && \
sudo chown -R root:root /etc/wire_py && sudo chmod 755 /etc/wire_py && \
sudo ln -sf /usr/bin/wirepy.py /usr/local/bin/wirepy && \
diff --git a/open_gitea.py b/open_gitea.py
new file mode 100755
index 0000000..4fdbad1
--- /dev/null
+++ b/open_gitea.py
@@ -0,0 +1,5 @@
+#!/usr/bin/python3
+
+import webbrowser
+
+webbrowser.open('https://git.ilunix.de/punix/Wire-Py')
\ No newline at end of file
diff --git a/run_as b/run_as
new file mode 100755
index 0000000..d15cff4
--- /dev/null
+++ b/run_as
@@ -0,0 +1,2 @@
+#!/bin/bash
+/usr/bin/./open_gitea.py
\ No newline at end of file
diff --git a/settings b/settings
deleted file mode 100644
index 66cb652..0000000
--- a/settings
+++ /dev/null
@@ -1 +0,0 @@
-Update on
\ No newline at end of file
diff --git a/settings.conf b/settings.conf
new file mode 100644
index 0000000..c0aaccd
--- /dev/null
+++ b/settings.conf
@@ -0,0 +1,8 @@
+[UPDATES]
+on
+[THEME]
+light
+[TOOLTIP]
+True
+[AUTOSTART ON]
+off
diff --git a/start_wg.py b/start_wg.py
index 41bb29b..3140e90 100755
--- a/start_wg.py
+++ b/start_wg.py
@@ -2,11 +2,13 @@
from subprocess import check_call
from pathlib import Path
-path_to_file = Path('/etc/wire_py/wg_py')
+path_to_file = Path('/etc/wire_py/settings.conf')
-if Path.exists(path_to_file):
- a_con = Path.read_text(path_to_file)
- check_call(['nmcli', 'connection', 'up', a_con])
-else:
- pass
+with open(path_to_file, 'r') as a_con:
+ lines = a_con.readlines()
+ a_con = lines[7].strip()
+ if a_con != 'off':
+ check_call(['nmcli', 'connection', 'up', a_con])
+ else:
+ pass
diff --git a/theme b/theme
deleted file mode 100644
index b8b4ecb..0000000
--- a/theme
+++ /dev/null
@@ -1 +0,0 @@
-light
\ No newline at end of file
diff --git a/wg_func.py b/wg_func.py
index 9f07af3..2dd71fc 100755
--- a/wg_func.py
+++ b/wg_func.py
@@ -3,6 +3,7 @@
import os
import shutil
import subprocess
+import time
import tkinter as tk
import zipfile
from datetime import datetime
@@ -15,9 +16,7 @@ import requests
''' 1 = 1. Year, 09 = Month of the Year, 2924 = Day and Year of the Year '''
version = 'v. 1.10.2124'
-path_to_file = Path('/etc/wire_py/wg_py')
-path_to_file2 = Path('/etc/wire_py/settings')
-path_to_file3 = Path('/etc/wire_py/theme')
+path_to_file2 = Path('/etc/wire_py/settings.conf')
_u = Path.read_text(Path('/tmp/_u'))
UPDATE_API_URL = 'https://git.ilunix.de/api/v1/repos/punix/Wire-Py/releases'
@@ -32,7 +31,7 @@ class WirePyUpdate:
response_dict = response_dict[0]
with open(path_to_file2, 'r') as set_file:
set_file = set_file.read()
- if 'Update on' in set_file:
+ if 'on\n' in set_file:
if version[3:] != response_dict['tag_name']:
return response_dict['tag_name']
else:
@@ -76,7 +75,8 @@ class WirePyUpdate:
res = WirePyUpdate.api_down()
-def msg_window(img_w, img_i, w_title, w_txt):
+
+def msg_window(img_w, img_i, w_title, w_txt, txt2=None, com=None):
"""
Function for different message windows for the user. with 4 arguments to be passed.
To create messages with your own images, icons, and titles. As an alternative to Python Messagebox.
@@ -93,13 +93,25 @@ def msg_window(img_w, img_i, w_title, w_txt):
msg.configure(pady=15, padx=15)
msg.img = tk.PhotoImage(file=img_w)
msg.i_window = tk.Label(msg, image=msg.img)
- msg.i_window.grid(column=0, row=0)
+
label = tk.Label(msg, text=w_txt)
- label.config(font=('Ubuntu', 11), padx=15)
+
label.grid(column=1, row=0)
- button = ttk.Button(msg, text='OK', command=msg.destroy, padding=4)
- button.config()
- button.grid(column=0, columnspan=2, row=1)
+
+ if txt2 != None and com != None:
+ label.config(font=('Ubuntu', 11), padx=15, justify='left')
+ msg.i_window.grid(column=0, row=0, sticky='nw')
+ button2 = ttk.Button(msg, text=f'{txt2}', command=com, padding=4)
+ button2.grid(column=0, row=1, sticky='e', columnspan=2)
+ button = ttk.Button(msg, text='OK', command=msg.destroy, padding=4)
+ button.grid(column=0, row=1, sticky='w', columnspan=2)
+
+ else:
+ label.config(font=('Ubuntu', 11), padx=15)
+ msg.i_window.grid(column=0, row=0)
+ button = ttk.Button(msg, text='OK', command=msg.destroy, padding=4)
+ button.grid(column=0, columnspan=2, row=1)
+
img_i = tk.PhotoImage(file=img_i)
msg.iconphoto(True, img_i)
msg.columnconfigure(0, weight=1)
@@ -107,43 +119,19 @@ def msg_window(img_w, img_i, w_title, w_txt):
msg.winfo_toplevel()
-class GreenLabel:
+class Tunnel:
+
"""
- Show the active tunnel in green in the label
+ Class of Methods for Wire-Py
"""
- def __init__(self):
- self.StrVar = None
- self.lb_tunnel = None
-
- def green_show_label(self):
- with open(path_to_file3, 'r') as read_file:
- if 'light' in read_file:
- self.lb_tunnel = ttk.Label(self, textvariable=self.StrVar, foreground='green')
-
- else:
- self.lb_tunnel = ttk.Label(self, textvariable=self.StrVar, foreground='yellow')
-
- self.lb_tunnel.config(font=('Ubuntu', 11, 'bold'))
- self.lb_tunnel.grid(column=2, padx=10, row=1)
- self.columnconfigure(2, weight=1)
- self.rowconfigure(0, weight=1)
-
- def columnconfigure(self, param, weight):
- pass
-
- def rowconfigure(self, param, weight):
- pass
-
-
-class ConToDict:
"""
The config file is packed into a dictionary,
to display the values Address , DNS and Peer in the labels
"""
@classmethod
- def covert_to_dict(cls, file):
+ def con_to_dict(cls, file):
dictlist = []
for lines in file.readlines():
@@ -184,7 +172,6 @@ class ConToDict:
return address, dns, endpoint, pre_key
-class TunnelActiv:
"""
Shows the Active Tunnel
"""
@@ -200,61 +187,12 @@ class TunnelActiv:
return active
-
-class ShowAddress:
- """
- Displays the value address, DNS and peer in the labels
- or empty it again
- """
-
- def __init__(self):
- self.lb_frame2 = None
- self.lb_frame = None
- self.endpoint = None
- self.dns = None
- self.address = None
- self.enp = None
- self.DNS = None
- self.add = None
-
- def init_and_report(self, data=None):
- """ Address Label """
- self.add = tk.StringVar()
- self.add.set('Address: ' + data[0])
- self.DNS = tk.StringVar()
- self.DNS.set(' DNS: ' + data[1])
- self.enp = tk.StringVar()
- self.enp.set('Endpoint: ' + data[2])
-
- def label_empty(self):
- self.add.set('')
- self.DNS.set('')
- self.enp.set('')
-
- def show_data(self):
- """ Address Label """
- self.address = ttk.Label(self.lb_frame, textvariable=self.add, foreground='#0071ff')
- self.address.grid(column=0, row=5, sticky='w', padx=10, pady=6)
- self.address.config(font=('Ubuntu', 9))
-
- ''' DNS Label '''
- self.dns = ttk.Label(self.lb_frame, textvariable=self.DNS, foreground='#0071ff')
- self.dns.grid(column=0, row=7, sticky='w', padx=10, pady=6)
- self.dns.config(font=('Ubuntu', 9))
-
- ''' Endpoint Label '''
- self.endpoint = ttk.Label(self.lb_frame2, textvariable=self.enp, foreground='#0071ff')
- self.endpoint.grid(column=0, row=8, sticky='w', padx=10, pady=20)
- self.endpoint.config(font=('Ubuntu', 9))
-
-
-class ListTunnels:
"""
Shows all existing Wireguard tunnels
"""
@staticmethod
- def tl_list():
+ def list():
wg_s = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
''' tl = Tunnel list # Show of 4.Element in list '''
@@ -262,84 +200,6 @@ class ListTunnels:
return tl
-class FileHandle:
- """
- This class will display the autostart label which
- Tunnel is automatically started regardless of the active tunnel.
- The selected tunnel is written into a file to read it after the start of the system.
- """
-
- def __init__(self):
-
- self.wg_autostart = None
- self.autoconnect = None
- self.auto_con = None
- self.autoconnect_var = None
- self.tl = None
- self.selected_option = None
- self.l_box = None
-
- def box_set(self):
-
- try:
- select_tunnel = self.l_box.curselection()
- select_tl = self.l_box.get(select_tunnel[0])
-
- if self.selected_option.get() == 0:
- Path.unlink(path_to_file)
- tl = ListTunnels.tl_list()
-
- if len(tl) == 0:
- self.wg_autostart.configure(state='disabled')
-
- if self.selected_option.get() >= 1:
- Path.write_text(path_to_file, select_tl)
-
- except IndexError:
- self.selected_option.set(1)
-
- OnOff.on_off(self)
-
-
-class OnOff:
- """
- Here it is checked whether the path to the file is there if not it is created.
- Set (on), the selected tunnel is displayed in the label.
- At (off) the label is first emptied then filled with No Autoconnect
- """
-
- def __init__(self):
-
- self.wg_autostart = None
- self.selected_option = None
- self.auto_con = None
- self.autoconnect = None
- self.autoconnect_var = None
- self.lb_frame_buttons = None
-
- def on_off(self):
-
- if Path.exists(path_to_file):
- self.selected_option.set(1)
- self.autoconnect_var.set('')
- if not Path.is_dir(Path('/etc/wire_py')):
- Path.mkdir(Path('/etc/wire_py'))
- self.auto_con = Path.read_text(path_to_file)
-
- else:
-
- self.wg_autostart.configure(state='disabled')
- self.auto_con = 'no Autoconnect'
- self.autoconnect_var.set('')
- self.autoconnect_var = tk.StringVar()
- self.autoconnect_var.set(self.auto_con)
-
- self.autoconnect = ttk.Label(self, textvariable=self.autoconnect_var, foreground='#0071ff')
- self.autoconnect.config(font=('Ubuntu', 11))
- self.autoconnect.grid(column=0, row=4, sticky='ne', pady=19)
-
-
-class ExportTunnels:
"""
This will export the tunnels.
A zipfile with current date and time is created
@@ -347,11 +207,11 @@ class ExportTunnels:
"""
@staticmethod
- def wg_export():
+ def export():
_u1 = str(_u[6:])
now_time = datetime.now()
now_datetime = now_time.strftime('wg-exp-' + '%m-%d-%Y' + '-' + '%H:%M')
- tl = ListTunnels.tl_list()
+ tl = Tunnel.list()
try:
if len(tl) != 0:
@@ -360,8 +220,7 @@ class ExportTunnels:
source = Path('/tmp/wire_py')
Path.unlink(Path(source) / 'wg_py', missing_ok=True)
Path.unlink(Path(source) / '.keys', missing_ok=True)
- Path.unlink(Path(source) / 'settings', missing_ok=True)
- Path.unlink(Path(source) / 'theme', missing_ok=True)
+ Path.unlink(Path(source) / 'settings.conf', missing_ok=True)
shutil.make_archive(wg_tar, 'zip', source)
shutil.chown(wg_tar + '.zip', 1000, 1000)
shutil.rmtree(source)
@@ -396,5 +255,16 @@ class ExportTunnels:
except TypeError:
pass
+ @staticmethod
+ def if_tip():
+ with open(path_to_file2, 'r') as set_file2:
+ lines2 = set_file2.readlines()
+ if 'False\n' in lines2:
+ return False
+ else:
+ return True
+
+tips = Tunnel.if_tip()
+
diff --git a/wg_main.py b/wg_main.py
index cdf1c67..e98155f 100755
--- a/wg_main.py
+++ b/wg_main.py
@@ -8,9 +8,7 @@ from subprocess import check_call
from tkinter import *
from tkinter import filedialog, ttk
-from wg_func import (TunnelActiv, ListTunnels, ConToDict, GreenLabel, ShowAddress, FileHandle,
- ExportTunnels, OnOff, msg_window, WirePyUpdate, res, _u, version, path_to_file2,
- path_to_file3)
+from wg_func import (Tunnel, msg_window, WirePyUpdate, res, _u, version, path_to_file2, tips)
tcl_path = Path('/usr/share/TK-Themes')
@@ -32,9 +30,10 @@ class MainWindow(tk.Tk):
self.geometry('%dx%d+%d+%d' % (self.x_width, self.y_height, self.monitor_center_x, self.monitor_center_y))
self.style = ttk.Style(self)
self.tk.call('source', str(tcl_path) + '/water.tcl')
- #self.tk.call('source', 'TK-Themes/water.tcl')
- with open(path_to_file3, 'r') as read_file:
- if 'light' in read_file:
+ ''' self.tk.call('source', 'TK-Themes/water.tcl') '''
+ with open(path_to_file2, 'r') as read_file:
+ lines = read_file.readlines()
+ if 'light\n' in lines:
self.tk.call('set_theme', 'light')
else:
self.tk.call('set_theme', 'dark')
@@ -42,41 +41,83 @@ class MainWindow(tk.Tk):
''' Load the image file from disk. '''
self.wg_icon = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_vpn.png')
- # Set it as the window icon.
+ ''' Set it as the window icon '''
self.iconphoto(True, self.wg_icon)
- #Set on or off in file
- def on_off():
- if set_option.get() == 1:
- with open(path_to_file2, 'w') as set_file2:
- set_file2.write('Update off')
+ ''' Set on or off in file '''
- if set_option.get() == 0:
+ def update():
+ if set_update.get() == 1:
+ with open(path_to_file2, 'r') as set_file2:
+ lines2 = set_file2.readlines()
+ lines2[1] = 'off\n'
with open(path_to_file2, 'w') as set_file2:
- set_file2.write('Update on')
+ set_file2.writelines(lines2)
+
+ if set_update.get() == 0:
+ with open(path_to_file2, 'r') as set_file2:
+ lines2 = set_file2.readlines()
+ lines2[1] = 'on\n'
+ with open(path_to_file2, 'w') as set_file2:
+ set_file2.writelines(lines2)
+
+ ''' Set on or off in file '''
+
+ def tooltip():
+ if set_tip.get():
+ with open(path_to_file2, 'r') as set_file2:
+ lines2 = set_file2.readlines()
+ lines2[5] = 'False\n'
+ with open(path_to_file2, 'w') as set_file2:
+ set_file2.writelines(lines2)
+
+ else:
+ with open(path_to_file2, 'r') as set_file2:
+ lines2 = set_file2.readlines()
+ lines2[5] = 'True\n'
+ with open(path_to_file2, 'w') as set_file2:
+ set_file2.writelines(lines2)
+
+ ''' Set dark or light '''
- # Set dark or light
def theme_change_light():
if self.tk.call("ttk::style", "theme", "use") == "water-dark":
- # Set light theme
+ ''' Set light theme '''
self.tk.call('set_theme', 'light')
- with open(path_to_file3, 'w') as theme_set2:
- theme_set2.write('light')
+ with open(path_to_file2, 'r') as theme_set2:
+ lines3 = theme_set2.readlines()
+ lines3[3] = 'light\n'
+ with open(path_to_file2, 'w') as theme_set2:
+ theme_set2.writelines(lines3)
def theme_change_dark():
if not self.tk.call("ttk::style", "theme", "use") == "water-dark":
- # Set dark theme
+ ''' Set dark theme '''
self.tk.call('set_theme', 'dark')
- with open(path_to_file3, 'w') as theme_set2:
- theme_set2.write('dark')
+ with open(path_to_file2, 'r') as theme_set2:
+ lines4 = theme_set2.readlines()
+ lines4[3] = 'dark\n'
+ with open(path_to_file2, 'w') as theme_set2:
+ theme_set2.writelines(lines4)
- def instruction():
- """img_w, img_i, w_title, w_txt hand over"""
+ def info():
+ def link_btn():
+ _u1 = str(_u[6:])
+ path_to_file = Path('/usr/bin/./run_as')
+ check_call(['su', _u1, path_to_file])
+
+ """img_w, img_i, w_title, w_txt , txt2, com hand over"""
iw = r'/usr/share/icons/wp-icons/48/wg_vpn.png'
ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
- wt = 'Instruction'
- msg_t = 'Here comes the instructions for Wire-Py'
- msg_window(iw, ii, wt, msg_t)
+ wt = 'Info'
+ msg_t = ('Wire-Py a simple Wireguard Gui for Linux systems.\n\n'
+ 'Wire-Py is open source software written in Python.\n\n'
+ 'Email: polunga40@unity-mail.de also likes for donation.\n\n'
+ 'Use without warranty!\n')
+ txt2 = 'Go to Wire-Py git'
+ com = link_btn
+
+ msg_window(iw, ii, wt, msg_t, txt2, com)
''' Frame for Menu '''
self.menu_frame = ttk.Frame(self)
@@ -85,16 +126,16 @@ class MainWindow(tk.Tk):
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
- # App Menu
+ ''' App Menu '''
self.version_lb = ttk.Label(self.menu_frame, text=version)
self.version_lb.config(font=('Ubuntu', 11), foreground='#00c4ff')
self.version_lb.grid(column=0, row=0, padx=10)
- def version_mouse_enter(event):
+ def version_enter(event):
""" The mouse moves into the Version widget """
window.my_tool_tip = MyToolTip(event.x_root, event.y_root, f'Version: {version[2:]}')
- def version_mouse_leave(event):
+ def version_leave(_):
""" The mouse moves from the entry widget """
''' Remove Tool-Tip '''
window.my_tool_tip.destroy()
@@ -102,106 +143,100 @@ class MainWindow(tk.Tk):
self.options_btn = ttk.Menubutton(self.menu_frame, text='Options')
self.options_btn.grid(column=1, row=0)
- def sets_mouse_enter(event):
+ def sets_enter(event):
""" The mouse moves into the entry widget """
window.my_tool_tip = MyToolTip(event.x_root, event.y_root, 'Click for Settings')
- def sets_mouse_leave(event):
+ def sets_leave(_):
""" The mouse moves from the entry widget """
''' Remove Tool-Tip '''
window.my_tool_tip.destroy()
- self.version_lb.bind('', version_mouse_enter)
- self.version_lb.bind('', version_mouse_leave)
- self.options_btn.bind('', sets_mouse_enter)
- self.options_btn.bind('', sets_mouse_leave)
+ self.version_lb.bind('', version_enter)
+ self.version_lb.bind('', version_leave)
+ self.options_btn.bind('', sets_enter)
+ self.options_btn.bind('', sets_leave)
- set_option = tk.IntVar()
-
- self.settings = tk.Menu(self)
+ set_update = tk.IntVar()
+ set_tip = tk.BooleanVar()
+ self.settings = tk.Menu(self, relief='flat')
self.options_btn.configure(menu=self.settings, style='Toolbutton')
- self.settings.add_checkbutton(label='Disable updates', command=on_off, variable=set_option)
+ self.settings.add_checkbutton(label='Disable Updates', command=update, variable=set_update)
+ self.settings.add_checkbutton(label='Disable Tooltips', command=tooltip, variable=set_tip)
self.settings.add_command(label='Light', command=theme_change_light)
self.settings.add_command(label='Dark', command=theme_change_dark)
- ''' Help BTN Menu / Label '''
- self.help_btn = ttk.Menubutton(self.menu_frame, text='Help')
- self.help_btn.grid(column=2, row=0)
+ ''' About BTN Menu / Label '''
+ self.about_btn = ttk.Button(self.menu_frame, text='About', style='Toolbutton', command=info)
+ self.about_btn.grid(column=2, row=0)
- def help_mouse_enter(event):
- """ The mouse moves into the entry widget """
- window.my_tool_tip = MyToolTip(event.x_root, event.y_root, 'Click for Help')
-
- def help_mouse_leave(event):
- """ The mouse moves from the entry widget """
- ''' Remove Tool-Tip '''
- window.my_tool_tip.destroy()
-
- self.help_btn.bind('', help_mouse_enter)
- self.help_btn.bind('', help_mouse_leave)
self.readme = tk.Menu(self)
- self.help_btn.configure(menu=self.readme, style='Toolbutton')
- self.readme.add_command(label='Instruction', command=instruction)
- ''' Update Label '''
+ ''' Update and Tooltip Label '''
self.updates_lb = ttk.Label(self.menu_frame)
self.updates_lb.grid(column=3, row=0, padx=10)
+ '''View Checkbox for enable or disable Tooltip '''
+ if tips:
+ set_tip.set(value=False)
+ else:
+ set_tip.set(value=True)
+
+ '''View Checkbox for enable or disable Updates '''
if res == 'False':
- set_option.set(value=1)
+ set_update.set(value=1)
self.updates_lb.configure(text='Update search off')
- def disable_mouse_enter(event):
+ def disable_enter(event):
""" The mouse moves into the entry widget """
window.my_tool_tip = MyToolTip(event.x_root, event.y_root, 'Updates you have disabled')
- def disable_mouse_leave(event):
+ def disable_leave(_):
""" The mouse moves from the entry widget """
''' Remove Tool-Tip '''
window.my_tool_tip.destroy()
- self.updates_lb.bind('', disable_mouse_enter)
- self.updates_lb.bind('', disable_mouse_leave)
+ self.updates_lb.bind('', disable_enter)
+ self.updates_lb.bind('', disable_leave)
elif res == 'No Internet Connection!':
self.updates_lb.configure(text='No Server Connection!', foreground='red')
elif res == 'No Updates':
self.updates_lb.configure(text='No Updates')
- def congratulations_mouse_enter(event):
+ def congratulations_enter(event):
""" The mouse moves into the entry widget """
window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
'Congratulations! Wire-Py is up to date')
- def congratulations_mouse_leave(event):
+ def congratulations_leave(_):
""" The mouse moves from the entry widget """
''' Remove Tool-Tip '''
window.my_tool_tip.destroy()
- self.updates_lb.bind('', congratulations_mouse_enter)
- self.updates_lb.bind('', congratulations_mouse_leave)
+ self.updates_lb.bind('', congratulations_enter)
+ self.updates_lb.bind('', congratulations_leave)
else:
- set_option.set(value=0)
+ set_update.set(value=0)
text = f'Update {res} available!'
''' Update BTN Menu'''
-
self.update_btn = ttk.Menubutton(self.menu_frame, text=text)
self.update_btn.grid(column=4, row=0, padx=0)
- def download_mouse_enter(event):
+ def download_enter(event):
""" The mouse moves into the entry widget """
window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
'Click to download new version')
- def download_mouse_leave(event):
+ def download_leave(_):
""" The mouse moves from the entry widget """
''' Remove Tool-Tip '''
window.my_tool_tip.destroy()
- self.update_btn.bind('', download_mouse_enter)
- self.update_btn.bind('', download_mouse_leave)
+ self.update_btn.bind('', download_enter)
+ self.update_btn.bind('', download_leave)
- self.download = tk.Menu(self)
+ self.download = tk.Menu(self, relief='flat')
self.update_btn.configure(menu=self.download, style='Toolbutton')
self.download.add_command(label='Download', command=WirePyUpdate.download)
@@ -209,183 +244,13 @@ class MainWindow(tk.Tk):
FrameWidgets(self).grid()
-class StartStopBTN:
- """
- Show Start and Stop Button in Label
- """
-
- def __init__(self):
- self.lb_frame_btn_lbox = None
- self.wg_switch = None
- self.btn_stst = None
- self.wg_vpn_start = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_vpn-start.png')
- self.wg_vpn_stop = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_vpn-stop.png')
-
- def button_stop(self):
- self.btn_stst = ttk.Button(self.lb_frame_btn_lbox, image=self.wg_vpn_stop, command=self.wg_switch, padding=0)
- self.btn_stst.grid(column=0, row=0, padx=5, pady=8)
-
- def stop_mouse_enter(event):
- """ The mouse moves into the entry widget """
- window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
- 'Click to stop selected Wireguard Tunnel')
-
- def stop_mouse_leave(event):
- """ The mouse moves from the entry widget """
- ''' Remove Tool-Tip '''
- window.my_tool_tip.destroy()
-
- self.btn_stst.bind('', stop_mouse_enter)
- self.btn_stst.bind('', stop_mouse_leave)
-
- def button_start(self):
- self.btn_stst = ttk.Button(self.lb_frame_btn_lbox, image=self.wg_vpn_start, command=self.wg_switch, padding=0)
- self.btn_stst.grid(column=0, row=0, padx=5, pady=8)
-
- def empty_list_start_mouse_enter(event):
- """ The mouse moves into the entry widget """
- window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
- 'No tunnels to start in the list')
-
- def empty_list_start_mouse_leave(event):
- """ The mouse moves from the entry widget """
- ''' Remove Tool-Tip '''
- window.my_tool_tip.destroy()
-
- def start_mouse_enter(event):
- """ The mouse moves into the entry widget """
- window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
- 'Click to start selected Wireguard Tunnel')
-
- def start_mouse_leave(event):
- """ The mouse moves from the entry widget """
- ''' Remove Tool-Tip '''
- window.my_tool_tip.destroy()
-
- tl = ListTunnels.tl_list()
- if len(tl) == 0:
- self.btn_stst.bind('', empty_list_start_mouse_enter)
- self.btn_stst.bind('', empty_list_start_mouse_leave)
- else:
- self.btn_stst.bind('', start_mouse_enter)
- self.btn_stst.bind('', start_mouse_leave)
-
-
-class ImportTunnel:
- """
- Import Class for Wireguard config Files.
- Before importing, it is checked whether PrivateKey and PublicKey are in the file.
- If True then it is checked whether the PreSharedKey is already in the key file
- to avoid an import error so that no double wgconf are imported.
- Thus, tunnels can be renamed without the problems arise. If False then the key is written into the file.
- Furthermore, it is checked whether the name is longer than 12 characters.
- If True then the name is automatically shortened to 12 characters and then imported.
- If in each case false comes out, a corresponding window comes to inform the user that something is wrong.
- """
-
- def __init__(self):
-
- self.select_tunnel = None
- self.wg_switch = None
- self.btn_stst = None
- self.lb_tunnel = None
- self.StrVar = None
- self.a = None
- self.l_box = None
-
- def wg_import_select(self):
-
- try:
- filepath = filedialog.askopenfilename(initialdir=str(_u), title='Select Wireguard config File',
- filetypes=[('WG config files', '*.conf')], )
-
- with open(filepath, 'r') as file:
- read = file.read()
- path_split = filepath.split('/')
- path_split1 = path_split[-1]
- self.a = TunnelActiv.active()
-
- if 'PrivateKey = ' in read and 'PublicKey = 'in read and 'Endpoint =' in read:
- with open(filepath, 'r') as file:
- key = ConToDict.covert_to_dict(file)
- pre_key = key[3]
- if len(pre_key) != 0:
- with open('/etc/wire_py/.keys', 'r') as readfile:
- p_key = readfile.readlines()
- if pre_key in p_key or pre_key + '\n' in p_key:
- """img_w, img_i, w_title, w_txt hand over"""
- iw = r'/usr/share/icons/wp-icons/64/error.png'
- ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
- wt = 'Import Error'
- msg_t = 'Tunnel already available!\nPlease use another file for import'
- msg_window(iw, ii, wt, msg_t)
-
- else:
-
- with open('/etc/wire_py/.keys', 'a') as keyfile:
- keyfile.write(pre_key + '\r')
- if len(path_split1) > 17:
- p1 = shutil.copy(filepath, Path('/etc/wire_py/'))
- path_split = path_split1[len(path_split1) - 17:]
- os.rename(p1, Path('/etc/wire_py') / str(path_split))
- new_conf = '/etc/wire_py/' + path_split
- if self.a != '':
- check_call(['nmcli', 'connection', 'down', TunnelActiv.active()])
- ShowAddress.label_empty(self)
-
- subprocess.check_output(['nmcli', 'connection', 'import', 'type',
- 'wireguard', 'file', new_conf], text=True)
-
- else:
- shutil.copy(filepath, Path('/etc/wire_py/'))
- if self.a != '':
- check_call(['nmcli', 'connection', 'down', TunnelActiv.active()])
- ShowAddress.label_empty(self)
-
- subprocess.check_output(['nmcli', 'connection', 'import', 'type',
- 'wireguard', 'file', filepath], text=True)
-
- self.StrVar.set('')
- self.a = TunnelActiv.active()
- self.l_box.insert(0, self.a)
- self.l_box.update()
- self.StrVar = tk.StringVar()
- self.StrVar.set(self.a)
- GreenLabel.green_show_label(self)
- StartStopBTN.button_stop(self)
- wg_read = Path('/etc/wire_py') / str(self.a + '.conf')
- with open(wg_read, 'r') as file_for_key:
- data = ConToDict.covert_to_dict(file_for_key)
-
- ''' Address Label '''
- ShowAddress.init_and_report(self, data)
- ShowAddress.show_data(self)
- check_call(['nmcli', 'con', 'mod', self.a, 'connection.autoconnect', 'no'])
- Path.chmod(wg_read, 0o600)
-
- if 'PrivateKey = ' and 'Endpoint = ' not in read:
- """img_w, img_i, w_title, w_txt hand over"""
- iw = r'/usr/share/icons/wp-icons/64/error.png'
- ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
- wt = 'Import Error'
- msg_t = 'Oh... no valid Wireguard File!\nPlease select a valid Wireguard File'
- msg_window(iw, ii, wt, msg_t)
-
- except EOFError:
- pass
- except TypeError:
- pass
- except FileNotFoundError:
- pass
- except subprocess.CalledProcessError:
-
- print('Tunnel exist!')
-
-
class FrameWidgets(ttk.Frame):
def __init__(self, container, **kwargs):
super().__init__(container, **kwargs)
+ self.endpoint = None
+ self.dns = None
+ self.address = None
self.btn_stst = None
self.auto_con = None
self.enp = None
@@ -401,9 +266,11 @@ class FrameWidgets(ttk.Frame):
self.tr_pic = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_trash.png')
self.exp_pic = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_export.png')
self.warning_pic = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/64/error.png')
+ self.wg_vpn_start = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_vpn-start.png')
+ self.wg_vpn_stop = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_vpn-stop.png')
''' Show active Tunnel '''
- self.a = TunnelActiv.active()
+ self.a = Tunnel.active()
''' Label Frame 1 '''
self.lb_frame_btn_lbox = ttk.Frame(self)
@@ -436,7 +303,7 @@ class FrameWidgets(ttk.Frame):
''' Label to Show active Tunnel '''
self.StrVar = tk.StringVar(value=self.a)
- GreenLabel.green_show_label(self)
+ self.color_label()
''' Interface Label '''
self.interface = ttk.Label(self.lb_frame, text='Interface')
@@ -450,34 +317,17 @@ class FrameWidgets(ttk.Frame):
''' Listbox with Scrollbar '''
+ def enable_check_box(_):
- def box_info_mouse_enter(event):
- """ The mouse moves into the entry widget """
- window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
- 'You must first import\na Wireguard tunnel')
-
- def box_info_mouse_leave(event):
- """ The mouse moves from the entry widget """
- ''' Remove Tool-Tip '''
- window.my_tool_tip.destroy()
-
-
- def enable_check_box(event):
-
- if len(tl) != 0:
+ if self.l_box.size() != 0:
self.wg_autostart.configure(state='normal')
self.lb_rename.config(state='normal')
self.lb_rename.delete(0, tk.END)
self.btn_rename.config(state='normal')
-
self.l_box = tk.Listbox(self.lb_frame_btn_lbox, selectmode='single')
self.l_box.config(relief='ridge', font=('Ubuntu', 12, 'bold'))
self.l_box.grid(column=1, rowspan=4, row=0, sticky='ns')
- tl = ListTunnels.tl_list()
- if len(tl) == 0:
- self.l_box.bind('', box_info_mouse_enter)
- self.l_box.bind('', box_info_mouse_leave)
self.l_box.event_add('<>', '')
self.l_box.bind('<>', enable_check_box)
self.scrollbar = ttk.Scrollbar(self.lb_frame_btn_lbox, orient='vertical', command=self.l_box.yview)
@@ -486,49 +336,75 @@ class FrameWidgets(ttk.Frame):
self.rowconfigure(0, weight=1)
''' Tunnel List '''
- self.tl = ListTunnels.tl_list()
+ self.tl = Tunnel.list()
for tunnels in self.tl:
self.l_box.insert("end", tunnels)
self.l_box.update()
+ def list_empty_enter(event):
+ """ The mouse moves into the entry widget """
+ window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
+ 'You must first import\na Wireguard tunnel')
+
+ def list_empty_leave(_):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ def list_not_empty_enter(event):
+ """ The mouse moves into the entry widget """
+ window.my_tool_tip = MyToolTip(event.x_root, event.y_root, 'Select a Tunnel')
+
+ def list_not_empty_leave(_):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ if self.l_box.size() == 0:
+ self.l_box.bind('', list_empty_enter)
+ self.l_box.bind('', list_empty_leave)
+ else:
+ self.l_box.bind('', list_not_empty_enter)
+ self.l_box.bind('', list_not_empty_leave)
+
''' Button Vpn '''
if self.a != '':
- StartStopBTN.button_stop(self)
+ self.stop()
wg_read = Path('/etc/wire_py') / str(self.a + '.conf')
with open(wg_read, 'r') as file:
- data = ConToDict.covert_to_dict(file)
+ data = Tunnel.con_to_dict(file)
''' Address Label '''
- ShowAddress.init_and_report(self, data)
- ShowAddress.show_data(self)
+ self.init_and_report(data)
+ self.show_data()
else:
- StartStopBTN.button_start(self)
+ self.start()
''' Address Label '''
self.add = tk.StringVar()
self.DNS = tk.StringVar()
self.enp = tk.StringVar()
- ShowAddress.label_empty(self)
- ShowAddress.show_data(self)
+ self.label_empty()
+ self.show_data()
''' Button Import '''
self.btn_i = ttk.Button(self.lb_frame_btn_lbox,
- image=self.imp_pic, command=lambda: ImportTunnel.wg_import_select(self),
+ image=self.imp_pic, command=self.import_sl,
padding=0)
self.btn_i.grid(column=0, row=1, padx=15, pady=8)
- def import_mouse_enter(event):
+ def imp_enter(event):
""" The mouse moves into the entry widget """
window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
'Click to import a Wireguard Tunnel')
- def import_mouse_leave(event):
+ def imp_leave(_):
""" The mouse moves from the entry widget """
''' Remove Tool-Tip '''
window.my_tool_tip.destroy()
- self.btn_i.bind('', import_mouse_enter)
- self.btn_i.bind('', import_mouse_leave)
+ self.btn_i.bind('', imp_enter)
+ self.btn_i.bind('', imp_leave)
def delete():
@@ -536,18 +412,19 @@ class FrameWidgets(ttk.Frame):
self.select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(self.select_tunnel[0])
with open('/etc/wire_py/' + select_tl + '.conf', 'r+') as file2:
- key = ConToDict.covert_to_dict(file2)
+ key = Tunnel.con_to_dict(file2)
pre_key = key[3]
check_call(['nmcli', 'connection', 'delete', select_tl])
self.l_box.delete(self.select_tunnel[0])
- if Path.is_file(Path('/etc/wire_py/wg_py')):
- path_to_file = Path('/etc/wire_py') / 'wg_py'
- a_con = Path.read_text(path_to_file)
- if select_tl == a_con:
+ with open(path_to_file2, 'r') as set_file6:
+ lines6 = set_file6.readlines()
+ if select_tl == lines6[7].strip() and 'off' not in lines6[7].strip():
+ lines6[7] = 'off'
+ with open(path_to_file2, 'w') as set_file7:
+ set_file7.writelines(lines6)
self.selected_option.set(0)
self.autoconnect_var.set('no Autoconnect')
- self.wg_autostart.configure(state='disabled')
- Path.unlink(path_to_file)
+
Path.unlink(Path('/etc/wire_py') / str(select_tl + '.conf'))
with open('/etc/wire_py/.keys', 'r') as readfile:
with open('/etc/wire_py/.keys2', 'w') as writefile:
@@ -557,14 +434,40 @@ class FrameWidgets(ttk.Frame):
file_one = Path('/etc/wire_py/.keys2')
file_two = file_one.with_name('.keys')
file_one.replace(file_two)
+ self.wg_autostart.configure(state='disabled')
''' for disable checkbox when Listbox empty '''
- if len(tl) == 0:
+ def empty_list_start_enter(event):
+ """ The mouse moves into the entry widget """
+ window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
+ 'No tunnels to start in the list')
+
+ def empty_list_start_leave(_):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ if self.l_box.size() == 0:
self.wg_autostart.configure(state='disabled')
+ self.lb_rename.configure(state='disabled')
+ self.l_box.bind('', list_empty_enter)
+ self.l_box.bind('', list_empty_leave)
+ self.wg_autostart.bind('', chk_enter)
+ self.wg_autostart.bind('', chk_leave)
+ self.btn_tr.bind('', empty_list_enter)
+ self.btn_tr.bind('', empty_list_leave)
+ self.btn_exp.bind('', empty_list_enter)
+ self.btn_exp.bind('', empty_list_leave)
+ self.btn_stst.bind('', empty_list_start_enter)
+ self.btn_stst.bind('', empty_list_start_leave)
+ self.lb_rename.bind('', rename_no_active_enter)
+ self.lb_rename.bind('', rename_no_active_leave)
+ self.lb_rename.insert(0, 'Max. 12 characters!')
+
if self.a != '' and self.a == select_tl:
self.StrVar.set(value='')
- StartStopBTN.button_start(self)
+ self.start()
self.l_box.update()
''' Address Label '''
@@ -572,9 +475,10 @@ class FrameWidgets(ttk.Frame):
self.DNS.set('')
self.enp.set('')
return select_tl
+
except IndexError:
- if len(tl) != 0:
+ if self.l_box.size() != 0:
"""img_w, img_i, w_title, w_txt hand over"""
iw = r'/usr/share/icons/wp-icons/64/info.png'
@@ -597,94 +501,98 @@ class FrameWidgets(ttk.Frame):
style='CButton.TButton')
self.btn_tr.grid(column=0, row=2, padx=15, pady=8)
- def empty_list_del_mouse_enter(event):
+ def empty_list_enter(event):
""" The mouse moves into the entry widget """
window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
'No tunnels to delete in the list')
- def empty_list_del_mouse_leave(event):
+ def empty_list_leave(_):
""" The mouse moves from the entry widget """
''' Remove Tool-Tip '''
window.my_tool_tip.destroy()
- def delete_mouse_enter(event):
+ def del_enter(event):
""" The mouse moves into the entry widget """
window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
'Click to delete a Wireguard Tunnel\nSelect from the list!')
- def delete_mouse_leave(event):
+ def del_leave(_):
""" The mouse moves from the entry widget """
''' Remove Tool-Tip '''
window.my_tool_tip.destroy()
- if len(tl) == 0:
- self.btn_tr.bind('', empty_list_del_mouse_enter)
- self.btn_tr.bind('', empty_list_del_mouse_leave)
+ if self.l_box.size() == 0:
+ self.btn_tr.bind('', empty_list_enter)
+ self.btn_tr.bind('', empty_list_leave)
else:
- self.btn_tr.bind('', delete_mouse_enter)
- self.btn_tr.bind('', delete_mouse_leave)
+ self.btn_tr.bind('', del_enter)
+ self.btn_tr.bind('', del_leave)
''' Button Export '''
- self.btn_exp = ttk.Button(self.lb_frame_btn_lbox, image=self.exp_pic, command=ExportTunnels.wg_export,
+ self.btn_exp = ttk.Button(self.lb_frame_btn_lbox, image=self.exp_pic, command=Tunnel.export,
padding=0)
self.btn_exp.grid(column=0, row=3, padx=15, pady=8)
- def empty_list_mouse_enter(event):
+
+ def empty_list_enter(event):
""" The mouse moves into the entry widget """
window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
'No Tunnels in List for Export')
- def empty_list_mouse_leave(event):
+ def empty_list_leave(_):
""" The mouse moves from the entry widget """
''' Remove Tool-Tip '''
window.my_tool_tip.destroy()
- def export_mouse_enter(event):
+ def exp_enter(event):
""" The mouse moves into the entry widget """
window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
' Click to export all\nWireguard Tunnel to Zipfile')
- def export_mouse_leave(event):
+ def exp_leave(_):
""" The mouse moves from the entry widget """
''' Remove Tool-Tip '''
window.my_tool_tip.destroy()
- if len(tl) == 0:
- self.btn_exp.bind('', empty_list_mouse_enter)
- self.btn_exp.bind('', empty_list_mouse_leave)
+ if self.l_box.size() == 0:
+ self.btn_exp.bind('', empty_list_enter)
+ self.btn_exp.bind('', empty_list_leave)
else:
- self.btn_exp.bind('', export_mouse_enter)
- self.btn_exp.bind('', export_mouse_leave)
+ self.btn_exp.bind('', exp_enter)
+ self.btn_exp.bind('', exp_leave)
''' Label Entry '''
self.lb_rename = ttk.Entry(self, width=20)
self.lb_rename.grid(column=2, row=4, padx=30, pady=15, sticky='nw')
self.lb_rename.insert(0, 'Max. 12 characters!')
self.lb_rename.config(state='disable')
- def rename_mouse_enter(event):
- """ The mouse moves into the entry widget """
- window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
- 'To rename a tunnel, you need to\nselect a tunnel from the list')
- def rename_no_active_mouse_leave(event):
+ def rename_no_active_leave(_):
""" The mouse moves from the entry widget """
''' Remove Tool-Tip '''
window.my_tool_tip.destroy()
- def rename_no_active_mouse_enter(event):
+ def rename_no_active_enter(event):
""" The mouse moves into the entry widget """
window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
'To rename a tunnel, at least one must be in the list')
- def rename_mouse_leave(event):
+ def rename_enter(event):
+ """ The mouse moves into the entry widget """
+ window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
+ 'To rename a tunnel, you need to\nselect a tunnel from the list')
+
+ def rename_leave(_):
""" The mouse moves from the entry widget """
''' Remove Tool-Tip '''
window.my_tool_tip.destroy()
- if len(tl) != 0:
- self.lb_rename.bind('', rename_mouse_enter)
- self.lb_rename.bind('', rename_mouse_leave)
+
+ if self.l_box.size() != 0:
+ self.lb_rename.bind('', rename_enter)
+ self.lb_rename.bind('', rename_leave)
else:
- self.lb_rename.bind('', rename_no_active_mouse_enter)
- self.lb_rename.bind('', rename_no_active_mouse_leave)
+ self.lb_rename.bind('', rename_no_active_enter)
+ self.lb_rename.bind('', rename_no_active_leave)
+
def tl_rename():
special_characters = ['\\', '/', '{', '}', ' ']
@@ -732,14 +640,16 @@ class FrameWidgets(ttk.Frame):
new_a_connect = self.lb_rename.get()
self.lb_rename.delete(0, tk.END)
if self.a != '' and self.a == select_tl:
- self.a = TunnelActiv.active()
+ self.a = Tunnel.active()
self.StrVar.set(value=self.a)
- if Path.is_file(Path('/etc/wire_py/wg_py')):
- path_to_file = Path('/etc/wire_py') / 'wg_py'
- a_con = Path.read_text(path_to_file)
- if select_tl == a_con:
+ with open(path_to_file2, 'r') as set_file5:
+ lines5 = set_file5.readlines()
+ if select_tl == lines5[7].strip() and 'off' not in lines5[7].strip():
+ lines5[7] = new_a_connect
+ with open(path_to_file2, 'w') as theme_set5:
+ theme_set5.writelines(lines5)
self.autoconnect_var.set(value=new_a_connect)
- Path.write_text(path_to_file, new_a_connect)
+
return select_tl
except IndexError:
@@ -756,7 +666,6 @@ class FrameWidgets(ttk.Frame):
style='RnButton.TButton')
self.btn_rename.grid(column=2, row=4, padx=20, pady=15, sticky='ne')
-
''' Check Buttons '''
self.selected_option = tk.IntVar()
self.autoconnect_var = tk.StringVar()
@@ -765,87 +674,426 @@ class FrameWidgets(ttk.Frame):
self.autoconnect = ttk.Label(self, textvariable=self.autoconnect_var)
self.autoconnect.config(font=('Ubuntu', 11))
self.autoconnect.grid(column=0, row=4, sticky='ne', padx=10, pady=15)
- self.wg_autostart = ttk.Checkbutton(self,
- text='Autoconnect on:',
- variable=self.selected_option,
- command=lambda: FileHandle.box_set(self))
+ self.wg_autostart = ttk.Checkbutton(self, text='Autoconnect on:', variable=self.selected_option,
+ command=self.box_set)
self.wg_autostart.grid(column=0, row=4, pady=15, padx=15, sticky='nw')
- def chk_mouse_enter(event):
+
+ def chk_enter(event):
""" The mouse moves into the entry widget """
window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
'You must have at least one\n'
'tunnel in the list,to use the autostart')
- def chk_mouse_leave(event):
+ def chk_leave(_):
""" The mouse moves from the entry widget """
''' Remove Tool-Tip '''
window.my_tool_tip.destroy()
- if len(tl) == 0:
- self.wg_autostart.bind('', chk_mouse_enter)
- self.wg_autostart.bind('', chk_mouse_leave)
- else:
- def chk_a_mouse_enter(event):
+ if self.l_box.size() >= 1 and len(self.l_box.curselection()) >= 1:
+ def chk_a_enter(event):
""" The mouse moves into the entry widget """
window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
- 'To use the autostart, a tunnel must be selected from the list')
+ 'To use the autostart, enable this Checkbox')
- def chk_a_mouse_leave(event):
+ def chk_a_leave(_):
""" The mouse moves from the entry widget """
''' Remove Tool-Tip '''
window.my_tool_tip.destroy()
- self.wg_autostart.bind('', chk_a_mouse_enter)
- self.wg_autostart.bind('', chk_a_mouse_leave)
+ self.wg_autostart.bind('', chk_a_enter)
+ self.wg_autostart.bind('', chk_a_leave)
- OnOff.on_off(self)
+ if self.l_box.size() == 0:
+ self.wg_autostart.bind('', chk_enter)
+ self.wg_autostart.bind('', chk_leave)
+ else:
+ def chk_a_enter(event):
+ """ The mouse moves into the entry widget """
+ window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
+ 'To use the autostart, a tunnel must be selected from the list')
+
+ def chk_a_leave(_):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ self.wg_autostart.bind('', chk_a_enter)
+ self.wg_autostart.bind('', chk_a_leave)
+
+ self.on_off()
+
+ """
+ Import Methode for Wireguard config Files.
+ Before importing, it is checked whether PrivateKey and PublicKey are in the file.
+ If True then it is checked whether the PreSharedKey is already in the key file
+ to avoid an import error so that no double wgconf are imported.
+ Thus, tunnels can be renamed without the problems arise. If False then the key is written into the file.
+ Furthermore, it is checked whether the name is longer than 12 characters.
+ If True then the name is automatically shortened to 12 characters and then imported.
+ If in each case false comes out, a corresponding window comes to inform the user that something is wrong.
+ """
+
+ def import_sl(self):
+
+ try:
+ filepath = filedialog.askopenfilename(initialdir=str(_u), title='Select Wireguard config File',
+ filetypes=[('WG config files', '*.conf')], )
+
+ with open(filepath, 'r') as file:
+ read = file.read()
+ path_split = filepath.split('/')
+ path_split1 = path_split[-1]
+ self.a = Tunnel.active()
+
+ if 'PrivateKey = ' in read and 'PublicKey = ' in read and 'Endpoint =' in read:
+ with open(filepath, 'r') as file:
+ key = Tunnel.con_to_dict(file)
+ pre_key = key[3]
+ if len(pre_key) != 0:
+ with open('/etc/wire_py/.keys', 'r') as readfile:
+ p_key = readfile.readlines()
+ if pre_key in p_key or pre_key + '\n' in p_key:
+ """img_w, img_i, w_title, w_txt hand over"""
+ iw = r'/usr/share/icons/wp-icons/64/error.png'
+ ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
+ wt = 'Import Error'
+ msg_t = 'Tunnel already available!\nPlease use another file for import'
+ msg_window(iw, ii, wt, msg_t)
+
+ else:
+
+ with open('/etc/wire_py/.keys', 'a') as keyfile:
+ keyfile.write(pre_key + '\r')
+ if len(path_split1) > 17:
+ p1 = shutil.copy(filepath, Path('/etc/wire_py/'))
+ path_split = path_split1[len(path_split1) - 17:]
+ os.rename(p1, Path('/etc/wire_py') / str(path_split))
+ new_conf = '/etc/wire_py/' + path_split
+ if self.a != '':
+ check_call(['nmcli', 'connection', 'down', Tunnel.active()])
+ self.label_empty()
+
+ subprocess.check_output(['nmcli', 'connection', 'import', 'type',
+ 'wireguard', 'file', new_conf], text=True)
+
+ else:
+ shutil.copy(filepath, Path('/etc/wire_py/'))
+ if self.a != '':
+ check_call(['nmcli', 'connection', 'down', Tunnel.active()])
+ self.label_empty()
+
+ subprocess.check_output(['nmcli', 'connection', 'import', 'type',
+ 'wireguard', 'file', filepath], text=True)
+
+ self.StrVar.set('')
+ self.a = Tunnel.active()
+ self.l_box.insert(0, self.a)
+ self.wg_autostart.configure(state='normal')
+ self.l_box.selection_clear(0, tk.END)
+ self.l_box.update()
+ self.l_box.selection_set(0)
+
+ def chk_a_enter(event):
+ """ The mouse moves into the entry widget """
+ window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
+ 'To use the autostart, enable this '
+ 'Checkbox')
+
+ def chk_a_leave(_):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ def list_info_enter(event):
+ """ The mouse moves into the entry widget """
+ window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
+ 'List of available tunnels')
+
+ def list_info_leave(_):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ def del_enter(event):
+ """ The mouse moves into the entry widget """
+ window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
+ 'Click to delete a Wireguard '
+ 'Tunnel\nSelect from the list!')
+
+ def del_leave(_):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ def exp_enter(event):
+ """ The mouse moves into the entry widget """
+ window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
+ ' Click to export '
+ 'all\nWireguard Tunnel to Zipfile')
+
+ def exp_leave(_):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ def rename_enter(event):
+ """ The mouse moves into the entry widget """
+ window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
+ 'To rename a tunnel, you need to\n'
+ 'select a tunnel from the list')
+
+ def rename_leave(_):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ self.wg_autostart.bind('', chk_a_enter)
+ self.wg_autostart.bind('', chk_a_leave)
+ self.l_box.bind('', list_info_enter)
+ self.l_box.bind('', list_info_leave)
+ self.btn_tr.bind('', del_enter)
+ self.btn_tr.bind('', del_leave)
+ self.btn_exp.bind('', exp_enter)
+ self.btn_exp.bind('', exp_leave)
+ self.lb_rename.bind('', rename_enter)
+ self.lb_rename.bind('', rename_leave)
+ self.lb_rename.insert(0, 'Max. 12 characters!')
+ self.StrVar = tk.StringVar()
+ self.StrVar.set(self.a)
+ self.color_label()
+ self.stop()
+ wg_read = Path('/etc/wire_py') / str(self.a + '.conf')
+ with open(wg_read, 'r') as file_for_key:
+ data = Tunnel.con_to_dict(file_for_key)
+
+ ''' Address Label '''
+ self.init_and_report(data)
+ self.show_data()
+ check_call(['nmcli', 'con', 'mod', self.a, 'connection.autoconnect', 'no'])
+ Path.chmod(wg_read, 0o600)
+
+ if 'PrivateKey = ' and 'Endpoint = ' not in read:
+ """img_w, img_i, w_title, w_txt hand over"""
+ iw = r'/usr/share/icons/wp-icons/64/error.png'
+ ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
+ wt = 'Import Error'
+ msg_t = 'Oh... no valid Wireguard File!\nPlease select a valid Wireguard File'
+ msg_window(iw, ii, wt, msg_t)
+
+ except EOFError:
+ pass
+ except TypeError:
+ pass
+ except FileNotFoundError:
+ pass
+ except subprocess.CalledProcessError:
+
+ print('Tunnel exist!')
+
+ '''
+ This Method will display the autostart label which
+ Tunnel is automatically started regardless of the active tunnel.
+ The selected tunnel is written into a file to read it after the start of the system.
+ '''
+
+ def box_set(self):
+
+ try:
+ select_tunnel = self.l_box.curselection()
+ select_tl = self.l_box.get(select_tunnel[0])
+
+ if self.selected_option.get() == 0:
+ with open(path_to_file2, 'r') as set_file3:
+ lines3 = set_file3.readlines()
+ lines3[7] = 'off'
+ with open(path_to_file2, 'w') as set_file3:
+ set_file3.writelines(lines3)
+
+ tl = Tunnel.list()
+
+ if len(tl) == 0:
+ self.wg_autostart.configure(state='disabled')
+
+ if self.selected_option.get() >= 1:
+ with open(path_to_file2, 'r') as set_file3:
+ lines3 = set_file3.readlines()
+ lines3[7] = select_tl
+ with open(path_to_file2, 'w') as set_file3:
+ set_file3.writelines(lines3)
+
+ except IndexError:
+ self.selected_option.set(1)
+
+ self.on_off()
+
+ '''
+ Here it is checked whether the path to the file is there if not it is created.
+ Set (on), the selected tunnel is displayed in the label.
+ At (off) the label is first emptied then filled with No Autoconnect
+ '''
+
+ def on_off(self):
+ with open(path_to_file2, 'r') as set_file4:
+ lines4 = set_file4.readlines()
+
+ if lines4[7] != 'off':
+ self.selected_option.set(1)
+ self.autoconnect_var.set('')
+ self.auto_con = lines4[7]
+
+ else:
+
+ self.wg_autostart.configure(state='disabled')
+ self.auto_con = 'no Autoconnect'
+ self.autoconnect_var.set('')
+ self.autoconnect_var = tk.StringVar()
+ self.autoconnect_var.set(self.auto_con)
+
+ self.autoconnect = ttk.Label(self, textvariable=self.autoconnect_var, foreground='#0071ff')
+ self.autoconnect.config(font=('Ubuntu', 11))
+ self.autoconnect.grid(column=0, row=4, sticky='ne', pady=19)
+
+ """
+ Displays the value address, DNS and peer in the labels
+ or empty it again
+ """
+
+ def init_and_report(self, data=None):
+ """ Address Label """
+ self.add = tk.StringVar()
+ self.add.set('Address: ' + data[0])
+ self.DNS = tk.StringVar()
+ self.DNS.set(' DNS: ' + data[1])
+ self.enp = tk.StringVar()
+ self.enp.set('Endpoint: ' + data[2])
+
+ def label_empty(self):
+ self.add.set('')
+ self.DNS.set('')
+ self.enp.set('')
+
+ def show_data(self):
+ """ Address Label """
+ self.address = ttk.Label(self.lb_frame, textvariable=self.add, foreground='#0071ff')
+ self.address.grid(column=0, row=5, sticky='w', padx=10, pady=6)
+ self.address.config(font=('Ubuntu', 9))
+
+ ''' DNS Label '''
+ self.dns = ttk.Label(self.lb_frame, textvariable=self.DNS, foreground='#0071ff')
+ self.dns.grid(column=0, row=7, sticky='w', padx=10, pady=6)
+ self.dns.config(font=('Ubuntu', 9))
+
+ ''' Endpoint Label '''
+ self.endpoint = ttk.Label(self.lb_frame2, textvariable=self.enp, foreground='#0071ff')
+ self.endpoint.grid(column=0, row=8, sticky='w', padx=10, pady=20)
+ self.endpoint.config(font=('Ubuntu', 9))
+
+ def stop(self):
+ self.btn_stst = ttk.Button(self.lb_frame_btn_lbox, image=self.wg_vpn_stop, command=self.wg_switch, padding=0)
+ self.btn_stst.grid(column=0, row=0, padx=5, pady=8)
+
+ def stop_enter(event):
+ """ The mouse moves into the entry widget """
+ window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
+ 'Click to stop selected Wireguard Tunnel')
+
+ def stop_leave(_):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ self.btn_stst.bind('', stop_enter)
+ self.btn_stst.bind('', stop_leave)
+
+ def start(self):
+ self.btn_stst = ttk.Button(self.lb_frame_btn_lbox, image=self.wg_vpn_start, command=self.wg_switch, padding=0)
+ self.btn_stst.grid(column=0, row=0, padx=5, pady=8)
+
+ def empty_list_start_enter(event):
+ """ The mouse moves into the entry widget """
+ window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
+ 'No tunnels to start in the list')
+
+ def empty_list_start_leave(_):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ def start_enter(event):
+ """ The mouse moves into the entry widget """
+ window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
+ 'Click to start selected Wireguard Tunnel')
+
+ def start_leave(_):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ tl = Tunnel.list()
+ if len(tl) == 0:
+ self.btn_stst.bind('', empty_list_start_enter)
+ self.btn_stst.bind('', empty_list_start_leave)
+ else:
+ self.btn_stst.bind('', start_enter)
+ self.btn_stst.bind('', start_leave)
+
+ def color_label(self):
+ with open(path_to_file2, 'r') as read_file:
+ lines = read_file.readlines()
+ if 'light\n' in lines:
+ self.lb_tunnel = ttk.Label(self, textvariable=self.StrVar, foreground='green')
+
+ else:
+ self.lb_tunnel = ttk.Label(self, textvariable=self.StrVar, foreground='yellow')
+
+ self.lb_tunnel.config(font=('Ubuntu', 11, 'bold'))
+ self.lb_tunnel.grid(column=2, padx=10, row=1)
def wg_switch(self):
- self.a = TunnelActiv.active()
+ self.a = Tunnel.active()
try:
if self.a == '':
- StartStopBTN.button_start(self)
+ self.start()
self.select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(self.select_tunnel[0])
check_call(['nmcli', 'connection', 'up', select_tl])
wg_read = Path('/etc/wire_py') / str(select_tl + '.conf')
with open(wg_read, 'r') as file:
- data = ConToDict.covert_to_dict(file)
+ data = Tunnel.con_to_dict(file)
''' Address Label '''
- ShowAddress.init_and_report(self, data)
- ShowAddress.show_data(self)
+ self.init_and_report(data)
+ self.show_data()
''' Button Start/Stop '''
- StartStopBTN.button_stop(self)
- self.a = TunnelActiv.active()
+ self.stop()
+ self.a = Tunnel.active()
self.StrVar = tk.StringVar()
self.StrVar.set(self.a)
- GreenLabel.green_show_label(self)
+ self.color_label()
elif self.a != '':
''' Button Start/Stop '''
- StartStopBTN.button_stop(self)
+ self.stop()
check_call(['nmcli', 'connection', 'down', self.a])
''' Button Start/Stop '''
- StartStopBTN.button_start(self)
- self.a = TunnelActiv.active()
+ self.start()
+ self.a = Tunnel.active()
self.StrVar.set('')
- GreenLabel.green_show_label(self)
+ self.color_label()
''' Address Label '''
self.add.set('')
self.DNS.set('')
self.enp.set('')
- ShowAddress.show_data(self)
+ self.show_data()
except IndexError:
- tl = ListTunnels.tl_list()
- if len(tl) != 0:
+ if self.l_box.size() != 0:
"""img_w, img_i, w_title, w_txt hand over"""
iw = r'/usr/share/icons/wp-icons/64/info.png'
@@ -865,11 +1113,14 @@ class FrameWidgets(ttk.Frame):
class MyToolTip(tk.Toplevel):
- TIP_X_OFFSET = 8
- TIP_Y_OFFSET = 8
- AUTO_CLEAR_TIME = 10 # Millisecond. (1/100 sec.)
+ TIP_X_OFFSET = 20
+ TIP_Y_OFFSET = 20
+ if not tips:
+ AUTO_CLEAR_TIME = 0
+ else:
+ AUTO_CLEAR_TIME = 900 # Millisecond. (1/90 sec.)
- def __init__(self, x_pos, y_pos, message=None, auto_clear=False):
+ def __init__(self, x_pos, y_pos, message=None, auto_clear=True):
self.x_pos = x_pos
self.y_pos = y_pos
self.message = message
@@ -878,7 +1129,7 @@ class MyToolTip(tk.Toplevel):
tk.Toplevel.__init__(self)
self.overrideredirect(True)
- self.message_label = ttk.Label(self, compound='left', text=self.message, padding=4)
+ self.message_label = ttk.Label(self, compound='left', text=self.message, padding=6)
self.message_label.pack()
self.geometry("+%d+%d" % (self.x_pos + self.TIP_X_OFFSET,