finished up scan page, added the ability to add miners and them get listed in the miner list, and started adding the individual miner pages

This commit is contained in:
UpstreamData
2022-03-01 12:28:36 -07:00
parent 385943755d
commit 3558a1a6b1
3 changed files with 60 additions and 23 deletions

View File

@@ -1,4 +1,5 @@
import json
import os
import asyncio
import uvicorn
from fastapi import FastAPI
@@ -17,17 +18,43 @@ templates = Jinja2Templates(directory="templates")
@app.get("/")
def dashboard(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
return templates.TemplateResponse("index.html", {
"request": request,
"cur_miners": get_current_miner_list()
})
@app.get("/scan")
def scan(request: Request):
return templates.TemplateResponse("scan.html", {"request": request})
return templates.TemplateResponse("scan.html", {
"request": request,
"cur_miners": get_current_miner_list()
})
@app.get("/miner")
def miner(request: Request, miner_ip):
return get_miner
@app.get("/miner/{miner_ip}")
def get_miner(request: Request, miner_ip):
return miner_ip
def get_current_miner_list():
cur_miners = []
if os.path.exists(os.path.join(os.getcwd(), "miner_list.txt")):
with open(os.path.join(os.getcwd(), "miner_list.txt")) as file:
for line in file.readlines():
cur_miners.append(line.strip())
return cur_miners
@app.post("/scan/add_miners")
async def add_miners_scan(request: Request):
print(await request.json())
miners = await request.json()
with open("miner_list.txt", "a+") as file:
for miner in miners["miners"]:
file.write(miner + "\n")
return scan
@@ -56,6 +83,7 @@ async def websocket_scan(websocket: WebSocket):
async def do_websocket_scan(websocket: WebSocket, network_ip: str):
cur_miners = get_current_miner_list()
try:
if "/" in network_ip:
network_ip, network_subnet = network_ip.split("/")
@@ -65,7 +93,7 @@ async def do_websocket_scan(websocket: WebSocket, network_ip: str):
miner_generator = network.scan_network_generator()
miners = []
async for miner in miner_generator:
if miner:
if miner and str(miner) not in cur_miners:
miners.append(miner)
get_miner_genenerator = miner_factory.get_miner_generator(miners)

View File

@@ -130,3 +130,22 @@ main {
border-color: transparent;
box-shadow: 0 0 0 3px rgba(255, 255, 255, .25);
}
.btn-toggle-nav{
max-height: 300px;
-webkit-overflow-scrolling: touch;
}
/* Scrollbar */
.btn-toggle-nav::-webkit-scrollbar {
width: 5px;
}
.btn-toggle-nav::-webkit-scrollbar-track {
box-shadow: inset 0 0 5px grey;
border-radius: 10px;
}
.btn-toggle-nav::-webkit-scrollbar-thumb {
background-image: linear-gradient(180deg, #D0368A 0%, #708AD4 99%);
box-shadow: inset 2px 2px 5px 0 rgba(#fff, 0.5);
border-radius: 100px;
}

View File

@@ -70,25 +70,15 @@
Miners
</a>
<div class="collapse mt-1" id="miners-collapse" style="">
<ul class="btn-toggle-nav list-unstyled fw-normal pb-1 small">
<li>
<a href="#" class="text-white rounded">
<svg class="bi me-2 mt-1" width="16" height="16"><use xlink:href="#miner"></use></svg>
192.168.1.1
</a>
</li>
<li>
<a href="#" class="text-white rounded">
<svg class="bi me-2 mt-1" width="16" height="16"><use xlink:href="#miner"></use></svg>
192.168.1.2
</a>
</li>
<li>
<a href="#" class="text-white rounded">
<svg class="bi me-2 mt-1" width="16" height="16"><use xlink:href="#miner"></use></svg>
192.168.1.3
</a>
</li>
<ul class="btn-toggle-nav overflow-auto list-unstyled fw-normal pb-1 small">
{% for miner in cur_miners %}
<li>
<a href="{{url_for('miner')}}/{{miner}}" class="text-white rounded">
<svg class="bi me-2 mt-1" width="16" height="16"><use xlink:href="#miner"></use></svg>
{{miner}}
</a>
</li>
{% endfor %}
</ul>
</div>
</li>