diff --git a/Netch/Controllers/HTTPController.cs b/Netch/Controllers/HTTPController.cs index 4dce0eeb..e880bac0 100644 --- a/Netch/Controllers/HTTPController.cs +++ b/Netch/Controllers/HTTPController.cs @@ -25,21 +25,22 @@ namespace Netch.Controllers PrivoxyController.Start(MainController.Server!); Global.Job.AddProcess(PrivoxyController.Instance!); - if (mode.Type is 3 or 5) + if (mode.Type is 3) { + using var service = new ProxyService(); + _oldState = service.Query(); + if (MainController.Server is Socks5 or Trojan && mode.BypassChina) { - PACServerHandle.InitPACServer("127.0.0.1"); + service.AutoConfigUrl = PACServerHandle.InitPACServer("127.0.0.1"); + + service.Pac(); } else { - using var service = new ProxyService - { - Server = $"127.0.0.1:{Global.Settings.HTTPLocalPort}", - Bypass = string.Join(";", ProxyService.LanIp) - }; + service.Server = $"127.0.0.1:{Global.Settings.HTTPLocalPort}"; + service.Bypass = string.Join(";", ProxyService.LanIp); - _oldState = service.Query(); service.Global(); } } @@ -57,8 +58,11 @@ namespace Netch.Controllers { PACServerHandle.Stop(); - using var service = new ProxyService(); - service.Set(_oldState!); + if (_oldState != null) + { + using var service = new ProxyService(); + service.Set(_oldState!); + } }) }; diff --git a/Netch/Models/Setting.cs b/Netch/Models/Setting.cs index 3e6b3b70..a2c4414e 100644 --- a/Netch/Models/Setting.cs +++ b/Netch/Models/Setting.cs @@ -176,11 +176,6 @@ namespace Netch.Models /// public int Pac_Port { get; set; } = 2803; - /// - /// PAC URL - /// - public string Pac_Url { get; set; } = ""; - /// /// 不代理TCP /// diff --git a/Netch/Utils/HttpProxyHandler/PACServerHandle.cs b/Netch/Utils/HttpProxyHandler/PACServerHandle.cs index 9b951836..d4e925fc 100644 --- a/Netch/Utils/HttpProxyHandler/PACServerHandle.cs +++ b/Netch/Utils/HttpProxyHandler/PACServerHandle.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.IO; using System.Net; using System.Text; -using WindowsProxy; namespace Netch.Utils.HttpProxyHandler { @@ -16,36 +15,28 @@ namespace Netch.Utils.HttpProxyHandler private static readonly Hashtable httpWebServer = new(); private static readonly Hashtable pacList = new(); - public static void InitPACServer(string address) + public static string InitPACServer(string address) { try { if (!pacList.ContainsKey(address)) pacList.Add(address, GetPacList(address)); - var prefixes = string.Format("http://{0}:{1}/pac/", address, Global.Settings.Pac_Port); + var prefixes = $"http://{address}:{Global.Settings.Pac_Port}/pac/"; var ws = new HttpWebServer(SendResponse, prefixes); ws.Run(); - if (!httpWebServer.ContainsKey(address) && ws != null) + if (!httpWebServer.ContainsKey(address)) httpWebServer.Add(address, ws); - Global.Settings.Pac_Url = GetPacUrl(); - - using var service = new ProxyService - { - AutoConfigUrl = Global.Settings.Pac_Url - }; - - service.Pac(); - - Logging.Info(service.Set(service.Query()) + ""); - Logging.Info($"Webserver InitServer OK: {Global.Settings.Pac_Url}"); + var pacUrl = GetPacUrl(); + Logging.Info($"Webserver InitServer OK: {pacUrl}"); + return pacUrl; } catch (Exception ex) { - Logging.Error("Webserver InitServer " + ex.Message); + throw new Exception("Webserver InitServer Error:" + ex.Message); } }