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):
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)
return send_file(os.path.join(app.config['UPLOAD_FOLDER'], config_name+".pub"))

View File

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

View File

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

View File

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

View File

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