Revert "Remove V2Ray support"

This reverts commit c235713c1b.
This commit is contained in:
Connection Refused
2020-02-09 22:23:55 +08:00
committed by Tindy X
parent c235713c1b
commit 7fe227bb49
11 changed files with 6105 additions and 3 deletions

View File

@@ -30,6 +30,11 @@ namespace Netch.Controllers
/// </summary>
public SSRController pSSRController;
/// <summary>
/// V2Ray 控制器
/// </summary>
public VMessController pVMessController;
/// <summary>
/// NF 控制器
/// </summary>
@@ -83,6 +88,14 @@ namespace Netch.Controllers
}
result = pSSRController.Start(server, mode);
break;
case "VMess":
KillProcess("v2ray");
if (pVMessController == null)
{
pVMessController = new VMessController();
}
result = pVMessController.Start(server, mode);
break;
}
if (result)
@@ -154,6 +167,10 @@ namespace Netch.Controllers
{
pSSRController.Stop();
}
else if (pVMessController != null)
{
pVMessController.Stop();
}
if (pNFController != null)
{

View File

@@ -0,0 +1,257 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading;
namespace Netch.Controllers
{
public class VMessController
{
/// <summary>
/// 进程实例
/// </summary>
public Process Instance;
/// <summary>
/// 当前状态
/// </summary>
public Models.State State = Models.State.Waiting;
/// <summary>
/// 启动
/// </summary>
/// <param name="server">服务器</param>
/// <param name="mode">模式</param>
/// <returns>是否启动成功</returns>
public bool Start(Models.Server server, Models.Mode mode)
{
if (!File.Exists("bin\\v2ray.exe") || !File.Exists("bin\\v2ctl.exe"))
{
return false;
}
File.WriteAllText("data\\last.json", Newtonsoft.Json.JsonConvert.SerializeObject(new Models.Information.VMess.Config
{
inbounds = new List<Models.Information.VMess.Inbounds>
{
new Models.Information.VMess.Inbounds
{
settings = new Models.Information.VMess.InboundSettings(),
port = Global.Settings.Socks5LocalPort,
listen = Global.Settings.LocalAddress
}
},
outbounds = new List<Models.Information.VMess.Outbounds>
{
new Models.Information.VMess.Outbounds
{
settings = new Models.Information.VMess.OutboundSettings
{
vnext = new List<Models.Information.VMess.VNext>
{
new Models.Information.VMess.VNext
{
address = server.Hostname,
port = server.Port,
users = new List<Models.Information.VMess.User>
{
new Models.Information.VMess.User
{
id = server.UserID,
alterId = server.AlterID,
security = server.EncryptMethod
}
}
}
}
},
streamSettings = new Models.Information.VMess.StreamSettings
{
network = server.TransferProtocol,
security = server.TLSSecure ? "tls" : "",
wsSettings = server.TransferProtocol == "ws" ? new Models.Information.VMess.WebSocketSettings
{
path = server.Path == "" ? "/" : server.Path,
headers = new Models.Information.VMess.WSHeaders
{
Host = server.Host == "" ? server.Hostname : server.Host
}
} : null,
tcpSettings = server.FakeType == "http" ? new Models.Information.VMess.TCPSettings
{
header = new Models.Information.VMess.TCPHeaders
{
type = server.FakeType,
request = new Models.Information.VMess.TCPRequest
{
path = server.Path == "" ? "/" : server.Path,
headers = new Models.Information.VMess.TCPRequestHeaders
{
Host = server.Host == "" ? server.Hostname : server.Host
}
}
}
} : null,
kcpSettings = server.TransferProtocol == "kcp" ? new Models.Information.VMess.KCPSettings
{
header = new Models.Information.VMess.TCPHeaders
{
type = server.FakeType
}
} : null,
quicSettings = server.TransferProtocol == "quic" ? new Models.Information.VMess.QUICSettings
{
security = server.QUICSecure,
key = server.QUICSecret,
header = new Models.Information.VMess.TCPHeaders
{
type = server.FakeType
}
} : null,
httpSettings = server.TransferProtocol == "h2" ? new Models.Information.VMess.HTTPSettings
{
host = server.Host == "" ? server.Hostname : server.Host,
path = server.Path == "" ? "/" : server.Path
} : null,
tlsSettings = new Models.Information.VMess.TLSSettings
{
allowInsecure = true,
serverName = server.Host == "" ? server.Hostname : server.Host
}
},
mux = new Models.Information.VMess.OutboundMux
{
enabled = server.UseMux
}
},
new Models.Information.VMess.Outbounds
{
tag = "direct",
protocol = "freedom",
settings = null,
streamSettings = null,
mux = null
}
},
routing = new Models.Information.VMess.Routing
{
rules = new List<Models.Information.VMess.RoutingRules>
{
mode.BypassChina ? new Models.Information.VMess.RoutingRules
{
type = "field",
ip = new List<string>
{
"geoip:cn",
"geoip:private"
},
domain = new List<string>
{
"geosite:cn"
},
outboundTag = "direct"
} : new Models.Information.VMess.RoutingRules
{
type = "field",
ip = new List<string>
{
"geoip:private"
},
outboundTag = "direct"
}
}
}
}));
// 清理上一次的日志文件,防止淤积占用磁盘空间
if (Directory.Exists("logging"))
{
if (File.Exists("logging\\v2ray.log"))
{
File.Delete("logging\\v2ray.log");
}
}
Instance = MainController.GetProcess();
Instance.StartInfo.FileName = "bin\\v2ray.exe";
Instance.StartInfo.Arguments = "-config ..\\data\\last.json";
Instance.OutputDataReceived += OnOutputDataReceived;
Instance.ErrorDataReceived += OnOutputDataReceived;
State = Models.State.Starting;
Instance.Start();
Instance.BeginOutputReadLine();
Instance.BeginErrorReadLine();
for (var i = 0; i < 1000; i++)
{
Thread.Sleep(10);
if (State == Models.State.Started)
{
if (File.Exists("data\\last.json"))
{
File.Delete("data\\last.json");
}
return true;
}
if (State == Models.State.Stopped)
{
Utils.Logging.Info("V2Ray 进程启动失败");
Stop();
return false;
}
}
Utils.Logging.Info("V2Ray 进程启动超时");
Stop();
return false;
}
/// <summary>
/// 停止
/// </summary>
public void Stop()
{
try
{
if (Instance != null && !Instance.HasExited)
{
Instance.Kill();
}
}
catch (Exception e)
{
Utils.Logging.Info(e.ToString());
}
}
public void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (!string.IsNullOrWhiteSpace(e.Data))
{
File.AppendAllText("logging\\v2ray.log", $"{e.Data}\r\n");
if (State == Models.State.Starting)
{
if (Instance.HasExited)
{
State = Models.State.Stopped;
}
else if (e.Data.Contains("started"))
{
State = Models.State.Started;
}
else if (e.Data.Contains("config file not readable") || e.Data.Contains("failed to"))
{
State = Models.State.Stopped;
}
}
}
}
}
}

