feat: status page + maintenance

This commit is contained in:
mco-system 2023-05-27 14:25:10 +11:00
parent a7a52e7d4c
commit 614c16750d
6 changed files with 144 additions and 0 deletions

13
maintenance/reboot.py Normal file
View File

@ -0,0 +1,13 @@
#!/usr/bin/python3
import docker
client = docker.from_env()
for container in client.containers.list():
if container.name == "thsf":
print("[+] Rebooting container<br>")
print(" '-> Stopping container<br>")
container.stop()
print(" '-> Starting container<br>")
container.start()
print("[\o/] Container restarted<br>")

View File

@ -0,0 +1,13 @@
function reboot() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("logs").innerHTML = this.responseText;
}
};
xhttp.open("GET", "https://www.thsf.net/maintenance/reboot.py", true);
xhttp.send();
setTimeout(function () {
document.location="https://www.thsf.net/maintenance/status.py"}, 5000
);
}

19
maintenance/status.py Normal file
View File

@ -0,0 +1,19 @@
#!/usr/bin/python3
import docker
import jinja2
base_path = "/var/www/www.thsf.net/thsf.net/maintenance/templates"
status_template = "status.html"
env = jinja2.Environment(loader=jinja2.FileSystemLoader(base_path),
autoescape=True)
template = env.get_template(status_template)
client = docker.from_env()
for container in client.containers.list():
if container.name == "thsf":
cont = dict()
cont["name"] = container.name
cont["status"] = container.status
cont["log"] = container.logs().decode('utf-8').replace('\n', '<br>')
print(template.render(containers=[container]))

View File

@ -0,0 +1,59 @@
.body {
}
.page_wrapper {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
align-content: center;
text-align: center;
padding-bottom: 5em;
background-color: red;
}
.center_wrapper {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
background-color: blue;
}
.container_list {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
background-color: yellow;
}
.table_headers, .line {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
background-color: green;
}
.header, .status {
font-weight: bold;
border-width: 1px;
border-style: solid;
background-color: violet;
}
.table_content {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
background-color: cyan;
}
.status {
font-weight: normal;
}
.container_log {
}
.button {
font-weight: bold;
}

View File

@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang='zxx'>
<head>
<title>THSF 2023: Status page</title>
<meta name="viewport" content="initial-scale=1.0">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script src="/maintenance/scripts/maintenance.js"></script>
<link rel="stylesheet"
href="/maintenance/style/maintenance.css">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body>
<div class="page_wrapper">
<div class="center_wrapper">
<div class="container_list">
<div class="table_headers">
<div class="header">Name</div>
<div class="header">Status</div>
<div class="header">Action</div>
</div>
<div class="table_content">
{% for container in containers %}
<div class="line">
<div class="status">{{ container.name }}</div>
<div class="status">{{ container.status }}</div>
<div class="status">
<i class="button fa-regular fa-recycle" onclick=""></i>
</div>
</div>
<div class="container_log" id="logs">
{{ container.logs }}
</div>
{% endfor %}
</div>
</div>
</div>
</div>
</body>
</html>

BIN
resources/thsf_2023.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB