|
|
@ -17,67 +17,59 @@ namespace ServiceLib.Handler.SysProxy
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var port = AppHandler.Instance.GetLocalPort(EInboundProtocol.http);
|
|
|
|
var port = AppHandler.Instance.GetLocalPort(EInboundProtocol.http);
|
|
|
|
var portSocks = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
|
|
|
|
var portSocks = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
|
|
|
|
var portPac = AppHandler.Instance.GetLocalPort(EInboundProtocol.pac);
|
|
|
|
|
|
|
|
if (port <= 0)
|
|
|
|
if (port <= 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type == ESysProxyType.ForcedChange)
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (Utils.IsWindows())
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var strExceptions = "";
|
|
|
|
case ESysProxyType.ForcedChange when Utils.IsWindows():
|
|
|
|
if (config.systemProxyItem.notProxyLocalAddress)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
strExceptions = $"<local>;{config.constItem.defIEProxyExceptions};{config.systemProxyItem.systemProxyExceptions}";
|
|
|
|
GetWindowsProxyString(config, port, portSocks, out var strProxy, out var strExceptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var strProxy = string.Empty;
|
|
|
|
|
|
|
|
if (Utils.IsNullOrEmpty(config.systemProxyItem.systemProxyAdvancedProtocol))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strProxy = $"{Global.Loopback}:{port}";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strProxy = config.systemProxyItem.systemProxyAdvancedProtocol
|
|
|
|
|
|
|
|
.Replace("{ip}", Global.Loopback)
|
|
|
|
|
|
|
|
.Replace("{http_port}", port.ToString())
|
|
|
|
|
|
|
|
.Replace("{socks_port}", portSocks.ToString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ProxySettingWindows.SetProxy(strProxy, strExceptions, 2);
|
|
|
|
ProxySettingWindows.SetProxy(strProxy, strExceptions, 2);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (Utils.IsLinux())
|
|
|
|
case ESysProxyType.ForcedChange when Utils.IsLinux():
|
|
|
|
{
|
|
|
|
|
|
|
|
await ProxySettingLinux.SetProxy(Global.Loopback, port);
|
|
|
|
await ProxySettingLinux.SetProxy(Global.Loopback, port);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
else if (Utils.IsOSX())
|
|
|
|
|
|
|
|
|
|
|
|
case ESysProxyType.ForcedChange:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (Utils.IsOSX())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await ProxySettingOSX.SetProxy(Global.Loopback, port);
|
|
|
|
await ProxySettingOSX.SetProxy(Global.Loopback, port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == ESysProxyType.ForcedClear)
|
|
|
|
case ESysProxyType.ForcedClear when Utils.IsWindows():
|
|
|
|
{
|
|
|
|
|
|
|
|
if (Utils.IsWindows())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ProxySettingWindows.UnsetProxy();
|
|
|
|
ProxySettingWindows.UnsetProxy();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
else if (Utils.IsLinux())
|
|
|
|
|
|
|
|
{
|
|
|
|
case ESysProxyType.ForcedClear when Utils.IsLinux():
|
|
|
|
await ProxySettingLinux.UnsetProxy();
|
|
|
|
await ProxySettingLinux.UnsetProxy();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
else if (Utils.IsOSX())
|
|
|
|
|
|
|
|
|
|
|
|
case ESysProxyType.ForcedClear:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (Utils.IsOSX())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await ProxySettingOSX.UnsetProxy();
|
|
|
|
await ProxySettingOSX.UnsetProxy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == ESysProxyType.Pac)
|
|
|
|
case ESysProxyType.Pac when Utils.IsWindows():
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
var portPac = AppHandler.Instance.GetLocalPort(EInboundProtocol.pac);
|
|
|
|
PacHandler.Start(Utils.GetConfigPath(), port, portPac);
|
|
|
|
PacHandler.Start(Utils.GetConfigPath(), port, portPac);
|
|
|
|
var strProxy = $"{Global.HttpProtocol}{Global.Loopback}:{portPac}/pac?t={DateTime.Now.Ticks}";
|
|
|
|
var strProxy = $"{Global.HttpProtocol}{Global.Loopback}:{portPac}/pac?t={DateTime.Now.Ticks}";
|
|
|
|
ProxySettingWindows.SetProxy(strProxy, "", 4);
|
|
|
|
ProxySettingWindows.SetProxy(strProxy, "", 4);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (type != ESysProxyType.Pac)
|
|
|
|
if (type != ESysProxyType.Pac && Utils.IsWindows())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
PacHandler.Stop();
|
|
|
|
PacHandler.Stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -88,5 +80,27 @@ namespace ServiceLib.Handler.SysProxy
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void GetWindowsProxyString(Config config, int port, int portSocks, out string strProxy, out string strExceptions)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strExceptions = "";
|
|
|
|
|
|
|
|
if (config.systemProxyItem.notProxyLocalAddress)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strExceptions = $"<local>;{config.constItem.defIEProxyExceptions};{config.systemProxyItem.systemProxyExceptions}";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
strProxy = string.Empty;
|
|
|
|
|
|
|
|
if (Utils.IsNullOrEmpty(config.systemProxyItem.systemProxyAdvancedProtocol))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strProxy = $"{Global.Loopback}:{port}";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strProxy = config.systemProxyItem.systemProxyAdvancedProtocol
|
|
|
|
|
|
|
|
.Replace("{ip}", Global.Loopback)
|
|
|
|
|
|
|
|
.Replace("{http_port}", port.ToString())
|
|
|
|
|
|
|
|
.Replace("{socks_port}", portSocks.ToString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|