code cleanup

This commit is contained in:
Mateusz779 2023-04-21 16:39:25 +02:00
parent ebd558a690
commit 5b59bb99c2
5 changed files with 18 additions and 15 deletions

3
app.py
View File

@ -112,7 +112,8 @@ def create_conf_post():
if os.path.exists(folder): if os.path.exists(folder):
shutil.rmtree(folder) shutil.rmtree(folder)
output = subprocess.run(['openssl','passwd','-6', password], capture_output=True, text=True) output = subprocess.run(
['openssl', 'passwd', '-6', password], capture_output=True, text=True)
db.add_conf_image(config_name+".squashfs", token_name, ip, output.stdout) db.add_conf_image(config_name+".squashfs", token_name, ip, output.stdout)
return send_file(os.path.join(app.config['UPLOAD_FOLDER'], config_name+".pub")) return send_file(os.path.join(app.config['UPLOAD_FOLDER'], config_name+".pub"))

View File

@ -1,7 +1,7 @@
database="praktyki" database = "praktyki"
host="localhost" host = "localhost"
user="praktyki" user = "praktyki"
password="2a7driUITXFy73tO" password = "2a7driUITXFy73tO"
port="5432" port = "5432"
default_file = "default.squashfs" default_file = "default.squashfs"
webssh_port = "8000" webssh_port = "8000"

View File

@ -5,6 +5,7 @@ class Image:
self.token = token self.token = token
self.vpn_ip = vpn_ip self.vpn_ip = vpn_ip
class ImageManager: class ImageManager:
def __init__(self): def __init__(self):
self.images = [] self.images = []

View File

@ -7,6 +7,8 @@ class Machine:
self.iplocal = iplocal self.iplocal = iplocal
self.username = username self.username = username
self.password = password self.password = password
class MachineManager: class MachineManager:
def __init__(self): def __init__(self):
self.machines = [] self.machines = []

View File

@ -11,6 +11,7 @@ import db
import config import config
import ipaddress import ipaddress
def generate_random_string(length): def generate_random_string(length):
letters = string.ascii_letters letters = string.ascii_letters
random_string = ''.join(random.choice(letters) for i in range(length)) random_string = ''.join(random.choice(letters) for i in range(length))
@ -41,6 +42,7 @@ def ssh_thread_function():
def check_allocation_thread_function(): def check_allocation_thread_function():
while True: while True:
ids = db.get_image_allocation_all() ids = db.get_image_allocation_all()
if ids is not None:
for x in ids: for x in ids:
ip = db.get_image_allocation_clientip_id_vpn(x[0]) ip = db.get_image_allocation_clientip_id_vpn(x[0])
ping_thread = PingThread(ip, x[0]) ping_thread = PingThread(ip, x[0])
@ -61,15 +63,11 @@ class PingThread(threading.Thread):
return return
if ping_client(self.Ip) == False: if ping_client(self.Ip) == False:
date = db.get_image_allocation_time_id(self.Id) date = db.get_image_allocation_time_id(self.Id)
print(date)
if date is None: if date is None:
return return
delta = datetime.datetime.utcnow() - date delta = datetime.datetime.utcnow() - date
print(datetime.datetime.utcnow())
print(delta.total_seconds())
if delta.total_seconds() > 30: if delta.total_seconds() > 30:
db.del_image_allocation_id(self.Id) db.del_image_allocation_id(self.Id)
print("deleted")
else: else:
db.update_image_allocation_time(self.Id) db.update_image_allocation_time(self.Id)
@ -82,6 +80,7 @@ def init_threads():
target=check_allocation_thread_function) target=check_allocation_thread_function)
allocation_thread.start() allocation_thread.start()
def is_valid_ip_address(ip: str) -> bool: def is_valid_ip_address(ip: str) -> bool:
try: try:
ipaddress.IPv4Address(ip) ipaddress.IPv4Address(ip)