c-router-emulator/www/fw.html

116 lines
2.9 KiB
HTML
Executable File

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="zifan">
<meta name="keywords" content="物联网">
<title>黑名单列表</title>
<style>
html,
body {
height: 100%;
margin: 0;
padding: 50px;
}
body {
display: flex;
flex-direction: column;
justify-content: space-between;
justify-items: center;
align-items: center;
}
.back {
background-color: rgba(41, 117, 117, 0.667);
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.5);
}
form {
padding: 10px;
}
</style>
</head>
<body>
<div>
<form class="blackfrom">
<label>ip地址:</label>
<input name="ipaddr" id="ipInputID">
<button type="button" onclick="add_ip()">添加</button>
<button type="button" id="del" onclick="del_ip()">删除</button>
</form>
<table class="balckTable back" width="250" align="center" border="1" cellspacing="0">
<thead>
<th>ip地址</th>
</thead>
<tbody id="blackTableBody" align="center">
</tbody>
</table>
</div>
<script>
function loadData() {
fetch("/cgi-bin/fw.cgi").then(resp => resp.json()).then(data => {
blackTableBody.innerText = "";
data.forEach(rowData => {
let tr = document.createElement("tr");
let td1 = document.createElement("td");
td1.innerText = rowData.ip;
tr.append(td1);
blackTableBody.append(tr);
});
})
}
window.onload = function () {
loadData();
}
function add_ip() {
let url = "/cgi-bin/send.cgi";
let data = {
"code": 0,
"ip": ipInputID.value.trim()
};
fetch(url, {
method: "post",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json;charset=utf-8"
}
}).then(resp => resp.json()).then(d => {
console.log(d);
loadData();
});
}
function del_ip() {
let url = "/cgi-bin/send.cgi";
let data = {
"code": 1,
"ip": ipInputID.value.trim()
};
fetch(url, {
method: "post",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json;charset=utf-8"
}
}).then(resp => resp.json()).then(d => {
console.log(d);
loadData();
});
}
</script>
</body>
</html>