add-new-cls-mth-fc-file
This commit is contained in:
parent
6e54529c0f
commit
a5eb6293c6
@ -5,6 +5,7 @@ import locale
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from subprocess import check_call
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
import zipfile
|
import zipfile
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@ -19,8 +20,41 @@ gettext.bindtextdomain(APP, LOCALE_DIR)
|
|||||||
gettext.textdomain(APP)
|
gettext.textdomain(APP)
|
||||||
_ = gettext.gettext
|
_ = gettext.gettext
|
||||||
|
|
||||||
wg_set = Path('/etc/wire_py/settings.conf')
|
def dirs_and_files():
|
||||||
_u = Path.read_text(Path('/tmp/_u'))
|
|
||||||
|
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:
|
class GiteaUpdate:
|
||||||
@ -53,10 +87,10 @@ class GiteaUpdate:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def download(urld, down_ok_image, down_not_ok_image, res):
|
def download(urld, down_ok_image, down_not_ok_image, res):
|
||||||
try:
|
try:
|
||||||
to_down = 'wget -qP ' + str(_u) + ' ' + urld
|
to_down = 'wget -qP ' + str(Path.home()) + ' ' + urld
|
||||||
result = subprocess.call(to_down, shell=True)
|
result = subprocess.call(to_down, shell=True)
|
||||||
if result == 0:
|
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"""
|
"""img_w, img_i, w_title, w_txt hand over"""
|
||||||
iw = r'/usr/share/icons/lx-icons/64/info.png'
|
iw = r'/usr/share/icons/lx-icons/64/info.png'
|
||||||
ii = down_ok_image
|
ii = down_ok_image
|
||||||
@ -145,6 +179,8 @@ class Tunnel:
|
|||||||
for items in dictlist:
|
for items in dictlist:
|
||||||
if items == '=':
|
if items == '=':
|
||||||
dictlist.remove(items)
|
dictlist.remove(items)
|
||||||
|
if items == '::/0':
|
||||||
|
dictlist.remove(items)
|
||||||
|
|
||||||
''' Here is the beginning (Loop) of convert List to Dictionary '''
|
''' Here is the beginning (Loop) of convert List to Dictionary '''
|
||||||
for _ in dictlist:
|
for _ in dictlist:
|
||||||
@ -189,15 +225,16 @@ class Tunnel:
|
|||||||
return active
|
return active
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Shows all existing Wireguard tunnels
|
Shows all existing Wireguard tunnels a login user
|
||||||
"""
|
"""
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def list():
|
def list():
|
||||||
wg_s = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
|
dirname = Path.home() / '.config/wire_py/'
|
||||||
|
wg_s = os.listdir(dirname)
|
||||||
|
wg_s.remove('keys')
|
||||||
|
wg_s.remove('settings')
|
||||||
|
|
||||||
''' tl = Tunnel list # Show of 4.Element in list '''
|
return wg_s
|
||||||
tl = wg_s[::3]
|
|
||||||
return tl
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This will export the tunnels.
|
This will export the tunnels.
|
||||||
@ -206,21 +243,20 @@ class Tunnel:
|
|||||||
"""
|
"""
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def export():
|
def export():
|
||||||
_u1 = str(_u[6:])
|
|
||||||
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 = Tunnel.list()
|
tl = Tunnel.list()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if len(tl) != 0:
|
if len(tl) != 0:
|
||||||
wg_tar = str(_u) + '/' + now_datetime
|
wg_tar = str(Path.home()) + '/' + now_datetime
|
||||||
shutil.copytree('/etc/wire_py', '/tmp/wire_py', dirs_exist_ok=True)
|
shutil.copytree(Path.home() / '.config/wire_py/', '/tmp/wire_py', dirs_exist_ok=True)
|
||||||
source = Path('/tmp/wire_py')
|
source = Path('/tmp/wire_py')
|
||||||
Path.unlink(Path(source) / 'wg_py', missing_ok=True)
|
Path.unlink(Path(source) / 'wg_py', missing_ok=True)
|
||||||
Path.unlink(Path(source) / '.keys', missing_ok=True)
|
Path.unlink(Path(source) / 'keys', missing_ok=True)
|
||||||
Path.unlink(Path(source) / 'settings.conf', missing_ok=True)
|
Path.unlink(Path(source) / 'settings', missing_ok=True)
|
||||||
shutil.make_archive(wg_tar, 'zip', source)
|
shutil.make_archive(wg_tar, 'zip', source)
|
||||||
shutil.chown(wg_tar + '.zip', 1000, 1000)
|
#shutil.chown(wg_tar + '.zip', 1000, 1000)
|
||||||
shutil.rmtree(source)
|
shutil.rmtree(source)
|
||||||
with zipfile.ZipFile((wg_tar + '.zip'), 'r') as zf:
|
with zipfile.ZipFile((wg_tar + '.zip'), 'r') as zf:
|
||||||
if len(zf.namelist()) != 0:
|
if len(zf.namelist()) != 0:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user