From 8ccba920c6d25366b47da0834be9b8ffbfc1d503 Mon Sep 17 00:00:00 2001 From: wisdomwei201804 Date: Thu, 21 Jun 2018 17:31:30 +0800 Subject: [PATCH] =?UTF-8?q?v3.8.3.5=20=201=E3=80=81=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B0=83=E8=AF=95=E6=88=90=E5=8A=9F=EF=BC=8C?= =?UTF-8?q?ngrok=E7=BD=91=E7=BB=9C=E7=A9=BF=E9=80=8F=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net.nutcore.aliddns/Form_main.Designer.cs | 3 +- .../net.nutcore.aliddns/Form_main.cs | 51 ++- .../Form_ngrok.Designer.cs | 417 +++++++----------- .../net.nutcore.aliddns/Form_ngrok.cs | 70 ++- .../net.nutcore.aliddns/ngrok.cs | 42 +- 5 files changed, 317 insertions(+), 266 deletions(-) diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.Designer.cs b/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.Designer.cs index d6c2e22..2c8c1e3 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.Designer.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.Designer.cs @@ -665,6 +665,7 @@ this.Text = "AliDDNS"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.mainForm_FormClosing); this.Load += new System.EventHandler(this.mainForm_Load); + this.Shown += new System.EventHandler(this.mainForm_Shown); this.timeSetGroup.ResumeLayout(false); this.timeSetGroup.PerformLayout(); this.debugMessage.ResumeLayout(false); @@ -710,7 +711,6 @@ private System.Windows.Forms.NotifyIcon notifyIcon_sysTray; private System.Windows.Forms.ContextMenuStrip contextMenuStrip_sysTrayMenu; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem_Exit; - private System.Windows.Forms.TextBox textBox_log; private System.Windows.Forms.GroupBox groupBox_netstate; private System.Windows.Forms.Label label_DomainIpStatus; private System.Windows.Forms.Label label_localIpStatus; @@ -737,6 +737,7 @@ private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_checkUpdate; private System.Windows.Forms.Button button_ngrok; private System.Windows.Forms.CheckBox checkBox_ngrok; + public System.Windows.Forms.TextBox textBox_log; } } diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.cs b/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.cs index be23c0f..e4fec94 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.cs @@ -20,6 +20,8 @@ namespace net.nutcore.aliddns public static bool checkUpdate; static IClientProfile clientProfile; static DefaultAcsClient client; + //初始化ngrok操作类 + private Ngrok ngrok = new Ngrok(); public mainForm() { @@ -203,7 +205,16 @@ namespace net.nutcore.aliddns textBox_TTL.Text = nodes[10].InnerText; if (nodes[11].InnerText == "On") checkUpdate = true; else checkUpdate = false; - + if (nodes[12].InnerText == "On") + { + checkBox_ngrok.Checked = true; + button_ngrok.Enabled = false; + } + else + { + checkBox_ngrok.Checked = false; + button_ngrok.Enabled = true; + } textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "设置文件读取成功!" + "\r\n"); return true; } @@ -299,6 +310,13 @@ namespace net.nutcore.aliddns textWriter.WriteString("On"); textWriter.WriteEndElement(); + textWriter.WriteStartElement("ngrokauto", ""); + if (checkBox_ngrok.Checked == false) + textWriter.WriteString("Off"); + else + textWriter.WriteString("On"); + textWriter.WriteEndElement(); + textWriter.WriteEndElement(); //设置项目结束 textWriter.WriteEndDocument();//文档结束 textWriter.Close(); //文档保存关闭 @@ -857,12 +875,28 @@ namespace net.nutcore.aliddns MessageBox.Show("获取新版本信息失败!"); } - private void checkBox_ngrok_CheckedChanged(object sender, EventArgs e) + private async void checkBox_ngrok_CheckedChanged(object sender, EventArgs e) { if (checkBox_ngrok.Checked == true) - textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "Ngrok功能启用,再次启动会自动加载!" + "\r\n"); + { + button_ngrok.Enabled = false; + //检测ngrok.exe是否存在 + if (ngrok.IsExists()) + { + await ngrok.Start(); + textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "Ngrok功能启用,ngrok.exe将自动加载!通过浏览器打开:http://127.0.0.1:4040 查看运行状态。" + "\r\n"); + } + else + { + textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "Ngrok功能启用,但当前目录没有发现ngrok.exe,请往官网下载自行编译:https://ngrok.com/download" + "\r\n"); + } + } else - textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "Ngrok功能关闭,再次启动不会加载!" + "\r\n"); + { + await ngrok.Stop(); + button_ngrok.Enabled = true; + textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "Ngrok功能关闭,再次启动将不会加载!" + "\r\n"); + } } private void button_ngrok_Click(object sender, EventArgs e) @@ -870,6 +904,15 @@ namespace net.nutcore.aliddns Form_ngrok ngrok = new Form_ngrok(); ngrok.Show(this); } + + private void mainForm_Shown(object sender, EventArgs e) + { + //检测ngrok.exe是否存在 + if (( checkBox_ngrok.Checked == true ) && ( !ngrok.IsExists() )) + { + MessageBox.Show("设置在当前目录没有发现ngrok.exe,请往官网下载自行编译。\nNgrok官网:https://ngrok.com/download"); + } + } } /// diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/Form_ngrok.Designer.cs b/net.nutcore.aliddns/net.nutcore.aliddns/Form_ngrok.Designer.cs index 03a3560..bf3959b 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/Form_ngrok.Designer.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/Form_ngrok.Designer.cs @@ -32,33 +32,27 @@ this.groupBox_AuthToken = new System.Windows.Forms.GroupBox(); this.textBox_AuthToken = new System.Windows.Forms.TextBox(); this.groupBox_Ngrokserver = new System.Windows.Forms.GroupBox(); + this.textBox_serverAddr = new System.Windows.Forms.TextBox(); + this.label_NgrokDomain = new System.Windows.Forms.Label(); this.groupBox_Url = new System.Windows.Forms.GroupBox(); + this.textBox_lanPort2 = new System.Windows.Forms.TextBox(); + this.textBox_remotePort2 = new System.Windows.Forms.TextBox(); + this.textBox_lanPort1 = new System.Windows.Forms.TextBox(); + this.label_lanport = new System.Windows.Forms.Label(); + this.label_remoteport = new System.Windows.Forms.Label(); + this.label_tunnels = new System.Windows.Forms.Label(); + this.textBox_lanHttp = new System.Windows.Forms.TextBox(); + this.textBox_subDomain = new System.Windows.Forms.TextBox(); + this.label_lanHttp = new System.Windows.Forms.Label(); + this.label_subDomain = new System.Windows.Forms.Label(); this.button_cancel = new System.Windows.Forms.Button(); this.button_save = new System.Windows.Forms.Button(); - this.label_NgrokDomain = new System.Windows.Forms.Label(); - this.label_tunnelAddr = new System.Windows.Forms.Label(); - this.label_Defaultport = new System.Windows.Forms.Label(); - this.label_http = new System.Windows.Forms.Label(); - this.label_https = new System.Windows.Forms.Label(); - this.textBox1 = new System.Windows.Forms.TextBox(); - this.textBox_tunnelAddr = new System.Windows.Forms.TextBox(); - this.textBox_httpAddr = new System.Windows.Forms.TextBox(); - this.textBox_httpsAddr = new System.Windows.Forms.TextBox(); - this.label_subDomain = new System.Windows.Forms.Label(); - this.label_lanHttp = new System.Windows.Forms.Label(); - this.label_lanhttps = new System.Windows.Forms.Label(); - this.textBox_subDomain = new System.Windows.Forms.TextBox(); - this.textBox_lanHttp = new System.Windows.Forms.TextBox(); - this.textBox_Https = new System.Windows.Forms.TextBox(); - this.label_lanTcp = new System.Windows.Forms.Label(); - this.label_remoteport = new System.Windows.Forms.Label(); - this.label_lanport = new System.Windows.Forms.Label(); - this.textBox_lanTunnel1 = new System.Windows.Forms.TextBox(); this.textBox_remotePort1 = new System.Windows.Forms.TextBox(); - this.textBox_lanPort1 = new System.Windows.Forms.TextBox(); - this.textBox_lanTunnel2 = new System.Windows.Forms.TextBox(); - this.textBox_remotePort2 = new System.Windows.Forms.TextBox(); - this.textBox_lanPort2 = new System.Windows.Forms.TextBox(); + this.label_tunnel1 = new System.Windows.Forms.Label(); + this.label_tunnel2 = new System.Windows.Forms.Label(); + this.label_tunnel3 = new System.Windows.Forms.Label(); + this.textBox_remotePort3 = new System.Windows.Forms.TextBox(); + this.textBox_lanPort3 = new System.Windows.Forms.TextBox(); this.groupBox_AuthToken.SuspendLayout(); this.groupBox_Ngrokserver.SuspendLayout(); this.groupBox_Url.SuspendLayout(); @@ -83,201 +77,85 @@ // // groupBox_Ngrokserver // - this.groupBox_Ngrokserver.Controls.Add(this.textBox_httpsAddr); - this.groupBox_Ngrokserver.Controls.Add(this.textBox_httpAddr); - this.groupBox_Ngrokserver.Controls.Add(this.textBox_tunnelAddr); - this.groupBox_Ngrokserver.Controls.Add(this.textBox1); - this.groupBox_Ngrokserver.Controls.Add(this.label_https); - this.groupBox_Ngrokserver.Controls.Add(this.label_http); - this.groupBox_Ngrokserver.Controls.Add(this.label_Defaultport); - this.groupBox_Ngrokserver.Controls.Add(this.label_tunnelAddr); + this.groupBox_Ngrokserver.Controls.Add(this.textBox_serverAddr); this.groupBox_Ngrokserver.Controls.Add(this.label_NgrokDomain); this.groupBox_Ngrokserver.Location = new System.Drawing.Point(6, 68); this.groupBox_Ngrokserver.Name = "groupBox_Ngrokserver"; - this.groupBox_Ngrokserver.Size = new System.Drawing.Size(273, 97); + this.groupBox_Ngrokserver.Size = new System.Drawing.Size(273, 48); this.groupBox_Ngrokserver.TabIndex = 1; this.groupBox_Ngrokserver.TabStop = false; this.groupBox_Ngrokserver.Text = "服务端Ngrokd"; // - // groupBox_Url + // textBox_serverAddr // - this.groupBox_Url.Controls.Add(this.textBox_lanPort2); - this.groupBox_Url.Controls.Add(this.textBox_remotePort2); - this.groupBox_Url.Controls.Add(this.textBox_lanTunnel2); - this.groupBox_Url.Controls.Add(this.textBox_lanPort1); - this.groupBox_Url.Controls.Add(this.textBox_remotePort1); - this.groupBox_Url.Controls.Add(this.textBox_lanTunnel1); - this.groupBox_Url.Controls.Add(this.label_lanport); - this.groupBox_Url.Controls.Add(this.label_remoteport); - this.groupBox_Url.Controls.Add(this.label_lanTcp); - this.groupBox_Url.Controls.Add(this.textBox_Https); - this.groupBox_Url.Controls.Add(this.textBox_lanHttp); - this.groupBox_Url.Controls.Add(this.textBox_subDomain); - this.groupBox_Url.Controls.Add(this.label_lanhttps); - this.groupBox_Url.Controls.Add(this.label_lanHttp); - this.groupBox_Url.Controls.Add(this.label_subDomain); - this.groupBox_Url.Location = new System.Drawing.Point(6, 171); - this.groupBox_Url.Name = "groupBox_Url"; - this.groupBox_Url.Size = new System.Drawing.Size(273, 140); - this.groupBox_Url.TabIndex = 2; - this.groupBox_Url.TabStop = false; - this.groupBox_Url.Text = "内网端Ngrok"; - // - // button_cancel - // - this.button_cancel.Location = new System.Drawing.Point(40, 317); - this.button_cancel.Name = "button_cancel"; - this.button_cancel.Size = new System.Drawing.Size(80, 23); - this.button_cancel.TabIndex = 3; - this.button_cancel.Text = "取消"; - this.button_cancel.UseVisualStyleBackColor = true; - this.button_cancel.Click += new System.EventHandler(this.button_cancel_Click); - // - // button_save - // - this.button_save.Location = new System.Drawing.Point(156, 317); - this.button_save.Name = "button_save"; - this.button_save.Size = new System.Drawing.Size(80, 23); - this.button_save.TabIndex = 4; - this.button_save.Text = "保存"; - this.button_save.UseVisualStyleBackColor = true; - this.button_save.Click += new System.EventHandler(this.button_save_Click); + this.textBox_serverAddr.Location = new System.Drawing.Point(50, 18); + this.textBox_serverAddr.Name = "textBox_serverAddr"; + this.textBox_serverAddr.Size = new System.Drawing.Size(211, 21); + this.textBox_serverAddr.TabIndex = 5; // // label_NgrokDomain // this.label_NgrokDomain.AutoSize = true; - this.label_NgrokDomain.Location = new System.Drawing.Point(9, 22); + this.label_NgrokDomain.Location = new System.Drawing.Point(11, 21); this.label_NgrokDomain.Name = "label_NgrokDomain"; this.label_NgrokDomain.Size = new System.Drawing.Size(35, 12); this.label_NgrokDomain.TabIndex = 0; - this.label_NgrokDomain.Text = "域名:"; + this.label_NgrokDomain.Text = "地址:"; // - // label_tunnelAddr + // groupBox_Url // - this.label_tunnelAddr.AutoSize = true; - this.label_tunnelAddr.Location = new System.Drawing.Point(9, 47); - this.label_tunnelAddr.Name = "label_tunnelAddr"; - this.label_tunnelAddr.Size = new System.Drawing.Size(59, 12); - this.label_tunnelAddr.TabIndex = 1; - this.label_tunnelAddr.Text = "侦听端口:"; + this.groupBox_Url.Controls.Add(this.textBox_lanPort3); + this.groupBox_Url.Controls.Add(this.textBox_remotePort3); + this.groupBox_Url.Controls.Add(this.label_tunnel3); + this.groupBox_Url.Controls.Add(this.label_tunnel2); + this.groupBox_Url.Controls.Add(this.label_tunnel1); + this.groupBox_Url.Controls.Add(this.textBox_lanPort2); + this.groupBox_Url.Controls.Add(this.textBox_remotePort2); + this.groupBox_Url.Controls.Add(this.textBox_lanPort1); + this.groupBox_Url.Controls.Add(this.textBox_remotePort1); + this.groupBox_Url.Controls.Add(this.label_lanport); + this.groupBox_Url.Controls.Add(this.label_remoteport); + this.groupBox_Url.Controls.Add(this.label_tunnels); + this.groupBox_Url.Controls.Add(this.textBox_lanHttp); + this.groupBox_Url.Controls.Add(this.textBox_subDomain); + this.groupBox_Url.Controls.Add(this.label_lanHttp); + this.groupBox_Url.Controls.Add(this.label_subDomain); + this.groupBox_Url.Location = new System.Drawing.Point(6, 123); + this.groupBox_Url.Name = "groupBox_Url"; + this.groupBox_Url.Size = new System.Drawing.Size(273, 170); + this.groupBox_Url.TabIndex = 2; + this.groupBox_Url.TabStop = false; + this.groupBox_Url.Text = "内网端Ngrok"; // - // label_Defaultport + // textBox_lanPort2 // - this.label_Defaultport.AutoSize = true; - this.label_Defaultport.Location = new System.Drawing.Point(9, 73); - this.label_Defaultport.Name = "label_Defaultport"; - this.label_Defaultport.Size = new System.Drawing.Size(83, 12); - this.label_Defaultport.TabIndex = 2; - this.label_Defaultport.Text = "默认服务端口:"; + this.textBox_lanPort2.Location = new System.Drawing.Point(191, 112); + this.textBox_lanPort2.Name = "textBox_lanPort2"; + this.textBox_lanPort2.Size = new System.Drawing.Size(50, 21); + this.textBox_lanPort2.TabIndex = 14; // - // label_http + // textBox_remotePort2 // - this.label_http.AutoSize = true; - this.label_http.Location = new System.Drawing.Point(89, 73); - this.label_http.Name = "label_http"; - this.label_http.Size = new System.Drawing.Size(29, 12); - this.label_http.TabIndex = 3; - this.label_http.Text = "http"; + this.textBox_remotePort2.Location = new System.Drawing.Point(96, 112); + this.textBox_remotePort2.Name = "textBox_remotePort2"; + this.textBox_remotePort2.Size = new System.Drawing.Size(50, 21); + this.textBox_remotePort2.TabIndex = 13; // - // label_https + // textBox_lanPort1 // - this.label_https.AutoSize = true; - this.label_https.Location = new System.Drawing.Point(174, 73); - this.label_https.Name = "label_https"; - this.label_https.Size = new System.Drawing.Size(35, 12); - this.label_https.TabIndex = 4; - this.label_https.Text = "https"; + this.textBox_lanPort1.Location = new System.Drawing.Point(191, 85); + this.textBox_lanPort1.Name = "textBox_lanPort1"; + this.textBox_lanPort1.Size = new System.Drawing.Size(50, 21); + this.textBox_lanPort1.TabIndex = 11; // - // textBox1 + // label_lanport // - this.textBox1.Location = new System.Drawing.Point(50, 17); - this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(211, 21); - this.textBox1.TabIndex = 5; - // - // textBox_tunnelAddr - // - this.textBox_tunnelAddr.Location = new System.Drawing.Point(72, 43); - this.textBox_tunnelAddr.Name = "textBox_tunnelAddr"; - this.textBox_tunnelAddr.Size = new System.Drawing.Size(50, 21); - this.textBox_tunnelAddr.TabIndex = 6; - this.textBox_tunnelAddr.Text = "8083"; - // - // textBox_httpAddr - // - this.textBox_httpAddr.Location = new System.Drawing.Point(120, 70); - this.textBox_httpAddr.Name = "textBox_httpAddr"; - this.textBox_httpAddr.Size = new System.Drawing.Size(50, 21); - this.textBox_httpAddr.TabIndex = 7; - this.textBox_httpAddr.Text = "8081"; - // - // textBox_httpsAddr - // - this.textBox_httpsAddr.Location = new System.Drawing.Point(211, 70); - this.textBox_httpsAddr.Name = "textBox_httpsAddr"; - this.textBox_httpsAddr.Size = new System.Drawing.Size(50, 21); - this.textBox_httpsAddr.TabIndex = 8; - this.textBox_httpsAddr.Text = "8082"; - // - // label_subDomain - // - this.label_subDomain.AutoSize = true; - this.label_subDomain.Location = new System.Drawing.Point(9, 18); - this.label_subDomain.Name = "label_subDomain"; - this.label_subDomain.Size = new System.Drawing.Size(53, 12); - this.label_subDomain.TabIndex = 0; - this.label_subDomain.Text = "次级域名"; - // - // label_lanHttp - // - this.label_lanHttp.AutoSize = true; - this.label_lanHttp.Location = new System.Drawing.Point(84, 18); - this.label_lanHttp.Name = "label_lanHttp"; - this.label_lanHttp.Size = new System.Drawing.Size(77, 12); - this.label_lanHttp.TabIndex = 1; - this.label_lanHttp.Text = "http服务端口"; - // - // label_lanhttps - // - this.label_lanhttps.AutoSize = true; - this.label_lanhttps.Location = new System.Drawing.Point(178, 18); - this.label_lanhttps.Name = "label_lanhttps"; - this.label_lanhttps.Size = new System.Drawing.Size(83, 12); - this.label_lanhttps.TabIndex = 2; - this.label_lanhttps.Text = "https服务端口"; - // - // textBox_subDomain - // - this.textBox_subDomain.Location = new System.Drawing.Point(10, 37); - this.textBox_subDomain.Name = "textBox_subDomain"; - this.textBox_subDomain.Size = new System.Drawing.Size(50, 21); - this.textBox_subDomain.TabIndex = 3; - this.textBox_subDomain.Text = "web"; - // - // textBox_lanHttp - // - this.textBox_lanHttp.Location = new System.Drawing.Point(96, 37); - this.textBox_lanHttp.Name = "textBox_lanHttp"; - this.textBox_lanHttp.Size = new System.Drawing.Size(50, 21); - this.textBox_lanHttp.TabIndex = 4; - this.textBox_lanHttp.Text = "80"; - // - // textBox_Https - // - this.textBox_Https.Location = new System.Drawing.Point(191, 37); - this.textBox_Https.Name = "textBox_Https"; - this.textBox_Https.Size = new System.Drawing.Size(50, 21); - this.textBox_Https.TabIndex = 5; - this.textBox_Https.Text = "80"; - // - // label_lanTcp - // - this.label_lanTcp.AutoSize = true; - this.label_lanTcp.Location = new System.Drawing.Point(12, 65); - this.label_lanTcp.Name = "label_lanTcp"; - this.label_lanTcp.Size = new System.Drawing.Size(47, 12); - this.label_lanTcp.TabIndex = 6; - this.label_lanTcp.Text = "TCP穿透"; + this.label_lanport.AutoSize = true; + this.label_lanport.Location = new System.Drawing.Point(178, 65); + this.label_lanport.Name = "label_lanport"; + this.label_lanport.Size = new System.Drawing.Size(77, 12); + this.label_lanport.TabIndex = 8; + this.label_lanport.Text = "内网服务端口"; // // label_remoteport // @@ -288,22 +166,66 @@ this.label_remoteport.TabIndex = 7; this.label_remoteport.Text = "远程端口"; // - // label_lanport + // label_tunnels // - this.label_lanport.AutoSize = true; - this.label_lanport.Location = new System.Drawing.Point(180, 65); - this.label_lanport.Name = "label_lanport"; - this.label_lanport.Size = new System.Drawing.Size(77, 12); - this.label_lanport.TabIndex = 8; - this.label_lanport.Text = "内网服务端口"; + this.label_tunnels.AutoSize = true; + this.label_tunnels.Location = new System.Drawing.Point(12, 65); + this.label_tunnels.Name = "label_tunnels"; + this.label_tunnels.Size = new System.Drawing.Size(71, 12); + this.label_tunnels.TabIndex = 6; + this.label_tunnels.Text = "TCP穿透服务"; // - // textBox_lanTunnel1 + // textBox_lanHttp // - this.textBox_lanTunnel1.Location = new System.Drawing.Point(10, 85); - this.textBox_lanTunnel1.Name = "textBox_lanTunnel1"; - this.textBox_lanTunnel1.Size = new System.Drawing.Size(50, 21); - this.textBox_lanTunnel1.TabIndex = 9; - this.textBox_lanTunnel1.Text = "ssh"; + this.textBox_lanHttp.Location = new System.Drawing.Point(96, 37); + this.textBox_lanHttp.Name = "textBox_lanHttp"; + this.textBox_lanHttp.Size = new System.Drawing.Size(50, 21); + this.textBox_lanHttp.TabIndex = 4; + // + // textBox_subDomain + // + this.textBox_subDomain.Location = new System.Drawing.Point(20, 37); + this.textBox_subDomain.Name = "textBox_subDomain"; + this.textBox_subDomain.Size = new System.Drawing.Size(50, 21); + this.textBox_subDomain.TabIndex = 3; + // + // label_lanHttp + // + this.label_lanHttp.AutoSize = true; + this.label_lanHttp.Location = new System.Drawing.Point(80, 18); + this.label_lanHttp.Name = "label_lanHttp"; + this.label_lanHttp.Size = new System.Drawing.Size(89, 12); + this.label_lanHttp.TabIndex = 1; + this.label_lanHttp.Text = "http/s服务端口"; + // + // label_subDomain + // + this.label_subDomain.AutoSize = true; + this.label_subDomain.Location = new System.Drawing.Point(19, 18); + this.label_subDomain.Name = "label_subDomain"; + this.label_subDomain.Size = new System.Drawing.Size(53, 12); + this.label_subDomain.TabIndex = 0; + this.label_subDomain.Text = "次级域名"; + // + // button_cancel + // + this.button_cancel.Location = new System.Drawing.Point(40, 299); + this.button_cancel.Name = "button_cancel"; + this.button_cancel.Size = new System.Drawing.Size(80, 23); + this.button_cancel.TabIndex = 3; + this.button_cancel.Text = "取消"; + this.button_cancel.UseVisualStyleBackColor = true; + this.button_cancel.Click += new System.EventHandler(this.button_cancel_Click); + // + // button_save + // + this.button_save.Location = new System.Drawing.Point(156, 299); + this.button_save.Name = "button_save"; + this.button_save.Size = new System.Drawing.Size(80, 23); + this.button_save.TabIndex = 4; + this.button_save.Text = "保存"; + this.button_save.UseVisualStyleBackColor = true; + this.button_save.Click += new System.EventHandler(this.button_save_Click); // // textBox_remotePort1 // @@ -311,45 +233,53 @@ this.textBox_remotePort1.Name = "textBox_remotePort1"; this.textBox_remotePort1.Size = new System.Drawing.Size(50, 21); this.textBox_remotePort1.TabIndex = 10; - this.textBox_remotePort1.Text = "2222"; // - // textBox_lanPort1 + // label_tunnel1 // - this.textBox_lanPort1.Location = new System.Drawing.Point(191, 85); - this.textBox_lanPort1.Name = "textBox_lanPort1"; - this.textBox_lanPort1.Size = new System.Drawing.Size(50, 21); - this.textBox_lanPort1.TabIndex = 11; - this.textBox_lanPort1.Text = "22"; + this.label_tunnel1.AutoSize = true; + this.label_tunnel1.Location = new System.Drawing.Point(17, 88); + this.label_tunnel1.Name = "label_tunnel1"; + this.label_tunnel1.Size = new System.Drawing.Size(53, 12); + this.label_tunnel1.TabIndex = 15; + this.label_tunnel1.Text = "Tunnel1:"; // - // textBox_lanTunnel2 + // label_tunnel2 // - this.textBox_lanTunnel2.Location = new System.Drawing.Point(10, 113); - this.textBox_lanTunnel2.Name = "textBox_lanTunnel2"; - this.textBox_lanTunnel2.Size = new System.Drawing.Size(50, 21); - this.textBox_lanTunnel2.TabIndex = 12; - this.textBox_lanTunnel2.Text = "ftp"; + this.label_tunnel2.AutoSize = true; + this.label_tunnel2.Location = new System.Drawing.Point(17, 115); + this.label_tunnel2.Name = "label_tunnel2"; + this.label_tunnel2.Size = new System.Drawing.Size(53, 12); + this.label_tunnel2.TabIndex = 16; + this.label_tunnel2.Text = "Tunnel2:"; // - // textBox_remotePort2 + // label_tunnel3 // - this.textBox_remotePort2.Location = new System.Drawing.Point(96, 113); - this.textBox_remotePort2.Name = "textBox_remotePort2"; - this.textBox_remotePort2.Size = new System.Drawing.Size(50, 21); - this.textBox_remotePort2.TabIndex = 13; - this.textBox_remotePort2.Text = "2221"; + this.label_tunnel3.AutoSize = true; + this.label_tunnel3.Location = new System.Drawing.Point(17, 142); + this.label_tunnel3.Name = "label_tunnel3"; + this.label_tunnel3.Size = new System.Drawing.Size(53, 12); + this.label_tunnel3.TabIndex = 17; + this.label_tunnel3.Text = "Tunnel3:"; // - // textBox_lanPort2 + // textBox_remotePort3 // - this.textBox_lanPort2.Location = new System.Drawing.Point(191, 112); - this.textBox_lanPort2.Name = "textBox_lanPort2"; - this.textBox_lanPort2.Size = new System.Drawing.Size(50, 21); - this.textBox_lanPort2.TabIndex = 14; - this.textBox_lanPort2.Text = "21"; + this.textBox_remotePort3.Location = new System.Drawing.Point(96, 140); + this.textBox_remotePort3.Name = "textBox_remotePort3"; + this.textBox_remotePort3.Size = new System.Drawing.Size(50, 21); + this.textBox_remotePort3.TabIndex = 18; + // + // textBox_lanPort3 + // + this.textBox_lanPort3.Location = new System.Drawing.Point(191, 140); + this.textBox_lanPort3.Name = "textBox_lanPort3"; + this.textBox_lanPort3.Size = new System.Drawing.Size(50, 21); + this.textBox_lanPort3.TabIndex = 19; // // Form_ngrok // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(284, 346); + this.ClientSize = new System.Drawing.Size(284, 330); this.Controls.Add(this.button_save); this.Controls.Add(this.button_cancel); this.Controls.Add(this.groupBox_Url); @@ -358,6 +288,7 @@ this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "Form_ngrok"; this.Text = "Ngrok设置"; + this.Shown += new System.EventHandler(this.Form_ngrok_Shown); this.groupBox_AuthToken.ResumeLayout(false); this.groupBox_AuthToken.PerformLayout(); this.groupBox_Ngrokserver.ResumeLayout(false); @@ -376,29 +307,23 @@ private System.Windows.Forms.Button button_cancel; private System.Windows.Forms.Button button_save; private System.Windows.Forms.TextBox textBox_AuthToken; - private System.Windows.Forms.TextBox textBox_httpsAddr; - private System.Windows.Forms.TextBox textBox_httpAddr; - private System.Windows.Forms.TextBox textBox_tunnelAddr; - private System.Windows.Forms.TextBox textBox1; - private System.Windows.Forms.Label label_https; - private System.Windows.Forms.Label label_http; - private System.Windows.Forms.Label label_Defaultport; - private System.Windows.Forms.Label label_tunnelAddr; + private System.Windows.Forms.TextBox textBox_serverAddr; private System.Windows.Forms.Label label_NgrokDomain; - private System.Windows.Forms.TextBox textBox_Https; private System.Windows.Forms.TextBox textBox_lanHttp; private System.Windows.Forms.TextBox textBox_subDomain; - private System.Windows.Forms.Label label_lanhttps; private System.Windows.Forms.Label label_lanHttp; private System.Windows.Forms.Label label_subDomain; private System.Windows.Forms.TextBox textBox_lanPort2; private System.Windows.Forms.TextBox textBox_remotePort2; - private System.Windows.Forms.TextBox textBox_lanTunnel2; private System.Windows.Forms.TextBox textBox_lanPort1; - private System.Windows.Forms.TextBox textBox_remotePort1; - private System.Windows.Forms.TextBox textBox_lanTunnel1; private System.Windows.Forms.Label label_lanport; private System.Windows.Forms.Label label_remoteport; - private System.Windows.Forms.Label label_lanTcp; + private System.Windows.Forms.Label label_tunnels; + private System.Windows.Forms.TextBox textBox_remotePort1; + private System.Windows.Forms.TextBox textBox_lanPort3; + private System.Windows.Forms.TextBox textBox_remotePort3; + private System.Windows.Forms.Label label_tunnel3; + private System.Windows.Forms.Label label_tunnel2; + private System.Windows.Forms.Label label_tunnel1; } } \ No newline at end of file diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/Form_ngrok.cs b/net.nutcore.aliddns/net.nutcore.aliddns/Form_ngrok.cs index 2e14558..65ec2c4 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/Form_ngrok.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/Form_ngrok.cs @@ -1,17 +1,12 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace net.nutcore.aliddns { public partial class Form_ngrok : Form { + //初始化ngrok操作类 + private Ngrok ngrok = new Ngrok(); public Form_ngrok() { InitializeComponent(); @@ -27,8 +22,69 @@ namespace net.nutcore.aliddns private void button_save_Click(object sender, EventArgs e) { + var token = textBox_AuthToken.Text.ToString(); + var server_addr = textBox_serverAddr.Text.ToString(); + + var lanhttp = 80; + int.TryParse(textBox_lanHttp.Text, out lanhttp); + textBox_lanHttp.Text = lanhttp.ToString(); + + var subdomain = textBox_subDomain.Text.ToString(); + + var remoteport1 = 2221; + int.TryParse(textBox_remotePort1.Text, out remoteport1); + textBox_remotePort1.Text = remoteport1.ToString(); + var lanport1 = 21; + int.TryParse(textBox_lanPort1.Text, out lanport1); + textBox_lanPort1.Text = lanport1.ToString(); + + var remoteport2 = 2222; + int.TryParse(textBox_remotePort2.Text, out remoteport2); + textBox_remotePort2.Text = remoteport2.ToString(); + var lanport2 = 22; + int.TryParse(textBox_lanPort2.Text, out lanport2); + textBox_lanPort2.Text = lanport2.ToString(); + + var remoteport3 = 33890; + int.TryParse(textBox_remotePort3.Text, out remoteport3); + textBox_remotePort3.Text = remoteport3.ToString(); + var lanport3 = 3389; + int.TryParse(textBox_lanPort3.Text, out lanport3); + textBox_lanPort3.Text = lanport3.ToString(); + + ngrok.Save(token, server_addr, lanhttp, subdomain, remoteport1, lanport1, remoteport2, lanport2, remoteport3, lanport3, true, true); this.Close(); this.Dispose(); } + + private void Form_ngrok_Shown(object sender, EventArgs e) + { + //检测ngrok.exe是否存在 + if (!ngrok.IsExists()) + { + MessageBox.Show("设置在当前目录没有发现ngrok.exe,请往官网下载自行编译。\nNgrok官网:https://ngrok.com/download"); + } + //读取配置文件 + try + { + var config = ngrok.Load(); + textBox_AuthToken.Text = config.authtoken; + textBox_serverAddr.Text = config.server_addr; + textBox_subDomain.Text = config.tunnels.website.subdomain.ToString(); + textBox_lanHttp.Text = config.tunnels.website.proto.http.ToString(); + textBox_remotePort1.Text = config.tunnels.tcp1.remote_port.ToString(); + textBox_lanPort1.Text = config.tunnels.tcp1.proto.tcp.ToString(); + textBox_remotePort2.Text = config.tunnels.tcp2.remote_port.ToString(); + textBox_lanPort2.Text = config.tunnels.tcp2.proto.tcp.ToString(); + textBox_remotePort3.Text = config.tunnels.tcp3.remote_port.ToString(); + textBox_lanPort3.Text = config.tunnels.tcp3.proto.tcp.ToString(); + } + catch (Exception error) + { + MessageBox.Show("设置文件ngrok.cfg读取出错!错误信息:\n" + error); + this.Dispose(); + } + + } } } diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/ngrok.cs b/net.nutcore.aliddns/net.nutcore.aliddns/ngrok.cs index a89ea91..b0aea41 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/ngrok.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/ngrok.cs @@ -36,7 +36,9 @@ namespace net.nutcore.aliddns public class Tunnel { public Protocol website { get; set; } - public Protocol tcp { get; set; } + public Protocol tcp1 { get; set; } + public Protocol tcp2 { get; set; } + public Protocol tcp3 { get; set; } } public class Protocol @@ -72,7 +74,7 @@ namespace net.nutcore.aliddns var config = new Config { authtoken = string.Empty, - server_addr = string.Empty, + server_addr = "tunnels.ngrok.io:443", console_ui = true, region = "us", log_level = "info", @@ -92,13 +94,29 @@ namespace net.nutcore.aliddns } }, - tcp = new Protocol + tcp1 = new Protocol + { + remote_port = 2221, + proto = new Proto + { + tcp = 21 + } + }, + tcp2 = new Protocol { remote_port = 2222, proto = new Proto { tcp = 22 } + }, + tcp3 = new Protocol + { + remote_port = 33890, + proto = new Proto + { + tcp = 3389 + } } } }; @@ -140,15 +158,19 @@ namespace net.nutcore.aliddns return config; } - public void Save(string token, string server_addr, int http, string subdomain, int tcp, int lanport, bool run_website, bool run_tcp) + public void Save(string token, string server_addr, int http, string subdomain, int remoteport1, int lanport1, int remoteport2, int lanport2, int remoteport3, int lanport3, bool run_website, bool run_tcp) { var config = Load(); config.authtoken = token; config.server_addr = server_addr; config.tunnels.website.proto.http = http; config.tunnels.website.subdomain = subdomain; - config.tunnels.tcp.remote_port = tcp; - config.tunnels.tcp.proto.tcp = lanport; + config.tunnels.tcp1.remote_port = remoteport1; + config.tunnels.tcp1.proto.tcp = lanport1; + config.tunnels.tcp2.remote_port = remoteport2; + config.tunnels.tcp2.proto.tcp = lanport2; + config.tunnels.tcp3.remote_port = remoteport3; + config.tunnels.tcp3.proto.tcp = lanport3; config.run_website = run_website; config.run_tcp = run_tcp; @@ -173,11 +195,15 @@ namespace net.nutcore.aliddns break; case 2: - exec.Arguments += "tcp"; + exec.Arguments += "website tcp1"; + break; + + case 3: + exec.Arguments += "website tcp1 tcp2"; break; default: - exec.Arguments += "website tcp"; + exec.Arguments += "website tcp1 tcp2 tcp3"; break; }