code cleanup
This commit is contained in:
parent
ebd558a690
commit
5b59bb99c2
3
app.py
3
app.py
@ -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"))
|
||||
|
@ -5,6 +5,7 @@ class Image:
|
||||
self.token = token
|
||||
self.vpn_ip = vpn_ip
|
||||
|
||||
|
||||
class ImageManager:
|
||||
def __init__(self):
|
||||
self.images = []
|
||||
|
@ -7,6 +7,8 @@ class Machine:
|
||||
self.iplocal = iplocal
|
||||
self.username = username
|
||||
self.password = password
|
||||
|
||||
|
||||
class MachineManager:
|
||||
def __init__(self):
|
||||
self.machines = []
|
||||
|
7
utils.py
7
utils.py
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user