dodanie listy obrazów i poprawa buga
This commit is contained in:
parent
8d2455724e
commit
26275a0674
11
app.py
11
app.py
@ -47,7 +47,16 @@ def logout():
|
|||||||
return response
|
return response
|
||||||
return render_template('login.html')
|
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():
|
def create_conf():
|
||||||
auth_token = request.cookies.get('auth_token')
|
auth_token = request.cookies.get('auth_token')
|
||||||
if auth_token != "" or auth_token is not None:
|
if auth_token != "" or auth_token is not None:
|
||||||
|
@ -82,13 +82,11 @@ fi
|
|||||||
|
|
||||||
mkdir /tmp/output/vpn/scripts
|
mkdir /tmp/output/vpn/scripts
|
||||||
cat <<EOF> /tmp/output/vpn/scripts/starttap.sh
|
cat <<EOF> /tmp/output/vpn/scripts/starttap.sh
|
||||||
|
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
ifconfig uvpnT2 $ip netmask 255.255.255.0 up
|
ifconfig uvpnT2 $ip netmask 255.255.255.0 up
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
cat <<EOF> /tmp/output/vpn/scripts/arpinggw.sh
|
cat <<EOF> /tmp/output/vpn/scripts/arpinggw.sh
|
||||||
|
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
ip -s -s neigh flush all dev uvpnT2
|
ip -s -s neigh flush all dev uvpnT2
|
||||||
EOF
|
EOF
|
||||||
|
16
db.py
16
db.py
@ -2,6 +2,7 @@ import psycopg2
|
|||||||
import config
|
import config
|
||||||
import utils
|
import utils
|
||||||
import machines
|
import machines
|
||||||
|
import images
|
||||||
|
|
||||||
def connect():
|
def connect():
|
||||||
global cur, conn
|
global cur, conn
|
||||||
@ -172,6 +173,21 @@ def get_machines():
|
|||||||
return machinesall
|
return machinesall
|
||||||
except:
|
except:
|
||||||
return None
|
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():
|
def get_image_allocation_all_id():
|
||||||
connect()
|
connect()
|
||||||
|
21
images.py
Normal file
21
images.py
Normal file
@ -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
|
11
machines.py
11
machines.py
@ -7,11 +7,6 @@ class Machine:
|
|||||||
self.iplocal = iplocal
|
self.iplocal = iplocal
|
||||||
self.username = username
|
self.username = username
|
||||||
self.password = password
|
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:
|
class MachineManager:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.machines = []
|
self.machines = []
|
||||||
@ -27,9 +22,3 @@ class MachineManager:
|
|||||||
if machine.name == name:
|
if machine.name == name:
|
||||||
return machine
|
return machine
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
result = ""
|
|
||||||
for machine in self.machines:
|
|
||||||
result += str(machine) + "\n\n"
|
|
||||||
return result
|
|
||||||
|
@ -20,7 +20,10 @@
|
|||||||
<a class="nav-link" href="/">Lista maszyn</a>
|
<a class="nav-link" href="/">Lista maszyn</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="/create/conf">Tworzenie obrazu</a>
|
<a class="nav-link" href="/create">Tworzenie obrazu</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/images">Lista obrazów</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="/logout">Wyloguj</a>
|
<a class="nav-link" href="/logout">Wyloguj</a>
|
||||||
|
33
templates/images.html
Normal file
33
templates/images.html
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}Obrazy{% endblock %}
|
||||||
|
{% block style %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<h1 class="my-4">Lista obrazów</h1>
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Token</th>
|
||||||
|
<th>Nazwa</th>
|
||||||
|
<th>Usuń</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for image in images %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ image.token }}</td>
|
||||||
|
<td>{{ image.name }}</td>
|
||||||
|
<td>
|
||||||
|
<form method="post" action="/api/delete_image/{{ image.id }}">
|
||||||
|
<button type="submit" class="btn btn-danger">Usuń</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user