diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 5c6d238..1b6ddde 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -350,7 +350,7 @@
1727379755537
-
+
1727380793216
@@ -579,7 +579,7 @@
-
+
diff --git a/Changelog b/Changelog
index f1d0035..443a545 100644
--- a/Changelog
+++ b/Changelog
@@ -6,8 +6,17 @@ My standard System: Linux Mint 22 Cinnamon
- os import in cls_mth_fc.py replaced by other methods
- If Wire-Py already runs, prevent further start
- for loops with lists replaced by List Comprehensions
- - Update search after start of Wire-Py
+ - Crypt and Decrypt Config Files in ~/.config/wire_py
+ ### Added
+02-03-2025
+
+ - Fix ipv6 in Config File on import
+ - Wirepy run now as user
+ - settings, keys and Config Files now in ~/.config/wire_py
+ - For new users, the required files are created and autostart service is started.
+ - Tunnels are now read from the directory to view them in the list.
+ To display only own tunnels, and read errors are minimized.
### Added
10-11-2024
@@ -57,7 +66,7 @@ My standard System: Linux Mint 22 Cinnamon
### Added
27-10-2024
- - Add Autoconnect settings to settings.conf
+ - Add Autoconnect settings to settings
### Added
@@ -65,7 +74,7 @@ My standard System: Linux Mint 22 Cinnamon
- 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
+ - Rename settings to settings for theme, updates and tooltip enable in one file
### Added
diff --git a/Wire-Py.desktop b/Wire-Py.desktop
index 19e5690..cda2352 100755
--- a/Wire-Py.desktop
+++ b/Wire-Py.desktop
@@ -1,7 +1,7 @@
[Desktop Entry]
Type=Application
Name=Wire-Py
-Exec=/usr/bin/wirepy.py
+Exec=/usr/local/bin/wg_main.py
Terminal=false
Categories=Network;
Icon=/usr/share/icons/wp-icons/128/wg_vpn.png
diff --git a/__pycache__/cls_mth_fc.cpython-312.pyc b/__pycache__/cls_mth_fc.cpython-312.pyc
index 9e274fb..3856fbf 100644
Binary files a/__pycache__/cls_mth_fc.cpython-312.pyc and b/__pycache__/cls_mth_fc.cpython-312.pyc differ
diff --git a/cls_mth_fc.py b/cls_mth_fc.py
index 811c862..3244eb4 100755
--- a/cls_mth_fc.py
+++ b/cls_mth_fc.py
@@ -5,6 +5,7 @@ import locale
import os
import shutil
import subprocess
+from subprocess import check_call
import tkinter as tk
import zipfile
from datetime import datetime
@@ -19,8 +20,41 @@ gettext.bindtextdomain(APP, LOCALE_DIR)
gettext.textdomain(APP)
_ = gettext.gettext
-wg_set = Path('/etc/wire_py/settings.conf')
-_u = Path.read_text(Path('/tmp/_u'))
+def dirs_and_files():
+
+ pth = Path.home() / '.config/wire_py'
+ pth.mkdir(parents=True, exist_ok=True)
+ sett = Path.home() / '.config/wire_py/settings'
+ ks = Path.home() / '.config/wire_py/keys'
+
+ if sett.exists():
+ pass
+
+ else:
+ sett.touch()
+ sett.write_text('[UPDATES]\non\n[THEME]\nlight\n[TOOLTIP]\nTrue\n[AUTOSTART ON]\noff')
+
+ if ks.exists():
+ pass
+
+ else:
+ ks.touch()
+
+def files_for_autostart():
+
+ pth2 = Path.home() / '.config/systemd/user'
+ pth2.mkdir(parents=True, exist_ok=True)
+ wg_ser = Path.home() / '.config/systemd/user/wg_start.service'
+
+ if wg_ser.exists():
+ pass
+
+ else:
+ wg_ser.touch()
+ sett.write_text('[Unit]\nDescription=Automatic Tunnel Start\nAfter=network-online.target\n\n[Service]\nType=oneshot\nExecStartPre=/bin/sleep 5\nExecStart=/usr/local/bin/start_wg.py\n[Install]\nWantedBy=default.target')
+ check_call(['systemctl', '--user', 'enable', wg_start.service])
+
+wg_set = Path(Path.home() / '.config/wire_py/settings')
class GiteaUpdate:
@@ -53,10 +87,10 @@ class GiteaUpdate:
@staticmethod
def download(urld, down_ok_image, down_not_ok_image, res):
try:
- to_down = 'wget -qP ' + str(_u) + ' ' + urld
+ to_down = 'wget -qP ' + str(Path.home()) + ' ' + urld
result = subprocess.call(to_down, shell=True)
if result == 0:
- shutil.chown(str(_u) + f'/{res}.zip', 1000, 1000)
+ shutil.chown(str(Path.home()) + f'/{res}.zip', 1000, 1000)
"""img_w, img_i, w_title, w_txt hand over"""
iw = r'/usr/share/icons/lx-icons/64/info.png'
ii = down_ok_image
@@ -145,6 +179,8 @@ class Tunnel:
for items in dictlist:
if items == '=':
dictlist.remove(items)
+ if items == '::/0':
+ dictlist.remove(items)
''' Here is the beginning (Loop) of convert List to Dictionary '''
for _ in dictlist:
@@ -189,15 +225,16 @@ class Tunnel:
return active
"""
- Shows all existing Wireguard tunnels
+ Shows all existing Wireguard tunnels a login user
"""
@staticmethod
def list():
- wg_s = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
-
- ''' tl = Tunnel list # Show of 4.Element in list '''
- tl = wg_s[::3]
- return tl
+ dirname = Path.home() / '.config/wire_py/'
+ wg_s = os.listdir(dirname)
+ wg_s.remove('keys')
+ wg_s.remove('settings')
+
+ return wg_s
"""
This will export the tunnels.
@@ -206,21 +243,20 @@ class Tunnel:
"""
@staticmethod
def export():
- _u1 = str(_u[6:])
now_time = datetime.now()
now_datetime = now_time.strftime('wg-exp-' + '%m-%d-%Y' + '-' + '%H:%M')
tl = Tunnel.list()
try:
if len(tl) != 0:
- wg_tar = str(_u) + '/' + now_datetime
- shutil.copytree('/etc/wire_py', '/tmp/wire_py', dirs_exist_ok=True)
+ wg_tar = str(Path.home()) + '/' + now_datetime
+ shutil.copytree(Path.home() / '.config/wire_py/', '/tmp/wire_py', dirs_exist_ok=True)
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.conf', missing_ok=True)
+ Path.unlink(Path(source) / 'keys', missing_ok=True)
+ Path.unlink(Path(source) / 'settings', missing_ok=True)
shutil.make_archive(wg_tar, 'zip', source)
- shutil.chown(wg_tar + '.zip', 1000, 1000)
+ #shutil.chown(wg_tar + '.zip', 1000, 1000)
shutil.rmtree(source)
with zipfile.ZipFile((wg_tar + '.zip'), 'r') as zf:
if len(zf.namelist()) != 0:
diff --git a/install b/install
index 9978256..c10ecfa 100755
--- a/install
+++ b/install
@@ -6,24 +6,22 @@ BLUE='\033[30;1;34m'
install_file_with(){
clear
+ mkdir -p ~/.config/wire_py && touch ~/.config/wire_py/keys && cp -u settings ~/.config/wire_py/ && \
+ mkdir -p ~/.config/systemd/user && cp -u wg_start.service ~/.config/systemd/user/ && \
+ systemctl --user enable wg_start.service
sudo apt install python3-tk && \
- sudo cp -u wg_main.py start_wg.py cls_mth_fc.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 -u wg_main.py start_wg.py cls_mth_fc.py /usr/local/bin/ && \
sudo cp -uR wp-icons lx-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 cp -u languages/de/*.mo /usr/share/locale/de/LC_MESSAGES/ && \
- sudo ln -sf /usr/bin/wirepy.py /usr/local/bin/wirepy && \
- sudo cp -u org.wirepy.policy /usr/share/polkit-1/actions/ && \
- sudo cp -u Wire-Py.desktop /usr/share/applications/ && \
- sudo cp -u wg_start.service /lib/systemd/system/ && \
- sudo systemctl enable wg_start.service
+ sudo ln -sf /usr/local/bin/wg_main.py /usr/local/bin/wirepy && \
+ sudo cp -u Wire-Py.desktop /usr/share/applications/
}
install_arch_d(){
clear
sudo pacman -S --noconfirm tk python3 python-requests && \
- sudo cp -u wg_main.py start_wg.py cls_mth_fc.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 -u wg_main.py start_wg.py cls_mth_fc.py && \
+ sudo mkdir -p /etc/wire_py && sudo touch /etc/wire_py/keys && sudo cp -u settings /etc/wire_py/ && \
sudo cp -uR wp-icons lx-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 cp -u languages/de/*.mo /usr/share/locale/de/LC_MESSAGES/ && \
@@ -91,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 cls_mth_fc.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 -u wg_main.py start_wg.py cls_mth_fc.py && \
+ sudo mkdir -p /etc/wire_py && sudo touch /etc/wire_py/keys && \
+ sudo cp -u settings /etc/wire_py/ && \
sudo cp -u languages/de/*.mo /usr/share/locale/de/LC_MESSAGES/ && \
sudo cp -uR wp-icons lx-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 && \
@@ -108,9 +106,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 cls_mth_fc.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 -u wg_main.py start_wg.py cls_mth_fc.py && \
+ sudo mkdir -p /etc/wire_py && sudo touch /etc/wire_py/keys && \
+ sudo cp -u settings /etc/wire_py/ && \
sudo cp -u languages/de/*.mo /usr/share/locale/de/LC_MESSAGES/ && \
sudo cp -uR wp-icons lx-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 && \
diff --git a/open_gitea.py b/open_gitea.py
deleted file mode 100755
index 4fdbad1..0000000
--- a/open_gitea.py
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/usr/bin/python3
-
-import webbrowser
-
-webbrowser.open('https://git.ilunix.de/punix/Wire-Py')
\ No newline at end of file
diff --git a/org.wirepy.policy b/org.wirepy.policy
deleted file mode 100644
index c4c1694..0000000
--- a/org.wirepy.policy
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
- Project Wire-Py
- https://git.ilunix.de/punix/Wire-Py
- wg-vpn
-
-
- auth_admin_keep
- auth_admin_keep
- yes
-
- /usr/bin/wg_main.py
- true
-
-
diff --git a/run_as b/run_as
deleted file mode 100755
index d15cff4..0000000
--- a/run_as
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/bash
-/usr/bin/./open_gitea.py
\ No newline at end of file
diff --git a/settings.conf b/settings
similarity index 100%
rename from settings.conf
rename to settings
diff --git a/start_wg.py b/start_wg.py
index 3140e90..b11f828 100755
--- a/start_wg.py
+++ b/start_wg.py
@@ -2,7 +2,7 @@
from subprocess import check_call
from pathlib import Path
-path_to_file = Path('/etc/wire_py/settings.conf')
+path_to_file = Path(Path.home() / '.config/wire_py/settings')
with open(path_to_file, 'r') as a_con:
lines = a_con.readlines()
diff --git a/wg_main.py b/wg_main.py
index 8d81627..938f54f 100755
--- a/wg_main.py
+++ b/wg_main.py
@@ -2,6 +2,7 @@
import gettext
import locale
+import webbrowser
import os
import shutil
import subprocess
@@ -9,12 +10,12 @@ import tkinter as tk
from pathlib import Path
from subprocess import check_call
from tkinter import filedialog, ttk, TclError
-from cls_mth_fc import (Tunnel, msg_window, GiteaUpdate, _u, wg_tips, wg_set)
+from cls_mth_fc import (Tunnel, msg_window, GiteaUpdate, wg_tips, dirs_and_files, wg_set, files_for_autostart)
tcl_path = Path('/usr/share/TK-Themes')
''' 1 = 1. Year, 09 = Month of the Year, 2924 = Day and Year of the Year '''
-version = 'v. 2.02.2425'
+version = 'v. 2.03.0225'
res = GiteaUpdate.api_down('https://git.ilunix.de/api/v1/repos/punix/Wire-Py/releases', version)
@@ -26,7 +27,6 @@ gettext.bindtextdomain(APP, LOCALE_DIR)
gettext.textdomain(APP)
_ = gettext.gettext
-
class MainWindow(tk.Tk):
def __init__(self, *args, **kwargs):
@@ -141,9 +141,7 @@ class FrameWidgets(ttk.Frame):
def info():
def link_btn():
- _u1 = str(_u[6:])
- path_to_file = Path('/usr/bin/./run_as')
- check_call(['su', _u1, path_to_file])
+ webbrowser.open('https://git.ilunix.de/punix/Wire-Py')
"""img_w, img_i, w_title, w_txt , txt2, com hand over"""
iw = r'/usr/share/icons/wp-icons/48/wg_vpn.png'
@@ -332,7 +330,7 @@ class FrameWidgets(ttk.Frame):
''' Listbox with Scrollbar '''
def enable_check_box(_):
-
+ files_for_autostart()
if self.l_box.size() != 0:
self.wg_autostart.configure(state='normal')
self.lb_rename.config(state='normal')
@@ -351,7 +349,7 @@ class FrameWidgets(ttk.Frame):
''' Tunnel List '''
self.tl = Tunnel.list()
for tunnels in self.tl:
- self.l_box.insert("end", tunnels)
+ self.l_box.insert("end", tunnels[:-5])
self.l_box.update()
def list_empty_enter(event):
@@ -382,7 +380,7 @@ class FrameWidgets(ttk.Frame):
''' Button Vpn '''
if self.a != '':
self.stop()
- wg_read = Path('/etc/wire_py') / str(self.a + '.conf')
+ wg_read = str(Path.home()) + '/.config/wire_py/' + str(self.a + '.conf')
with open(wg_read, 'r') as file:
data = Tunnel.con_to_dict(file)
@@ -420,7 +418,7 @@ class FrameWidgets(ttk.Frame):
try:
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:
+ with open(str(Path.home()) + '/.config/wire_py/' + select_tl + '.conf', 'r+') as file2:
key = Tunnel.con_to_dict(file2)
pre_key = key[3]
check_call(['nmcli', 'connection', 'delete', select_tl])
@@ -434,14 +432,14 @@ class FrameWidgets(ttk.Frame):
self.selected_option.set(0)
self.autoconnect_var.set(_('no Autoconnect'))
- 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:
+ Path.unlink(str(Path.home()) + '/.config/wire_py/' + str(select_tl + '.conf'))
+ with open(str(Path.home()) + '/.config/wire_py/keys', 'r') as readfile:
+ with open(str(Path.home()) + '/.config/wire_py/keys2', 'w') as writefile:
for line in readfile:
if pre_key not in line.strip("\n"):
writefile.write(line)
- file_one = Path('/etc/wire_py/.keys2')
- file_two = file_one.with_name('.keys')
+ file_one = Path(str(Path.home()) + '/.config/wire_py/keys2')
+ file_two = file_one.with_name('keys')
file_one.replace(file_two)
self.wg_autostart.configure(state='disabled')
@@ -636,7 +634,7 @@ class FrameWidgets(ttk.Frame):
''' nmcli connection modify old connection.id iphone '''
check_call(['nmcli', 'connection', 'modify', select_tl, 'connection.id', self.lb_rename.get()])
- source = Path('/etc/wire_py') / str(select_tl + '.conf')
+ source = Path.home() / '.config/wire_py' / str(select_tl + '.conf')
destination = source.with_name(str(self.lb_rename.get() + '.conf'))
source.replace(destination)
self.l_box.delete(self.select_tunnel[0])
@@ -738,8 +736,11 @@ class FrameWidgets(ttk.Frame):
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.
"""
+
+ dirs_and_files()
+
try:
- filepath = filedialog.askopenfilename(initialdir=str(_u), title=_('Select Wireguard config File'),
+ filepath = filedialog.askopenfilename(initialdir=str(Path.home()), title=_('Select Wireguard config File'),
filetypes=[(_('WG config files'), '*.conf')], )
with open(filepath, 'r') as file:
@@ -753,7 +754,7 @@ class FrameWidgets(ttk.Frame):
key = Tunnel.con_to_dict(file)
pre_key = key[3]
if len(pre_key) != 0:
- with open('/etc/wire_py/.keys', 'r') as readfile:
+ with open(str(Path.home()) + '/.config/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"""
@@ -765,13 +766,13 @@ class FrameWidgets(ttk.Frame):
else:
- with open('/etc/wire_py/.keys', 'a') as keyfile:
+ with open(str(Path.home()) + '/.config/wire_py/keys', 'a') as keyfile:
keyfile.write(pre_key + '\r')
if len(path_split1) > 17:
- p1 = shutil.copy(filepath, Path('/etc/wire_py/'))
+ p1 = shutil.copy(filepath, str(Path.home()) + '/.config/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
+ os.rename(p1, str(Path.home()) + '/.config/wire_py/' + str(path_split))
+ new_conf = str(Path.home()) + '/.config/wire_py/' + path_split
if self.a != '':
check_call(['nmcli', 'connection', 'down', Tunnel.active()])
self.label_empty()
@@ -780,7 +781,7 @@ class FrameWidgets(ttk.Frame):
'wireguard', 'file', new_conf], text=True)
else:
- shutil.copy(filepath, Path('/etc/wire_py/'))
+ shutil.copy(filepath, str(Path.home()) + '/.config/wire_py/')
if self.a != '':
check_call(['nmcli', 'connection', 'down', Tunnel.active()])
self.label_empty()
@@ -865,7 +866,7 @@ class FrameWidgets(ttk.Frame):
self.StrVar.set(self.a)
self.color_label()
self.stop()
- wg_read = Path('/etc/wire_py') / str(self.a + '.conf')
+ wg_read = str(Path.home()) + '/.config/wire_py/' + str(self.a + '.conf')
with open(wg_read, 'r') as file_for_key:
data = Tunnel.con_to_dict(file_for_key)
@@ -1061,7 +1062,7 @@ class FrameWidgets(ttk.Frame):
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')
+ wg_read = str(Path.home()) + '/.config/wire_py/' + str(select_tl + '.conf')
with open(wg_read, 'r') as file:
data = Tunnel.con_to_dict(file)
diff --git a/wg_start.service b/wg_start.service
index cc5f2bb..0352b4e 100644
--- a/wg_start.service
+++ b/wg_start.service
@@ -5,6 +5,6 @@ After=network-online.target
[Service]
Type=oneshot
ExecStartPre=/bin/sleep 5
-ExecStart=/usr/bin/start_wg.py
+ExecStart=/usr/local/bin/start_wg.py
[Install]
-WantedBy=multi-user.target
+WantedBy=default.target
diff --git a/wirepy.py b/wirepy.py
deleted file mode 100755
index 592fa67..0000000
--- a/wirepy.py
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/usr/bin/python3
-from subprocess import check_call
-from pathlib import Path
-
-Path.write_text(Path('/tmp/_u'), str(Path.home()))
-check_call(['pkexec', '/usr/bin/wg_main.py'])