From 5ec275a7e0549a221464394e23424e82db1cec61 Mon Sep 17 00:00:00 2001 From: 2dust Date: Wed, 21 Aug 2019 16:34:22 +0800 Subject: [PATCH] add socks user --- .../v2rayN/Forms/AddServer4Form.Designer.cs | 44 +- v2rayN/v2rayN/Forms/AddServer4Form.cs | 10 + v2rayN/v2rayN/Forms/AddServer4Form.resx | 549 +++++++++++------- .../v2rayN/Forms/AddServer4Form.zh-Hans.resx | 26 +- v2rayN/v2rayN/Handler/ConfigHandler.cs | 4 +- v2rayN/v2rayN/Handler/V2rayConfigHandler.cs | 84 ++- v2rayN/v2rayN/Mode/V2rayConfig.cs | 22 + 7 files changed, 482 insertions(+), 257 deletions(-) diff --git a/v2rayN/v2rayN/Forms/AddServer4Form.Designer.cs b/v2rayN/v2rayN/Forms/AddServer4Form.Designer.cs index fb950a5c..3ae98f0b 100644 --- a/v2rayN/v2rayN/Forms/AddServer4Form.Designer.cs +++ b/v2rayN/v2rayN/Forms/AddServer4Form.Designer.cs @@ -31,6 +31,10 @@ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AddServer4Form)); this.btnClose = new System.Windows.Forms.Button(); this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.txtSecurity = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.txtId = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); this.label13 = new System.Windows.Forms.Label(); this.txtRemarks = new System.Windows.Forms.TextBox(); this.label6 = new System.Windows.Forms.Label(); @@ -51,15 +55,18 @@ // // btnClose // - resources.ApplyResources(this.btnClose, "btnClose"); this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel; + resources.ApplyResources(this.btnClose, "btnClose"); this.btnClose.Name = "btnClose"; this.btnClose.UseVisualStyleBackColor = true; this.btnClose.Click += new System.EventHandler(this.btnClose_Click); // // groupBox1 // - resources.ApplyResources(this.groupBox1, "groupBox1"); + this.groupBox1.Controls.Add(this.txtSecurity); + this.groupBox1.Controls.Add(this.label4); + this.groupBox1.Controls.Add(this.txtId); + this.groupBox1.Controls.Add(this.label3); this.groupBox1.Controls.Add(this.label13); this.groupBox1.Controls.Add(this.txtRemarks); this.groupBox1.Controls.Add(this.label6); @@ -67,9 +74,30 @@ this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.txtAddress); this.groupBox1.Controls.Add(this.label1); + resources.ApplyResources(this.groupBox1, "groupBox1"); this.groupBox1.Name = "groupBox1"; this.groupBox1.TabStop = false; // + // txtSecurity + // + resources.ApplyResources(this.txtSecurity, "txtSecurity"); + this.txtSecurity.Name = "txtSecurity"; + // + // label4 + // + resources.ApplyResources(this.label4, "label4"); + this.label4.Name = "label4"; + // + // txtId + // + resources.ApplyResources(this.txtId, "txtId"); + this.txtId.Name = "txtId"; + // + // label3 + // + resources.ApplyResources(this.label3, "label3"); + this.label3.Name = "label3"; + // // label13 // resources.ApplyResources(this.label13, "label13"); @@ -107,9 +135,9 @@ // // panel2 // - resources.ApplyResources(this.panel2, "panel2"); this.panel2.Controls.Add(this.btnClose); this.panel2.Controls.Add(this.btnOK); + resources.ApplyResources(this.panel2, "panel2"); this.panel2.Name = "panel2"; // // btnOK @@ -126,22 +154,22 @@ // // menuServer // - resources.ApplyResources(this.menuServer, "menuServer"); this.menuServer.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.MenuItem1}); + resources.ApplyResources(this.menuServer, "menuServer"); this.menuServer.Name = "menuServer"; // // MenuItem1 // - resources.ApplyResources(this.MenuItem1, "MenuItem1"); this.MenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.menuItemImportClipboard}); this.MenuItem1.Name = "MenuItem1"; + resources.ApplyResources(this.MenuItem1, "MenuItem1"); // // menuItemImportClipboard // - resources.ApplyResources(this.menuItemImportClipboard, "menuItemImportClipboard"); this.menuItemImportClipboard.Name = "menuItemImportClipboard"; + resources.ApplyResources(this.menuItemImportClipboard, "menuItemImportClipboard"); this.menuItemImportClipboard.Click += new System.EventHandler(this.menuItemImportClipboard_Click); // // AddServer4Form @@ -184,5 +212,9 @@ private System.Windows.Forms.MenuStrip menuServer; private System.Windows.Forms.ToolStripMenuItem MenuItem1; private System.Windows.Forms.ToolStripMenuItem menuItemImportClipboard; + private System.Windows.Forms.TextBox txtId; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox txtSecurity; + private System.Windows.Forms.Label label4; } } \ No newline at end of file diff --git a/v2rayN/v2rayN/Forms/AddServer4Form.cs b/v2rayN/v2rayN/Forms/AddServer4Form.cs index edb80516..d331bec2 100644 --- a/v2rayN/v2rayN/Forms/AddServer4Form.cs +++ b/v2rayN/v2rayN/Forms/AddServer4Form.cs @@ -36,6 +36,8 @@ namespace v2rayN.Forms { txtAddress.Text = vmessItem.address; txtPort.Text = vmessItem.port.ToString(); + txtId.Text = vmessItem.id; + txtSecurity.Text = vmessItem.security; txtRemarks.Text = vmessItem.remarks; } @@ -47,6 +49,8 @@ namespace v2rayN.Forms { txtAddress.Text = ""; txtPort.Text = ""; + txtId.Text = ""; + txtSecurity.Text = ""; txtRemarks.Text = ""; } @@ -54,6 +58,8 @@ namespace v2rayN.Forms { string address = txtAddress.Text; string port = txtPort.Text; + string id = txtId.Text; + string security = txtSecurity.Text; string remarks = txtRemarks.Text; if (Utils.IsNullOrEmpty(address)) @@ -69,6 +75,8 @@ namespace v2rayN.Forms vmessItem.address = address; vmessItem.port = Utils.ToInt(port); + vmessItem.id = id; + vmessItem.security = security; vmessItem.remarks = remarks; if (ConfigHandler.AddSocksServer(ref config, vmessItem, EditIndex) == 0) @@ -112,6 +120,8 @@ namespace v2rayN.Forms txtAddress.Text = vmessItem.address; txtPort.Text = vmessItem.port.ToString(); + txtSecurity.Text = vmessItem.security; + txtId.Text = vmessItem.id; txtRemarks.Text = vmessItem.remarks; } diff --git a/v2rayN/v2rayN/Forms/AddServer4Form.resx b/v2rayN/v2rayN/Forms/AddServer4Form.resx index d1e34f1a..566de4b3 100644 --- a/v2rayN/v2rayN/Forms/AddServer4Form.resx +++ b/v2rayN/v2rayN/Forms/AddServer4Form.resx @@ -117,367 +117,472 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - txtAddress + + + 396, 17 - - Server address + + 75, 23 - - 3 + + 4 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + &Cancel - - - Bottom + + btnClose - - groupBox1 + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True + + panel2 - - menuServer + + 0 - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 127, 84 - - btnOK + + 278, 21 - - txtRemarks + + 26 - - - 194, 21 + + txtSecurity - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - AddServer4Form + + groupBox1 - + + 0 + + + True + + + + NoControl + + + 12, 88 + + 89, 12 - - label1 + + 25 - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + User(Optional) - + + label4 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + groupBox1 - - panel2 + + 1 - - 12, 158 + + 127, 117 - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + * - - Fill + + 278, 21 - - 194, 21 + + 24 - - groupBox1 + + txtId - - 6, 12 + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 547, 25 + + groupBox1 - + + 2 + + True - - Alias (remarks) + + NoControl - - 127, 154 + + 12, 121 - - groupBox1 + + 113, 12 - - 6 + + 23 - - 7 + + Password(Optional) - + + label3 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + groupBox1 + + 3 + + + True + + + 337, 158 + 113, 12 - - MenuItem1 + + 22 - - Server + + * Fill in manually - - 162, 21 + + label13 - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 0 + + groupBox1 - - 2 + + 4 - - 547, 60 + + 127, 154 - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 194, 21 - - Edit or add a [Socks] server + + 11 - - 359, 21 + + txtRemarks - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 547, 10 + + groupBox1 - - * Fill in manually + + 5 - - 4 + + True + + + 12, 158 + + + 95, 12 10 - - 71, 12 + + Alias (remarks) - - 0 + + label6 - - panel1 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 75, 23 + + groupBox1 + + + 6 + + + 127, 56 + + + 194, 21 + + + 3 + + + txtPort + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 7 + + + True 12, 60 - - 1 + + 71, 12 - - $this + + 2 - - btnClose + + Server port - - label6 + + label2 - - 8 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 303, 17 + + groupBox1 + + + 8 127, 27 - - 75, 23 + + 359, 21 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 1 - - $this + + txtAddress - - Top + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 0, 35 + + groupBox1 - - 2 + + 9 - - $this + + True - - panel2 + + 12, 31 - - 547, 196 + + 89, 12 - - 2 + + 0 - - 6 + + Server address - - 235, 22 + + label1 - - 4 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 3 + + groupBox1 - - True + + 10 - - 5 + + Fill - - groupBox1 + + 0, 35 - - txtPort + + 547, 196 - - 127, 56 + + 3 - - 95, 12 + + Server + + + groupBox1 System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True + + $this - - Import URL from clipboard + + 0 - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 303, 17 - - &Cancel + + 75, 23 - - 12, 31 + + 5 &OK - - 11 + + btnOK - - 0 + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Server port + + panel2 - - 337, 158 + + 1 - - groupBox1 + + Bottom - - Import configuration file + + 0, 231 - - 0, 0 + + 547, 60 - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 7 - - 5 + + panel2 - - System.Windows.Forms.MenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 3 + + $this - + 1 + + Top + 0, 25 - - 1 + + 547, 10 - - label13 + + 6 - - 3 + + panel1 - - label2 + + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - groupBox1 + + $this - - panel2 + + 2 - - 0, 231 + + 17, 17 + + + 235, 22 - - 22 + + Import URL from clipboard - - 547, 291 + + 162, 21 - - 0 + + Import configuration file - - v2rayN.Forms.BaseForm, v2rayN, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + + 0, 0 - - menuItemImportClipboard + + 547, 25 - - $this + + 8 - - 396, 17 + + menuServer - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + System.Windows.Forms.MenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 1 + + $this - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 3 True - - 17, 17 - + + 6, 12 + + + 547, 291 + + + Edit or add a [Socks] server + + + MenuItem1 + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + menuItemImportClipboard + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + AddServer4Form + + + v2rayN.Forms.BaseForm, v2rayN, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/v2rayN/v2rayN/Forms/AddServer4Form.zh-Hans.resx b/v2rayN/v2rayN/Forms/AddServer4Form.zh-Hans.resx index 40b56c76..6a3cc081 100644 --- a/v2rayN/v2rayN/Forms/AddServer4Form.zh-Hans.resx +++ b/v2rayN/v2rayN/Forms/AddServer4Form.zh-Hans.resx @@ -123,10 +123,34 @@ 服务器 + + + 127, 85 + + + 12, 89 + + + 77, 12 + + + 用户名(可选) + + + 127, 115 + + + 12, 119 + + + 65, 12 + + + 密码(可选) + *手填,方便识别管理 - 83, 12 diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs index eccef7b5..c9d18b62 100644 --- a/v2rayN/v2rayN/Handler/ConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs @@ -366,7 +366,9 @@ namespace v2rayN.Handler { remark = "#" + WebUtility.UrlEncode(vmessItem.remarks); } - url = string.Format("{0}:{1}", + url = string.Format("{0}:{1}@{2}:{3}", + vmessItem.security, + vmessItem.id, vmessItem.address, vmessItem.port); url = Utils.Base64Encode(url); diff --git a/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs b/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs index 531c501b..fbd585bf 100644 --- a/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs @@ -400,6 +400,17 @@ namespace v2rayN.Handler serversItem.address = config.address(); serversItem.port = config.port(); + if (!string.IsNullOrEmpty(config.security()) + && !string.IsNullOrEmpty(config.id())) + { + var socksUsersItem = new SocksUsersItem(); + socksUsersItem.user = config.security(); + socksUsersItem.pass = config.id(); + socksUsersItem.level = 1; + + serversItem.users = new List() { socksUsersItem }; + } + outbound.mux.enabled = false; outbound.protocol = "socks"; @@ -425,7 +436,21 @@ namespace v2rayN.Handler { //远程服务器底层传输配置 streamSettings.network = config.network(); - streamSettings.security = config.streamSecurity(); + var host = config.requestHost(); + + //if tls + if (config.streamSecurity() == "tls") + { + streamSettings.security = config.streamSecurity(); + + TlsSettings tlsSettings = new TlsSettings(); + tlsSettings.allowInsecure = config.allowInsecure(); + if (!string.IsNullOrWhiteSpace(host)) + { + tlsSettings.serverName = host; + } + streamSettings.tlsSettings = tlsSettings; + } //streamSettings switch (config.network()) @@ -463,12 +488,11 @@ namespace v2rayN.Handler WsSettings wsSettings = new WsSettings(); wsSettings.connectionReuse = true; - string host2 = config.requestHost(); string path = config.path(); - if (!string.IsNullOrWhiteSpace(host2)) + if (!string.IsNullOrWhiteSpace(host)) { wsSettings.headers = new Headers(); - wsSettings.headers.Host = host2; + wsSettings.headers.Host = host; } if (!string.IsNullOrWhiteSpace(path)) { @@ -476,35 +500,34 @@ namespace v2rayN.Handler } streamSettings.wsSettings = wsSettings; - TlsSettings tlsSettings = new TlsSettings(); - tlsSettings.allowInsecure = config.allowInsecure(); - if (!string.IsNullOrWhiteSpace(host2)) - { - tlsSettings.serverName = host2; - } - streamSettings.tlsSettings = tlsSettings; + //TlsSettings tlsSettings = new TlsSettings(); + //tlsSettings.allowInsecure = config.allowInsecure(); + //if (!string.IsNullOrWhiteSpace(host)) + //{ + // tlsSettings.serverName = host; + //} + //streamSettings.tlsSettings = tlsSettings; break; //h2 case "h2": HttpSettings httpSettings = new HttpSettings(); - string host3 = config.requestHost(); - if (!string.IsNullOrWhiteSpace(host3)) + if (!string.IsNullOrWhiteSpace(host)) { - httpSettings.host = Utils.String2List(host3); + httpSettings.host = Utils.String2List(host); } httpSettings.path = config.path(); streamSettings.httpSettings = httpSettings; - TlsSettings tlsSettings2 = new TlsSettings(); - tlsSettings2.allowInsecure = config.allowInsecure(); - streamSettings.tlsSettings = tlsSettings2; + //TlsSettings tlsSettings2 = new TlsSettings(); + //tlsSettings2.allowInsecure = config.allowInsecure(); + //streamSettings.tlsSettings = tlsSettings2; break; //quic case "quic": QuicSettings quicsettings = new QuicSettings(); - quicsettings.security = config.requestHost(); + quicsettings.security = host; quicsettings.key = config.path(); quicsettings.header = new Header(); quicsettings.header.type = config.headerType(); @@ -524,9 +547,9 @@ namespace v2rayN.Handler { //request填入自定义Host string request = Utils.GetEmbedText(Global.v2raySampleHttprequestFileName); - string[] arrHost = config.requestHost().Split(','); - string host = string.Join("\",\"", arrHost); - request = request.Replace("$requestHost$", string.Format("\"{0}\"", host)); + string[] arrHost = host.Split(','); + string host2 = string.Join("\",\"", arrHost); + request = request.Replace("$requestHost$", string.Format("\"{0}\"", host2)); //request = request.Replace("$requestHost$", string.Format("\"{0}\"", config.requestHost())); //填入自定义Path @@ -1159,7 +1182,7 @@ namespace v2rayN.Handler result = result.Substring(0, indexRemark); } //part decode - int indexS = result.IndexOf(":"); + int indexS = result.IndexOf("@"); if (indexS > 0) { } @@ -1168,15 +1191,22 @@ namespace v2rayN.Handler result = Utils.Base64Decode(result); } - - string[] arr21 = result.Split(':'); - int indexPort = result.LastIndexOf(":"); + string[] arr1 = result.Split('@'); + if (arr1.Length != 2) + { + return null; + } + string[] arr21 = arr1[0].Split(':'); + //string[] arr22 = arr1[1].Split(':'); + int indexPort = arr1[1].LastIndexOf(":"); if (arr21.Length != 2 || indexPort < 0) { return null; } - vmessItem.address = result.Substring(0, indexPort); - vmessItem.port = Utils.ToInt(result.Substring(indexPort + 1, result.Length - (indexPort + 1))); + vmessItem.address = arr1[1].Substring(0, indexPort); + vmessItem.port = Utils.ToInt(arr1[1].Substring(indexPort + 1, arr1[1].Length - (indexPort + 1))); + vmessItem.security = arr21[0]; + vmessItem.id = arr21[1]; } else { diff --git a/v2rayN/v2rayN/Mode/V2rayConfig.cs b/v2rayN/v2rayN/Mode/V2rayConfig.cs index a57c885a..b6502abb 100644 --- a/v2rayN/v2rayN/Mode/V2rayConfig.cs +++ b/v2rayN/v2rayN/Mode/V2rayConfig.cs @@ -215,8 +215,30 @@ namespace v2rayN.Mode /// /// public int level { get; set; } + + /// + /// + /// + public List users { get; set; } + } + + public class SocksUsersItem + { + /// + /// + /// + public string user { get; set; } + /// + /// + /// + public string pass { get; set; } + /// + /// + /// + public int level { get; set; } } + public class Mux { ///