diff --git a/package/secubox/luci-app-crowdsec-dashboard/htdocs/luci-static/resources/view/crowdsec-dashboard/overview.js b/package/secubox/luci-app-crowdsec-dashboard/htdocs/luci-static/resources/view/crowdsec-dashboard/overview.js index 29cfccb9..1a9575bd 100644 --- a/package/secubox/luci-app-crowdsec-dashboard/htdocs/luci-static/resources/view/crowdsec-dashboard/overview.js +++ b/package/secubox/luci-app-crowdsec-dashboard/htdocs/luci-static/resources/view/crowdsec-dashboard/overview.js @@ -30,15 +30,33 @@ return view.extend({ } // Also handle direct countries object if present if (data.countries && typeof data.countries === 'object') { - Object.assign(countries, data.countries); + for (var k in data.countries) countries[k] = data.countries[k]; } return countries; }, + parseAlerts: function(data) { + var alerts = []; + // Handle alerts_raw (JSON string array) + if (data.alerts_raw) { + try { + alerts = typeof data.alerts_raw === 'string' + ? JSON.parse(data.alerts_raw) + : data.alerts_raw; + } catch (e) {} + } + // Also handle direct alerts array if present + if (Array.isArray(data.alerts) && data.alerts.length > 0) { + alerts = data.alerts; + } + return Array.isArray(alerts) ? alerts : []; + }, + render: function(data) { var self = this; var s = data || {}; s.countries = this.parseCountries(s); + s.alerts = this.parseAlerts(s); var view = E('div', { 'class': 'cs-view' }, [ // Header @@ -178,6 +196,7 @@ return view.extend({ var self = this; return api.getOverview().then(function(s) { s.countries = self.parseCountries(s); + s.alerts = self.parseAlerts(s); var el = document.getElementById('cs-stats'); if (el) dom.content(el, self.renderStats(s)); el = document.getElementById('cs-alerts'); diff --git a/package/secubox/luci-app-crowdsec-dashboard/root/usr/libexec/rpcd/luci.crowdsec-dashboard b/package/secubox/luci-app-crowdsec-dashboard/root/usr/libexec/rpcd/luci.crowdsec-dashboard index 6e27b33d..c00144fd 100755 --- a/package/secubox/luci-app-crowdsec-dashboard/root/usr/libexec/rpcd/luci.crowdsec-dashboard +++ b/package/secubox/luci-app-crowdsec-dashboard/root/usr/libexec/rpcd/luci.crowdsec-dashboard @@ -2317,27 +2317,21 @@ get_overview() { json_add_string "top_countries_raw" "[$countries]" # Recent decisions (limited to 10 for display) - json_add_array "decisions" + # Recent decisions as raw JSON array string + local decisions_raw="[]" if [ "$cs_running" = "1" ]; then - run_cscli decisions list -o json 2>/dev/null | \ - jsonfilter -e '@[0]' -e '@[1]' -e '@[2]' -e '@[3]' -e '@[4]' \ - -e '@[5]' -e '@[6]' -e '@[7]' -e '@[8]' -e '@[9]' 2>/dev/null | \ - while IFS= read -r line; do - [ -n "$line" ] && [ "$line" != "null" ] && json_add_string "" "$line" - done + decisions_raw=$(run_cscli decisions list -o json --limit 10 2>/dev/null || echo "[]") + [ -z "$decisions_raw" ] && decisions_raw="[]" fi - json_close_array + json_add_string "decisions_raw" "$decisions_raw" - # Recent alerts (limited to 8) - json_add_array "alerts" + # Recent alerts as raw JSON array string + local alerts_raw="[]" if [ "$cs_running" = "1" ]; then - run_cscli alerts list -o json --limit 8 2>/dev/null | \ - jsonfilter -e '@[*]' 2>/dev/null | head -8 | \ - while IFS= read -r line; do - [ -n "$line" ] && json_add_string "" "$line" - done + alerts_raw=$(run_cscli alerts list -o json --limit 8 2>/dev/null || echo "[]") + [ -z "$alerts_raw" ] && alerts_raw="[]" fi - json_close_array + json_add_string "alerts_raw" "$alerts_raw" # CrowdSec logs (last 30 lines) json_add_array "logs"