View File

@@ -38,6 +38,7 @@ namespace Netch.Forms
this.AddSocks5ServerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.AddShadowsocksServerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.AddShadowsocksRServerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.AddVMessServerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.CreateProcessModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ManageProcessModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@@ -109,7 +110,8 @@ namespace Netch.Forms
this.ImportServersFromClipboardToolStripMenuItem,
this.AddSocks5ServerToolStripMenuItem,
this.AddShadowsocksServerToolStripMenuItem,
this.AddShadowsocksRServerToolStripMenuItem});
this.AddShadowsocksRServerToolStripMenuItem,
this.AddVMessServerToolStripMenuItem});
this.ServerToolStripMenuItem.Margin = new System.Windows.Forms.Padding(3, 0, 0, 1);
this.ServerToolStripMenuItem.Name = "ServerToolStripMenuItem";
this.ServerToolStripMenuItem.Size = new System.Drawing.Size(57, 21);
@@ -143,6 +145,13 @@ namespace Netch.Forms
this.AddShadowsocksRServerToolStripMenuItem.Text = "Add [ShadowsocksR] Server";
this.AddShadowsocksRServerToolStripMenuItem.Click += new System.EventHandler(this.AddShadowsocksRServerToolStripMenuItem_Click);
//
// AddVMessServerToolStripMenuItem
//
this.AddVMessServerToolStripMenuItem.Name = "AddVMessServerToolStripMenuItem";
this.AddVMessServerToolStripMenuItem.Size = new System.Drawing.Size(259, 22);
this.AddVMessServerToolStripMenuItem.Text = "Add [VMess] Server";
this.AddVMessServerToolStripMenuItem.Click += new System.EventHandler(this.AddVMessServerToolStripMenuItem_Click);
//
// ModeToolStripMenuItem
//
this.ModeToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@@ -553,6 +562,7 @@ namespace Netch.Forms
private System.Windows.Forms.ToolStripMenuItem AddSocks5ServerToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem AddShadowsocksServerToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem AddShadowsocksRServerToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem AddVMessServerToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem ImportServersFromClipboardToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem ManageSubscribeLinksToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem UpdateServersFromSubscribeLinksToolStripMenuItem;

View File

@@ -305,6 +305,7 @@ namespace Netch.Forms
AddSocks5ServerToolStripMenuItem.Text = Utils.i18N.Translate(AddSocks5ServerToolStripMenuItem.Text);
AddShadowsocksServerToolStripMenuItem.Text = Utils.i18N.Translate(AddShadowsocksServerToolStripMenuItem.Text);
AddShadowsocksRServerToolStripMenuItem.Text = Utils.i18N.Translate(AddShadowsocksRServerToolStripMenuItem.Text);
AddVMessServerToolStripMenuItem.Text = Utils.i18N.Translate(AddVMessServerToolStripMenuItem.Text);
ModeToolStripMenuItem.Text = Utils.i18N.Translate(ModeToolStripMenuItem.Text);
CreateProcessModeToolStripMenuItem.Text = Utils.i18N.Translate(CreateProcessModeToolStripMenuItem.Text);
ManageProcessModeToolStripMenuItem.Text = Utils.i18N.Translate(ManageProcessModeToolStripMenuItem.Text);
@@ -438,6 +439,7 @@ namespace Netch.Forms
private void AddVMessServerToolStripMenuItem_Click(object sender, EventArgs e)
{
new Server.VMess().Show();
Hide();
}
@@ -702,6 +704,9 @@ namespace Netch.Forms
case "SSR":
new Server.ShadowsocksR(ServerComboBox.SelectedIndex).Show();
break;
case "VMess":
new Server.VMess(ServerComboBox.SelectedIndex).Show();
break;
default:
return;
}

427
Netch/Forms/Server/Vmess.Designer.cs generated Normal file
View File

