dodanie kolumny z ip po sieci lokalnej
This commit is contained in:
parent
8c87e36370
commit
407bb21168
2
app.py
2
app.py
@ -189,7 +189,7 @@ def add_ip():
|
|||||||
ip = request.form['ip']
|
ip = request.form['ip']
|
||||||
except:
|
except:
|
||||||
return jsonify(message="400")
|
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")
|
return jsonify(message="200")
|
||||||
else:
|
else:
|
||||||
return jsonify(message="400")
|
return jsonify(message="400")
|
||||||
|
17
db.py
17
db.py
@ -50,7 +50,8 @@ def connect():
|
|||||||
image_id INTEGER NOT NULL REFERENCES image(id),
|
image_id INTEGER NOT NULL REFERENCES image(id),
|
||||||
allocation_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
allocation_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
last_access_time TIMESTAMP,
|
last_access_time TIMESTAMP,
|
||||||
client_ip INET
|
client_ip_local INET,
|
||||||
|
client_ip_vpn INET
|
||||||
);""")
|
);""")
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
@ -148,13 +149,13 @@ def get_machines():
|
|||||||
connect()
|
connect()
|
||||||
with get_cur() as cur:
|
with get_cur() as cur:
|
||||||
cur.execute("""
|
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:
|
try:
|
||||||
machinesall = machines.MachineManager()
|
machinesall = machines.MachineManager()
|
||||||
for row in cur.fetchall():
|
for row in cur.fetchall():
|
||||||
token = get_one("SELECT token FROM image WHERE id = %s", row[0])
|
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])
|
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)
|
machinesall.add_machine(machine)
|
||||||
return machinesall
|
return machinesall
|
||||||
except:
|
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)
|
return get_one("SELECT last_access_time FROM image_allocation WHERE id = %s", id_image)
|
||||||
|
|
||||||
|
|
||||||
def get_image_allocation_clientip_id(id):
|
def get_image_allocation_clientip_id_vpn(id):
|
||||||
return get_one("SELECT client_ip FROM image_allocation WHERE id = %s", id)
|
return get_one("SELECT client_ip_vpn FROM image_allocation WHERE id = %s", id)
|
||||||
|
|
||||||
|
|
||||||
def set_image_allocation(token, client_ip):
|
def set_image_allocation(token, client_ip):
|
||||||
@ -225,7 +226,7 @@ def set_image_allocation(token, client_ip):
|
|||||||
connect()
|
connect()
|
||||||
with get_cur() as cur:
|
with get_cur() as cur:
|
||||||
cur.execute("""
|
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)
|
VALUES (%s, %s, CURRENT_TIMESTAMP)
|
||||||
""", (id_image, client_ip,))
|
""", (id_image, client_ip,))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
@ -271,14 +272,14 @@ def update_image_allocation_time(id):
|
|||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def update_image_allocation_ip(token, ip):
|
def update_image_allocation_ip_vpn(token, ip):
|
||||||
image_id = get_conf_id(token)
|
image_id = get_conf_id(token)
|
||||||
if image_id is None:
|
if image_id is None:
|
||||||
return None
|
return None
|
||||||
connect()
|
connect()
|
||||||
with get_cur() as cur:
|
with get_cur() as cur:
|
||||||
cur.execute("""
|
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,))
|
""", (ip, image_id,))
|
||||||
try:
|
try:
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
26
machines.py
26
machines.py
@ -1,14 +1,16 @@
|
|||||||
class Machine:
|
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.name = name
|
||||||
self.image_name = image_name
|
self.image_name = image_name
|
||||||
self.start_time = start_time
|
self.start_time = start_time
|
||||||
self.ip = ip
|
self.ipvpn = ipvpn
|
||||||
|
self.iplocal = iplocal
|
||||||
self.username = username
|
self.username = username
|
||||||
self.password = password
|
self.password = password
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
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:
|
class MachineManager:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -31,21 +33,3 @@ class MachineManager:
|
|||||||
for machine in self.machines:
|
for machine in self.machines:
|
||||||
result += str(machine) + "\n\n"
|
result += str(machine) + "\n\n"
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def to_html_table(self):
|
|
||||||
html = "<table>"
|
|
||||||
html += """<th>Nazwa maszyny</th>
|
|
||||||
<th>Obraz</th>
|
|
||||||
<th>Czas uruchomienia</th>
|
|
||||||
<th>IP uVPN</th>
|
|
||||||
<th></th>"""
|
|
||||||
for machine in self.machines:
|
|
||||||
html += f"""<tr>
|
|
||||||
<td>{ machine.name }</td>
|
|
||||||
<td>{ machine.image_name }</td>
|
|
||||||
<td>{ machine.start_time }</td>
|
|
||||||
<td>{ machine.ip }</td>
|
|
||||||
<td><button onclick="ssh('{ machine.ip, machine.username, machine.password }')">SSH</button></td>
|
|
||||||
</tr>"""
|
|
||||||
html += "</table>"
|
|
||||||
return html
|
|
||||||
|
@ -67,6 +67,7 @@
|
|||||||
<th>Obraz</th>
|
<th>Obraz</th>
|
||||||
<th>Czas uruchomienia</th>
|
<th>Czas uruchomienia</th>
|
||||||
<th>IP uVPN</th>
|
<th>IP uVPN</th>
|
||||||
|
<th>IP lokalne</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -76,7 +77,8 @@
|
|||||||
<td>{{ machine.name }}</td>
|
<td>{{ machine.name }}</td>
|
||||||
<td>{{ machine.image_name }}</td>
|
<td>{{ machine.image_name }}</td>
|
||||||
<td>{{ machine.start_time }}</td>
|
<td>{{ machine.start_time }}</td>
|
||||||
<td>{{ machine.ip }}</td>
|
<td>{{ machine.ipvpn }}</td>
|
||||||
|
<td>{{ machine.iplocal }}</td>
|
||||||
<td><button onclick="ssh('{{ machine.ip }}', '{{ machine.username }}', '{{ machine.password }}')">SSH</button></td>
|
<td><button onclick="ssh('{{ machine.ip }}', '{{ machine.username }}', '{{ machine.password }}')">SSH</button></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
2
utils.py
2
utils.py
@ -42,7 +42,7 @@ def check_allocation_thread_function():
|
|||||||
while True:
|
while True:
|
||||||
ids = db.get_image_allocation_all()
|
ids = db.get_image_allocation_all()
|
||||||
for x in ids:
|
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 = PingThread(ip, x[0])
|
||||||
ping_thread.start()
|
ping_thread.start()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user