Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +39 -36
templates/index.html
CHANGED
|
@@ -18,6 +18,9 @@ body {
|
|
| 18 |
padding:15px;
|
| 19 |
border-radius:10px;
|
| 20 |
margin-bottom:15px;
|
|
|
|
|
|
|
|
|
|
| 21 |
}
|
| 22 |
.up { color:#22c55e }
|
| 23 |
.down { color:#ef4444 }
|
|
@@ -37,15 +40,19 @@ button {
|
|
| 37 |
background:#2563eb;
|
| 38 |
color:white;
|
| 39 |
}
|
| 40 |
-
canvas {
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
}
|
| 43 |
</style>
|
| 44 |
</head>
|
| 45 |
|
| 46 |
<body>
|
| 47 |
|
| 48 |
-
<h2>
|
| 49 |
|
| 50 |
<div class="card">
|
| 51 |
<input id="name" placeholder="Site name">
|
|
@@ -65,26 +72,29 @@ function load() {
|
|
| 65 |
fetch("/data")
|
| 66 |
.then(r => r.json())
|
| 67 |
.then(data => {
|
|
|
|
| 68 |
const box = document.getElementById("sites");
|
| 69 |
box.innerHTML = "";
|
| 70 |
|
| 71 |
-
data.forEach(s => {
|
| 72 |
const cls = s.status === "UP" ? "up" : "down";
|
| 73 |
-
|
| 74 |
box.innerHTML += `
|
| 75 |
<div class="card">
|
| 76 |
-
<
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
| 84 |
</div>`;
|
| 85 |
});
|
| 86 |
|
| 87 |
-
data.forEach(drawChart);
|
| 88 |
});
|
| 89 |
}
|
| 90 |
|
|
@@ -109,12 +119,14 @@ function drawChart(site) {
|
|
| 109 |
{
|
| 110 |
label: "Uptime %",
|
| 111 |
data: uptime,
|
|
|
|
| 112 |
yAxisID: "y1",
|
| 113 |
tension: 0.4
|
| 114 |
},
|
| 115 |
{
|
| 116 |
label: "Ping (ms)",
|
| 117 |
data: ping,
|
|
|
|
| 118 |
yAxisID: "y2",
|
| 119 |
tension: 0.4
|
| 120 |
}
|
|
@@ -122,17 +134,8 @@ function drawChart(site) {
|
|
| 122 |
},
|
| 123 |
options: {
|
| 124 |
scales: {
|
| 125 |
-
y1: {
|
| 126 |
-
|
| 127 |
-
position: "left",
|
| 128 |
-
min: 0,
|
| 129 |
-
max: 100
|
| 130 |
-
},
|
| 131 |
-
y2: {
|
| 132 |
-
type: "linear",
|
| 133 |
-
position: "right",
|
| 134 |
-
min: 0
|
| 135 |
-
}
|
| 136 |
}
|
| 137 |
}
|
| 138 |
});
|
|
@@ -145,25 +148,25 @@ function save() {
|
|
| 145 |
);
|
| 146 |
|
| 147 |
fetch(editId ? `/edit/${editId}` : "/add", {
|
| 148 |
-
method:
|
| 149 |
-
body:
|
| 150 |
}).then(r => {
|
| 151 |
-
if
|
| 152 |
-
editId
|
| 153 |
-
document.querySelectorAll("input").forEach(i
|
| 154 |
load();
|
| 155 |
});
|
| 156 |
}
|
| 157 |
|
| 158 |
-
function edit(id,name,url,intv)
|
| 159 |
-
editId
|
| 160 |
-
document.getElementById("name").value
|
| 161 |
-
document.getElementById("url").value
|
| 162 |
-
document.getElementById("interval").value
|
| 163 |
}
|
| 164 |
|
| 165 |
load();
|
| 166 |
-
setInterval(load,
|
| 167 |
</script>
|
| 168 |
|
| 169 |
</body>
|
|
|
|
| 18 |
padding:15px;
|
| 19 |
border-radius:10px;
|
| 20 |
margin-bottom:15px;
|
| 21 |
+
display:flex;
|
| 22 |
+
align-items:center;
|
| 23 |
+
gap:10px;
|
| 24 |
}
|
| 25 |
.up { color:#22c55e }
|
| 26 |
.down { color:#ef4444 }
|
|
|
|
| 40 |
background:#2563eb;
|
| 41 |
color:white;
|
| 42 |
}
|
| 43 |
+
canvas { margin-top:10px; }
|
| 44 |
+
.favicon {
|
| 45 |
+
width:32px;
|
| 46 |
+
height:32px;
|
| 47 |
+
border-radius:6px;
|
| 48 |
+
border:1px solid #1e293b;
|
| 49 |
}
|
| 50 |
</style>
|
| 51 |
</head>
|
| 52 |
|
| 53 |
<body>
|
| 54 |
|
| 55 |
+
<h2>🕒 Total Uptime: <span id="total_uptime">0d 0h 0m 0s</span></h2>
|
| 56 |
|
| 57 |
<div class="card">
|
| 58 |
<input id="name" placeholder="Site name">
|
|
|
|
| 72 |
fetch("/data")
|
| 73 |
.then(r => r.json())
|
| 74 |
.then(data => {
|
| 75 |
+
document.getElementById("total_uptime").innerText = data.total_uptime;
|
| 76 |
const box = document.getElementById("sites");
|
| 77 |
box.innerHTML = "";
|
| 78 |
|
| 79 |
+
data.sites.forEach(s => {
|
| 80 |
const cls = s.status === "UP" ? "up" : "down";
|
|
|
|
| 81 |
box.innerHTML += `
|
| 82 |
<div class="card">
|
| 83 |
+
<img class="favicon" src="${s.favicon ?? ''}" onerror="this.style.display='none'">
|
| 84 |
+
<div style="flex:1">
|
| 85 |
+
<b>${s.name}</b><br>
|
| 86 |
+
${s.url}<br>
|
| 87 |
+
Status: <b class="${cls}">${s.status}</b><br>
|
| 88 |
+
Uptime: ${s.uptime_percent}%<br>
|
| 89 |
+
Ping: ${s.last_ping ?? "-"} ms<br>
|
| 90 |
+
Next check: ${s.remaining}s
|
| 91 |
+
<canvas id="c${s.id}" height="100"></canvas>
|
| 92 |
+
<button onclick="edit(${s.id},'${s.name}','${s.url}',${s.interval})">Edit</button>
|
| 93 |
+
</div>
|
| 94 |
</div>`;
|
| 95 |
});
|
| 96 |
|
| 97 |
+
data.sites.forEach(drawChart);
|
| 98 |
});
|
| 99 |
}
|
| 100 |
|
|
|
|
| 119 |
{
|
| 120 |
label: "Uptime %",
|
| 121 |
data: uptime,
|
| 122 |
+
borderColor: "#22c55e",
|
| 123 |
yAxisID: "y1",
|
| 124 |
tension: 0.4
|
| 125 |
},
|
| 126 |
{
|
| 127 |
label: "Ping (ms)",
|
| 128 |
data: ping,
|
| 129 |
+
borderColor: "#facc15",
|
| 130 |
yAxisID: "y2",
|
| 131 |
tension: 0.4
|
| 132 |
}
|
|
|
|
| 134 |
},
|
| 135 |
options: {
|
| 136 |
scales: {
|
| 137 |
+
y1: { min:0, max:100, position:"left" },
|
| 138 |
+
y2: { min:0, position:"right" }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
}
|
| 140 |
}
|
| 141 |
});
|
|
|
|
| 148 |
);
|
| 149 |
|
| 150 |
fetch(editId ? `/edit/${editId}` : "/add", {
|
| 151 |
+
method:"POST",
|
| 152 |
+
body:f
|
| 153 |
}).then(r => {
|
| 154 |
+
if(r.status===401) alert("Wrong password");
|
| 155 |
+
editId=null;
|
| 156 |
+
document.querySelectorAll("input").forEach(i=>i.value="");
|
| 157 |
load();
|
| 158 |
});
|
| 159 |
}
|
| 160 |
|
| 161 |
+
function edit(id,name,url,intv){
|
| 162 |
+
editId=id;
|
| 163 |
+
document.getElementById("name").value=name;
|
| 164 |
+
document.getElementById("url").value=url;
|
| 165 |
+
document.getElementById("interval").value=intv;
|
| 166 |
}
|
| 167 |
|
| 168 |
load();
|
| 169 |
+
setInterval(load,5000);
|
| 170 |
</script>
|
| 171 |
|
| 172 |
</body>
|