From 26275a0674af347a36b9be4f1161917d8a851282 Mon Sep 17 00:00:00 2001 From: Mateusz779 Date: Wed, 19 Apr 2023 14:10:31 +0200 Subject: [PATCH] =?UTF-8?q?dodanie=20listy=20obraz=C3=B3w=20i=20poprawa=20?= =?UTF-8?q?buga?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 11 ++++++++++- configs/create.sh | 2 -- db.py | 16 ++++++++++++++++ images.py | 21 +++++++++++++++++++++ machines.py | 11 ----------- templates/base.html | 5 ++++- templates/images.html | 33 +++++++++++++++++++++++++++++++++ 7 files changed, 84 insertions(+), 15 deletions(-) create mode 100644 images.py create mode 100644 templates/images.html diff --git a/app.py b/app.py index 0420e7d..dca557e 100644 --- a/app.py +++ b/app.py @@ -47,7 +47,16 @@ def logout(): return response return render_template('login.html') -@app.route('/create/conf') +@app.route('/images') +def list_images(): + auth_token = request.cookies.get('auth_token') + if auth_token != "" or auth_token is not None: + if db.get_user_bytoken(auth_token) is None: + return redirect("/login") + images_all = db.get_images() + return render_template("images.html", images=images_all) + +@app.route('/create') def create_conf(): auth_token = request.cookies.get('auth_token') if auth_token != "" or auth_token is not None: diff --git a/configs/create.sh b/configs/create.sh index f1977d0..bfbfb7d 100755 --- a/configs/create.sh +++ b/configs/create.sh @@ -82,13 +82,11 @@ fi mkdir /tmp/output/vpn/scripts cat < /tmp/output/vpn/scripts/starttap.sh - #!/bin/sh ifconfig uvpnT2 $ip netmask 255.255.255.0 up EOF cat < /tmp/output/vpn/scripts/arpinggw.sh - #!/bin/sh ip -s -s neigh flush all dev uvpnT2 EOF diff --git a/db.py b/db.py index 70d79f8..f5b9ef1 100644 --- a/db.py +++ b/db.py @@ -2,6 +2,7 @@ import psycopg2 import config import utils import machines +import images def connect(): global cur, conn @@ -172,6 +173,21 @@ def get_machines(): return machinesall except: return None + + +def get_images(): + connect() + with get_cur() as cur: + cur.execute(""" + SELECT id, token, image_name FROM image""") + try: + images_all = images.ImageManager() + for row in cur.fetchall(): + image = images.Image(id = row[0], token=row[1], name=row[2]) + images_all.add_image(image) + return images_all + except: + return None def get_image_allocation_all_id(): connect() diff --git a/images.py b/images.py new file mode 100644 index 0000000..1462a2b --- /dev/null +++ b/images.py @@ -0,0 +1,21 @@ +class Image: + def __init__(self, id, token, name): + self.id = id + self.name = name + self.token = token + +class ImageManager: + def __init__(self): + self.images = [] + + def add_image(self, machine): + self.images.append(machine) + + def remove_image(self, machine): + self.images.remove(machine) + + def get_image_by_token(self, token): + for image in self.images: + if image.token == token: + return image + return None diff --git a/machines.py b/machines.py index 5f799b2..332b39a 100644 --- a/machines.py +++ b/machines.py @@ -7,11 +7,6 @@ class Machine: 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 VPN: {self.ipvpn}\nIP local: {self.iplocal}\nUsername: {self.username}\nPassword: {self.password}" - class MachineManager: def __init__(self): self.machines = [] @@ -27,9 +22,3 @@ class MachineManager: if machine.name == name: return machine return None - - def __str__(self): - result = "" - for machine in self.machines: - result += str(machine) + "\n\n" - return result diff --git a/templates/base.html b/templates/base.html index d63baba..38782c3 100644 --- a/templates/base.html +++ b/templates/base.html @@ -20,7 +20,10 @@ Lista maszyn +