Update HTTPController

This commit is contained in:
ChsBuffer
2021-03-01 21:07:14 +08:00
parent 389c385d18
commit f9503d61d3
3 changed files with 21 additions and 31 deletions

View File

@@ -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!);
}
})
};

View File

@@ -176,11 +176,6 @@ namespace Netch.Models
/// </summary>
public int Pac_Port { get; set; } = 2803;
/// <summary>
/// PAC URL
/// </summary>
public string Pac_Url { get; set; } = "";
/// <summary>
/// 不代理TCP
/// </summary>

View File

@@ -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);
}
}