format with blank and pylint
This commit is contained in:
parent
582ef21042
commit
39550b392d
@ -1,4 +1,4 @@
|
|||||||
""" Classes Method and functions for lx apps """
|
""" Classes Method and Functions for lx Apps """
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
import locale
|
import locale
|
||||||
@ -33,6 +33,9 @@ class Create:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def dir_and_files():
|
def dir_and_files():
|
||||||
|
"""
|
||||||
|
check and create folders and files if not present
|
||||||
|
"""
|
||||||
|
|
||||||
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)
|
||||||
@ -56,6 +59,9 @@ class Create:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def files_for_autostart():
|
def files_for_autostart():
|
||||||
|
"""
|
||||||
|
check and create file for auto start if not present and enable the service
|
||||||
|
"""
|
||||||
|
|
||||||
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)
|
||||||
@ -85,6 +91,9 @@ class Create:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def decrypt():
|
def decrypt():
|
||||||
|
"""
|
||||||
|
This start ssl_decrypt file
|
||||||
|
"""
|
||||||
process = subprocess.run(
|
process = subprocess.run(
|
||||||
["pkexec", "/usr/local/bin/ssl_decrypt.py"],
|
["pkexec", "/usr/local/bin/ssl_decrypt.py"],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
@ -98,6 +107,9 @@ class Create:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def encrypt():
|
def encrypt():
|
||||||
|
"""
|
||||||
|
this start ssl_encrypt file
|
||||||
|
"""
|
||||||
process = subprocess.run(
|
process = subprocess.run(
|
||||||
["pkexec", "/usr/local/bin/ssl_encrypt.py"],
|
["pkexec", "/usr/local/bin/ssl_encrypt.py"],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
@ -116,24 +128,20 @@ class UOS:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
"""
|
|
||||||
This method displays the user name of the logged-in user,
|
|
||||||
even if you are rooted in a shell
|
|
||||||
"""
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def username():
|
def username():
|
||||||
|
"""
|
||||||
|
This method displays the user name of the logged-in user,
|
||||||
|
even if you are rooted in a shell
|
||||||
|
"""
|
||||||
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", encoding="utf-8") 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.
|
|
||||||
Example: version = 'v. 1.1.1.1' GiteaUpdate.api_down(http://example.de, version)
|
|
||||||
|
|
||||||
Calling download requests the download URL of the running script,
|
Calling download requests the download URL of the running script,
|
||||||
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
|
||||||
@ -141,11 +149,15 @@ class GiteaUpdate:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def api_down(update_api_url, version):
|
def api_down(update_api_url, version):
|
||||||
|
"""
|
||||||
|
Calling api_down requests the URL and the version of the running script.
|
||||||
|
Example: version = 'v. 1.1.1.1' GiteaUpdate.api_down(http://example.de, 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", encoding="utf-8") 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"]:
|
||||||
@ -159,12 +171,15 @@ 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):
|
||||||
|
"""
|
||||||
|
this is for download new Version of wirepy
|
||||||
|
"""
|
||||||
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")
|
||||||
@ -172,14 +187,14 @@ class GiteaUpdate:
|
|||||||
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")
|
||||||
@ -190,7 +205,8 @@ class GiteaUpdate:
|
|||||||
def msg_window(img_w, img_i, w_title, w_txt, txt2=None, com=None):
|
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.
|
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.
|
To create messages with your own images, icons, and titles.
|
||||||
|
As an alternative to Python Messagebox.
|
||||||
Paths to images must be specified: r'/usr/share/icons/lx-icons/64/info.png'
|
Paths to images must be specified: r'/usr/share/icons/lx-icons/64/info.png'
|
||||||
img_w = Image for Tk Window
|
img_w = Image for Tk Window
|
||||||
img_i = Image for Icon
|
img_i = Image for Icon
|
||||||
@ -236,13 +252,12 @@ class Tunnel:
|
|||||||
Class of Methods for Wire-Py
|
Class of Methods for Wire-Py
|
||||||
"""
|
"""
|
||||||
|
|
||||||
"""
|
|
||||||
The config file is packed into a dictionary,
|
|
||||||
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):
|
||||||
|
"""
|
||||||
|
The config file is packed into a dictionary,
|
||||||
|
to display the values Address , DNS and Peer in the labels
|
||||||
|
"""
|
||||||
|
|
||||||
dictlist = []
|
dictlist = []
|
||||||
for lines in file.readlines():
|
for lines in file.readlines():
|
||||||
@ -256,7 +271,7 @@ class Tunnel:
|
|||||||
if items == "::/0":
|
if items == "::/0":
|
||||||
dictlist.remove(items)
|
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]]
|
||||||
@ -271,7 +286,7 @@ 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"]
|
||||||
@ -284,13 +299,11 @@ class Tunnel:
|
|||||||
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
|
|
||||||
"""
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def active():
|
def active():
|
||||||
|
"""
|
||||||
|
Shows the Active Tunnel
|
||||||
|
"""
|
||||||
active = (
|
active = (
|
||||||
os.popen('nmcli con show --active | grep -iPo "(.*)(wireguard)"')
|
os.popen('nmcli con show --active | grep -iPo "(.*)(wireguard)"')
|
||||||
.read()
|
.read()
|
||||||
@ -303,26 +316,23 @@ class Tunnel:
|
|||||||
|
|
||||||
return active
|
return active
|
||||||
|
|
||||||
"""
|
|
||||||
Shows all existing Wireguard tunnels a login user
|
|
||||||
"""
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def list():
|
def list():
|
||||||
|
"""
|
||||||
|
Shows all existing Wireguard tunnels a login user
|
||||||
|
"""
|
||||||
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.
|
|
||||||
A zipfile with current date and time is created
|
|
||||||
in the user's home directory with correct right
|
|
||||||
"""
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def export():
|
def export():
|
||||||
|
"""
|
||||||
|
This will export the tunnels.
|
||||||
|
A zipfile with current date and time is created
|
||||||
|
in the user's home directory with correct right
|
||||||
|
"""
|
||||||
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()
|
||||||
@ -338,7 +348,7 @@ class Tunnel:
|
|||||||
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")
|
||||||
@ -347,7 +357,7 @@ class Tunnel:
|
|||||||
|
|
||||||
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")
|
||||||
@ -356,7 +366,7 @@ class Tunnel:
|
|||||||
|
|
||||||
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")
|
||||||
@ -375,7 +385,10 @@ class Tipi:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def if_tip(path):
|
def if_tip(path):
|
||||||
with open(path, "r") as set_file2:
|
"""
|
||||||
|
method that writes in file whether tooltip is displayed or not
|
||||||
|
"""
|
||||||
|
with open(path, "r", encoding="utf-8") 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
|
||||||
|
@ -8,13 +8,13 @@ from subprocess import check_call
|
|||||||
|
|
||||||
uname = Path("/tmp/.loguser")
|
uname = Path("/tmp/.loguser")
|
||||||
|
|
||||||
with open(uname, "r") as f:
|
with open(uname, "r", encoding="utf-8") 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():
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ if not keyfile.is_file():
|
|||||||
"openssl",
|
"openssl",
|
||||||
"rsa",
|
"rsa",
|
||||||
"-in",
|
"-in",
|
||||||
pkeyfile,
|
PKEYFILE,
|
||||||
"-out",
|
"-out",
|
||||||
keyfile,
|
keyfile,
|
||||||
"-outform",
|
"-outform",
|
||||||
@ -49,7 +49,7 @@ if os.path.exists(dirname2 + "pbwgk.pem"):
|
|||||||
"pkeyutl",
|
"pkeyutl",
|
||||||
"-decrypt",
|
"-decrypt",
|
||||||
"-inkey",
|
"-inkey",
|
||||||
pkeyfile,
|
PKEYFILE,
|
||||||
"-in",
|
"-in",
|
||||||
detunnels,
|
detunnels,
|
||||||
"-out",
|
"-out",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/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
|
||||||
import shutil
|
import shutil
|
||||||
@ -8,12 +8,12 @@ from subprocess import check_call
|
|||||||
|
|
||||||
uname = Path("/tmp/.loguser")
|
uname = Path("/tmp/.loguser")
|
||||||
|
|
||||||
with open(uname, "r") as f:
|
with open(uname, "r", encoding="utf-8") 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():
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ if not keyfile.is_file():
|
|||||||
"openssl",
|
"openssl",
|
||||||
"rsa",
|
"rsa",
|
||||||
"-in",
|
"-in",
|
||||||
pkeyfile,
|
PKEYFILE,
|
||||||
"-out",
|
"-out",
|
||||||
keyfile,
|
keyfile,
|
||||||
"-outform",
|
"-outform",
|
||||||
@ -34,13 +34,13 @@ if not keyfile.is_file():
|
|||||||
|
|
||||||
if dirname.exists():
|
if dirname.exists():
|
||||||
tl = os.listdir(str(dirname))
|
tl = os.listdir(str(dirname))
|
||||||
cpth = str(keyfile)
|
CPTH = str(keyfile)
|
||||||
cryptfiles = cpth[:-9]
|
CRYPTFILES = CPTH[:-9]
|
||||||
|
|
||||||
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(
|
check_call(
|
||||||
[
|
[
|
||||||
"openssl",
|
"openssl",
|
||||||
@ -60,13 +60,13 @@ else:
|
|||||||
|
|
||||||
if dirname.exists():
|
if dirname.exists():
|
||||||
tl = os.listdir(str(dirname))
|
tl = os.listdir(str(dirname))
|
||||||
cpth = str(keyfile)
|
CPTH = str(keyfile)
|
||||||
cryptfiles = cpth[:-9]
|
CRYPTFILES = CPTH[:-9]
|
||||||
|
|
||||||
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(
|
check_call(
|
||||||
[
|
[
|
||||||
"openssl",
|
"openssl",
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
"""
|
||||||
|
This script belongs to wirepy and is for the auto start of the tunnel
|
||||||
|
"""
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from subprocess import check_call
|
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", encoding="utf-8") as a_con:
|
||||||
|
# This funtion is for the independent autostart of the previously selected tunnel
|
||||||
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":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user