first commit - skeletal frame
This commit is contained in:
7
frontend/Dockerfile
Normal file
7
frontend/Dockerfile
Normal file
@@ -0,0 +1,7 @@
|
||||
FROM node:20-alpine
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm install
|
||||
COPY . .
|
||||
EXPOSE 5173
|
||||
CMD ["npm", "run", "dev"]
|
||||
16
frontend/index.html
Normal file
16
frontend/index.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
||||
<meta name="theme-color" content="#2E473B" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||
<link rel="manifest" href="/manifest.json" />
|
||||
<title>BarkWho</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.jsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
21
frontend/package.json
Normal file
21
frontend/package.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "barkwho-frontend",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite --host 0.0.0.0",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-router-dom": "^6.20.0",
|
||||
"framer-motion": "^10.16.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-react": "^4.2.0",
|
||||
"vite": "^5.0.0"
|
||||
}
|
||||
}
|
||||
10
frontend/public/manifest.json
Normal file
10
frontend/public/manifest.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "BarkWho",
|
||||
"short_name": "BarkWho",
|
||||
"description": "Parental Control Dashboard",
|
||||
"start_url": "/",
|
||||
"display": "standalone",
|
||||
"background_color": "#2E473B",
|
||||
"theme_color": "#2E473B",
|
||||
"icons": []
|
||||
}
|
||||
20
frontend/src/App.jsx
Normal file
20
frontend/src/App.jsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import { BrowserRouter, Routes, Route } from 'react-router-dom';
|
||||
import BottomNav from './components/BottomNav.jsx';
|
||||
import ControlDashboard from './pages/ControlDashboard.jsx';
|
||||
import DeviceLibrary from './pages/DeviceLibrary.jsx';
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<div className="app-container">
|
||||
<div className="app-content">
|
||||
<Routes>
|
||||
<Route path="/" element={<ControlDashboard />} />
|
||||
<Route path="/devices" element={<DeviceLibrary />} />
|
||||
</Routes>
|
||||
</div>
|
||||
<BottomNav />
|
||||
</div>
|
||||
</BrowserRouter>
|
||||
);
|
||||
}
|
||||
131
frontend/src/components/BonusTimeDrawer.jsx
Normal file
131
frontend/src/components/BonusTimeDrawer.jsx
Normal file
@@ -0,0 +1,131 @@
|
||||
import { useState } from 'react';
|
||||
import { motion, AnimatePresence } from 'framer-motion';
|
||||
|
||||
const PRESETS = [
|
||||
{ label: '15m', minutes: 15 },
|
||||
{ label: '30m', minutes: 30 },
|
||||
{ label: '60m', minutes: 60 },
|
||||
];
|
||||
|
||||
export default function BonusTimeDrawer({ category, onSubmit, onClose }) {
|
||||
const [custom, setCustom] = useState('');
|
||||
|
||||
const handleCustomSubmit = () => {
|
||||
const mins = parseInt(custom, 10);
|
||||
if (mins > 0) onSubmit(mins);
|
||||
};
|
||||
|
||||
return (
|
||||
<AnimatePresence>
|
||||
<div className="drawer-overlay" onClick={onClose}>
|
||||
<motion.div
|
||||
className="drawer"
|
||||
initial={{ y: '100%' }}
|
||||
animate={{ y: 0 }}
|
||||
exit={{ y: '100%' }}
|
||||
transition={{ type: 'spring', damping: 25, stiffness: 300 }}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div className="drawer-handle" />
|
||||
<h3 className="drawer-title">Bonus Time: {category}</h3>
|
||||
|
||||
<div className="preset-buttons">
|
||||
{PRESETS.map((p) => (
|
||||
<button key={p.minutes} className="btn btn-allowed preset-btn" onClick={() => onSubmit(p.minutes)}>
|
||||
{p.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="custom-input">
|
||||
<input
|
||||
type="number"
|
||||
placeholder="Custom minutes"
|
||||
min="1"
|
||||
max="480"
|
||||
value={custom}
|
||||
onChange={(e) => setCustom(e.target.value)}
|
||||
onKeyDown={(e) => e.key === 'Enter' && handleCustomSubmit()}
|
||||
/>
|
||||
<button className="btn btn-allowed" onClick={handleCustomSubmit} disabled={!custom}>
|
||||
Set
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button className="btn btn-secondary drawer-close" onClick={onClose}>
|
||||
Cancel
|
||||
</button>
|
||||
</motion.div>
|
||||
</div>
|
||||
|
||||
<style>{`
|
||||
.drawer-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
z-index: 200;
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
justify-content: center;
|
||||
}
|
||||
.drawer {
|
||||
background: var(--bg-secondary);
|
||||
border-top: 1px solid var(--border);
|
||||
border-radius: 20px 20px 0 0;
|
||||
padding: 16px 24px 32px;
|
||||
width: 100%;
|
||||
max-width: 600px;
|
||||
}
|
||||
.drawer-handle {
|
||||
width: 40px;
|
||||
height: 4px;
|
||||
background: var(--border);
|
||||
border-radius: 2px;
|
||||
margin: 0 auto 16px;
|
||||
}
|
||||
.drawer-title {
|
||||
font-size: 1rem;
|
||||
margin-bottom: 20px;
|
||||
text-align: center;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
.preset-buttons {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.preset-btn {
|
||||
flex: 1;
|
||||
padding: 14px;
|
||||
font-size: 1rem;
|
||||
}
|
||||
.custom-input {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.custom-input input {
|
||||
flex: 1;
|
||||
padding: 10px 14px;
|
||||
background: var(--bg-primary);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
color: var(--text-primary);
|
||||
font-family: inherit;
|
||||
font-size: 0.9rem;
|
||||
outline: none;
|
||||
}
|
||||
.custom-input input:focus {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
.custom-input input::placeholder {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.drawer-close {
|
||||
width: 100%;
|
||||
}
|
||||
`}</style>
|
||||
</AnimatePresence>
|
||||
);
|
||||
}
|
||||
63
frontend/src/components/BottomNav.jsx
Normal file
63
frontend/src/components/BottomNav.jsx
Normal file
@@ -0,0 +1,63 @@
|
||||
import { useLocation, useNavigate } from 'react-router-dom';
|
||||
|
||||
const tabs = [
|
||||
{ path: '/', label: 'Control', icon: '[ ]' },
|
||||
{ path: '/devices', label: 'Devices', icon: '{*}' },
|
||||
];
|
||||
|
||||
export default function BottomNav() {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
return (
|
||||
<nav className="bottom-nav">
|
||||
{tabs.map((tab) => (
|
||||
<button
|
||||
key={tab.path}
|
||||
className={`bottom-nav-tab ${location.pathname === tab.path ? 'active' : ''}`}
|
||||
onClick={() => navigate(tab.path)}
|
||||
>
|
||||
<span className="bottom-nav-icon">{tab.icon}</span>
|
||||
<span className="bottom-nav-label">{tab.label}</span>
|
||||
</button>
|
||||
))}
|
||||
<style>{`
|
||||
.bottom-nav {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
display: flex;
|
||||
background: var(--bg-secondary);
|
||||
border-top: 1px solid var(--border);
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
z-index: 100;
|
||||
}
|
||||
.bottom-nav-tab {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 12px 0;
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--text-muted);
|
||||
font-family: inherit;
|
||||
font-size: 0.7rem;
|
||||
cursor: pointer;
|
||||
transition: color 0.2s;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
.bottom-nav-tab.active {
|
||||
color: var(--status-allowed);
|
||||
}
|
||||
.bottom-nav-icon {
|
||||
font-size: 1.2rem;
|
||||
font-weight: bold;
|
||||
}
|
||||
`}</style>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
103
frontend/src/components/CategoryCard.jsx
Normal file
103
frontend/src/components/CategoryCard.jsx
Normal file
@@ -0,0 +1,103 @@
|
||||
export default function CategoryCard({ name, config, timers, onToggle, onBonusTime, onAssignRules }) {
|
||||
const { allowed, rules } = config;
|
||||
const activeTimer = timers?.[0];
|
||||
|
||||
const iconMap = {
|
||||
social: '{ }',
|
||||
streaming: '> |',
|
||||
adult: '[X]',
|
||||
gaming: '</>',
|
||||
custom: '...',
|
||||
};
|
||||
|
||||
const formatRemaining = (ms) => {
|
||||
const mins = Math.ceil(ms / 60000);
|
||||
if (mins >= 60) return `${Math.floor(mins / 60)}h ${mins % 60}m`;
|
||||
return `${mins}m`;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={`card category-card ${allowed ? 'allowed' : 'blocked'}`}>
|
||||
<div className="category-header">
|
||||
<div className="category-info">
|
||||
<span className="category-icon">{iconMap[config.icon] || iconMap.custom}</span>
|
||||
<div>
|
||||
<h3 className="category-name">{name}</h3>
|
||||
<span className="category-meta">
|
||||
{rules.length} rule{rules.length !== 1 ? 's' : ''}
|
||||
{activeTimer && (
|
||||
<span className="timer-badge">
|
||||
{' '}| Bonus: {formatRemaining(activeTimer.remainingMs)}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
className={`toggle-switch ${allowed ? 'active' : ''}`}
|
||||
onClick={() => onToggle(!allowed)}
|
||||
title={allowed ? 'Click to block' : 'Click to allow'}
|
||||
>
|
||||
<div className="toggle-knob" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="category-actions">
|
||||
<button className="btn btn-secondary btn-sm" onClick={onBonusTime}>
|
||||
+ Bonus Time
|
||||
</button>
|
||||
<button className="btn btn-secondary btn-sm" onClick={onAssignRules}>
|
||||
Assign Rules
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<style>{`
|
||||
.category-card {
|
||||
border-left: 4px solid var(--status-blocked);
|
||||
}
|
||||
.category-card.allowed {
|
||||
border-left-color: var(--status-allowed);
|
||||
}
|
||||
.category-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.category-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
.category-icon {
|
||||
font-size: 1.2rem;
|
||||
font-weight: bold;
|
||||
color: var(--accent);
|
||||
width: 40px;
|
||||
text-align: center;
|
||||
}
|
||||
.category-name {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
.category-meta {
|
||||
font-size: 0.7rem;
|
||||
color: var(--text-muted);
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.timer-badge {
|
||||
color: var(--status-allowed);
|
||||
}
|
||||
.category-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
.btn-sm {
|
||||
padding: 6px 12px;
|
||||
font-size: 0.7rem;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
188
frontend/src/components/CurfewClock.jsx
Normal file
188
frontend/src/components/CurfewClock.jsx
Normal file
@@ -0,0 +1,188 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { apiFetch } from '../hooks/useApi.js';
|
||||
|
||||
export default function CurfewClock({ curfew, timers, onCancelTimer, refetchCurfew }) {
|
||||
const [now, setNow] = useState(Date.now());
|
||||
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => setNow(Date.now()), 1000);
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
if (!curfew) return null;
|
||||
|
||||
const getNextEvent = () => {
|
||||
const today = new Date();
|
||||
const [blockH, blockM] = curfew.blockTime.split(':').map(Number);
|
||||
const [unblockH, unblockM] = curfew.unblockTime.split(':').map(Number);
|
||||
|
||||
const blockToday = new Date(today);
|
||||
blockToday.setHours(blockH, blockM, 0, 0);
|
||||
|
||||
const unblockTomorrow = new Date(today);
|
||||
unblockTomorrow.setDate(unblockTomorrow.getDate() + 1);
|
||||
unblockTomorrow.setHours(unblockH, unblockM, 0, 0);
|
||||
|
||||
const unblockToday = new Date(today);
|
||||
unblockToday.setHours(unblockH, unblockM, 0, 0);
|
||||
|
||||
if (now < unblockToday.getTime()) {
|
||||
return { label: 'Curfew ends in', target: unblockToday.getTime() };
|
||||
} else if (now < blockToday.getTime()) {
|
||||
return { label: 'Curfew starts in', target: blockToday.getTime() };
|
||||
} else {
|
||||
return { label: 'Curfew ends in', target: unblockTomorrow.getTime() };
|
||||
}
|
||||
};
|
||||
|
||||
const formatCountdown = (ms) => {
|
||||
const totalSec = Math.max(0, Math.floor(ms / 1000));
|
||||
const h = Math.floor(totalSec / 3600);
|
||||
const m = Math.floor((totalSec % 3600) / 60);
|
||||
const s = totalSec % 60;
|
||||
return `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}`;
|
||||
};
|
||||
|
||||
const handleOverride = async (minutes) => {
|
||||
await apiFetch('/curfew/override', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ minutes }),
|
||||
});
|
||||
refetchCurfew();
|
||||
};
|
||||
|
||||
const event = curfew.enabled ? getNextEvent() : null;
|
||||
const activeTimers = (timers || []).filter((t) => t.remainingMs > 0);
|
||||
|
||||
return (
|
||||
<div className="card curfew-clock">
|
||||
<div className="curfew-header">
|
||||
<span className="curfew-label">CURFEW</span>
|
||||
<span className={`curfew-status ${curfew.enabled ? 'active' : 'off'}`}>
|
||||
{curfew.enabled ? 'ARMED' : 'OFF'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{event && (
|
||||
<div className="curfew-countdown">
|
||||
<span className="countdown-label">{event.label}</span>
|
||||
<span className="countdown-time">{formatCountdown(event.target - now)}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{curfew.overrideActive && (
|
||||
<div className="curfew-override">Override active</div>
|
||||
)}
|
||||
|
||||
{curfew.enabled && !curfew.overrideActive && (
|
||||
<div className="curfew-actions">
|
||||
<button className="btn btn-secondary btn-sm" onClick={() => handleOverride(30)}>
|
||||
Override 30m
|
||||
</button>
|
||||
<button className="btn btn-secondary btn-sm" onClick={() => handleOverride(60)}>
|
||||
Override 1h
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeTimers.length > 0 && (
|
||||
<div className="active-timers">
|
||||
<span className="timer-section-label">Active Bonus Timers</span>
|
||||
{activeTimers.map((t) => (
|
||||
<div key={t.id} className="timer-row">
|
||||
<span>{t.category}: {formatCountdown(t.remainingMs)}</span>
|
||||
<button className="btn btn-secondary btn-sm" onClick={() => onCancelTimer(t.id)}>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<style>{`
|
||||
.curfew-clock {
|
||||
background: var(--bg-secondary);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.curfew-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.curfew-label {
|
||||
font-size: 0.75rem;
|
||||
letter-spacing: 2px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.curfew-status {
|
||||
font-size: 0.7rem;
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
.curfew-status.active {
|
||||
background: rgba(76, 175, 80, 0.2);
|
||||
color: var(--status-allowed);
|
||||
}
|
||||
.curfew-status.off {
|
||||
background: rgba(138, 138, 114, 0.2);
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.curfew-countdown {
|
||||
text-align: center;
|
||||
padding: 8px 0;
|
||||
}
|
||||
.countdown-label {
|
||||
display: block;
|
||||
font-size: 0.7rem;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 4px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
.countdown-time {
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: 4px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
.curfew-override {
|
||||
text-align: center;
|
||||
color: var(--status-allowed);
|
||||
font-size: 0.75rem;
|
||||
padding: 4px 0;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
.curfew-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
justify-content: center;
|
||||
margin-top: 8px;
|
||||
}
|
||||
.active-timers {
|
||||
margin-top: 12px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
.timer-section-label {
|
||||
display: block;
|
||||
font-size: 0.7rem;
|
||||
color: var(--text-muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.timer-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
font-size: 0.8rem;
|
||||
padding: 4px 0;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
88
frontend/src/components/DeviceCard.jsx
Normal file
88
frontend/src/components/DeviceCard.jsx
Normal file
@@ -0,0 +1,88 @@
|
||||
import { useState } from 'react';
|
||||
|
||||
export default function DeviceCard({ device, onNuke, onUnnuke }) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const name = device.name || device.hostname || device.oui || 'Unknown Device';
|
||||
const isOnline = device.is_wired !== undefined || device._uptime_by_ugw !== undefined;
|
||||
const isBlocked = device.blocked === true;
|
||||
|
||||
const handleNuke = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
await onNuke();
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleUnnuke = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
await onUnnuke();
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={`card device-card ${isBlocked ? 'nuked' : ''}`}>
|
||||
<div className="device-header">
|
||||
<div className="device-info">
|
||||
<span className={`status-dot ${isOnline ? 'online' : 'offline'}`} />
|
||||
<div>
|
||||
<h3 className="device-name">{name}</h3>
|
||||
<div className="device-meta">
|
||||
<span>{device.mac}</span>
|
||||
{device.ip && <span> | {device.ip}</span>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isBlocked ? (
|
||||
<button className="btn btn-allowed btn-sm" onClick={handleUnnuke} disabled={loading}>
|
||||
Restore
|
||||
</button>
|
||||
) : (
|
||||
<button className="btn btn-nuke btn-sm" onClick={handleNuke} disabled={loading}>
|
||||
NUKE
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<style>{`
|
||||
.device-card.nuked {
|
||||
border: 1px solid var(--status-nuke);
|
||||
background: rgba(255, 23, 68, 0.08);
|
||||
}
|
||||
.device-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.device-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
min-width: 0;
|
||||
}
|
||||
.device-name {
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 200px;
|
||||
}
|
||||
.device-meta {
|
||||
font-size: 0.65rem;
|
||||
color: var(--text-muted);
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
.btn-sm {
|
||||
padding: 6px 12px;
|
||||
font-size: 0.7rem;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
140
frontend/src/components/RuleAssigner.jsx
Normal file
140
frontend/src/components/RuleAssigner.jsx
Normal file
@@ -0,0 +1,140 @@
|
||||
import { useState } from 'react';
|
||||
import { useApi } from '../hooks/useApi.js';
|
||||
|
||||
export default function RuleAssigner({ category, currentRuleIds, onSave, onClose }) {
|
||||
const { data: rules, loading, error } = useApi('/rules');
|
||||
const [selected, setSelected] = useState(new Set(currentRuleIds));
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
const toggleRule = (ruleId) => {
|
||||
const next = new Set(selected);
|
||||
if (next.has(ruleId)) {
|
||||
next.delete(ruleId);
|
||||
} else {
|
||||
next.add(ruleId);
|
||||
}
|
||||
setSelected(next);
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
setSaving(true);
|
||||
try {
|
||||
await onSave([...selected]);
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const ruleList = Array.isArray(rules) ? rules : [];
|
||||
|
||||
return (
|
||||
<div className="drawer-overlay" onClick={onClose}>
|
||||
<div className="assigner-modal" onClick={(e) => e.stopPropagation()}>
|
||||
<h3 className="assigner-title">Assign Rules: {category}</h3>
|
||||
|
||||
{loading && <div className="loading-spinner">Loading rules...</div>}
|
||||
{error && <div className="error-message">{error}</div>}
|
||||
|
||||
<div className="rule-list">
|
||||
{ruleList.length === 0 && !loading ? (
|
||||
<div className="empty-state">
|
||||
No traffic rules found. Connect to UDR to discover rules.
|
||||
</div>
|
||||
) : (
|
||||
ruleList.map((rule) => (
|
||||
<label key={rule._id} className="rule-item">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={selected.has(rule._id)}
|
||||
onChange={() => toggleRule(rule._id)}
|
||||
/>
|
||||
<div className="rule-info">
|
||||
<span className="rule-name">{rule.description || rule.name || rule._id}</span>
|
||||
<span className="rule-status">
|
||||
{rule.enabled ? 'Blocking' : 'Inactive'}
|
||||
</span>
|
||||
</div>
|
||||
</label>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="assigner-actions">
|
||||
<button className="btn btn-secondary" onClick={onClose}>
|
||||
Cancel
|
||||
</button>
|
||||
<button className="btn btn-allowed" onClick={handleSave} disabled={saving}>
|
||||
{saving ? 'Saving...' : `Save (${selected.size} rules)`}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<style>{`
|
||||
.assigner-modal {
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 16px;
|
||||
padding: 20px;
|
||||
width: 90%;
|
||||
max-width: 500px;
|
||||
max-height: 80vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin: auto;
|
||||
}
|
||||
.assigner-title {
|
||||
font-size: 1rem;
|
||||
margin-bottom: 16px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
.rule-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
margin-bottom: 16px;
|
||||
max-height: 50vh;
|
||||
}
|
||||
.rule-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 10px 8px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
cursor: pointer;
|
||||
}
|
||||
.rule-item:hover {
|
||||
background: var(--bg-card);
|
||||
}
|
||||
.rule-item input[type="checkbox"] {
|
||||
accent-color: var(--status-allowed);
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
}
|
||||
.rule-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
.rule-name {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.rule-status {
|
||||
font-size: 0.65rem;
|
||||
color: var(--text-muted);
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.assigner-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 30px;
|
||||
color: var(--text-muted);
|
||||
font-style: italic;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
40
frontend/src/hooks/useApi.js
Normal file
40
frontend/src/hooks/useApi.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
|
||||
const BASE = '/api';
|
||||
|
||||
export async function apiFetch(path, options = {}) {
|
||||
const res = await fetch(`${BASE}${path}`, {
|
||||
headers: { 'Content-Type': 'application/json', ...options.headers },
|
||||
...options,
|
||||
});
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => ({}));
|
||||
throw new Error(body.error || `HTTP ${res.status}`);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export function useApi(path, deps = []) {
|
||||
const [data, setData] = useState(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
const refetch = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const result = await apiFetch(path);
|
||||
setData(result);
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [path]);
|
||||
|
||||
useEffect(() => {
|
||||
refetch();
|
||||
}, [refetch, ...deps]);
|
||||
|
||||
return { data, loading, error, refetch };
|
||||
}
|
||||
205
frontend/src/index.css
Normal file
205
frontend/src/index.css
Normal file
@@ -0,0 +1,205 @@
|
||||
:root {
|
||||
--bg-primary: #2E473B;
|
||||
--bg-secondary: #1E3229;
|
||||
--bg-card: #3A5A4A;
|
||||
--bg-card-hover: #456B57;
|
||||
--text-primary: #F5F5DC;
|
||||
--text-secondary: #C4C4A8;
|
||||
--text-muted: #8A8A72;
|
||||
--status-allowed: #4CAF50;
|
||||
--status-blocked: #DC3545;
|
||||
--status-nuke: #FF1744;
|
||||
--accent: #6B8F71;
|
||||
--border: #4A6B55;
|
||||
--shadow: rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html, body {
|
||||
height: 100%;
|
||||
font-family: 'Courier New', 'Consolas', monospace;
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
body {
|
||||
background-image:
|
||||
radial-gradient(circle at 20% 50%, rgba(107, 143, 113, 0.08) 0%, transparent 50%),
|
||||
radial-gradient(circle at 80% 20%, rgba(107, 143, 113, 0.05) 0%, transparent 50%),
|
||||
linear-gradient(rgba(107, 143, 113, 0.03) 1px, transparent 1px),
|
||||
linear-gradient(90deg, rgba(107, 143, 113, 0.03) 1px, transparent 1px);
|
||||
background-size: 100% 100%, 100% 100%, 40px 40px, 40px 40px;
|
||||
}
|
||||
|
||||
#root {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.app-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100%;
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.app-content {
|
||||
flex: 1;
|
||||
padding: 16px;
|
||||
padding-bottom: 80px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 12px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.page-header h1 {
|
||||
font-size: 1.4rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: 1px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
padding: 16px;
|
||||
margin-bottom: 12px;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
background: var(--bg-card-hover);
|
||||
}
|
||||
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-family: inherit;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.btn-allowed {
|
||||
background: var(--status-allowed);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-blocked {
|
||||
background: var(--status-blocked);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-nuke {
|
||||
background: var(--status-nuke);
|
||||
color: #fff;
|
||||
box-shadow: 0 0 15px rgba(255, 23, 68, 0.4);
|
||||
}
|
||||
|
||||
.btn-nuke:hover {
|
||||
box-shadow: 0 0 25px rgba(255, 23, 68, 0.6);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: var(--bg-secondary);
|
||||
color: var(--text-primary);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.status-dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.status-dot.online {
|
||||
background: var(--status-allowed);
|
||||
box-shadow: 0 0 6px var(--status-allowed);
|
||||
}
|
||||
|
||||
.status-dot.offline {
|
||||
background: var(--text-muted);
|
||||
}
|
||||
|
||||
.toggle-switch {
|
||||
position: relative;
|
||||
width: 52px;
|
||||
height: 28px;
|
||||
background: var(--status-blocked);
|
||||
border-radius: 14px;
|
||||
cursor: pointer;
|
||||
transition: background 0.3s;
|
||||
border: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.toggle-switch.active {
|
||||
background: var(--status-allowed);
|
||||
}
|
||||
|
||||
.toggle-switch .toggle-knob {
|
||||
position: absolute;
|
||||
top: 3px;
|
||||
left: 3px;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
background: #fff;
|
||||
border-radius: 50%;
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
|
||||
.toggle-switch.active .toggle-knob {
|
||||
transform: translateX(24px);
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 40px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.error-message {
|
||||
background: rgba(220, 53, 69, 0.1);
|
||||
border: 1px solid var(--status-blocked);
|
||||
border-radius: 8px;
|
||||
padding: 12px;
|
||||
color: var(--status-blocked);
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.app-content {
|
||||
padding: 24px;
|
||||
padding-bottom: 80px;
|
||||
}
|
||||
}
|
||||
10
frontend/src/main.jsx
Normal file
10
frontend/src/main.jsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import App from './App.jsx';
|
||||
import './index.css';
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
||||
103
frontend/src/pages/ControlDashboard.jsx
Normal file
103
frontend/src/pages/ControlDashboard.jsx
Normal file
@@ -0,0 +1,103 @@
|
||||
import { useState } from 'react';
|
||||
import { useApi, apiFetch } from '../hooks/useApi.js';
|
||||
import CategoryCard from '../components/CategoryCard.jsx';
|
||||
import CurfewClock from '../components/CurfewClock.jsx';
|
||||
import BonusTimeDrawer from '../components/BonusTimeDrawer.jsx';
|
||||
import RuleAssigner from '../components/RuleAssigner.jsx';
|
||||
|
||||
export default function ControlDashboard() {
|
||||
const { data: policies, loading, error, refetch } = useApi('/policies');
|
||||
const { data: curfew, refetch: refetchCurfew } = useApi('/curfew');
|
||||
const { data: timers, refetch: refetchTimers } = useApi('/timers');
|
||||
const [bonusCategory, setBonusCategory] = useState(null);
|
||||
const [assignCategory, setAssignCategory] = useState(null);
|
||||
|
||||
const handleToggle = async (category, allowed) => {
|
||||
try {
|
||||
await apiFetch(`/policies/${encodeURIComponent(category)}/toggle`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ allowed }),
|
||||
});
|
||||
refetch();
|
||||
} catch (err) {
|
||||
console.error('Toggle failed:', err);
|
||||
}
|
||||
};
|
||||
|
||||
const handleBonusTime = async (category, minutes) => {
|
||||
try {
|
||||
await apiFetch('/timers', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ category, minutes }),
|
||||
});
|
||||
refetch();
|
||||
refetchTimers();
|
||||
setBonusCategory(null);
|
||||
} catch (err) {
|
||||
console.error('Bonus time failed:', err);
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancelTimer = async (timerId) => {
|
||||
try {
|
||||
await apiFetch(`/timers/${timerId}`, { method: 'DELETE' });
|
||||
refetchTimers();
|
||||
refetch();
|
||||
} catch (err) {
|
||||
console.error('Cancel timer failed:', err);
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) return <div className="loading-spinner">Loading policies...</div>;
|
||||
if (error) return <div className="error-message">Error: {error}</div>;
|
||||
|
||||
const categories = policies ? Object.entries(policies) : [];
|
||||
|
||||
return (
|
||||
<div className="control-dashboard">
|
||||
<div className="page-header">
|
||||
<h1>// Control</h1>
|
||||
</div>
|
||||
|
||||
<CurfewClock curfew={curfew} timers={timers} onCancelTimer={handleCancelTimer} refetchCurfew={refetchCurfew} />
|
||||
|
||||
<div className="category-list">
|
||||
{categories.map(([name, config]) => (
|
||||
<CategoryCard
|
||||
key={name}
|
||||
name={name}
|
||||
config={config}
|
||||
timers={timers?.filter((t) => t.category === name) || []}
|
||||
onToggle={(allowed) => handleToggle(name, allowed)}
|
||||
onBonusTime={() => setBonusCategory(name)}
|
||||
onAssignRules={() => setAssignCategory(name)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{bonusCategory && (
|
||||
<BonusTimeDrawer
|
||||
category={bonusCategory}
|
||||
onSubmit={(minutes) => handleBonusTime(bonusCategory, minutes)}
|
||||
onClose={() => setBonusCategory(null)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{assignCategory && (
|
||||
<RuleAssigner
|
||||
category={assignCategory}
|
||||
currentRuleIds={policies?.[assignCategory]?.ruleIds || []}
|
||||
onSave={async (ruleIds) => {
|
||||
await apiFetch(`/policies/${encodeURIComponent(assignCategory)}/rules`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ ruleIds }),
|
||||
});
|
||||
refetch();
|
||||
setAssignCategory(null);
|
||||
}}
|
||||
onClose={() => setAssignCategory(null)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
121
frontend/src/pages/DeviceLibrary.jsx
Normal file
121
frontend/src/pages/DeviceLibrary.jsx
Normal file
@@ -0,0 +1,121 @@
|
||||
import { useState } from 'react';
|
||||
import { useApi, apiFetch } from '../hooks/useApi.js';
|
||||
import DeviceCard from '../components/DeviceCard.jsx';
|
||||
|
||||
export default function DeviceLibrary() {
|
||||
const { data: devices, loading, error, refetch } = useApi('/devices');
|
||||
const [search, setSearch] = useState('');
|
||||
|
||||
const handleNuke = async (mac) => {
|
||||
if (!confirm(`NUKE device ${mac}? This will block all internet access.`)) return;
|
||||
try {
|
||||
await apiFetch(`/devices/${encodeURIComponent(mac)}/nuke`, { method: 'POST' });
|
||||
refetch();
|
||||
} catch (err) {
|
||||
console.error('Nuke failed:', err);
|
||||
}
|
||||
};
|
||||
|
||||
const handleUnnuke = async (mac) => {
|
||||
try {
|
||||
await apiFetch(`/devices/${encodeURIComponent(mac)}/unnuke`, { method: 'POST' });
|
||||
refetch();
|
||||
} catch (err) {
|
||||
console.error('Unnuke failed:', err);
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) return <div className="loading-spinner">Discovering devices...</div>;
|
||||
if (error) return <div className="error-message">Error: {error}</div>;
|
||||
|
||||
const deviceList = Array.isArray(devices) ? devices : [];
|
||||
const filtered = deviceList.filter((d) => {
|
||||
const term = search.toLowerCase();
|
||||
const name = (d.name || d.hostname || d.oui || '').toLowerCase();
|
||||
const mac = (d.mac || '').toLowerCase();
|
||||
const ip = (d.ip || '').toLowerCase();
|
||||
return name.includes(term) || mac.includes(term) || ip.includes(term);
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="device-library">
|
||||
<div className="page-header">
|
||||
<h1>// Devices</h1>
|
||||
<button className="btn btn-secondary" onClick={refetch}>
|
||||
Refresh
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="search-bar">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search devices..."
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
/>
|
||||
<span className="device-count">{filtered.length} devices</span>
|
||||
</div>
|
||||
|
||||
<div className="device-grid">
|
||||
{filtered.length === 0 ? (
|
||||
<div className="empty-state">
|
||||
{deviceList.length === 0
|
||||
? 'No devices found. Connect to UDR to discover devices.'
|
||||
: 'No devices match your search.'}
|
||||
</div>
|
||||
) : (
|
||||
filtered.map((device) => (
|
||||
<DeviceCard
|
||||
key={device.mac || device._id}
|
||||
device={device}
|
||||
onNuke={() => handleNuke(device.mac)}
|
||||
onUnnuke={() => handleUnnuke(device.mac)}
|
||||
/>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
|
||||
<style>{`
|
||||
.search-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.search-bar input {
|
||||
flex: 1;
|
||||
padding: 10px 14px;
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
color: var(--text-primary);
|
||||
font-family: inherit;
|
||||
font-size: 0.85rem;
|
||||
outline: none;
|
||||
}
|
||||
.search-bar input:focus {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
.search-bar input::placeholder {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.device-count {
|
||||
color: var(--text-muted);
|
||||
font-size: 0.75rem;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.device-grid {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 40px 20px;
|
||||
color: var(--text-muted);
|
||||
font-style: italic;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
16
frontend/vite.config.js
Normal file
16
frontend/vite.config.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
server: {
|
||||
host: '0.0.0.0',
|
||||
port: 5173,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://backend:3001',
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user