Major enhancements to Client Guardian: **Removed Captive Portal:** - Deleted portal.js and captive.js views - Removed portal configuration from UCI - Removed portal RPC methods (get_portal, update_portal, list_sessions, authorize_client, deauthorize_client) - Cleaned menu and ACL definitions - Updated default policy from 'captive' to 'quarantine' **Added Auto-Zoning System:** - Implemented get_vendor_from_mac() for OUI lookups - Added apply_auto_zoning() with rule-based zone assignment - Support for vendor, hostname pattern, and MAC prefix matching - 8 pre-configured auto-zoning rules (IoT devices, mobile, guests) - Auto-parking zone for unmatched clients - GridSection UI for managing auto-zoning rules **Threat Intelligence Integration:** - Added threat_policy UCI section - Auto-ban/quarantine based on threat score thresholds - Threat indicators on client displays - Integration with Security Threats Dashboard **Dashboard Improvements:** - Fixed boolean conversion (UCI "true"/"false" to JSON 0/1) - Fixed RPC expect parameter issues causing empty arrays - Added real-time polling with configurable intervals - Removed all window.location.reload() calls - Smooth DOM updates without page flickers **Settings Enhancements:** - Added reactiveness section (auto-refresh toggle, interval) - Added threat intelligence settings - Removed captive portal settings section - Updated policy descriptions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
206 lines
4.5 KiB
JavaScript
206 lines
4.5 KiB
JavaScript
'use strict';
|
|
'require baseclass';
|
|
'require rpc';
|
|
|
|
/**
|
|
* Client Guardian API
|
|
* Package: luci-app-client-guardian
|
|
* RPCD object: luci.client-guardian
|
|
*/
|
|
|
|
// Version: 0.4.0
|
|
|
|
var callStatus = rpc.declare({
|
|
object: 'luci.client-guardian',
|
|
method: 'status',
|
|
expect: { }
|
|
});
|
|
|
|
var callClients = rpc.declare({
|
|
object: 'luci.client-guardian',
|
|
method: 'clients',
|
|
expect: { clients: [] }
|
|
});
|
|
|
|
var callGetClient = rpc.declare({
|
|
object: 'luci.client-guardian',
|
|
method: 'get_client',
|
|
params: ['mac'],
|
|
expect: { }
|
|
});
|
|
|
|
var callZones = rpc.declare({
|
|
object: 'luci.client-guardian',
|
|
method: 'zones',
|
|
expect: { zones: [] }
|
|
});
|
|
|
|
var callParental = rpc.declare({
|
|
object: 'luci.client-guardian',
|
|
method: 'parental',
|
|
expect: { }
|
|
});
|
|
|
|
|
|
var callAlerts = rpc.declare({
|
|
object: 'luci.client-guardian',
|
|
method: 'alerts',
|
|
expect: { }
|
|
});
|
|
|
|
var callLogs = rpc.declare({
|
|
object: 'luci.client-guardian',
|
|
method: 'logs',
|
|
params: ['limit', 'level'],
|
|
expect: { logs: [] }
|
|
});
|
|
|
|
var callApproveClient = rpc.declare({
|
|
object: 'luci.client-guardian',
|
|
method: 'approve_client',
|
|
params: ['mac', 'name', 'zone', 'notes'],
|
|
expect: { success: false }
|
|
});
|
|
|
|
var callBanClient = rpc.declare({
|
|
object: 'luci.client-guardian',
|
|
method: 'ban_client',
|
|
params: ['mac', 'reason'],
|
|
expect: { success: false }
|
|
});
|
|
|
|
var callQuarantineClient = rpc.declare({
|
|
object: 'luci.client-guardian',
|
|
method: 'quarantine_client',
|
|
params: ['mac'],
|
|
expect: { success: false }
|
|
});
|
|
|
|
var callUpdateClient = rpc.declare({
|
|
object: 'luci.client-guardian',
|
|
method: 'update_client',
|
|
params: ['section', 'name', 'zone', 'notes', 'daily_quota', 'static_ip'],
|
|
expect: { success: false }
|
|
});
|
|
|
|
var callUpdateZone = rpc.declare({
|
|
object: 'luci.client-guardian',
|
|
method: 'update_zone',
|
|
params: ['id', 'name', 'bandwidth_limit', 'content_filter'],
|
|
expect: { success: false }
|
|
});
|
|
|
|
var callSendTestAlert = rpc.declare({
|
|
object: 'luci.client-guardian',
|
|
method: 'send_test_alert',
|
|
params: ['type'],
|
|
expect: { success: false }
|
|
});
|
|
|
|
var callGetPolicy = rpc.declare({
|
|
object: 'luci.client-guardian',
|
|
method: 'get_policy',
|
|
expect: { }
|
|
});
|
|
|
|
var callSetPolicy = rpc.declare({
|
|
object: 'luci.client-guardian',
|
|
method: 'set_policy',
|
|
params: ['policy', 'auto_approve', 'session_timeout'],
|
|
expect: { success: false }
|
|
});
|
|
|
|
var callSyncZones = rpc.declare({
|
|
object: 'luci.client-guardian',
|
|
method: 'sync_zones',
|
|
expect: { success: false }
|
|
});
|
|
|
|
function formatMac(mac) {
|
|
if (!mac) return '';
|
|
return mac.toUpperCase().replace(/(.{2})(?=.)/g, '$1:');
|
|
}
|
|
|
|
function formatDuration(seconds) {
|
|
if (!seconds) return 'Unlimited';
|
|
var h = Math.floor(seconds / 3600);
|
|
var m = Math.floor((seconds % 3600) / 60);
|
|
if (h > 24) return Math.floor(h / 24) + 'd';
|
|
if (h > 0) return h + 'h ' + m + 'm';
|
|
return m + 'm';
|
|
}
|
|
|
|
function formatBytes(bytes) {
|
|
if (!bytes || bytes === 0) return '0 B';
|
|
var units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
var i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
i = Math.min(i, units.length - 1);
|
|
return (bytes / Math.pow(1024, i)).toFixed(2) + ' ' + units[i];
|
|
}
|
|
|
|
function getDeviceIcon(hostname, mac) {
|
|
hostname = (hostname || '').toLowerCase();
|
|
mac = (mac || '').toLowerCase();
|
|
|
|
// Mobile devices
|
|
if (hostname.match(/android|iphone|ipad|mobile|phone|samsung|xiaomi|huawei/))
|
|
return '📱';
|
|
|
|
// Computers
|
|
if (hostname.match(/pc|laptop|desktop|macbook|imac|windows|linux|ubuntu/))
|
|
return '💻';
|
|
|
|
// IoT devices
|
|
if (hostname.match(/camera|bulb|switch|sensor|thermostat|doorbell|lock/))
|
|
return '📷';
|
|
|
|
// Smart TV / Media
|
|
if (hostname.match(/tv|roku|chromecast|firestick|appletv|media/))
|
|
return '📺';
|
|
|
|
// Gaming
|
|
if (hostname.match(/playstation|xbox|nintendo|switch|steam/))
|
|
return '🎮';
|
|
|
|
// Network equipment
|
|
if (hostname.match(/router|switch|ap|access[-_]?point|bridge/))
|
|
return '🌐';
|
|
|
|
// Printers
|
|
if (hostname.match(/printer|print|hp-|canon-|epson-/))
|
|
return '🖨️';
|
|
|
|
// Default
|
|
return '🔌';
|
|
}
|
|
|
|
return baseclass.extend({
|
|
// Core methods
|
|
getStatus: callStatus,
|
|
getClients: callClients,
|
|
getClient: callGetClient,
|
|
getZones: callZones,
|
|
getParental: callParental,
|
|
getAlerts: callAlerts,
|
|
getLogs: callLogs,
|
|
|
|
// Client management
|
|
approveClient: callApproveClient,
|
|
banClient: callBanClient,
|
|
quarantineClient: callQuarantineClient,
|
|
updateClient: callUpdateClient,
|
|
|
|
// Configuration
|
|
updateZone: callUpdateZone,
|
|
sendTestAlert: callSendTestAlert,
|
|
syncZones: callSyncZones,
|
|
getPolicy: callGetPolicy,
|
|
setPolicy: callSetPolicy,
|
|
|
|
// Utility functions
|
|
formatMac: formatMac,
|
|
formatDuration: formatDuration,
|
|
formatBytes: formatBytes,
|
|
getDeviceIcon: getDeviceIcon
|
|
});
|