wip website

This commit is contained in:
ramzcaca 2026-01-22 11:35:33 +01:00
parent 13e1f71432
commit 7f5a13694b
5 changed files with 73 additions and 22 deletions

Binary file not shown.

Binary file not shown.

39
app.py
View File

@ -8,15 +8,8 @@ from grabber import Grabber
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
ordi1 = Grabber()
@app.get("/ordi1", response_class=HTMLResponse)
async def read_item(request: Request):
return templates.TemplateResponse(
request=request, name="ordi.html", context={"ordi": ordi1}
)
@app.post("/endpoint")
async def receive_info(request: Request):
# Lire le body brut
@ -29,13 +22,31 @@ async def receive_info(request: Request):
except json.JSONDecodeError:
raise HTTPException(status_code=400, detail="Invalid JSON")
# Debug
print("Data grabbed :", data)
ordi1.hostname = data['HARDWARE']['hostname']
ordi1.mb_serial = data['HARDWARE']['mb_serial']
hw = data["HARDWARE"]
sw = data["SOFTWARE"]
print(f"Hostname is {ordi1.hostname}")
ordi1.host = hw["hostname"]
ordi1.cpu = hw["cpu_model"]
ordi1.cpu_id = hw["cpu_id"]
ordi1.cpu_cores_number = hw["cpu_cores"]
ordi1.cpu_threads_number = hw["cpu_threads"]
ordi1.cpu_frequency_min = hw["cpu_frequency_min"]
ordi1.cpu_frequency_cur = hw["cpu_frequency_cur"]
ordi1.cpu_frequency_max = hw["cpu_frequency_max"]
ordi1.os = sw["os"]
ordi1.arch = sw["arch"]
ordi1.desktop = sw["desktop_env"]
ordi1.wm = sw["window_manager"]
ordi1.kernel = sw["kernel"]
print(f"Hostname is {ordi1.host}")
print(f"Motherboard serial is {ordi1.mb_serial}")
return {"status": "ok"}
return {"status": "ok"}
@app.get("/ordi1") #page affichant les infos de l'ordi
async def show_info(request: Request):
return templates.TemplateResponse("item.html", {"request": request, "ordi": ordi1})

View File

@ -360,14 +360,6 @@ python_venv() {
source gbvenv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
if [ ! -d "./static" ]; then
echo "static folder doesn't exist, creating one..."
mkdir static
fi
if [ ! -d "./ordi1" ]; then
echo "1st computer folder doesn't exist, creating one..."
mkdir ordi1
fi
uvicorn app:app --reload --host 0.0.0.0 --port 8000
}

48
templates/item.html Normal file
View File

@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Informations Système</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
h1 { color: #333; }
.section { margin-bottom: 20px; border: 1px solid #ccc; padding: 10px; }
.section h2 { margin-top: 0; }
table { width: 100%; border-collapse: collapse; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background-color: #f2f2f2; }
</style>
</head>
<body>
<h1>Informations de l'Ordinateur</h1>
<div class="section">
<h2>[HARDWARE]</h2>
<table>
<tr><th>Propriété</th><th>Valeur</th></tr>
<tr><td>Hostname</td><td>{{ ordi.hostname }}</td></tr>
<tr><td>CPU</td><td>{{ ordi.cpu_model }}</td></tr>
<tr><td>ID CPU</td><td>{{ ordi.cpu_id }}</td></tr>
<tr><td>Nombre de Cœurs CPU</td><td>{{ ordi.cpu_cores }}</td></tr>
<tr><td>Nombre de Threads CPU</td><td>{{ ordi.cpu_threads }}</td></tr>
<tr><td>Fréquence Min CPU</td><td>{{ ordi.cpu_frequency_min }}</td></tr>
<tr><td>Fréquence Courante CPU</td><td>{{ ordi.cpu_frequency_cur }}</td></tr>
<tr><td>Fréquence Max CPU</td><td>{{ ordi.cpu_frequency_max }}</td></tr>
<tr><td>Nombre de slots de RAM</td><td>{{ ordi.ram_slots }}</td></tr>
</table>
</div>
<div class="section">
<h2>[SOFTWARE]</h2>
<table>
<tr><th>Propriété</th><th>Valeur</th></tr>
<tr><td>OS</td><td>{{ ordi.os }}</td></tr>
<tr><td>Architecture</td><td>{{ ordi.arch }}</td></tr>
<tr><td>Desktop</td><td>{{ ordi.desktop_env }}</td></tr>
<tr><td>Window Manager</td><td>{{ ordi.window_manager }}</td></tr>
<tr><td>Kernel</td><td>{{ ordi.kernel }}</td></tr>
</table>
</div>
</body>
</html>