Fix VPN verify script: add debug logging, remove set -e

The verify.sh had 'set -e' which could cause premature exit in
edge cases. Replaced with explicit logging to /tmp/openvpn-verify.log
so we can diagnose AUTH_FAILED on production servers.

Log shows: timestamp, username, HTTP code, response body, ALLOW/DENY.
Also redirected curl stderr to log file instead of /dev/null so
connection errors are visible for debugging.
This commit is contained in:
cnbugs
2026-08-09 23:21:05 +08:00
parent 8be6add7bc
commit 70341c78e5
+11 -3
View File
@@ -510,26 +510,34 @@ func (m *Manager) WriteVerifyScriptWithPort(instanceName, scriptPath string, por
# OpenVPN auth-user-pass-verify script (via-env). # OpenVPN auth-user-pass-verify script (via-env).
# Generated by openvpn-manager — do NOT edit manually. # Generated by openvpn-manager — do NOT edit manually.
# Calls manager API to verify bcrypt password. Exit 0=allow, 1=deny. # Calls manager API to verify bcrypt password. Exit 0=allow, 1=deny.
set -e LOG="/tmp/openvpn-verify.log"
PORT=%d PORT=%d
INSTANCE="%s" INSTANCE="%s"
user="${username:-}" user="${username:-}"
pass="${password:-}" pass="${password:-}"
echo "$(date '+%%Y-%%m-%%d %%H:%%M:%%S') VERIFY user=$user instance=$INSTANCE" >> "$LOG"
if [ -z "$user" ] || [ -z "$pass" ]; then if [ -z "$user" ] || [ -z "$pass" ]; then
echo "$(date '+%%Y-%%m-%%d %%H:%%M:%%S') DENY empty credentials" >> "$LOG"
exit 1 exit 1
fi fi
CODE=$(curl -sf -o /dev/null -w "%%{http_code}" \ CODE=$(curl -s -o /tmp/ovpn-verify-resp.txt -w "%%{http_code}" \
--connect-timeout 3 --max-time 5 \ --connect-timeout 3 --max-time 5 \
-X POST "http://127.0.0.1:${PORT}/api/vpn/verify" \ -X POST "http://127.0.0.1:${PORT}/api/vpn/verify" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "{\"instance\":\"${INSTANCE}\",\"username\":\"${user}\",\"password\":\"${pass}\"}" \ -d "{\"instance\":\"${INSTANCE}\",\"username\":\"${user}\",\"password\":\"${pass}\"}" \
2>/dev/null || echo "000") 2>>"$LOG" || echo "000")
BODY=$(cat /tmp/ovpn-verify-resp.txt 2>/dev/null)
echo "$(date '+%%Y-%%m-%%d %%H:%%M:%%S') HTTP_CODE=$CODE BODY=$BODY" >> "$LOG"
if [ "$CODE" = "200" ]; then if [ "$CODE" = "200" ]; then
echo "$(date '+%%Y-%%m-%%d %%H:%%M:%%S') ALLOW" >> "$LOG"
exit 0 exit 0
else else
echo "$(date '+%%Y-%%m-%%d %%H:%%M:%%S') DENY" >> "$LOG"
exit 1 exit 1
fi fi
`, port, instanceName) `, port, instanceName)