admin logs for IP stuff

This commit is contained in:
legop3
2026-01-23 02:59:25 -05:00
parent 622cd2875c
commit ba4cf80f41
8 changed files with 200 additions and 13 deletions
+35 -1
View File
@@ -10,7 +10,7 @@ const MODES = [
];
export default function AdminPanel() {
const { session, lockRover, setMode, requestControl, setCommunityGoal } = useSession();
const { session, lockRover, setMode, requestControl, setCommunityGoal, adminLogs } = useSession();
const roster = useMemo(() => session?.roster ?? [], [session?.roster]);
const [lockStates, setLockStates] = useState({});
const health = session?.health || null;
@@ -135,6 +135,7 @@ export default function AdminPanel() {
)}
/>
<ReplaySnapshotHealth health={health} />
<AdminIpLogPanel entries={adminLogs} />
</section>
);
}
@@ -200,3 +201,36 @@ function ReplaySnapshotHealth({ health }) {
</div>
);
}
function AdminIpLogPanel({ entries }) {
const logs = entries || [];
return (
<div className="panel-section space-y-0.5 text-base">
<div className="flex items-center justify-between text-sm text-slate-400">
<span>Admin IP log</span>
<span>{logs.length}</span>
</div>
<div className="surface h-64 overflow-y-auto font-mono text-xs">
{logs.length === 0 ? (
<p>No admin log entries yet.</p>
) : (
logs
.slice()
.reverse()
.map((entry) => (
<div key={entry.id} className="surface">
<span className="text-amber-400">
{entry.ts ? new Date(entry.ts).toLocaleTimeString() : '--'}
</span>{' '}
{entry.label && <span className="text-teal-400">[{entry.label}]</span>}{' '}
<span className="text-slate-200">{entry.message}</span>{' '}
{entry.ip && <span className="text-cyan-300">{entry.ip}</span>}{' '}
{entry.meta && <span className="text-slate-500">{JSON.stringify(entry.meta)}</span>}
</div>
))
)}
</div>
<p className="text-xs text-slate-500">Admin-only log stream; IPs never appear in user data.</p>
</div>
);
}
+14 -1
View File
@@ -7,6 +7,7 @@ const SessionContext = createContext({
connected: false,
session: null,
logs: [],
adminLogs: [],
login: async () => {},
setRole: async () => {},
requestControl: async () => {},
@@ -40,6 +41,7 @@ export function SessionProvider({ children }) {
const emitWithAck = useAckEmitter(socket);
const [session, setSession] = useState(null);
const [logs, setLogs] = useState([]);
const [adminLogs, setAdminLogs] = useState([]);
const [alerts, setAlerts] = useState([]);
const [connected, setConnected] = useState(socket.connected);
@@ -64,9 +66,17 @@ export function SessionProvider({ children }) {
function handleLogEntry(entry) {
setLogs((prev) => [...prev.slice(-199), entry]);
}
function handleAdminLogInit(entries = []) {
setAdminLogs(entries);
}
function handleAdminLogEntry(entry) {
setAdminLogs((prev) => [...prev.slice(-199), entry]);
}
socket.on('session:sync', handleSession);
socket.on('log:init', handleLogInit);
socket.on('log:entry', handleLogEntry);
socket.on('adminlog:init', handleAdminLogInit);
socket.on('adminlog:entry', handleAdminLogEntry);
socket.on('alert:new', (payload = {}) => {
setAlerts((prev) => [
...prev.slice(-49),
@@ -80,6 +90,8 @@ export function SessionProvider({ children }) {
socket.off('session:sync', handleSession);
socket.off('log:init', handleLogInit);
socket.off('log:entry', handleLogEntry);
socket.off('adminlog:init', handleAdminLogInit);
socket.off('adminlog:entry', handleAdminLogEntry);
socket.off('alert:new');
};
}, [socket]);
@@ -114,10 +126,11 @@ export function SessionProvider({ children }) {
connected,
session,
logs,
adminLogs,
alerts,
...actions,
}),
[actions, alerts, connected, logs, session],
[actions, adminLogs, alerts, connected, logs, session],
);
return <SessionContext.Provider value={value}>{children}</SessionContext.Provider>;