mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 01:21:20 -04:00
no more ips in session data
This commit is contained in:
@@ -22,33 +22,10 @@ logger.info('Discord invite loaded:', discordInvite ? 'present' : 'not configure
|
|||||||
logger.info('Ko-fi link loaded:', kofiLink ? 'present' : 'not configured');
|
logger.info('Ko-fi link loaded:', kofiLink ? 'present' : 'not configured');
|
||||||
|
|
||||||
const ACTIVITY_SYNC_COOLDOWN_MS = 3000;
|
const ACTIVITY_SYNC_COOLDOWN_MS = 3000;
|
||||||
const ADMIN_ROLES = new Set(['admin', 'lockdown', 'lockdown-admin']);
|
|
||||||
let lastActivitySync = 0;
|
let lastActivitySync = 0;
|
||||||
let pendingActivitySync = null;
|
let pendingActivitySync = null;
|
||||||
|
|
||||||
function extractSocketIp(socket) {
|
function buildUserEntry(socket) {
|
||||||
if (!socket) return null;
|
|
||||||
const headers = socket.handshake?.headers || {};
|
|
||||||
const forwardedFor = headers['x-forwarded-for'];
|
|
||||||
if (typeof forwardedFor === 'string' && forwardedFor.trim()) {
|
|
||||||
return forwardedFor.split(',')[0].trim();
|
|
||||||
}
|
|
||||||
if (Array.isArray(forwardedFor) && forwardedFor.length) {
|
|
||||||
return String(forwardedFor[0]).trim();
|
|
||||||
}
|
|
||||||
const realIp = headers['x-real-ip'];
|
|
||||||
if (typeof realIp === 'string' && realIp.trim()) {
|
|
||||||
return realIp.trim();
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
socket.handshake?.address ||
|
|
||||||
socket.conn?.remoteAddress ||
|
|
||||||
socket.request?.connection?.remoteAddress ||
|
|
||||||
null
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildUserEntry(socket, includeIp = false) {
|
|
||||||
if (!socket) return null;
|
if (!socket) return null;
|
||||||
const role = getRole(socket);
|
const role = getRole(socket);
|
||||||
const assignment = assignmentService.describeAssignment(socket.id);
|
const assignment = assignmentService.describeAssignment(socket.id);
|
||||||
@@ -58,14 +35,12 @@ function buildUserEntry(socket, includeIp = false) {
|
|||||||
nickname: getNickname(socket) || null,
|
nickname: getNickname(socket) || null,
|
||||||
role,
|
role,
|
||||||
roverId: primaryRover || assignment?.roverId || null,
|
roverId: primaryRover || assignment?.roverId || null,
|
||||||
ip: includeIp ? extractSocketIp(socket) : null,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildSession(socket) {
|
function buildSession(socket) {
|
||||||
const includeIps = ADMIN_ROLES.has(getRole(socket));
|
|
||||||
const users = Array.from(io.sockets.sockets.values())
|
const users = Array.from(io.sockets.sockets.values())
|
||||||
.map((sock) => buildUserEntry(sock, includeIps))
|
.map((sock) => buildUserEntry(sock))
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
return {
|
return {
|
||||||
socketId: socket?.id || null,
|
socketId: socket?.id || null,
|
||||||
|
|||||||
@@ -17,16 +17,6 @@ export default function AdminPanel() {
|
|||||||
const currentGoal = session?.communityGoal?.text || '';
|
const currentGoal = session?.communityGoal?.text || '';
|
||||||
const goalUpdatedAt = session?.communityGoal?.updatedAt || null;
|
const goalUpdatedAt = session?.communityGoal?.updatedAt || null;
|
||||||
const [goalDraft, setGoalDraft] = useState(currentGoal);
|
const [goalDraft, setGoalDraft] = useState(currentGoal);
|
||||||
const socketIps = useMemo(() => {
|
|
||||||
const users = session?.users ?? [];
|
|
||||||
return users
|
|
||||||
.map((user) => ({
|
|
||||||
socketId: user.socketId,
|
|
||||||
label: user.nickname || user.socketId?.slice(0, 6) || 'unknown',
|
|
||||||
ip: user.ip || null,
|
|
||||||
}))
|
|
||||||
.filter((entry) => entry.ip);
|
|
||||||
}, [session?.users]);
|
|
||||||
|
|
||||||
const isAdmin =
|
const isAdmin =
|
||||||
session?.role === 'admin' ||
|
session?.role === 'admin' ||
|
||||||
@@ -145,7 +135,6 @@ export default function AdminPanel() {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<ReplaySnapshotHealth health={health} />
|
<ReplaySnapshotHealth health={health} />
|
||||||
<WebsocketIpPanel entries={socketIps} />
|
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -211,30 +200,3 @@ function ReplaySnapshotHealth({ health }) {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function WebsocketIpPanel({ entries }) {
|
|
||||||
const total = entries?.length || 0;
|
|
||||||
const uniqueCount = useMemo(() => new Set((entries || []).map((entry) => entry.ip)).size, [entries]);
|
|
||||||
return (
|
|
||||||
<div className="space-y-0.5">
|
|
||||||
<div className="flex items-center justify-between text-xs text-slate-400">
|
|
||||||
<span className="panel-muted text-xs uppercase">Websocket IPs</span>
|
|
||||||
<span className="text-slate-500">
|
|
||||||
{uniqueCount} unique / {total} sockets
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div className="surface space-y-0.5 text-xs text-slate-200">
|
|
||||||
{total === 0 ? (
|
|
||||||
<p className="text-xs text-slate-500">No IPs reported yet.</p>
|
|
||||||
) : (
|
|
||||||
entries.map((entry) => (
|
|
||||||
<div key={entry.socketId} className="flex items-center justify-between">
|
|
||||||
<span className="text-slate-300">{entry.label}</span>
|
|
||||||
<span className="rounded bg-slate-800 px-1 text-[0.7rem] text-slate-200">{entry.ip}</span>
|
|
||||||
</div>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user