mirror of
https://github.com/netchx/netch.git
synced 2026-04-03 19:35:10 +08:00
Socks5无验证时不显示流量统计
更新PAC
This commit is contained in:
@@ -39,7 +39,7 @@ namespace Netch.Controllers
|
||||
|
||||
if (mode.Type == 3)
|
||||
{
|
||||
if (mode.BypassChina)
|
||||
if ((MainController.Server.Type == "Socks5" || MainController.Server.Type == "Trojan") && mode.BypassChina)
|
||||
{
|
||||
//启动PAC服务器
|
||||
PACServerHandle.InitPACServer("127.0.0.1");
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace Netch.Controllers
|
||||
get => _udpServerController ?? _serverController;
|
||||
set => _udpServerController = value;
|
||||
}
|
||||
public static Mode Mode;
|
||||
|
||||
/// TCP or Both Server
|
||||
public static Server Server;
|
||||
@@ -53,6 +54,7 @@ namespace Netch.Controllers
|
||||
{
|
||||
Logging.Info($"启动主控制器: {server.Type} [{mode.Type}]{mode.Remark}");
|
||||
Server = server;
|
||||
Mode = mode;
|
||||
|
||||
if (server is Socks5 && mode.Type == 4)
|
||||
{
|
||||
|
||||
@@ -285,18 +285,11 @@ namespace Netch.Forms
|
||||
NotifyTip(i18N.Translate("Updating in the background"));
|
||||
try
|
||||
{
|
||||
var req = WebUtil.CreateRequest(Global.Settings.GFWLIST);
|
||||
var req = WebUtil.CreateRequest(Global.Settings.PAC);
|
||||
|
||||
string gfwlist = Path.Combine(Global.NetchDir, $"bin\\gfwlist");
|
||||
string pac = Path.Combine(Global.NetchDir, $"bin\\pac.txt");
|
||||
|
||||
await WebUtil.DownloadFileAsync(req, gfwlist);
|
||||
|
||||
var gfwContent = File.ReadAllText(gfwlist);
|
||||
List<string> lines = PACUtil.ParseResult(gfwContent);
|
||||
string abpContent = PACUtil.UnGzip(Resources.abp_js);
|
||||
abpContent = abpContent.Replace("__RULES__", JsonConvert.SerializeObject(lines, Formatting.Indented));
|
||||
File.WriteAllText(pac, abpContent, Encoding.UTF8);
|
||||
await WebUtil.DownloadFileAsync(req, pac);
|
||||
|
||||
NotifyTip(i18N.Translate("PAC updated successfully"));
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using Netch.Controllers;
|
||||
using Netch.Models;
|
||||
using Netch.Servers.Socks5;
|
||||
using Netch.Utils;
|
||||
|
||||
namespace Netch.Forms
|
||||
@@ -68,7 +70,18 @@ namespace Netch.Forms
|
||||
|
||||
ProfileGroupBox.Enabled = true;
|
||||
|
||||
UsedBandwidthLabel.Visible /*= UploadSpeedLabel.Visible*/ = DownloadSpeedLabel.Visible = Global.Flags.IsWindows10Upper;
|
||||
//Socks5
|
||||
Boolean s5BwFlag = true;
|
||||
if (MainController.Server.Type == "Socks5")
|
||||
{
|
||||
Socks5 SocksServer = (Socks5) MainController.Server;
|
||||
|
||||
if (!SocksServer.Auth()) s5BwFlag = false;
|
||||
}
|
||||
|
||||
//Socks5无身份验证且为网页代理模式时无法统计流量不显示流量状态栏,Socks5有身份验证时将统计V2ray的流量
|
||||
if (s5BwFlag || (MainController.Mode.Type == 0 || MainController.Mode.Type == 1 || MainController.Mode.Type == 2))
|
||||
UsedBandwidthLabel.Visible /*= UploadSpeedLabel.Visible*/ = DownloadSpeedLabel.Visible = Global.Flags.IsWindows10Upper;
|
||||
break;
|
||||
case State.Stopping:
|
||||
ControlButton.Enabled = false;
|
||||
|
||||
@@ -260,7 +260,7 @@ namespace Netch.Models
|
||||
/// <summary>
|
||||
/// GFWList
|
||||
/// </summary>
|
||||
public string GFWLIST = "https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt";
|
||||
public string PAC = "https://raw.githubusercontent.com/HMBSbige/Text_Translation/master/ShadowsocksR/ss_white.pac";
|
||||
|
||||
/// <summary>
|
||||
/// 是否使用DLL启动Shadowsocks
|
||||
|
||||
@@ -100,6 +100,7 @@ namespace Netch.Utils
|
||||
Logging.Info("流量统计进程:" + string.Join(",",
|
||||
instances.Select(instance => $"({instance.Id})" + instance.ProcessName).ToArray()));
|
||||
|
||||
received = 0;
|
||||
Task.Run(() =>
|
||||
{
|
||||
tSession = new TraceEventSession("KernelAndClrEventsSession");
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using Netch.Forms;
|
||||
using Netch.Properties;
|
||||
|
||||
namespace Netch.Utils.HttpProxyHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// 提供PAC功能支持
|
||||
/// </summary>
|
||||
class PACUtil
|
||||
{
|
||||
private static readonly IEnumerable<char> IgnoredLineBegins = new[] {'!', '['};
|
||||
|
||||
public static List<string> ParseResult(string response)
|
||||
{
|
||||
byte[] bytes = Convert.FromBase64String(response);
|
||||
string content = Encoding.ASCII.GetString(bytes);
|
||||
List<string> valid_lines = new List<string>();
|
||||
using (var sr = new StringReader(content))
|
||||
{
|
||||
foreach (var line in sr.NonWhiteSpaceLines())
|
||||
{
|
||||
if (line.BeginWithAny(IgnoredLineBegins))
|
||||
continue;
|
||||
valid_lines.Add(line);
|
||||
}
|
||||
}
|
||||
return valid_lines;
|
||||
}
|
||||
|
||||
public static string UnGzip(byte[] buf)
|
||||
{
|
||||
byte[] buffer = new byte[1024];
|
||||
int n;
|
||||
using (MemoryStream sb = new MemoryStream())
|
||||
{
|
||||
using (GZipStream input = new GZipStream(new MemoryStream(buf),
|
||||
CompressionMode.Decompress,
|
||||
false))
|
||||
{
|
||||
while ((n = input.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
sb.Write(buffer, 0, n);
|
||||
}
|
||||
}
|
||||
return System.Text.Encoding.UTF8.GetString(sb.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
binaries
2
binaries
Submodule binaries updated: 9e6cf791ce...7b5ce30669
Reference in New Issue
Block a user