From a5eb6293c6f056ed2222748c493170208a81afea Mon Sep 17 00:00:00 2001 From: punix Date: Sun, 2 Mar 2025 15:27:37 +0100 Subject: [PATCH] add-new-cls-mth-fc-file --- cls_mth_fc.py | 68 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 16 deletions(-) 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: