fix some bugs in web monitor
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
import os
|
import os
|
||||||
import ipaddress
|
import ipaddress
|
||||||
|
|
||||||
|
dir_path = "\\".join(os.path.dirname(os.path.realpath(__file__)).split("\\")[:-1])
|
||||||
|
|
||||||
|
|
||||||
def get_current_miner_list():
|
def get_current_miner_list():
|
||||||
cur_miners = []
|
cur_miners = []
|
||||||
if os.path.exists(os.path.join(os.getcwd(), "miner_list.txt")):
|
if os.path.exists(os.path.join(dir_path, "miner_list.txt")):
|
||||||
with open(os.path.join(os.getcwd(), "miner_list.txt")) as file:
|
with open(os.path.join(dir_path, "miner_list.txt")) as file:
|
||||||
for line in file.readlines():
|
for line in file.readlines():
|
||||||
cur_miners.append(line.strip())
|
cur_miners.append(line.strip())
|
||||||
cur_miners = sorted(cur_miners, key=lambda x: ipaddress.ip_address(x))
|
cur_miners = sorted(cur_miners, key=lambda x: ipaddress.ip_address(x))
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ from tools.web_monitor.func import get_current_miner_list
|
|||||||
|
|
||||||
from .ws import router as ws_router
|
from .ws import router as ws_router
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
dir_path = "\\".join(os.path.dirname(os.path.realpath(__file__)).split("\\")[:-1])
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
router.include_router(ws_router)
|
router.include_router(ws_router)
|
||||||
|
|
||||||
@@ -19,7 +23,7 @@ def scan(request: Request):
|
|||||||
@router.post("/add_miners")
|
@router.post("/add_miners")
|
||||||
async def add_miners_scan(request: Request):
|
async def add_miners_scan(request: Request):
|
||||||
miners = await request.json()
|
miners = await request.json()
|
||||||
with open("miner_list.txt", "a+") as file:
|
with open(os.path.join(dir_path, "miner_list.txt"), "a+") as file:
|
||||||
for miner_ip in miners["miners"]:
|
for miner_ip in miners["miners"]:
|
||||||
file.write(miner_ip + "\n")
|
file.write(miner_ip + "\n")
|
||||||
return scan
|
return scan
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
window.post = function(url, data) {
|
window.post = function(url, data) {
|
||||||
return fetch(url, {method: "POST", headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data)});
|
return fetch(url, {method: "POST", headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data)});
|
||||||
}
|
}
|
||||||
var ws = new WebSocket("ws://{{request.url.hostname}}:{{request.url.port}}/scan/ws");
|
var ws = new WebSocket("ws://{{request.url.hostname}}:{% if request.port %}{{request.url.port}}{% else %}80{% endif %}/scan/ws");
|
||||||
ws.onmessage = function(event) {
|
ws.onmessage = function(event) {
|
||||||
if (event.data == "Done") {
|
if (event.data == "Done") {
|
||||||
document.getElementById("scanButton").innerHTML = "Scan"
|
document.getElementById("scanButton").innerHTML = "Scan"
|
||||||
|
|||||||
Reference in New Issue
Block a user