Log upstream proxy auth details

This commit is contained in:
2026-04-11 11:57:02 +03:00
parent d73a640142
commit e1734f82ef
2 changed files with 12 additions and 2 deletions

View File

@@ -17,6 +17,10 @@ class Program
static string PASS = "pass";
static readonly string UPSTREAM_USER = ResolveUpstreamUser();
static readonly string UPSTREAM_PASS = Environment.GetEnvironmentVariable("UPSTREAM_PASS") ?? string.Empty;
static readonly bool FORCE_UPSTREAM_BASIC = string.Equals(
Environment.GetEnvironmentVariable("FORCE_UPSTREAM_BASIC"),
"1",
StringComparison.OrdinalIgnoreCase);
static readonly string UPSTREAM_PROXY_AUTH_HEADER = BuildUpstreamProxyAuthHeader();
static long _connectionSeq;
@@ -30,7 +34,7 @@ class Program
Log.Info($"login: {USER}");
Log.Info($"pass : {PASS}");
Log.Info($"upstream auth user: {UPSTREAM_USER}");
Log.Info("upstream auth pass: <empty>");
Log.Info($"force upstream basic: {(FORCE_UPSTREAM_BASIC ? "on" : "off")}");
var listener = new TcpListener(IPAddress.Any, port);
listener.Start();
@@ -424,14 +428,18 @@ class Program
static string BuildUpstreamProxyAuthHeader()
{
if (!FORCE_UPSTREAM_BASIC)
return string.Empty;
if (string.IsNullOrWhiteSpace(UPSTREAM_USER))
{
Log.Warn("UPSTREAM_USER is empty; upstream Proxy-Authorization is disabled");
Log.Warn("FORCE_UPSTREAM_BASIC=1 but UPSTREAM_USER is empty; upstream Basic auth is disabled");
return string.Empty;
}
string pass = UPSTREAM_PASS ?? string.Empty;
string encoded = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{UPSTREAM_USER}:{pass}"));
Log.Info("Upstream Basic auth header enabled");
return $"Proxy-Authorization: Basic {encoded}\r\n";
}

View File

@@ -12,10 +12,12 @@ if not exist "%EXE%" (
set "UPSTREAM_PROXY=proxy.syktsu.ru:3128"
set "UPSTREAM_USER=%USERNAME%"
set "UPSTREAM_PASS="
set "FORCE_UPSTREAM_BASIC=0"
echo [run] UPSTREAM_PROXY=%UPSTREAM_PROXY%
echo [run] UPSTREAM_USER=%UPSTREAM_USER%
echo [run] UPSTREAM_PASS is empty
echo [run] FORCE_UPSTREAM_BASIC=%FORCE_UPSTREAM_BASIC%
echo [run] Starting proxy...
"%EXE%"