fix(mitmproxy): Fix JSON output corruption from grep -c exit codes
grep -c returns exit code 1 when no matches found (even though it
outputs 0), causing `|| echo 0` to append an extra 0 and corrupt
the JSON response. This broke ubus calls and LuCI status display.
Use `: ${var:=0}` pattern instead to provide defaults.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
b2f0e23c32
commit
c0991336bb
@ -67,7 +67,8 @@ get_status() {
|
||||
local threats_log="${data_path:-/srv/mitmproxy}/threats.log"
|
||||
if [ -f "$threats_log" ]; then
|
||||
local today=$(date -u +%Y-%m-%d)
|
||||
threats_today=$(grep -c "\"timestamp\": \"$today" "$threats_log" 2>/dev/null || echo 0)
|
||||
threats_today=$(grep -c "\"timestamp\": \"$today" "$threats_log" 2>/dev/null)
|
||||
: ${threats_today:=0}
|
||||
fi
|
||||
|
||||
# Count processed autobans
|
||||
@ -77,7 +78,8 @@ get_status() {
|
||||
if [ -f "$autoban_log" ]; then
|
||||
autobans_total=$(wc -l < "$autoban_log" 2>/dev/null || echo 0)
|
||||
local today=$(date +%Y-%m-%d)
|
||||
autobans_today=$(grep -c "^$today" "$autoban_log" 2>/dev/null || echo 0)
|
||||
autobans_today=$(grep -c "^$today" "$autoban_log" 2>/dev/null)
|
||||
: ${autobans_today:=0}
|
||||
fi
|
||||
|
||||
# Pending autoban requests
|
||||
|
||||
Loading…
Reference in New Issue
Block a user