@@ -0,0 +1,427 @@
namespace Netch.Forms.Server
{
partial class VMess
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(VMess));
this.ConfigurationGroupBox = new System.Windows.Forms.GroupBox();
this.UseMuxCheckBox = new System.Windows.Forms.CheckBox();
this.TLSSecureCheckBox = new System.Windows.Forms.CheckBox();
this.QUICSecretLabel = new System.Windows.Forms.Label();
this.QUICSecurityLabel = new System.Windows.Forms.Label();
this.QUICSecretTextBox = new System.Windows.Forms.TextBox();
this.QUICSecurityComboBox = new System.Windows.Forms.ComboBox();
this.PathLabel = new System.Windows.Forms.Label();
this.PathTextBox = new System.Windows.Forms.TextBox();
this.HostLabel = new System.Windows.Forms.Label();
this.HostTextBox = new System.Windows.Forms.TextBox();
this.FakeTypeLabel = new System.Windows.Forms.Label();
this.FakeTypeComboBox = new System.Windows.Forms.ComboBox();
this.TransferProtocolLabel = new System.Windows.Forms.Label();
this.TransferProtocolComboBox = new System.Windows.Forms.ComboBox();
this.EncryptMethodLabel = new System.Windows.Forms.Label();
this.EncryptMethodComboBox = new System.Windows.Forms.ComboBox();
this.AlterIDLabel = new System.Windows.Forms.Label();
this.AlterIDTextBox = new System.Windows.Forms.TextBox();
this.UserIDLabel = new System.Windows.Forms.Label();
this.UserIDTextBox = new System.Windows.Forms.TextBox();
this.PortTextBox = new System.Windows.Forms.TextBox();
this.AddressTextBox = new System.Windows.Forms.TextBox();
this.AddressLabel = new System.Windows.Forms.Label();
this.RemarkTextBox = new System.Windows.Forms.TextBox();
this.RemarkLabel = new System.Windows.Forms.Label();
this.PortLabel = new System.Windows.Forms.Label();
this.ControlButton = new System.Windows.Forms.Button();
this.ConfigurationGroupBox.SuspendLayout();
this.SuspendLayout();
//
// ConfigurationGroupBox
//
this.ConfigurationGroupBox.Controls.Add(this.UseMuxCheckBox);
this.ConfigurationGroupBox.Controls.Add(this.TLSSecureCheckBox);
this.ConfigurationGroupBox.Controls.Add(this.QUICSecretLabel);
this.ConfigurationGroupBox.Controls.Add(this.QUICSecurityLabel);
this.ConfigurationGroupBox.Controls.Add(this.QUICSecretTextBox);
this.ConfigurationGroupBox.Controls.Add(this.QUICSecurityComboBox);
this.ConfigurationGroupBox.Controls.Add(this.PathLabel);
this.ConfigurationGroupBox.Controls.Add(this.PathTextBox);
this.ConfigurationGroupBox.Controls.Add(this.HostLabel);
this.ConfigurationGroupBox.Controls.Add(this.HostTextBox);
this.ConfigurationGroupBox.Controls.Add(this.FakeTypeLabel);
this.ConfigurationGroupBox.Controls.Add(this.FakeTypeComboBox);
this.ConfigurationGroupBox.Controls.Add(this.TransferProtocolLabel);
this.ConfigurationGroupBox.Controls.Add(this.TransferProtocolComboBox);
this.ConfigurationGroupBox.Controls.Add(this.EncryptMethodLabel);
this.ConfigurationGroupBox.Controls.Add(this.EncryptMethodComboBox);
this.ConfigurationGroupBox.Controls.Add(this.AlterIDLabel);
this.ConfigurationGroupBox.Controls.Add(this.AlterIDTextBox);
this.ConfigurationGroupBox.Controls.Add(this.UserIDLabel);
this.ConfigurationGroupBox.Controls.Add(this.UserIDTextBox);
this.ConfigurationGroupBox.Controls.Add(this.PortTextBox);
this.ConfigurationGroupBox.Controls.Add(this.AddressTextBox);
this.ConfigurationGroupBox.Controls.Add(this.AddressLabel);
this.ConfigurationGroupBox.Controls.Add(this.RemarkTextBox);
this.ConfigurationGroupBox.Controls.Add(this.RemarkLabel);
this.ConfigurationGroupBox.Controls.Add(this.PortLabel);
this.ConfigurationGroupBox.Location = new System.Drawing.Point(18, 18);
this.ConfigurationGroupBox.Margin = new System.Windows.Forms.Padding(4);
this.ConfigurationGroupBox.Name = "ConfigurationGroupBox";
this.ConfigurationGroupBox.Padding = new System.Windows.Forms.Padding(4);
this.ConfigurationGroupBox.Size = new System.Drawing.Size(630, 560);
this.ConfigurationGroupBox.TabIndex = 1;
this.ConfigurationGroupBox.TabStop = false;
this.ConfigurationGroupBox.Text = "Configuration";
//
// UseMuxCheckBox
//
this.UseMuxCheckBox.AutoSize = true;
this.UseMuxCheckBox.Location = new System.Drawing.Point(292, 519);
this.UseMuxCheckBox.Margin = new System.Windows.Forms.Padding(4);
this.UseMuxCheckBox.Name = "UseMuxCheckBox";
this.UseMuxCheckBox.Size = new System.Drawing.Size(110, 28);
this.UseMuxCheckBox.TabIndex = 25;
this.UseMuxCheckBox.Text = "Use Mux";
this.UseMuxCheckBox.UseVisualStyleBackColor = true;
//
// TLSSecureCheckBox
//
this.TLSSecureCheckBox.AutoSize = true;
this.TLSSecureCheckBox.Location = new System.Drawing.Point(453, 519);
this.TLSSecureCheckBox.Margin = new System.Windows.Forms.Padding(4);
this.TLSSecureCheckBox.Name = "TLSSecureCheckBox";
this.TLSSecureCheckBox.Size = new System.Drawing.Size(127, 28);
this.TLSSecureCheckBox.TabIndex = 24;
this.TLSSecureCheckBox.Text = "TLS Secure";
this.TLSSecureCheckBox.UseVisualStyleBackColor = true;
//
// QUICSecretLabel
//
this.QUICSecretLabel.AutoSize = true;
this.QUICSecretLabel.Location = new System.Drawing.Point(15, 480);
this.QUICSecretLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.QUICSecretLabel.Name = "QUICSecretLabel";
this.QUICSecretLabel.Size = new System.Drawing.Size(113, 24);
this.QUICSecretLabel.TabIndex = 22;
this.QUICSecretLabel.Text = "QUIC Secret";
//
// QUICSecurityLabel
//
this.QUICSecurityLabel.AutoSize = true;
this.QUICSecurityLabel.Location = new System.Drawing.Point(15, 435);
this.QUICSecurityLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.QUICSecurityLabel.Name = "QUICSecurityLabel";
this.QUICSecurityLabel.Size = new System.Drawing.Size(129, 24);
this.QUICSecurityLabel.TabIndex = 20;
this.QUICSecurityLabel.Text = "QUIC Security";
//
// QUICSecretTextBox
//
this.QUICSecretTextBox.Location = new System.Drawing.Point(180, 476);
this.QUICSecretTextBox.Margin = new System.Windows.Forms.Padding(4);
this.QUICSecretTextBox.Name = "QUICSecretTextBox";
this.QUICSecretTextBox.Size = new System.Drawing.Size(439, 31);
this.QUICSecretTextBox.TabIndex = 23;
this.QUICSecretTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// QUICSecurityComboBox
//
this.QUICSecurityComboBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.QUICSecurityComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.QUICSecurityComboBox.FormattingEnabled = true;
this.QUICSecurityComboBox.Location = new System.Drawing.Point(180, 429);
this.QUICSecurityComboBox.Margin = new System.Windows.Forms.Padding(4);
this.QUICSecurityComboBox.Name = "QUICSecurityComboBox";
this.QUICSecurityComboBox.Size = new System.Drawing.Size(439, 32);
this.QUICSecurityComboBox.TabIndex = 21;
this.QUICSecurityComboBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ComboBox_DrawItem);
//
// PathLabel
//
this.PathLabel.AutoSize = true;
this.PathLabel.Location = new System.Drawing.Point(15, 390);
this.PathLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.PathLabel.Name = "PathLabel";
this.PathLabel.Size = new System.Drawing.Size(49, 24);
this.PathLabel.TabIndex = 18;
this.PathLabel.Text = "Path";
//
// PathTextBox
//
this.PathTextBox.Location = new System.Drawing.Point(180, 386);
this.PathTextBox.Margin = new System.Windows.Forms.Padding(4);
this.PathTextBox.Name = "PathTextBox";
this.PathTextBox.Size = new System.Drawing.Size(439, 31);
this.PathTextBox.TabIndex = 19;
this.PathTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// HostLabel
//
this.HostLabel.AutoSize = true;
this.HostLabel.Location = new System.Drawing.Point(15, 346);
this.HostLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.HostLabel.Name = "HostLabel";
this.HostLabel.Size = new System.Drawing.Size(50, 24);
this.HostLabel.TabIndex = 16;
this.HostLabel.Text = "Host";
//
// HostTextBox
//
this.HostTextBox.Location = new System.Drawing.Point(180, 342);
this.HostTextBox.Margin = new System.Windows.Forms.Padding(4);
this.HostTextBox.Name = "HostTextBox";
this.HostTextBox.Size = new System.Drawing.Size(439, 31);
this.HostTextBox.TabIndex = 17;
this.HostTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// FakeTypeLabel
//
this.FakeTypeLabel.AutoSize = true;
this.FakeTypeLabel.Location = new System.Drawing.Point(15, 302);
this.FakeTypeLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.FakeTypeLabel.Name = "FakeTypeLabel";
this.FakeTypeLabel.Size = new System.Drawing.Size(97, 24);
this.FakeTypeLabel.TabIndex = 14;
this.FakeTypeLabel.Text = "Fake Type";
//
// FakeTypeComboBox
//
this.FakeTypeComboBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.FakeTypeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.FakeTypeComboBox.FormattingEnabled = true;
this.FakeTypeComboBox.Location = new System.Drawing.Point(180, 296);
this.FakeTypeComboBox.Margin = new System.Windows.Forms.Padding(4);
this.FakeTypeComboBox.Name = "FakeTypeComboBox";
this.FakeTypeComboBox.Size = new System.Drawing.Size(439, 32);
this.FakeTypeComboBox.TabIndex = 15;
this.FakeTypeComboBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ComboBox_DrawItem);
//
// TransferProtocolLabel
//
this.TransferProtocolLabel.AutoSize = true;
this.TransferProtocolLabel.Location = new System.Drawing.Point(15, 255);
this.TransferProtocolLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.TransferProtocolLabel.Name = "TransferProtocolLabel";
this.TransferProtocolLabel.Size = new System.Drawing.Size(156, 24);
this.TransferProtocolLabel.TabIndex = 12;
this.TransferProtocolLabel.Text = "Transfer Protocol";
//
// TransferProtocolComboBox
//
this.TransferProtocolComboBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.TransferProtocolComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.TransferProtocolComboBox.FormattingEnabled = true;
this.TransferProtocolComboBox.Location = new System.Drawing.Point(180, 249);
this.TransferProtocolComboBox.Margin = new System.Windows.Forms.Padding(4);
this.TransferProtocolComboBox.Name = "TransferProtocolComboBox";
this.TransferProtocolComboBox.Size = new System.Drawing.Size(439, 32);
this.TransferProtocolComboBox.TabIndex = 13;
this.TransferProtocolComboBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ComboBox_DrawItem);
//
// EncryptMethodLabel
//
this.EncryptMethodLabel.AutoSize = true;
this.EncryptMethodLabel.Location = new System.Drawing.Point(15, 208);
this.EncryptMethodLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.EncryptMethodLabel.Name = "EncryptMethodLabel";
this.EncryptMethodLabel.Size = new System.Drawing.Size(150, 24);
this.EncryptMethodLabel.TabIndex = 10;
this.EncryptMethodLabel.Text = "Encrypt Method";
//
// EncryptMethodComboBox
//
this.EncryptMethodComboBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.EncryptMethodComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.EncryptMethodComboBox.FormattingEnabled = true;
this.EncryptMethodComboBox.Location = new System.Drawing.Point(180, 202);
this.EncryptMethodComboBox.Margin = new System.Windows.Forms.Padding(4);
this.EncryptMethodComboBox.Name = "EncryptMethodComboBox";
this.EncryptMethodComboBox.Size = new System.Drawing.Size(439, 32);
this.EncryptMethodComboBox.TabIndex = 11;
this.EncryptMethodComboBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ComboBox_DrawItem);
//
// AlterIDLabel
//
this.AlterIDLabel.AutoSize = true;
this.AlterIDLabel.Location = new System.Drawing.Point(15, 164);
this.AlterIDLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.AlterIDLabel.Name = "AlterIDLabel";
this.AlterIDLabel.Size = new System.Drawing.Size(76, 24);
this.AlterIDLabel.TabIndex = 8;
this.AlterIDLabel.Text = "Alter ID";
//
// AlterIDTextBox
//
this.AlterIDTextBox.Location = new System.Drawing.Point(180, 159);
this.AlterIDTextBox.Margin = new System.Windows.Forms.Padding(4);
this.AlterIDTextBox.Name = "AlterIDTextBox";
this.AlterIDTextBox.Size = new System.Drawing.Size(79, 31);
this.AlterIDTextBox.TabIndex = 9;
this.AlterIDTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// UserIDLabel
//
this.UserIDLabel.AutoSize = true;
this.UserIDLabel.Location = new System.Drawing.Point(15, 120);
this.UserIDLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.UserIDLabel.Name = "UserIDLabel";
this.UserIDLabel.Size = new System.Drawing.Size(72, 24);
this.UserIDLabel.TabIndex = 6;
this.UserIDLabel.Text = "User ID";
//
// UserIDTextBox
//
this.UserIDTextBox.Location = new System.Drawing.Point(180, 116);
this.UserIDTextBox.Margin = new System.Windows.Forms.Padding(4);
this.UserIDTextBox.Name = "UserIDTextBox";
this.UserIDTextBox.Size = new System.Drawing.Size(439, 31);
this.UserIDTextBox.TabIndex = 7;
this.UserIDTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// PortTextBox
//
this.PortTextBox.Location = new System.Drawing.Point(540, 72);
this.PortTextBox.Margin = new System.Windows.Forms.Padding(4);
this.PortTextBox.Name = "PortTextBox";
this.PortTextBox.Size = new System.Drawing.Size(79, 31);
this.PortTextBox.TabIndex = 5;
this.PortTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// AddressTextBox
//
this.AddressTextBox.Location = new System.Drawing.Point(180, 72);
this.AddressTextBox.Margin = new System.Windows.Forms.Padding(4);
this.AddressTextBox.Name = "AddressTextBox";
this.AddressTextBox.Size = new System.Drawing.Size(349, 31);
this.AddressTextBox.TabIndex = 3;
this.AddressTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// AddressLabel
//
this.AddressLabel.AutoSize = true;
this.AddressLabel.Location = new System.Drawing.Point(15, 76);
this.AddressLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.AddressLabel.Name = "AddressLabel";
this.AddressLabel.Size = new System.Drawing.Size(80, 24);
this.AddressLabel.TabIndex = 2;
this.AddressLabel.Text = "Address";
//
// RemarkTextBox
//
this.RemarkTextBox.Location = new System.Drawing.Point(180, 28);
this.RemarkTextBox.Margin = new System.Windows.Forms.Padding(4);
this.RemarkTextBox.Name = "RemarkTextBox";
this.RemarkTextBox.Size = new System.Drawing.Size(439, 31);
this.RemarkTextBox.TabIndex = 1;
this.RemarkTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// RemarkLabel
//
this.RemarkLabel.AutoSize = true;
this.RemarkLabel.Location = new System.Drawing.Point(15, 33);
this.RemarkLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.RemarkLabel.Name = "RemarkLabel";
this.RemarkLabel.Size = new System.Drawing.Size(76, 24);
this.RemarkLabel.TabIndex = 0;
this.RemarkLabel.Text = "Remark";
//
// PortLabel
//
this.PortLabel.AutoSize = true;
this.PortLabel.Location = new System.Drawing.Point(530, 76);
this.PortLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.PortLabel.Name = "PortLabel";
this.PortLabel.Size = new System.Drawing.Size(14, 24);
this.PortLabel.TabIndex = 4;
this.PortLabel.Text = ":";
//
// ControlButton
//
this.ControlButton.Location = new System.Drawing.Point(536, 586);
this.ControlButton.Margin = new System.Windows.Forms.Padding(4);
this.ControlButton.Name = "ControlButton";
this.ControlButton.Size = new System.Drawing.Size(112, 34);
this.ControlButton.TabIndex = 2;
this.ControlButton.Text = "Save";
this.ControlButton.UseVisualStyleBackColor = true;
this.ControlButton.Click += new System.EventHandler(this.ControlButton_Click);
//
// VMess
//
this.AutoScaleDimensions = new System.Drawing.SizeF(144F, 144F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.ClientSize = new System.Drawing.Size(666, 639);
this.Controls.Add(this.ControlButton);
this.Controls.Add(this.ConfigurationGroupBox);
this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Margin = new System.Windows.Forms.Padding(4, 6, 4, 6);
this.MaximizeBox = false;
this.Name = "VMess";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "VMess";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.VMess_FormClosing);
this.Load += new System.EventHandler(this.VMess_Load);
this.ConfigurationGroupBox.ResumeLayout(false);
this.ConfigurationGroupBox.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox ConfigurationGroupBox;
private System.Windows.Forms.TextBox PortTextBox;
private System.Windows.Forms.TextBox AddressTextBox;
private System.Windows.Forms.Label AddressLabel;
private System.Windows.Forms.TextBox RemarkTextBox;
private System.Windows.Forms.Label RemarkLabel;
private System.Windows.Forms.Label PortLabel;
private System.Windows.Forms.Label UserIDLabel;
private System.Windows.Forms.TextBox UserIDTextBox;
private System.Windows.Forms.Label AlterIDLabel;
private System.Windows.Forms.TextBox AlterIDTextBox;
private System.Windows.Forms.Label EncryptMethodLabel;
private System.Windows.Forms.ComboBox EncryptMethodComboBox;
private System.Windows.Forms.Label TransferProtocolLabel;
private System.Windows.Forms.ComboBox TransferProtocolComboBox;
private System.Windows.Forms.Label FakeTypeLabel;
private System.Windows.Forms.ComboBox FakeTypeComboBox;
private System.Windows.Forms.Label HostLabel;
private System.Windows.Forms.TextBox HostTextBox;
private System.Windows.Forms.Label PathLabel;
private System.Windows.Forms.TextBox PathTextBox;
private System.Windows.Forms.Label QUICSecurityLabel;
private System.Windows.Forms.TextBox QUICSecretTextBox;
private System.Windows.Forms.ComboBox QUICSecurityComboBox;
private System.Windows.Forms.Label QUICSecretLabel;
private System.Windows.Forms.CheckBox TLSSecureCheckBox;
private System.Windows.Forms.Button ControlButton;
private System.Windows.Forms.CheckBox UseMuxCheckBox;
}
}

