Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +58 -123
templates/index.html
CHANGED
|
@@ -7,56 +7,25 @@
|
|
| 7 |
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
| 8 |
|
| 9 |
<style>
|
| 10 |
-
body {
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
}
|
| 16 |
-
.card {
|
| 17 |
-
background:#020617;
|
| 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 }
|
| 27 |
-
input,button {
|
| 28 |
-
width:100%;
|
| 29 |
-
padding:8px;
|
| 30 |
-
margin-top:6px;
|
| 31 |
-
border-radius:6px;
|
| 32 |
-
border:none;
|
| 33 |
-
}
|
| 34 |
-
input {
|
| 35 |
-
background:#020617;
|
| 36 |
-
color:white;
|
| 37 |
-
border:1px solid #1e293b;
|
| 38 |
-
}
|
| 39 |
-
button {
|
| 40 |
-
background:#2563eb;
|
| 41 |
-
color:white;
|
| 42 |
-
}
|
| 43 |
canvas { margin-top:10px; }
|
| 44 |
-
.
|
| 45 |
-
|
| 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">
|
| 59 |
<input id="url" placeholder="https://example.com">
|
|
|
|
| 60 |
<input id="interval" type="number" placeholder="Interval (seconds)">
|
| 61 |
<input id="password" type="password" placeholder="Admin password">
|
| 62 |
<button onclick="save()">Save</button>
|
|
@@ -65,109 +34,75 @@ canvas { margin-top:10px; }
|
|
| 65 |
<div id="sites"></div>
|
| 66 |
|
| 67 |
<script>
|
| 68 |
-
let editId
|
| 69 |
-
const charts
|
| 70 |
-
|
| 71 |
-
function load()
|
| 72 |
-
fetch("/data")
|
| 73 |
-
|
| 74 |
-
.
|
| 75 |
-
|
| 76 |
-
const
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
<
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 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 |
|
| 101 |
-
function drawChart(site)
|
| 102 |
-
const ctx
|
| 103 |
-
if
|
| 104 |
-
|
| 105 |
-
const
|
| 106 |
-
|
| 107 |
-
);
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
if (charts[site.id]) charts[site.id].destroy();
|
| 113 |
-
|
| 114 |
-
charts[site.id] = new Chart(ctx, {
|
| 115 |
-
type: "line",
|
| 116 |
-
data: {
|
| 117 |
labels,
|
| 118 |
-
datasets:
|
| 119 |
-
{
|
| 120 |
-
|
| 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 |
-
}
|
| 133 |
]
|
| 134 |
},
|
| 135 |
-
options:
|
| 136 |
-
scales:
|
| 137 |
-
y1:
|
| 138 |
-
y2:
|
| 139 |
}
|
| 140 |
}
|
| 141 |
});
|
| 142 |
}
|
| 143 |
|
| 144 |
-
function save()
|
| 145 |
-
const f
|
| 146 |
-
["name","url","interval","password"].forEach(i
|
| 147 |
-
|
| 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>
|
| 173 |
</html>
|
|
|
|
| 7 |
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
| 8 |
|
| 9 |
<style>
|
| 10 |
+
body { background:#0f172a; color:#e5e7eb; font-family:Arial; padding:20px; }
|
| 11 |
+
.card { background:#020617; padding:15px; border-radius:10px; margin-bottom:15px; }
|
| 12 |
+
.up { color:#22c55e } .down { color:#ef4444 }
|
| 13 |
+
input,button { width:100%; padding:8px; margin-top:6px; border-radius:6px; border:none; }
|
| 14 |
+
input { background:#020617; color:white; border:1px solid #1e293b; }
|
| 15 |
+
button { background:#2563eb; color:white; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
canvas { margin-top:10px; }
|
| 17 |
+
.img-box { width:100px; height:100px; overflow:hidden; margin:10px auto; border-radius:10px; background:#1e293b; display:flex; align-items:center; justify-content:center; }
|
| 18 |
+
.img-box img { width:100%; height:100%; object-fit:cover; }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</style>
|
| 20 |
</head>
|
| 21 |
|
| 22 |
<body>
|
| 23 |
+
<h2>📈 Uptime + Ping Monitor</h2>
|
|
|
|
| 24 |
|
| 25 |
<div class="card">
|
| 26 |
<input id="name" placeholder="Site name">
|
| 27 |
<input id="url" placeholder="https://example.com">
|
| 28 |
+
<input id="img" placeholder="Image URL (optional)">
|
| 29 |
<input id="interval" type="number" placeholder="Interval (seconds)">
|
| 30 |
<input id="password" type="password" placeholder="Admin password">
|
| 31 |
<button onclick="save()">Save</button>
|
|
|
|
| 34 |
<div id="sites"></div>
|
| 35 |
|
| 36 |
<script>
|
| 37 |
+
let editId=null;
|
| 38 |
+
const charts={};
|
| 39 |
+
|
| 40 |
+
function load(){
|
| 41 |
+
fetch("/data").then(r=>r.json()).then(data=>{
|
| 42 |
+
const box=document.getElementById("sites");
|
| 43 |
+
box.innerHTML="";
|
| 44 |
+
data.forEach(s=>{
|
| 45 |
+
const cls=s.status==="UP"?"up":"down";
|
| 46 |
+
const img_html = s.img ? `<div class="img-box"><img src="${s.img}"></div>`:"";
|
| 47 |
+
box.innerHTML+=`
|
| 48 |
+
<div class="card">
|
| 49 |
+
${img_html}
|
| 50 |
+
<b>${s.name}</b><br>${s.url}<br>
|
| 51 |
+
Status: <b class="${cls}">${s.status}</b><br>
|
| 52 |
+
Uptime: ${s.uptime_str}<br>
|
| 53 |
+
Uptime %: ${s.uptime_percent}%<br>
|
| 54 |
+
Ping: ${s.last_ping ?? "-"} ms<br>
|
| 55 |
+
Next check: ${s.remaining}s
|
| 56 |
+
<canvas id="c${s.id}" height="100"></canvas>
|
| 57 |
+
<button onclick="edit(${s.id},'${s.name}','${s.url}','${s.img}',${s.interval})">Edit</button>
|
| 58 |
+
</div>`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
});
|
| 60 |
+
data.forEach(drawChart);
|
| 61 |
+
});
|
| 62 |
}
|
| 63 |
|
| 64 |
+
function drawChart(site){
|
| 65 |
+
const ctx=document.getElementById("c"+site.id);
|
| 66 |
+
if(!ctx) return;
|
| 67 |
+
const labels = site.history.map(h=>new Date(h.time*1000).toLocaleTimeString());
|
| 68 |
+
const uptime = site.history.map(h=>h.uptime);
|
| 69 |
+
const ping = site.history.map(h=>h.ping);
|
| 70 |
+
if(charts[site.id]) charts[site.id].destroy();
|
| 71 |
+
charts[site.id]=new Chart(ctx,{
|
| 72 |
+
type:"line",
|
| 73 |
+
data:{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
labels,
|
| 75 |
+
datasets:[
|
| 76 |
+
{label:"Uptime %", data:uptime, yAxisID:"y1", borderColor:"#22c55e", tension:0.4},
|
| 77 |
+
{label:"Ping (ms)", data:ping, yAxisID:"y2", borderColor:"#facc15", tension:0.4}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
]
|
| 79 |
},
|
| 80 |
+
options:{
|
| 81 |
+
scales:{
|
| 82 |
+
y1:{type:"linear",position:"left",min:0,max:100},
|
| 83 |
+
y2:{type:"linear",position:"right",min:0}
|
| 84 |
}
|
| 85 |
}
|
| 86 |
});
|
| 87 |
}
|
| 88 |
|
| 89 |
+
function save(){
|
| 90 |
+
const f=new FormData();
|
| 91 |
+
["name","url","img","interval","password"].forEach(i=>f.append(i,document.getElementById(i).value));
|
| 92 |
+
fetch(editId?`/edit/${editId}`:"/add",{method:"POST",body:f})
|
| 93 |
+
.then(r=>{if(r.status===401)alert("Wrong password"); editId=null; document.querySelectorAll("input").forEach(i=>i.value=""); load();});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
}
|
| 95 |
|
| 96 |
+
function edit(id,name,url,img,intv){
|
| 97 |
editId=id;
|
| 98 |
document.getElementById("name").value=name;
|
| 99 |
document.getElementById("url").value=url;
|
| 100 |
+
document.getElementById("img").value=img;
|
| 101 |
document.getElementById("interval").value=intv;
|
| 102 |
}
|
| 103 |
|
| 104 |
load();
|
| 105 |
setInterval(load,5000);
|
| 106 |
</script>
|
|
|
|
| 107 |
</body>
|
| 108 |
</html>
|