fix(mitmproxy): Fix token capture with background job and tee

The previous pipe approach didn't work because the while loop
runs in a subshell. Now using a background job to poll the log
file for the token while tee outputs to both console and log.

Bump release to r13.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
CyberMind-FR 2026-01-17 08:55:34 +01:00
parent 1dd0c95a09
commit 287bd24e3e
2 changed files with 21 additions and 12 deletions

View File

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=secubox-app-mitmproxy
PKG_RELEASE:=12
PKG_RELEASE:=13
PKG_VERSION:=0.4.0
PKG_ARCH:=all
PKG_MAINTAINER:=CyberMind Studio <contact@cybermind.fr>

View File

@ -358,17 +358,26 @@ if [ "$FILTERING_ENABLED" = "1" ] && [ -n "$ADDON_SCRIPT" ] && [ -f "$ADDON_SCRI
fi
# Run mitmweb and capture token
# The token is printed to stderr, capture it and save to file
mitmweb $ARGS --web-host "$WEB_HOST" --web-port "$WEB_PORT" --no-web-open-browser 2>&1 | while IFS= read -r line; do
echo "$line"
# Extract and save token if present
case "$line" in
*"token="*)
token=$(echo "$line" | sed -n 's/.*token=\([a-f0-9]*\).*/\1/p')
[ -n "$token" ] && echo "$token" > /data/.mitmproxy_token
;;
esac
done
# Use tee to both display output and capture token
LOG_FILE="/tmp/mitmweb.log"
rm -f "$LOG_FILE" /data/.mitmproxy_token
# Background job to capture token from log
(
for i in $(seq 1 30); do
if [ -f "$LOG_FILE" ]; then
token=$(grep -o 'token=[a-f0-9]*' "$LOG_FILE" 2>/dev/null | head -1 | cut -d= -f2)
if [ -n "$token" ]; then
echo "$token" > /data/.mitmproxy_token
break
fi
fi
sleep 1
done
) &
# Run mitmweb with output to both console and log file
exec mitmweb $ARGS --web-host "$WEB_HOST" --web-port "$WEB_PORT" --no-web-open-browser 2>&1 | tee "$LOG_FILE"
START
chmod +x "$rootfs/opt/start-mitmproxy.sh"