From 407bb21168f6b78b98426f54800ca8e786e05815 Mon Sep 17 00:00:00 2001 From: Mateusz779 Date: Wed, 19 Apr 2023 12:01:53 +0200 Subject: [PATCH] dodanie kolumny z ip po sieci lokalnej --- app.py | 2 +- db.py | 17 +++++++++-------- machines.py | 26 +++++--------------------- templates/index.html | 4 +++- utils.py | 2 +- 5 files changed, 19 insertions(+), 32 deletions(-) diff --git a/app.py b/app.py index aa31d8f..74bd8ba 100644 --- a/app.py +++ b/app.py @@ -189,7 +189,7 @@ def add_ip(): ip = request.form['ip'] except: return jsonify(message="400") - if db.update_image_allocation_ip(token, ip) is not None: + if db.update_image_allocation_ip_vpn(token, ip) is not None: return jsonify(message="200") else: return jsonify(message="400") diff --git a/db.py b/db.py index 5c1a89e..05991f3 100644 --- a/db.py +++ b/db.py @@ -50,7 +50,8 @@ def connect(): image_id INTEGER NOT NULL REFERENCES image(id), allocation_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, last_access_time TIMESTAMP, - client_ip INET + client_ip_local INET, + client_ip_vpn INET );""") conn.commit() @@ -148,13 +149,13 @@ def get_machines(): connect() with get_cur() as cur: cur.execute(""" - SELECT image_id, allocation_time, client_ip FROM image_allocation""") + SELECT image_id, allocation_time, client_ip_vpn, client_ip_local FROM image_allocation""") try: machinesall = machines.MachineManager() for row in cur.fetchall(): token = get_one("SELECT token FROM image WHERE id = %s", row[0]) image_name = get_one("SELECT image_name FROM image WHERE id = %s", row[0]) - machine = machines.Machine(token, image_name, start_time=row[1], ip=row[2], username="root", password="") + machine = machines.Machine(token, image_name, start_time=row[1], ipvpn=row[2], iplocal=row[3], username="root", password="") machinesall.add_machine(machine) return machinesall except: @@ -213,8 +214,8 @@ def get_image_allocation_clientip(token): return get_one("SELECT last_access_time FROM image_allocation WHERE id = %s", id_image) -def get_image_allocation_clientip_id(id): - return get_one("SELECT client_ip FROM image_allocation WHERE id = %s", id) +def get_image_allocation_clientip_id_vpn(id): + return get_one("SELECT client_ip_vpn FROM image_allocation WHERE id = %s", id) def set_image_allocation(token, client_ip): @@ -225,7 +226,7 @@ def set_image_allocation(token, client_ip): connect() with get_cur() as cur: cur.execute(""" - INSERT INTO image_allocation (image_id, client_ip, last_access_time) + INSERT INTO image_allocation (image_id, client_ip_local, last_access_time) VALUES (%s, %s, CURRENT_TIMESTAMP) """, (id_image, client_ip,)) conn.commit() @@ -271,14 +272,14 @@ def update_image_allocation_time(id): except: return None -def update_image_allocation_ip(token, ip): +def update_image_allocation_ip_vpn(token, ip): image_id = get_conf_id(token) if image_id is None: return None connect() with get_cur() as cur: cur.execute(""" - UPDATE image_allocation SET client_ip = %s WHERE image_id = %s + UPDATE image_allocation SET client_ip_vpn = %s WHERE image_id = %s """, (ip, image_id,)) try: conn.commit() diff --git a/machines.py b/machines.py index 3df79b1..5f799b2 100644 --- a/machines.py +++ b/machines.py @@ -1,14 +1,16 @@ class Machine: - def __init__(self, name, image_name, start_time, ip, username, password): + def __init__(self, name, image_name, start_time, ipvpn, iplocal, username, password): self.name = name self.image_name = image_name self.start_time = start_time - self.ip = ip + self.ipvpn = ipvpn + self.iplocal = iplocal self.username = username self.password = password + def __str__(self): - return f"Name: {self.name}\nImage name: {self.image_name}\nStart time: {self.start_time}\nIP: {self.ip}\nUsername: {self.username}\nPassword: {self.password}" + return f"Name: {self.name}\nImage name: {self.image_name}\nStart time: {self.start_time}\nIP VPN: {self.ipvpn}\nIP local: {self.iplocal}\nUsername: {self.username}\nPassword: {self.password}" class MachineManager: def __init__(self): @@ -31,21 +33,3 @@ class MachineManager: for machine in self.machines: result += str(machine) + "\n\n" return result - - def to_html_table(self): - html = "" - html += """ - - - - """ - for machine in self.machines: - html += f""" - - - - - - """ - html += "
Nazwa maszynyObrazCzas uruchomieniaIP uVPN
{ machine.name }{ machine.image_name }{ machine.start_time }{ machine.ip }
" - return html diff --git a/templates/index.html b/templates/index.html index 5d8686d..b69a84a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -67,6 +67,7 @@ Obraz Czas uruchomienia IP uVPN + IP lokalne @@ -76,7 +77,8 @@ {{ machine.name }} {{ machine.image_name }} {{ machine.start_time }} - {{ machine.ip }} + {{ machine.ipvpn }} + {{ machine.iplocal }} {% endfor %} diff --git a/utils.py b/utils.py index 709bb71..b8c753d 100644 --- a/utils.py +++ b/utils.py @@ -42,7 +42,7 @@ def check_allocation_thread_function(): while True: ids = db.get_image_allocation_all() for x in ids: - ip = db.get_image_allocation_clientip_id(x[0]) + ip = db.get_image_allocation_clientip_id_vpn(x[0]) ping_thread = PingThread(ip, x[0]) ping_thread.start()