secubox-openwrt/package/secubox/luci-app-crowdsec-dashboard/htdocs/luci-static/resources/crowdsec-dashboard/api.js
CyberMind-FR 31a87c5d7a feat(structure): reorganize luci-app packages into package/secubox/ + appstore migration
Major structural reorganization and feature additions:

## Folder Reorganization
- Move 17 luci-app-* packages to package/secubox/ (except luci-app-secubox core hub)
- Update all tooling to support new structure:
  - secubox-tools/quick-deploy.sh: search both locations
  - secubox-tools/validate-modules.sh: validate both directories
  - secubox-tools/fix-permissions.sh: fix permissions in both locations
  - .github/workflows/test-validate.yml: build from both paths
- Update README.md links to new package/secubox/ paths

## AppStore Migration (Complete)
- Add catalog entries for all remaining luci-app packages:
  - network-tweaks.json: Network optimization tools
  - secubox-bonus.json: Documentation & demos hub
- Total: 24 apps in AppStore catalog (22 existing + 2 new)
- New category: 'documentation' for docs/demos/tutorials

## VHost Manager v2.0 Enhancements
- Add profile activation system for Internal Services and Redirects
- Implement createVHost() API wrapper for template-based deployment
- Fix Virtual Hosts view rendering with proper LuCI patterns
- Fix RPCD backend shell script errors (remove invalid local declarations)
- Extend backend validation for nginx return directives (redirect support)
- Add section_id parameter for named VHost profiles
- Add Remove button to Redirects page for feature parity
- Update README to v2.0 with comprehensive feature documentation

## Network Tweaks Dashboard
- Close button added to component details modal

Files changed: 340+ (336 renames with preserved git history)
Packages affected: 19 luci-app, 2 secubox-app, 1 theme, 4 tools

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-01 14:59:38 +01:00

210 lines
4.4 KiB
JavaScript

'use strict';
'require baseclass';
'require rpc';
/**
* CrowdSec Dashboard API
* Package: luci-app-crowdsec-dashboard
* RPCD object: luci.crowdsec-dashboard
* CrowdSec Core: 1.7.4+
*/
// Version: 0.5.0
var callStatus = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'status',
expect: { }
});
var callDecisions = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'decisions',
expect: { decisions: [] }
});
var callAlerts = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'alerts',
expect: { alerts: [] }
});
var callBouncers = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'bouncers',
expect: { bouncers: [] }
});
var callMetrics = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'metrics',
expect: { }
});
var callMachines = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'machines',
expect: { machines: [] }
});
var callHub = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'hub',
expect: { }
});
var callStats = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'stats',
expect: { }
});
var callSecuboxLogs = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'seccubox_logs',
expect: { }
});
var callCollectDebug = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'collect_debug',
expect: { success: false }
});
var callBan = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'ban',
params: ['ip', 'duration', 'reason'],
expect: { success: false }
});
var callUnban = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'unban',
params: ['ip'],
expect: { success: false }
});
// CrowdSec v1.7.4+ features
var callWAFStatus = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'waf_status',
expect: { }
});
var callMetricsConfig = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'metrics_config',
expect: { }
});
var callConfigureMetrics = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'configure_metrics',
params: ['enable'],
expect: { success: false }
});
var callCollections = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'collections',
expect: { }
});
var callInstallCollection = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'install_collection',
params: ['collection'],
expect: { success: false }
});
var callRemoveCollection = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'remove_collection',
params: ['collection'],
expect: { success: false }
});
var callUpdateHub = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'update_hub',
expect: { success: false }
});
var callRegisterBouncer = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'register_bouncer',
params: ['bouncer_name'],
expect: { success: false }
});
var callDeleteBouncer = rpc.declare({
object: 'luci.crowdsec-dashboard',
method: 'delete_bouncer',
params: ['bouncer_name'],
expect: { success: false }
});
function formatDuration(seconds) {
if (!seconds) return 'N/A';
if (seconds < 60) return seconds + 's';
if (seconds < 3600) return Math.floor(seconds / 60) + 'm';
if (seconds < 86400) return Math.floor(seconds / 3600) + 'h';
return Math.floor(seconds / 86400) + 'd';
}
function formatDate(dateStr) {
if (!dateStr) return 'N/A';
try {
var date = new Date(dateStr);
return date.toLocaleString();
} catch(e) {
return dateStr;
}
}
return baseclass.extend({
getStatus: callStatus,
getDecisions: callDecisions,
getAlerts: callAlerts,
getBouncers: callBouncers,
getMetrics: callMetrics,
getMachines: callMachines,
getHub: callHub,
getStats: callStats,
getSecuboxLogs: callSecuboxLogs,
collectDebugSnapshot: callCollectDebug,
addBan: callBan,
removeBan: callUnban,
// CrowdSec v1.7.4+ features
getWAFStatus: callWAFStatus,
getMetricsConfig: callMetricsConfig,
configureMetrics: callConfigureMetrics,
getCollections: callCollections,
installCollection: callInstallCollection,
removeCollection: callRemoveCollection,
updateHub: callUpdateHub,
registerBouncer: callRegisterBouncer,
deleteBouncer: callDeleteBouncer,
formatDuration: formatDuration,
formatDate: formatDate,
getDashboardData: function() {
return Promise.all([
callStatus(),
callStats(),
callDecisions(),
callAlerts()
]).then(function(results) {
return {
status: results[0] || {},
stats: results[1] || {},
decisions: (results[2] && results[2].decisions) || [],
alerts: (results[3] && results[3].alerts) || []
};
});
}
});