Log upstream proxy auth details
This commit is contained in:
12
Program.cs
12
Program.cs
@@ -17,6 +17,10 @@ class Program
|
|||||||
static string PASS = "pass";
|
static string PASS = "pass";
|
||||||
static readonly string UPSTREAM_USER = ResolveUpstreamUser();
|
static readonly string UPSTREAM_USER = ResolveUpstreamUser();
|
||||||
static readonly string UPSTREAM_PASS = Environment.GetEnvironmentVariable("UPSTREAM_PASS") ?? string.Empty;
|
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 readonly string UPSTREAM_PROXY_AUTH_HEADER = BuildUpstreamProxyAuthHeader();
|
||||||
static long _connectionSeq;
|
static long _connectionSeq;
|
||||||
|
|
||||||
@@ -30,7 +34,7 @@ class Program
|
|||||||
Log.Info($"login: {USER}");
|
Log.Info($"login: {USER}");
|
||||||
Log.Info($"pass : {PASS}");
|
Log.Info($"pass : {PASS}");
|
||||||
Log.Info($"upstream auth user: {UPSTREAM_USER}");
|
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);
|
var listener = new TcpListener(IPAddress.Any, port);
|
||||||
listener.Start();
|
listener.Start();
|
||||||
@@ -424,14 +428,18 @@ class Program
|
|||||||
|
|
||||||
static string BuildUpstreamProxyAuthHeader()
|
static string BuildUpstreamProxyAuthHeader()
|
||||||
{
|
{
|
||||||
|
if (!FORCE_UPSTREAM_BASIC)
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(UPSTREAM_USER))
|
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;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
string pass = UPSTREAM_PASS ?? string.Empty;
|
string pass = UPSTREAM_PASS ?? string.Empty;
|
||||||
string encoded = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{UPSTREAM_USER}:{pass}"));
|
string encoded = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{UPSTREAM_USER}:{pass}"));
|
||||||
|
Log.Info("Upstream Basic auth header enabled");
|
||||||
return $"Proxy-Authorization: Basic {encoded}\r\n";
|
return $"Proxy-Authorization: Basic {encoded}\r\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
run.bat
2
run.bat
@@ -12,10 +12,12 @@ if not exist "%EXE%" (
|
|||||||
set "UPSTREAM_PROXY=proxy.syktsu.ru:3128"
|
set "UPSTREAM_PROXY=proxy.syktsu.ru:3128"
|
||||||
set "UPSTREAM_USER=%USERNAME%"
|
set "UPSTREAM_USER=%USERNAME%"
|
||||||
set "UPSTREAM_PASS="
|
set "UPSTREAM_PASS="
|
||||||
|
set "FORCE_UPSTREAM_BASIC=0"
|
||||||
|
|
||||||
echo [run] UPSTREAM_PROXY=%UPSTREAM_PROXY%
|
echo [run] UPSTREAM_PROXY=%UPSTREAM_PROXY%
|
||||||
echo [run] UPSTREAM_USER=%UPSTREAM_USER%
|
echo [run] UPSTREAM_USER=%UPSTREAM_USER%
|
||||||
echo [run] UPSTREAM_PASS is empty
|
echo [run] UPSTREAM_PASS is empty
|
||||||
|
echo [run] FORCE_UPSTREAM_BASIC=%FORCE_UPSTREAM_BASIC%
|
||||||
echo [run] Starting proxy...
|
echo [run] Starting proxy...
|
||||||
|
|
||||||
"%EXE%"
|
"%EXE%"
|
||||||
|
|||||||
Reference in New Issue
Block a user