round26: Ping vor Portscan, Liste neuer Dienste, Suchmaschinen-Integration (OpenSearch), API-Scanner

This commit is contained in:
2026-07-24 02:21:58 +02:00
parent 458f58af6f
commit 0fc063b2a2
17 changed files with 507 additions and 4 deletions

View File

@@ -0,0 +1,57 @@
import type { FastifyInstance } from "fastify";
import * as serviceRepo from "../db/repositories/services.js";
import * as apiRepo from "../db/repositories/apis.js";
import * as logRepo from "../db/repositories/logs.js";
import { detectApis } from "../scanner/apiDetector.js";
/**
* API-Scanner: eigener, von den Geräte-/FritzBox-Scannern komplett
* unabhängiger manueller Scan (siehe Scanner-Seite) - durchsucht bereits
* bekannte Dienste nach üblichen API-Pfaden (siehe scanner/apiDetector.ts)
* und speichert die Funde. Läuft NIE automatisch, nur auf Knopfdruck.
*/
export async function apiRoutes(app: FastifyInstance): Promise<void> {
app.get("/api/detected-apis", async () => {
return apiRepo.listDetectedApis();
});
app.post("/api/scan/apis", async () => {
const services = serviceRepo.listServices();
let servicesWithApi = 0;
let totalFound = 0;
for (const service of services) {
const found = await detectApis(service.url);
if (found.length > 0) {
apiRepo.replaceApisForService(service.id, found);
servicesWithApi++;
totalFound += found.length;
} else {
apiRepo.deleteApisForService(service.id);
}
}
logRepo.logScan({
type: "api",
targetId: null,
level: "info",
message: `API-Scan: ${services.length} Dienst(e) geprüft, bei ${servicesWithApi} Dienst(en) ${totalFound} API-Endpunkt(e) gefunden.`,
});
return { checked: services.length, servicesWithApi, totalFound };
});
app.post("/api/scan/apis/:serviceId", async (request, reply) => {
const { serviceId } = request.params as { serviceId: string };
const service = serviceRepo.getService(serviceId);
if (!service) {
return reply.code(404).send({ error: "Dienst nicht gefunden" });
}
const found = await detectApis(service.url);
const saved = found.length > 0 ? apiRepo.replaceApisForService(service.id, found) : [];
if (found.length === 0) apiRepo.deleteApisForService(service.id);
return { serviceId, apis: saved };
});
}

View File

@@ -147,6 +147,7 @@ export async function scanRoutes(app: FastifyInstance): Promise<void> {
created,
updated,
services: results.map((r) => r.service),
newServices: results.filter((r) => r.created).map((r) => r.service),
staleServices,
nameChanges,
deviceNameSuggestion,