reformat files
This commit is contained in:
parent
ca58ac86a4
commit
582ef21042
230
cls_mth_fc.py
230
cls_mth_fc.py
@ -1,49 +1,52 @@
|
|||||||
''' Classes Method and functions for lx apps '''
|
""" Classes Method and functions for lx apps """
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
import locale
|
import locale
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from subprocess import check_call
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
import zipfile
|
import zipfile
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from subprocess import check_call
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
APP = "wirepy"
|
||||||
APP = 'wirepy'
|
LOCALE_DIR = "/usr/share/locale/"
|
||||||
LOCALE_DIR = '/usr/share/locale/'
|
|
||||||
locale.bindtextdomain(APP, LOCALE_DIR)
|
locale.bindtextdomain(APP, LOCALE_DIR)
|
||||||
gettext.bindtextdomain(APP, LOCALE_DIR)
|
gettext.bindtextdomain(APP, LOCALE_DIR)
|
||||||
gettext.textdomain(APP)
|
gettext.textdomain(APP)
|
||||||
_ = gettext.gettext
|
_ = gettext.gettext
|
||||||
|
|
||||||
wg_set = Path(Path.home() / '.config/wire_py/settings')
|
wg_set = Path(Path.home() / ".config/wire_py/settings")
|
||||||
|
|
||||||
class Create():
|
|
||||||
|
class Create:
|
||||||
"""
|
"""
|
||||||
This class is for the creation of the folders and files
|
This class is for the creation of the folders and files
|
||||||
required by Wire-Py, as well as for decryption
|
required by Wire-Py, as well as for decryption
|
||||||
the tunnel from the user's home directory
|
the tunnel from the user's home directory
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def dir_and_files():
|
def dir_and_files():
|
||||||
|
|
||||||
pth = Path.home() / '.config/wire_py'
|
pth = Path.home() / ".config/wire_py"
|
||||||
pth.mkdir(parents=True, exist_ok=True)
|
pth.mkdir(parents=True, exist_ok=True)
|
||||||
sett = Path.home() / '.config/wire_py/settings'
|
sett = Path.home() / ".config/wire_py/settings"
|
||||||
ks = Path.home() / '.config/wire_py/keys'
|
ks = Path.home() / ".config/wire_py/keys"
|
||||||
|
|
||||||
if sett.exists():
|
if sett.exists():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
sett.touch()
|
sett.touch()
|
||||||
sett.write_text('[UPDATES]\non\n[THEME]\nlight\n[TOOLTIP]\nTrue\n[AUTOSTART ON]\noff\n')
|
sett.write_text(
|
||||||
|
"[UPDATES]\non\n[THEME]\nlight\n[TOOLTIP]\nTrue\n[AUTOSTART ON]\noff\n"
|
||||||
|
)
|
||||||
|
|
||||||
if ks.exists():
|
if ks.exists():
|
||||||
pass
|
pass
|
||||||
@ -54,25 +57,27 @@ class Create():
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def files_for_autostart():
|
def files_for_autostart():
|
||||||
|
|
||||||
pth2 = Path.home() / '.config/systemd/user'
|
pth2 = Path.home() / ".config/systemd/user"
|
||||||
pth2.mkdir(parents=True, exist_ok=True)
|
pth2.mkdir(parents=True, exist_ok=True)
|
||||||
wg_ser = Path.home() / '.config/systemd/user/wg_start.service'
|
wg_ser = Path.home() / ".config/systemd/user/wg_start.service"
|
||||||
|
|
||||||
if wg_ser.exists():
|
if wg_ser.exists():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
wg_ser.touch()
|
wg_ser.touch()
|
||||||
wg_ser.write_text('[Unit]\nDescription=Automatic Tunnel Start\nAfter=network-online.target'
|
wg_ser.write_text(
|
||||||
'\n\n[Service]\nType=oneshot\nExecStartPre=/bin/sleep 5\nExecStart=/usr/'
|
"[Unit]\nDescription=Automatic Tunnel Start\nAfter=network-online.target"
|
||||||
'local/bin/start_wg.py\n[Install]\nWantedBy=default.target')
|
"\n\n[Service]\nType=oneshot\nExecStartPre=/bin/sleep 5\nExecStart=/usr/"
|
||||||
check_call(['systemctl', '--user', 'enable', 'wg_start.service'])
|
"local/bin/start_wg.py\n[Install]\nWantedBy=default.target"
|
||||||
|
)
|
||||||
|
check_call(["systemctl", "--user", "enable", "wg_start.service"])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def make_dir():
|
def make_dir():
|
||||||
''' Dirname "tlecdewg" = Tunnel Encrypt Decrypt Wireguard '''
|
"""Dirname "tlecdewg" = Tunnel Encrypt Decrypt Wireguard"""
|
||||||
|
|
||||||
dirname = Path('/tmp/tlecdcwg/')
|
dirname = Path("/tmp/tlecdcwg/")
|
||||||
if dirname.exists():
|
if dirname.exists():
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@ -80,41 +85,50 @@ class Create():
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def decrypt():
|
def decrypt():
|
||||||
process = subprocess.run(['pkexec', '/usr/local/bin/ssl_decrypt.py'], stdout=subprocess.PIPE, text=True)
|
process = subprocess.run(
|
||||||
#print(process.stdout)
|
["pkexec", "/usr/local/bin/ssl_decrypt.py"],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
# print(process.stdout)
|
||||||
if process.returncode == 0:
|
if process.returncode == 0:
|
||||||
print('File successfully decrypted...')
|
print("File successfully decrypted...")
|
||||||
else:
|
else:
|
||||||
print(f'Error with the following code... {process.returncode}')
|
print(f"Error with the following code... {process.returncode}")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def encrypt():
|
def encrypt():
|
||||||
process = subprocess.run(['pkexec', '/usr/local/bin/ssl_encrypt.py'], stdout=subprocess.PIPE, text=True)
|
process = subprocess.run(
|
||||||
|
["pkexec", "/usr/local/bin/ssl_encrypt.py"],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
print(process.stdout)
|
print(process.stdout)
|
||||||
if process.returncode == 0:
|
if process.returncode == 0:
|
||||||
print('All Files successfully encrypted...')
|
print("All Files successfully encrypted...")
|
||||||
else:
|
else:
|
||||||
print(f'Error with the following code... {process.returncode}')
|
print(f"Error with the following code... {process.returncode}")
|
||||||
|
|
||||||
|
|
||||||
class UOS:
|
class UOS:
|
||||||
"""
|
|
||||||
The class is only for unixoidal systems "UOS" = UnixOS
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
The class is only for unixoidal systems "UOS" = UnixOS
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This method displays the user name of the logged-in user,
|
This method displays the user name of the logged-in user,
|
||||||
even if you are rooted in a shell
|
even if you are rooted in a shell
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def username():
|
def username():
|
||||||
logname = str(Path.home())[6:]
|
logname = str(Path.home())[6:]
|
||||||
file = Path.home() / '/tmp/.loguser'
|
file = Path.home() / "/tmp/.loguser"
|
||||||
with open(file, 'w') as f:
|
with open(file, "w") as f:
|
||||||
f.write(logname)
|
f.write(logname)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class GiteaUpdate:
|
class GiteaUpdate:
|
||||||
"""
|
"""
|
||||||
Calling api_down requests the URL and the version of the running script.
|
Calling api_down requests the URL and the version of the running script.
|
||||||
@ -124,51 +138,52 @@ class GiteaUpdate:
|
|||||||
the taskbar image for the “Download OK” window, the taskbar image for the
|
the taskbar image for the “Download OK” window, the taskbar image for the
|
||||||
“Download error” window and the variable res
|
“Download error” window and the variable res
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def api_down(update_api_url, version):
|
def api_down(update_api_url, version):
|
||||||
try:
|
try:
|
||||||
response = requests.get(update_api_url)
|
response = requests.get(update_api_url)
|
||||||
response_dict = response.json()
|
response_dict = response.json()
|
||||||
response_dict = response_dict[0]
|
response_dict = response_dict[0]
|
||||||
with open(wg_set, 'r') as set_file:
|
with open(wg_set, "r") as set_file:
|
||||||
set_file = set_file.read()
|
set_file = set_file.read()
|
||||||
if 'on\n' in set_file:
|
if "on\n" in set_file:
|
||||||
if version[3:] != response_dict['tag_name']:
|
if version[3:] != response_dict["tag_name"]:
|
||||||
return response_dict['tag_name']
|
return response_dict["tag_name"]
|
||||||
else:
|
else:
|
||||||
return 'No Updates'
|
return "No Updates"
|
||||||
else:
|
else:
|
||||||
return 'False'
|
return "False"
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
return 'No Internet Connection!'
|
return "No Internet Connection!"
|
||||||
|
|
||||||
@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(Path.home()) + ' ' + 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(Path.home()) + 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
|
||||||
wt = _('Download Successful')
|
wt = _("Download Successful")
|
||||||
msg_t = _('Your zip file is in home directory')
|
msg_t = _("Your zip file is in home directory")
|
||||||
msg_window(iw, ii, wt, msg_t)
|
msg_window(iw, ii, wt, msg_t)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
"""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/error.png'
|
iw = r"/usr/share/icons/lx-icons/64/error.png"
|
||||||
ii = down_not_ok_image
|
ii = down_not_ok_image
|
||||||
wt = _('Download error')
|
wt = _("Download error")
|
||||||
msg_t = _('Download failed! Please try again')
|
msg_t = _("Download failed! Please try again")
|
||||||
msg_window(iw, ii, wt, msg_t)
|
msg_window(iw, ii, wt, msg_t)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
"""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/error.png'
|
iw = r"/usr/share/icons/lx-icons/64/error.png"
|
||||||
ii = down_not_ok_image
|
ii = down_not_ok_image
|
||||||
wt = _('Download error')
|
wt = _("Download error")
|
||||||
msg_t = _('Download failed! No internet connection!')
|
msg_t = _("Download failed! No internet connection!")
|
||||||
msg_window(iw, ii, wt, msg_t)
|
msg_window(iw, ii, wt, msg_t)
|
||||||
|
|
||||||
|
|
||||||
@ -196,17 +211,17 @@ def msg_window(img_w, img_i, w_title, w_txt, txt2=None, com=None):
|
|||||||
label.grid(column=1, row=0)
|
label.grid(column=1, row=0)
|
||||||
|
|
||||||
if txt2 is not None and com is not None:
|
if txt2 is not None and com is not None:
|
||||||
label.config(font=('Ubuntu', 11), padx=15, justify='left')
|
label.config(font=("Ubuntu", 11), padx=15, justify="left")
|
||||||
msg.i_window.grid(column=0, row=0, sticky='nw')
|
msg.i_window.grid(column=0, row=0, sticky="nw")
|
||||||
button2 = ttk.Button(msg, text=f'{txt2}', command=com, padding=4)
|
button2 = ttk.Button(msg, text=f"{txt2}", command=com, padding=4)
|
||||||
button2.grid(column=0, row=1, sticky='e', columnspan=2)
|
button2.grid(column=0, row=1, sticky="e", columnspan=2)
|
||||||
button = ttk.Button(msg, text='OK', command=msg.destroy, padding=4)
|
button = ttk.Button(msg, text="OK", command=msg.destroy, padding=4)
|
||||||
button.grid(column=0, row=1, sticky='w', columnspan=2)
|
button.grid(column=0, row=1, sticky="w", columnspan=2)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
label.config(font=('Ubuntu', 11), padx=15)
|
label.config(font=("Ubuntu", 11), padx=15)
|
||||||
msg.i_window.grid(column=0, row=0)
|
msg.i_window.grid(column=0, row=0)
|
||||||
button = ttk.Button(msg, text='OK', command=msg.destroy, padding=4)
|
button = ttk.Button(msg, text="OK", command=msg.destroy, padding=4)
|
||||||
button.grid(column=0, columnspan=2, row=1)
|
button.grid(column=0, columnspan=2, row=1)
|
||||||
|
|
||||||
img_i = tk.PhotoImage(file=img_i)
|
img_i = tk.PhotoImage(file=img_i)
|
||||||
@ -225,6 +240,7 @@ class Tunnel:
|
|||||||
The config file is packed into a dictionary,
|
The config file is packed into a dictionary,
|
||||||
to display the values Address , DNS and Peer in the labels
|
to display the values Address , DNS and Peer in the labels
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def con_to_dict(cls, file):
|
def con_to_dict(cls, file):
|
||||||
|
|
||||||
@ -232,15 +248,15 @@ class Tunnel:
|
|||||||
for lines in file.readlines():
|
for lines in file.readlines():
|
||||||
line_plit = lines.split()
|
line_plit = lines.split()
|
||||||
dictlist = dictlist + line_plit
|
dictlist = dictlist + line_plit
|
||||||
dictlist.remove('[Interface]')
|
dictlist.remove("[Interface]")
|
||||||
dictlist.remove('[Peer]')
|
dictlist.remove("[Peer]")
|
||||||
for items in dictlist:
|
for items in dictlist:
|
||||||
if items == '=':
|
if items == "=":
|
||||||
|
dictlist.remove(items)
|
||||||
|
if items == "::/0":
|
||||||
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:
|
||||||
a = [dictlist[0], dictlist[1]]
|
a = [dictlist[0], dictlist[1]]
|
||||||
b = [dictlist[2], dictlist[3]]
|
b = [dictlist[2], dictlist[3]]
|
||||||
@ -255,28 +271,33 @@ class Tunnel:
|
|||||||
for elements in new_list:
|
for elements in new_list:
|
||||||
final_dict[elements[0]] = elements[1]
|
final_dict[elements[0]] = elements[1]
|
||||||
|
|
||||||
''' end... result a Dictionary '''
|
""" end... result a Dictionary """
|
||||||
|
|
||||||
address = final_dict['Address']
|
address = final_dict["Address"]
|
||||||
dns = final_dict['DNS']
|
dns = final_dict["DNS"]
|
||||||
if ',' in dns:
|
if "," in dns:
|
||||||
dns = dns[:-1]
|
dns = dns[:-1]
|
||||||
endpoint = final_dict['Endpoint']
|
endpoint = final_dict["Endpoint"]
|
||||||
if 'PresharedKey' in final_dict:
|
if "PresharedKey" in final_dict:
|
||||||
pre_key = final_dict['PresharedKey']
|
pre_key = final_dict["PresharedKey"]
|
||||||
else:
|
else:
|
||||||
pre_key = final_dict['PreSharedKey']
|
pre_key = final_dict["PreSharedKey"]
|
||||||
return address, dns, endpoint, pre_key
|
return address, dns, endpoint, pre_key
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Shows the Active Tunnel
|
Shows the Active Tunnel
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def active():
|
def active():
|
||||||
|
|
||||||
active = os.popen('nmcli con show --active | grep -iPo "(.*)(wireguard)"').read().split()
|
active = (
|
||||||
|
os.popen('nmcli con show --active | grep -iPo "(.*)(wireguard)"')
|
||||||
|
.read()
|
||||||
|
.split()
|
||||||
|
)
|
||||||
if not active:
|
if not active:
|
||||||
active = ''
|
active = ""
|
||||||
else:
|
else:
|
||||||
active = active[0]
|
active = active[0]
|
||||||
|
|
||||||
@ -285,60 +306,61 @@ class Tunnel:
|
|||||||
"""
|
"""
|
||||||
Shows all existing Wireguard tunnels a login user
|
Shows all existing Wireguard tunnels a login user
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def list():
|
def list():
|
||||||
|
|
||||||
dirname = Path('/tmp/tlecdcwg/')
|
dirname = Path("/tmp/tlecdcwg/")
|
||||||
wg_s = os.listdir(dirname)
|
wg_s = os.listdir(dirname)
|
||||||
|
|
||||||
return wg_s
|
return wg_s
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This will export the tunnels.
|
This will export the tunnels.
|
||||||
A zipfile with current date and time is created
|
A zipfile with current date and time is created
|
||||||
in the user's home directory with correct right
|
in the user's home directory with correct right
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def export():
|
def 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 = Tunnel.list()
|
tl = Tunnel.list()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if len(tl) != 0:
|
if len(tl) != 0:
|
||||||
wg_tar = str(Path.home()) + '/' + now_datetime
|
wg_tar = str(Path.home()) + "/" + now_datetime
|
||||||
shutil.copytree('/tmp/tlecdcwg/', '/tmp/wire_py', dirs_exist_ok=True)
|
shutil.copytree("/tmp/tlecdcwg/", "/tmp/wire_py", dirs_exist_ok=True)
|
||||||
source = Path('/tmp/wire_py')
|
source = Path("/tmp/wire_py")
|
||||||
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:
|
||||||
|
|
||||||
"""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 = r'/usr/share/icons/lx-icons/48/wg_vpn.png'
|
ii = r"/usr/share/icons/lx-icons/48/wg_vpn.png"
|
||||||
wt = _('Export Successful')
|
wt = _("Export Successful")
|
||||||
msg_t = _('Your zip file is in home directory')
|
msg_t = _("Your zip file is in home directory")
|
||||||
msg_window(iw, ii, wt, msg_t)
|
msg_window(iw, ii, wt, msg_t)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
"""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/error.png'
|
iw = r"/usr/share/icons/lx-icons/64/error.png"
|
||||||
ii = r'/usr/share/icons/lx-icons/48/wg_msg.png'
|
ii = r"/usr/share/icons/lx-icons/48/wg_msg.png"
|
||||||
wt = _('Export error')
|
wt = _("Export error")
|
||||||
msg_t = _('Export failed! Please try again')
|
msg_t = _("Export failed! Please try again")
|
||||||
msg_window(iw, ii, wt, msg_t)
|
msg_window(iw, ii, wt, msg_t)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
"""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 = r'/usr/share/icons/lx-icons/48/wg_msg.png'
|
ii = r"/usr/share/icons/lx-icons/48/wg_msg.png"
|
||||||
wt = _('Select tunnel')
|
wt = _("Select tunnel")
|
||||||
msg_t = _('Please first import tunnel')
|
msg_t = _("Please first import tunnel")
|
||||||
msg_window(iw, ii, wt, msg_t)
|
msg_window(iw, ii, wt, msg_t)
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
@ -350,12 +372,12 @@ class Tipi:
|
|||||||
Class for Tooltip setting write in File
|
Class for Tooltip setting write in File
|
||||||
Calling request path to file
|
Calling request path to file
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def if_tip(path):
|
def if_tip(path):
|
||||||
with open(path, 'r') as set_file2:
|
with open(path, "r") as set_file2:
|
||||||
lines2 = set_file2.readlines()
|
lines2 = set_file2.readlines()
|
||||||
if 'False\n' in lines2:
|
if "False\n" in lines2:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -1,34 +1,59 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
''' This Script decrypt Wireguardfiles for Wirepy users '''
|
""" This Script decrypt Wireguardfiles for Wirepy users """
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from subprocess import check_call
|
|
||||||
from pathlib import Path
|
|
||||||
import shutil
|
import shutil
|
||||||
uname = Path('/tmp/.loguser')
|
from pathlib import Path
|
||||||
|
from subprocess import check_call
|
||||||
|
|
||||||
with open(uname, 'r') as f:
|
uname = Path("/tmp/.loguser")
|
||||||
|
|
||||||
|
with open(uname, "r") as f:
|
||||||
logname = f.readline()
|
logname = f.readline()
|
||||||
|
|
||||||
''' Dirname "tlecdewg" = Tunnel Encrypt Decrypt Wireguard '''
|
""" Dirname "tlecdewg" = Tunnel Encrypt Decrypt Wireguard """
|
||||||
dirname = Path('/tmp/tlecdcwg/')
|
dirname = Path("/tmp/tlecdcwg/")
|
||||||
keyfile = Path(f'/home/{logname}/.config/wire_py/pbwgk.pem')
|
keyfile = Path(f"/home/{logname}/.config/wire_py/pbwgk.pem")
|
||||||
pkeyfile = '/usr/local/etc/ssl/pwgk.pem'
|
pkeyfile = "/usr/local/etc/ssl/pwgk.pem"
|
||||||
|
|
||||||
if not keyfile.is_file():
|
if not keyfile.is_file():
|
||||||
|
|
||||||
check_call(['openssl', 'rsa', '-in', pkeyfile, '-out', keyfile, '-outform', 'PEM', '-pubout'])
|
check_call(
|
||||||
|
[
|
||||||
|
"openssl",
|
||||||
|
"rsa",
|
||||||
|
"-in",
|
||||||
|
pkeyfile,
|
||||||
|
"-out",
|
||||||
|
keyfile,
|
||||||
|
"-outform",
|
||||||
|
"PEM",
|
||||||
|
"-pubout",
|
||||||
|
]
|
||||||
|
)
|
||||||
shutil.chown(keyfile, 1000, 1000)
|
shutil.chown(keyfile, 1000, 1000)
|
||||||
|
|
||||||
dirname2 = ('/home/' + logname + '/.config/wire_py/')
|
dirname2 = "/home/" + logname + "/.config/wire_py/"
|
||||||
detl = os.listdir(dirname2)
|
detl = os.listdir(dirname2)
|
||||||
os.chdir(dirname2)
|
os.chdir(dirname2)
|
||||||
detl.remove('keys')
|
detl.remove("keys")
|
||||||
detl.remove('settings')
|
detl.remove("settings")
|
||||||
if os.path.exists(dirname2 + 'pbwgk.pem'):
|
if os.path.exists(dirname2 + "pbwgk.pem"):
|
||||||
detl.remove('pbwgk.pem')
|
detl.remove("pbwgk.pem")
|
||||||
for detunnels in detl:
|
for detunnels in detl:
|
||||||
tlname2 = detunnels[:-4] + '.conf'
|
tlname2 = detunnels[:-4] + ".conf"
|
||||||
extpath = str(dirname) + '/' + tlname2
|
extpath = str(dirname) + "/" + tlname2
|
||||||
check_call(['openssl', 'pkeyutl', '-decrypt', '-inkey', pkeyfile, '-in', detunnels, '-out', extpath])
|
check_call(
|
||||||
shutil.chown(extpath, 1000, 1000)
|
[
|
||||||
|
"openssl",
|
||||||
|
"pkeyutl",
|
||||||
|
"-decrypt",
|
||||||
|
"-inkey",
|
||||||
|
pkeyfile,
|
||||||
|
"-in",
|
||||||
|
detunnels,
|
||||||
|
"-out",
|
||||||
|
extpath,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
shutil.chown(extpath, 1000, 1000)
|
||||||
|
@ -1,25 +1,37 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
''' This Script encrypt Wireguardfiles for Wirepy users for more Security'''
|
""" This Script encrypt Wireguardfiles for Wirepy users for more Security"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from subprocess import check_call
|
|
||||||
from pathlib import Path
|
|
||||||
import shutil
|
import shutil
|
||||||
|
from pathlib import Path
|
||||||
|
from subprocess import check_call
|
||||||
|
|
||||||
uname = Path('/tmp/.loguser')
|
uname = Path("/tmp/.loguser")
|
||||||
|
|
||||||
with open(uname, 'r') as f:
|
with open(uname, "r") as f:
|
||||||
logname = f.readline()
|
logname = f.readline()
|
||||||
|
|
||||||
keyfile = Path(f'/home/{logname}/.config/wire_py/pbwgk.pem')
|
keyfile = Path(f"/home/{logname}/.config/wire_py/pbwgk.pem")
|
||||||
dirname = Path('/tmp/tlecdcwg/')
|
dirname = Path("/tmp/tlecdcwg/")
|
||||||
pkeyfile = '/usr/local/etc/ssl/pwgk.pem'
|
pkeyfile = "/usr/local/etc/ssl/pwgk.pem"
|
||||||
|
|
||||||
if not keyfile.is_file():
|
if not keyfile.is_file():
|
||||||
|
|
||||||
check_call(['openssl', 'rsa', '-in', pkeyfile, '-out', keyfile, '-outform', 'PEM', '-pubout'])
|
check_call(
|
||||||
|
[
|
||||||
|
"openssl",
|
||||||
|
"rsa",
|
||||||
|
"-in",
|
||||||
|
pkeyfile,
|
||||||
|
"-out",
|
||||||
|
keyfile,
|
||||||
|
"-outform",
|
||||||
|
"PEM",
|
||||||
|
"-pubout",
|
||||||
|
]
|
||||||
|
)
|
||||||
shutil.chown(keyfile, 1000, 1000)
|
shutil.chown(keyfile, 1000, 1000)
|
||||||
|
|
||||||
if dirname.exists():
|
if dirname.exists():
|
||||||
tl = os.listdir(str(dirname))
|
tl = os.listdir(str(dirname))
|
||||||
cpth = str(keyfile)
|
cpth = str(keyfile)
|
||||||
@ -27,9 +39,22 @@ if not keyfile.is_file():
|
|||||||
|
|
||||||
if keyfile.exists() and len(tl) != 0:
|
if keyfile.exists() and len(tl) != 0:
|
||||||
for tunnels in tl:
|
for tunnels in tl:
|
||||||
sourcetl = str(dirname) + '/' + tunnels
|
sourcetl = str(dirname) + "/" + tunnels
|
||||||
tlname = cryptfiles + tunnels[:-5] + '.dat'
|
tlname = cryptfiles + tunnels[:-5] + ".dat"
|
||||||
check_call(['openssl', 'pkeyutl', '-encrypt', '-inkey', keyfile, '-pubin', '-in', sourcetl, '-out', tlname])
|
check_call(
|
||||||
|
[
|
||||||
|
"openssl",
|
||||||
|
"pkeyutl",
|
||||||
|
"-encrypt",
|
||||||
|
"-inkey",
|
||||||
|
keyfile,
|
||||||
|
"-pubin",
|
||||||
|
"-in",
|
||||||
|
sourcetl,
|
||||||
|
"-out",
|
||||||
|
tlname,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
@ -40,10 +65,19 @@ else:
|
|||||||
|
|
||||||
if keyfile.exists() and len(tl) != 0:
|
if keyfile.exists() and len(tl) != 0:
|
||||||
for tunnels in tl:
|
for tunnels in tl:
|
||||||
sourcetl = str(dirname) + '/' + tunnels
|
sourcetl = str(dirname) + "/" + tunnels
|
||||||
tlname = cryptfiles + tunnels[:-5] + '.dat'
|
tlname = cryptfiles + tunnels[:-5] + ".dat"
|
||||||
check_call(['openssl', 'pkeyutl', '-encrypt', '-inkey', keyfile, '-pubin', '-in', sourcetl, '-out', tlname])
|
check_call(
|
||||||
|
[
|
||||||
|
"openssl",
|
||||||
|
"pkeyutl",
|
||||||
|
"-encrypt",
|
||||||
|
"-inkey",
|
||||||
|
keyfile,
|
||||||
|
"-pubin",
|
||||||
|
"-in",
|
||||||
|
sourcetl,
|
||||||
|
"-out",
|
||||||
|
tlname,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
11
start_wg.py
11
start_wg.py
@ -1,14 +1,13 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
from subprocess import check_call
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from subprocess import check_call
|
||||||
|
|
||||||
path_to_file = Path(Path.home() / '.config/wire_py/settings')
|
path_to_file = Path(Path.home() / ".config/wire_py/settings")
|
||||||
|
|
||||||
with open(path_to_file, 'r') as a_con:
|
with open(path_to_file, "r") as a_con:
|
||||||
lines = a_con.readlines()
|
lines = a_con.readlines()
|
||||||
a_con = lines[7].strip()
|
a_con = lines[7].strip()
|
||||||
if a_con != 'off':
|
if a_con != "off":
|
||||||
check_call(['nmcli', 'connection', 'up', a_con])
|
check_call(["nmcli", "connection", "up", a_con])
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user