168
Netch/Forms/Server/Vmess.cs Normal file
View File

@@ -0,0 +1,168 @@
using System;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace Netch.Forms.Server
{
public partial class VMess : Form
{
public int Index;
public VMess(int index = -1)
{
InitializeComponent();
Index = index;
}
private void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
{
var cbx = sender as ComboBox;
if (cbx != null)
{
e.DrawBackground();
if (e.Index >= 0)
{
var sf = new StringFormat();
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;
var brush = new SolidBrush(cbx.ForeColor);
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
brush = SystemBrushes.HighlightText as SolidBrush;
}
e.Graphics.DrawString(cbx.Items[e.Index].ToString(), cbx.Font, brush, e.Bounds, sf);
}
}
}
private void VMess_Load(object sender, EventArgs e)
{
ConfigurationGroupBox.Text = Utils.i18N.Translate(ConfigurationGroupBox.Text);
RemarkLabel.Text = Utils.i18N.Translate(RemarkLabel.Text);
AddressLabel.Text = Utils.i18N.Translate(AddressLabel.Text);
UserIDLabel.Text = Utils.i18N.Translate(UserIDLabel.Text);
AlterIDLabel.Text = Utils.i18N.Translate(AlterIDLabel.Text);
EncryptMethodLabel.Text = Utils.i18N.Translate(EncryptMethodLabel.Text);
TransferProtocolLabel.Text = Utils.i18N.Translate(TransferProtocolLabel.Text);
FakeTypeLabel.Text = Utils.i18N.Translate(FakeTypeLabel.Text);
HostLabel.Text = Utils.i18N.Translate(HostLabel.Text);
PathLabel.Text = Utils.i18N.Translate(PathLabel.Text);
QUICSecurityLabel.Text = Utils.i18N.Translate(QUICSecurityLabel.Text);
QUICSecretLabel.Text = Utils.i18N.Translate(QUICSecretLabel.Text);
TLSSecureCheckBox.Text = Utils.i18N.Translate(TLSSecureCheckBox.Text);
UseMuxCheckBox.Text = Utils.i18N.Translate(UseMuxCheckBox.Text);
ControlButton.Text = Utils.i18N.Translate(ControlButton.Text);
foreach (var encrypt in Global.EncryptMethods.VMess)
{
EncryptMethodComboBox.Items.Add(encrypt);
}
foreach (var protocol in Global.TransferProtocols)
{
TransferProtocolComboBox.Items.Add(protocol);
}
foreach (var fake in Global.FakeTypes)
{
FakeTypeComboBox.Items.Add(fake);
}
foreach (var security in Global.EncryptMethods.VMessQUIC)
{
QUICSecurityComboBox.Items.Add(security);
}
if (Index != -1)
{
RemarkTextBox.Text = Global.Settings.Server[Index].Remark;
AddressTextBox.Text = Global.Settings.Server[Index].Hostname;
PortTextBox.Text = Global.Settings.Server[Index].Port.ToString();
UserIDTextBox.Text = Global.Settings.Server[Index].UserID;
AlterIDTextBox.Text = Global.Settings.Server[Index].AlterID.ToString();
EncryptMethodComboBox.SelectedIndex = Global.EncryptMethods.VMess.IndexOf(Global.Settings.Server[Index].EncryptMethod);
TransferProtocolComboBox.SelectedIndex = Global.TransferProtocols.IndexOf(Global.Settings.Server[Index].TransferProtocol);
FakeTypeComboBox.SelectedIndex = Global.FakeTypes.IndexOf(Global.Settings.Server[Index].FakeType);
HostTextBox.Text = Global.Settings.Server[Index].Host;
PathTextBox.Text = Global.Settings.Server[Index].Path;
QUICSecurityComboBox.SelectedIndex = Global.EncryptMethods.VMessQUIC.IndexOf(Global.Settings.Server[Index].QUICSecure);
QUICSecretTextBox.Text = Global.Settings.Server[Index].QUICSecret;
TLSSecureCheckBox.Checked = Global.Settings.Server[Index].TLSSecure;
UseMuxCheckBox.Checked = Global.Settings.Server[Index].UseMux;
}
else
{
EncryptMethodComboBox.SelectedIndex = 0;
TransferProtocolComboBox.SelectedIndex = 0;
FakeTypeComboBox.SelectedIndex = 0;
QUICSecurityComboBox.SelectedIndex = 0;
}
}
private void VMess_FormClosing(object sender, FormClosingEventArgs e)
{
Global.MainForm.Show();
}
private void ControlButton_Click(object sender, EventArgs e)
{
if (!Regex.Match(PortTextBox.Text, "^[0-9]+$").Success)
{
return;
}
if (Index == -1)
{
Global.Settings.Server.Add(new Models.Server
{
Remark = RemarkTextBox.Text,
Type = "VMess",
Hostname = AddressTextBox.Text,
Port = int.Parse(PortTextBox.Text),
UserID = UserIDTextBox.Text,
AlterID = int.Parse(AlterIDTextBox.Text),
EncryptMethod = EncryptMethodComboBox.Text,
TransferProtocol = TransferProtocolComboBox.Text,
FakeType = FakeTypeComboBox.Text,
Host = HostTextBox.Text,
Path = PathTextBox.Text,
QUICSecure = QUICSecurityComboBox.Text,
QUICSecret = QUICSecretTextBox.Text,
TLSSecure = TLSSecureCheckBox.Checked,
UseMux = UseMuxCheckBox.Checked
});
}
else
{
Global.Settings.Server[Index] = new Models.Server
{
Remark = RemarkTextBox.Text,
Type = "VMess",
Hostname = AddressTextBox.Text,
Port = int.Parse(PortTextBox.Text),
UserID = UserIDTextBox.Text,
AlterID = int.Parse(AlterIDTextBox.Text),
EncryptMethod = EncryptMethodComboBox.Text,
TransferProtocol = TransferProtocolComboBox.Text,
FakeType = FakeTypeComboBox.Text,
Host = HostTextBox.Text,
Path = PathTextBox.Text,
QUICSecure = QUICSecurityComboBox.Text,
QUICSecret = QUICSecretTextBox.Text,
TLSSecure = TLSSecureCheckBox.Checked,
UseMux = UseMuxCheckBox.Checked
};
}
Utils.Configuration.Save();
MessageBox.Show(Utils.i18N.Translate("Saved"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
Global.MainForm.InitServer();
Close();
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -19,7 +19,7 @@ namespace Netch.Models
public string Group = "None";
/// <summary>
/// 代理类型HTTP、HTTPS、Socks5、SS、SSR
/// 代理类型HTTP、HTTPS、Socks5、SS、SSR、VMess
/// </summary>
public string Type;
@@ -49,7 +49,17 @@ namespace Netch.Models
public string Password;
/// <summary>
/// 加密方式SS、SSR
/// 用户 IDVMess
/// </summary>
public string UserID = string.Empty;
/// <summary>
/// 额外 IDVMess
/// </summary>
public int AlterID = 0;
/// <summary>
/// 加密方式SS、SSR、VMess
/// </summary>
public string EncryptMethod;
@@ -83,6 +93,46 @@ namespace Netch.Models
/// </summary>
public string OBFSParam;
/// <summary>
/// 传输协议VMess
/// </summary>
public string TransferProtocol = "tcp";
/// <summary>
/// 伪装类型VMess
/// </summary>
public string FakeType = string.Empty;
/// <summary>
/// 伪装域名VMessHTTP、WebSocket、HTTP/2
/// </summary>
public string Host = string.Empty;
/// <summary>
/// 传输路径VMessWebSocket、HTTP/2
/// </summary>
public string Path = string.Empty;
/// <summary>
/// QUIC 加密方式VMess
/// </summary>
public string QUICSecure = "none";
/// <summary>
/// QUIC 加密密钥VMess
/// </summary>
public string QUICSecret = string.Empty;
/// <summary>
/// TLS 底层传输安全VMess
/// </summary>
public bool TLSSecure = false;
/// <summary>
/// Mux 多路复用VMess
/// </summary>
public bool UseMux = false;
/// <summary>
/// 延迟
/// </summary>
@@ -107,6 +157,8 @@ namespace Netch.Models
return $"[SS] {Remark}";
case "SSR":
return $"[SR] {Remark}";
case "VMess":
return $"[V2] {Remark}";
default:
return "WTF";
}

76
Netch/Models/VMess.cs Normal file
View File

@@ -0,0 +1,76 @@
namespace Netch.Models
{
/// <summary>
/// 使用 v2rayN 定义的 VMess 链接格式
/// </summary>
public class VMess
{
/// <summary>
/// Mux Class
/// </summary>
public class Mux
{
public object enabled;
}
/// <summary>
/// 链接版本
/// </summary>
public string v;
/// <summary>
/// 备注
/// </summary>
public string ps;
/// <summary>
/// 地址
/// </summary>
public string add;
/// <summary>
/// 端口
/// </summary>
public int port;
/// <summary>
/// 用户 ID
/// </summary>
public string id;
/// <summary>
/// 额外 ID
/// </summary>
public int aid = 0;
/// <summary>
/// 传输协议
/// </summary>
public string net;
/// <summary>
/// 伪装类型
/// </summary>
public string type;
/// <summary>
/// 伪装域名HTTPWS
/// </summary>
public string host;
/// <summary>
/// 伪装路径
/// </summary>
public string path;
/// <summary>
/// 是否使用 TLS
/// </summary>
public string tls;
/// <summary>
/// Mux 多路复用
/// </summary>
public Mux mux;
}
}

View File

@@ -51,6 +51,10 @@ namespace Netch.Utils
{
Global.Settings.Server[i].Type = "SSR";
}
else if (Global.Settings.Server[i].Type == "VMess")
{
Global.Settings.Server[i].QUICSecure = LegacySettingConfig.Server[i].QUICSecurity;
}
}
}
}

