drop IPv6 prefix for IPv4 addrs

This commit is contained in:
2026-04-02 19:20:13 +02:00
parent 22d750e3ab
commit 596a810681

View File

@@ -5,6 +5,7 @@ import { createNodeWebSocket } from '@hono/node-ws';
import RotRouter from './RotRouter.js'; import RotRouter from './RotRouter.js';
import N1mmServer from './N1mmServer.js'; import N1mmServer from './N1mmServer.js';
import WebsocketManager from './WebsocketManager.js'; import WebsocketManager from './WebsocketManager.js';
import { getConnInfo } from '@hono/node-server/conninfo';
const router = new RotRouter(); const router = new RotRouter();
@@ -37,7 +38,8 @@ app.post('/turn/:label', async (c) => {
const body = await c.req.parseBody(); const body = await c.req.parseBody();
const az = Number(body['ROT']); const az = Number(body['ROT']);
if (isNaN(az)) return c.text('Invalid azimuth', 400); if (isNaN(az)) return c.text('Invalid azimuth', 400);
const sourceIp = c.req.header('x-forwarded-for') ?? c.req.header('x-real-ip') ?? 'unknown'; const rawIp = c.req.header('x-forwarded-for') ?? getConnInfo(c).remote.address ?? 'unknown';
const sourceIp = rawIp.startsWith('::ffff:') ? rawIp.slice(7) : rawIp;
const ok = router.turn(label, az, sourceIp); const ok = router.turn(label, az, sourceIp);
return ok ? c.text(`Turning ${label} to ${az}`) : c.text('Unknown rotator', 404); return ok ? c.text(`Turning ${label} to ${az}`) : c.text('Unknown rotator', 404);
}); });