From 38ec164b6dcf7207050a01eb9dcf618ef66b33d0 Mon Sep 17 00:00:00 2001 From: wisdomwei201804 Date: Wed, 20 Jun 2018 22:37:30 +0800 Subject: [PATCH] =?UTF-8?q?v3.8.3.5=20=201=E3=80=81=E5=A2=9E=E5=8A=A0ngrok?= =?UTF-8?q?=E7=B1=BB=E3=80=822=E3=80=81=E5=A2=9E=E5=8A=A0yml=E7=B1=BB?= =?UTF-8?q?=E3=80=823=E3=80=81=E5=A2=9E=E5=8A=A0ngrok=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E3=80=824=E3=80=81=E5=A2=9E=E5=8A=A0JSON?= =?UTF-8?q?=E7=B1=BB=E3=80=825=E3=80=81=E4=BF=AE=E6=94=B9=E4=B8=BB?= =?UTF-8?q?=E7=AA=97=E4=BD=93=E5=8A=A0=E8=BD=BD=E6=97=B6=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=9B=B4=E6=96=B0IP=E3=80=826=E3=80=81?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E8=AF=95=E4=B8=AD...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...main.Designer.cs => Form_main.Designer.cs} | 0 .../{main.cs => Form_main.cs} | 4 ++ .../{main.resx => Form_main.resx} | 0 .../net.nutcore.aliddns.csproj | 23 +++++-- .../net.nutcore.aliddns/ngrok.cs | 67 +++++++++++++------ .../net.nutcore.aliddns/packages.config | 5 ++ 6 files changed, 71 insertions(+), 28 deletions(-) rename net.nutcore.aliddns/net.nutcore.aliddns/{main.Designer.cs => Form_main.Designer.cs} (100%) rename net.nutcore.aliddns/net.nutcore.aliddns/{main.cs => Form_main.cs} (99%) rename net.nutcore.aliddns/net.nutcore.aliddns/{main.resx => Form_main.resx} (100%) create mode 100644 net.nutcore.aliddns/net.nutcore.aliddns/packages.config diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/main.Designer.cs b/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.Designer.cs similarity index 100% rename from net.nutcore.aliddns/net.nutcore.aliddns/main.Designer.cs rename to net.nutcore.aliddns/net.nutcore.aliddns/Form_main.Designer.cs diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/main.cs b/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.cs similarity index 99% rename from net.nutcore.aliddns/net.nutcore.aliddns/main.cs rename to net.nutcore.aliddns/net.nutcore.aliddns/Form_main.cs index 600e57b..be23c0f 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/main.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.cs @@ -136,6 +136,10 @@ namespace net.nutcore.aliddns try //获取WAN口IP { localIP.Text = getLocalIP(); + if ((localIP.Text != domainIP.Text) && (checkBox_autoBoot.Checked = true)) + { + updatePrepare(); + } } catch (Exception error) { diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/main.resx b/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.resx similarity index 100% rename from net.nutcore.aliddns/net.nutcore.aliddns/main.resx rename to net.nutcore.aliddns/net.nutcore.aliddns/Form_main.resx diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/net.nutcore.aliddns.csproj b/net.nutcore.aliddns/net.nutcore.aliddns/net.nutcore.aliddns.csproj index 56ee17c..c38a82a 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/net.nutcore.aliddns.csproj +++ b/net.nutcore.aliddns/net.nutcore.aliddns/net.nutcore.aliddns.csproj @@ -58,6 +58,10 @@ aliyun-net-sdk-core.dll + + ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + True + @@ -77,6 +81,10 @@ + + ..\packages\YamlDotNet.4.3.2\lib\net45\YamlDotNet.dll + True + @@ -91,11 +99,11 @@ Form_ngrok.cs - + Form - - main.cs + + Form_main.cs @@ -107,8 +115,8 @@ Form_ngrok.cs - - main.cs + + Form_main.cs ResXFileCodeGenerator @@ -120,6 +128,7 @@ Resources.resx True + SettingsSingleFileGenerator Settings.Designer.cs @@ -157,7 +166,9 @@ false - + + + copy "$(SolutionDir)net.nutcore.aliddns\updateinfo.txt" "$(TargetDir)" diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/ngrok.cs b/net.nutcore.aliddns/net.nutcore.aliddns/ngrok.cs index b77218f..a89ea91 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/ngrok.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/ngrok.cs @@ -1,14 +1,18 @@ -using System; +using Newtonsoft.Json; +using System; +using System.Diagnostics; using System.IO; +using System.Net; using System.Threading.Tasks; using System.Windows.Forms; +using YamlDotNet.Serialization; namespace net.nutcore.aliddns { - class ngrok + internal class Ngrok { private static readonly string NgrokExecutable = "ngrok.exe"; - private static readonly string NgrokYaml = "ngrok.yaml"; + private static readonly string NgrokYaml = "ngrok.cfg"; public static readonly string CurrentDirectory = Path.GetDirectoryName(Application.ExecutablePath); public static readonly string FileNgrokExecutable = Path.Combine(CurrentDirectory, NgrokExecutable); public static readonly string FileConfig = Path.Combine(CurrentDirectory, NgrokYaml); @@ -17,6 +21,7 @@ namespace net.nutcore.aliddns public class Config { public string authtoken { get; set; } + public string server_addr { get; set; } public string region { get; set; } public bool console_ui { get; set; } public string log_level { get; set; } @@ -24,23 +29,30 @@ namespace net.nutcore.aliddns public string log { get; set; } public string web_addr { get; set; } public bool run_website { get; set; } - public bool run_ssh { get; set; } + public bool run_tcp { get; set; } public Tunnel tunnels { get; set; } } public class Tunnel { public Protocol website { get; set; } - public Protocol ssh { get; set; } + public Protocol tcp { get; set; } } public class Protocol { - public int addr { get; set; } - public string proto { get; set; } + public string subdomain { get; set; } + public int remote_port { get; set; } + public Proto proto { get; set; } public string auth { get; set; } } + public class Proto + { + public int http { get; set; } + public int tcp { get; set; } + } + public class Response { public JsonTunnel[] tunnels { get; set; } @@ -53,13 +65,14 @@ namespace net.nutcore.aliddns public string proto { get; set; } } - public void Ngrok() + public Ngrok() { if (!File.Exists(FileConfig)) { var config = new Config { authtoken = string.Empty, + server_addr = string.Empty, console_ui = true, region = "us", log_level = "info", @@ -67,18 +80,25 @@ namespace net.nutcore.aliddns log = "ngrok.log", web_addr = LocalHost, run_website = true, - run_ssh = false, + run_tcp = true, tunnels = new Tunnel { website = new Protocol { - addr = 80, - proto = "http" + subdomain = "www", + proto = new Proto + { + http = 80 + } + }, - ssh = new Protocol + tcp = new Protocol { - addr = 22, - proto = "tcp" + remote_port = 2222, + proto = new Proto + { + tcp = 22 + } } } }; @@ -120,14 +140,17 @@ namespace net.nutcore.aliddns return config; } - public void Save(string token, int http, int tcp, bool website, bool ssh) + public void Save(string token, string server_addr, int http, string subdomain, int tcp, int lanport, bool run_website, bool run_tcp) { var config = Load(); config.authtoken = token; - config.tunnels.website.addr = http; - config.tunnels.ssh.addr = tcp; - config.run_website = website; - config.run_ssh = ssh; + 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.run_website = run_website; + config.run_tcp = run_tcp; var serializer = new SerializerBuilder().Build(); var yaml = serializer.Serialize(config); @@ -141,7 +164,7 @@ namespace net.nutcore.aliddns exec.FileName = NgrokExecutable; exec.CreateNoWindow = true; exec.UseShellExecute = false; - exec.Arguments = $"start -config \"{NgrokYaml}\" "; + exec.Arguments = $"-config \"{NgrokYaml}\" start "; switch (code) { @@ -150,11 +173,11 @@ namespace net.nutcore.aliddns break; case 2: - exec.Arguments += "ssh"; + exec.Arguments += "tcp"; break; default: - exec.Arguments += "website ssh"; + exec.Arguments += "website tcp"; break; } diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/packages.config b/net.nutcore.aliddns/net.nutcore.aliddns/packages.config new file mode 100644 index 0000000..6100b09 --- /dev/null +++ b/net.nutcore.aliddns/net.nutcore.aliddns/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file