View File

@@ -305,6 +305,86 @@ namespace Netch.Utils
list.Add(data);
}
else if (text.StartsWith("vmess://"))
{
var data = new Server();
data.Type = "VMess";
text = text.Substring(8);
var vmess = JsonConvert.DeserializeObject<VMess>(URLSafeBase64Decode(text));
data.Remark = vmess.ps;
data.Hostname = vmess.add;
data.Port = vmess.port;
data.UserID = vmess.id;
data.AlterID = vmess.aid;
data.TransferProtocol = vmess.net;
if (!Global.TransferProtocols.Contains(data.TransferProtocol))
{
Logging.Info(string.Format("不支持的 VMess 传输协议:{0}", data.TransferProtocol));
return null;
}
data.FakeType = vmess.type;
if (!Global.FakeTypes.Contains(data.FakeType))
{
Logging.Info(string.Format("不支持的 VMess 伪装类型:{0}", data.FakeType));
return null;
}
if (vmess.v == null || vmess.v == "1")
{
var info = vmess.host.Split(';');
if (info.Length == 2)
{
vmess.host = info[0];
vmess.path = info[1];
}
}
if (data.TransferProtocol == "quic")
{
if (!Global.EncryptMethods.VMessQUIC.Contains(vmess.host))
{
Logging.Info(string.Format("不支持的 VMess QUIC 加密方式:{0}", vmess.host));
return null;
}
data.QUICSecure = vmess.host;
data.QUICSecret = vmess.path;
}
else
{
data.Host = vmess.host;
data.Path = vmess.path;
}
data.TLSSecure = vmess.tls == "tls";
if (vmess.mux == null)
{
data.UseMux = false;
}
else
{
if (vmess.mux.enabled is bool enabled)
{
data.UseMux = enabled;
}
else if (vmess.mux.enabled is string muxEnabled)
{
data.UseMux = muxEnabled == "true"; // 针对使用字符串当作布尔值的情况
}
else
{
data.UseMux = false;
}
}
data.EncryptMethod = "auto"; // V2Ray 加密方式不包括在链接中,主动添加一个
list.Add(data);
}
else if (text.StartsWith("Netch://"))
{
text = text.Substring(8);
@@ -343,6 +423,26 @@ namespace Netch.Utils
return null;
}
break;
case "VMess":
if (!Global.TransferProtocols.Contains(NetchLink.TransferProtocol))
{
Logging.Info($"不支持的 VMess 传输协议:{NetchLink.TransferProtocol}");
return null;
}
if (!Global.FakeTypes.Contains(NetchLink.FakeType))
{
Logging.Info($"不支持的 VMess 伪装类型:{NetchLink.FakeType}");
return null;
}
if (NetchLink.TransferProtocol == "quic")
{
if (!Global.EncryptMethods.VMessQUIC.Contains(NetchLink.QUICSecure))
{
Logging.Info($"不支持的 VMess QUIC 加密方式:{NetchLink.QUICSecure}");
return null;
}
}
break;
default:
return null;
}