1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
<meta name=viewport content='width=device-width, initial-scale=1.0'>
<meta charset=utf-8 />
<style>
table, td, tr, th {
border: 1px solid red;
}
</style>
<title>napad/nadzor.py</title>
<h1>napad/nadzor.py</h1>
<table>
<tr>
<th>
ime podatka
</th>
<th>
vrednost
</th>
</tr>
<tr><td>čas zadnje ACCEPTED zastavice</td><td id=lastaccepteddate></td></tr>
<tr><td>neposlanih zastavic</td><td id=notsentcount></td></tr>
</table>
<div id=groupbymsg></div>
<label for=customquery>
<h3>custom query</h3>
</label>
<textarea cols=80 id=customquery placeholder="select * from flags limit 10">select flag,date,msg from flags limit 10</textarea>
<div id=customqueryres></div>
<script>
function htmltablefromquery (rows) {
let table = document.createElement("table");
for (let i = 0; i < rows.length; i++) {
let tr = document.createElement("tr");
for (let j = 0; j < rows[i].length; j++) {
let td = document.createElement("td");
td.innerText = rows[i][j];
tr.appendChild(td);
}
let td = document.createElement("td");
td.innerText = rows[i][1];
table.appendChild(tr);
}
return table;
}
async function refreshview () {
fetch("sql", {"method": "post", "body": "select count(flag) from flags where sent=0"}).then((r) => {r.json().then((t)=>{notsentcount.innerText = t[0][0]})});
let msgskip = 6; // 36 v dejanski igri
fetch("sql", {"method": "post", "body": "select substr(msg, " + msgskip + "),count(substr(msg, " + msgskip + ")) from flags group by substr(msg, " + msgskip + ")"}).then((r) => {r.json().then((rows)=>{
groupbymsg.innerHTML = "";
groupbymsg.appendChild(htmltablefromquery(rows));
})});
fetch("sql", {"method": "post", "body": "select submitted from flags where status='ACCEPTED' order by submitted desc limit 1"}).then((r) => {r.json().then((t)=>{lastaccepteddate.innerText = t[0][0]})});
fetch("sql", {"method": "post", "body": customquery.value}).then((r) => {r.json().then((rows)=>{
customqueryres.innerHTML = "";
customqueryres.appendChild(htmltablefromquery(rows));
})});
}
setInterval(refreshview, 5555);
</script>
|