From b28eab2ee42c9b56ab4fc5325be3bb4fd870d86d Mon Sep 17 00:00:00 2001 From: SpringHgui <740360381@qq.com> Date: Wed, 1 Jul 2020 17:47:08 +0800 Subject: [PATCH] remove suidao project --- FastTunnel.Core/FastTunnel.Core.csproj | 13 + FastTunnel.sln | 23 -- SuiDao.Client/HttpHelper.cs | 32 --- SuiDao.Client/Models/LogInByKeyMassage.cs | 14 - SuiDao.Client/Models/ServerConfig.cs | 22 -- SuiDao.Client/Program.cs | 271 ------------------ SuiDao.Client/SuiDao.Client.csproj | 16 -- SuiDao.Server/Handlers/SuiDaoConfigHandler.cs | 64 ----- SuiDao.Server/Model/Appsettings.cs | 13 - SuiDao.Server/Model/Tunnel.cs | 24 -- SuiDao.Server/Program.cs | 80 ------ .../PublishProfiles/FolderProfile.pubxml | 14 - .../PublishProfiles/FolderProfile.pubxml.user | 6 - SuiDao.Server/SuiDao.Server.csproj | 23 -- SuiDao.Server/SuiDao.Server.csproj.user | 7 - SuiDao.Server/appsettings.json | 20 -- publish.cmd | 2 +- 17 files changed, 14 insertions(+), 630 deletions(-) delete mode 100644 SuiDao.Client/HttpHelper.cs delete mode 100644 SuiDao.Client/Models/LogInByKeyMassage.cs delete mode 100644 SuiDao.Client/Models/ServerConfig.cs delete mode 100644 SuiDao.Client/Program.cs delete mode 100644 SuiDao.Client/SuiDao.Client.csproj delete mode 100644 SuiDao.Server/Handlers/SuiDaoConfigHandler.cs delete mode 100644 SuiDao.Server/Model/Appsettings.cs delete mode 100644 SuiDao.Server/Model/Tunnel.cs delete mode 100644 SuiDao.Server/Program.cs delete mode 100644 SuiDao.Server/Properties/PublishProfiles/FolderProfile.pubxml delete mode 100644 SuiDao.Server/Properties/PublishProfiles/FolderProfile.pubxml.user delete mode 100644 SuiDao.Server/SuiDao.Server.csproj delete mode 100644 SuiDao.Server/SuiDao.Server.csproj.user delete mode 100644 SuiDao.Server/appsettings.json diff --git a/FastTunnel.Core/FastTunnel.Core.csproj b/FastTunnel.Core/FastTunnel.Core.csproj index b8937ef..199ac07 100644 --- a/FastTunnel.Core/FastTunnel.Core.csproj +++ b/FastTunnel.Core/FastTunnel.Core.csproj @@ -5,6 +5,19 @@ netcoreapp3.1 + https://github.com/SpringHgui/FastTunnel + MIT + FastTunnel + expose a local server behind a NAT or firewall to the internet like ngrok and frp + SpringHgui + FastTunnel + FastTunnel + false + true + https://github.com/SpringHgui/FastTunnel + git + FastTunnel.Core + FastTunnel.Core diff --git a/FastTunnel.sln b/FastTunnel.sln index 7f9c790..472314a 100644 --- a/FastTunnel.sln +++ b/FastTunnel.sln @@ -9,14 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastTunnel.Core", "FastTunn EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastTunnel.Server", "FastTunnel.Server\FastTunnel.Server.csproj", "{DEF2E322-9075-4C3F-9967-7EAF0EE28CEB}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SuiDao.Client", "SuiDao.Client\SuiDao.Client.csproj", "{23E6C767-3927-4281-9C1D-C0A724D869A9}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuiDao.Server", "SuiDao.Server\SuiDao.Server.csproj", "{9DA66955-1497-42BA-B345-3C4D2F3E37A9}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "suidao.io", "suidao.io", "{024D84DC-BA2E-4CBC-8D9B-0187C0C09AE1}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "FastTunnel", "FastTunnel", "{051B4BB3-621D-4386-BA67-BB8896FDB29E}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -35,25 +27,10 @@ Global {DEF2E322-9075-4C3F-9967-7EAF0EE28CEB}.Debug|Any CPU.Build.0 = Debug|Any CPU {DEF2E322-9075-4C3F-9967-7EAF0EE28CEB}.Release|Any CPU.ActiveCfg = Release|Any CPU {DEF2E322-9075-4C3F-9967-7EAF0EE28CEB}.Release|Any CPU.Build.0 = Release|Any CPU - {23E6C767-3927-4281-9C1D-C0A724D869A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {23E6C767-3927-4281-9C1D-C0A724D869A9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {23E6C767-3927-4281-9C1D-C0A724D869A9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {23E6C767-3927-4281-9C1D-C0A724D869A9}.Release|Any CPU.Build.0 = Release|Any CPU - {9DA66955-1497-42BA-B345-3C4D2F3E37A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9DA66955-1497-42BA-B345-3C4D2F3E37A9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9DA66955-1497-42BA-B345-3C4D2F3E37A9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9DA66955-1497-42BA-B345-3C4D2F3E37A9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {29DA74AE-FFBD-4A24-82B9-B5675593B63A} = {051B4BB3-621D-4386-BA67-BB8896FDB29E} - {C8ADFEB1-59DB-4CE3-8D04-5B547107BCCB} = {051B4BB3-621D-4386-BA67-BB8896FDB29E} - {DEF2E322-9075-4C3F-9967-7EAF0EE28CEB} = {051B4BB3-621D-4386-BA67-BB8896FDB29E} - {23E6C767-3927-4281-9C1D-C0A724D869A9} = {024D84DC-BA2E-4CBC-8D9B-0187C0C09AE1} - {9DA66955-1497-42BA-B345-3C4D2F3E37A9} = {024D84DC-BA2E-4CBC-8D9B-0187C0C09AE1} - EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {3D9C6B44-6706-4EE8-9043-802BBE474A2E} EndGlobalSection diff --git a/SuiDao.Client/HttpHelper.cs b/SuiDao.Client/HttpHelper.cs deleted file mode 100644 index 046e5df..0000000 --- a/SuiDao.Client/HttpHelper.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; - -namespace SuiDao.Client -{ - public static class HttpHelper - { - public static Task PostAsJson(string uri, string strContent) - { - using (var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.None }) - using (var httpclient = new HttpClient(handler)) - { - httpclient.BaseAddress = new Uri(uri); - var content = new StringContent(strContent, Encoding.UTF8, "application/json"); - - var response = httpclient.PostAsync(uri, content).Result; - if (response.StatusCode == HttpStatusCode.OK) - { - return response.Content.ReadAsStringAsync(); - } - else - { - throw new Exception(response.ReasonPhrase); - } - } - } - } -} diff --git a/SuiDao.Client/Models/LogInByKeyMassage.cs b/SuiDao.Client/Models/LogInByKeyMassage.cs deleted file mode 100644 index 35427b7..0000000 --- a/SuiDao.Client/Models/LogInByKeyMassage.cs +++ /dev/null @@ -1,14 +0,0 @@ -using FastTunnel.Core.Models; -using System; -using System.Collections.Generic; -using System.Text; - -namespace SuiDao.Client.Models -{ - public class LogInByKeyMassage : TunnelMassage - { - public string key { get; set; } - - public long server_id { get; set; } - } -} diff --git a/SuiDao.Client/Models/ServerConfig.cs b/SuiDao.Client/Models/ServerConfig.cs deleted file mode 100644 index a1b7b8f..0000000 --- a/SuiDao.Client/Models/ServerConfig.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace SuiDao.Client.Models -{ - public class SuiDaoServerConfig - { - public SuiDaoServerInfo[] servers { get; set; } - } - - public class SuiDaoServerInfo - { - public string ip { get; set; } - - public int bind_port { get; set; } - - public string server_name { get; set; } - - public long server_id { get; set; } - } -} \ No newline at end of file diff --git a/SuiDao.Client/Program.cs b/SuiDao.Client/Program.cs deleted file mode 100644 index d8d0026..0000000 --- a/SuiDao.Client/Program.cs +++ /dev/null @@ -1,271 +0,0 @@ -using FastTunnel.Core; -using FastTunnel.Core.Config; -using FastTunnel.Core.Core; -using FastTunnel.Core.Handlers.Client; -using FastTunnel.Core.Host; -using FastTunnel.Core.Logger; -using FastTunnel.Core.Models; -using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using NLog; -using NLog.Extensions.Logging; -using SuiDao.Client.Models; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net.Sockets; -using System.Text; -using System.Threading; - -namespace SuiDao.Client -{ - class Program - { - const string KeyLogName = ".key"; - - /// - /// suidao.io 客户端 - /// - /// - static void Main(string[] args) - { - LogManager.Configuration = NlogConfig.getNewConfig(); - var logger = LogManager.GetCurrentClassLogger(); - logger.Info("===== SuiDao Client Start ====="); - - var keyFile = Path.Combine(AppContext.BaseDirectory, KeyLogName); - if (!File.Exists(keyFile)) - { - NewKey(logger); - return; - } - - List keys = new List(); - using (var reader = new StreamReader(keyFile)) - { - while (!reader.EndOfStream) - { - var line = reader.ReadLine(); - if (!string.IsNullOrEmpty(line)) - { - keys.Add(line); - } - } - } - - keys = keys.Distinct().ToList(); - if (keys.Count > 0) - { - Console.WriteLine("请选择要启动的客户端:" + Environment.NewLine); - - Console.WriteLine($" 0:其他密钥登录"); - for (int i = 0; i < keys.Count; i++) - { - Console.WriteLine($" {i + 1}:{keys[i]}"); - } - - Console.WriteLine(Environment.NewLine + "输入编号回车键继续:"); - - HandleNum(keys, logger); - return; - } - } - - private static void NewKey(ILogger logger) - { - string key; - while (true) - { - Console.Write("请输入登录密钥:"); - key = Console.ReadLine(); - - if (string.IsNullOrEmpty(key)) - { - continue; - } - - break; - } - - LogByKey(key, logger, true); - } - - private static void HandleNum(List keys, ILogger logger) - { - while (true) - { - var str = Console.ReadLine(); - if (string.IsNullOrEmpty(str)) - { - continue; - } - - int index; - if (!int.TryParse(str, out index)) - { - Console.WriteLine("输入错误 请重新选择"); - continue; - } - - if (index < 0 || index > keys.Count) - { - Console.WriteLine("输入错误 请重新选择"); - continue; - } - - if (index == 0) - { - NewKey(logger); - } - else - { - LogByKey(keys[index - 1], logger, false); - } - - break; - } - } - - static IServiceProvider servicesProvider; - - private static void LogByKey(string key, ILogger logger, bool log) - { - Console.WriteLine("登录中..."); - - try - { - if (servicesProvider == null) - servicesProvider = new Host().Config(Config).Build(); - - Run(servicesProvider, logger, key, log); - - while (true) - { - Thread.Sleep(10000 * 60); - } - } - catch (Exception ex) - { - // NLog: catch any exception and log it. - logger.Error(ex, "Stopped program because of exception"); - throw; - } - finally - { - // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) - LogManager.Shutdown(); - } - } - - private static void Run(IServiceProvider servicesProvider, ILogger _logger, string key, bool log) - { - var res_str = HttpHelper.PostAsJson("https://api1.suidao.io/api/Client/GetServerByKey", $"{{ \"key\":\"{key}\"}}").Result; - var jobj = JObject.Parse(res_str); - if ((bool)jobj["success"] == true) - { - // 记录登录记录 - if (log) - { - AppendTextToFile(Path.Combine(AppContext.BaseDirectory, KeyLogName), Environment.NewLine + key); - } - - SuiDaoServerInfo server; - var res = jobj["data"].ToObject(); - if (res.servers != null && res.servers.Count() > 0) - { - // 选择其中一个服务器继续 - if (res.servers.Count() == 1) - { - server = res.servers.First(); - } - else - { - Console.WriteLine("请选择其中一个服务器进行连接(输入序号,回车键确认):"); - for (int i = 0; i < res.servers.Length; i++) - { - Console.WriteLine($"{i}:{res.servers[i].server_name}"); - } - - while (true) - { - var input = Console.ReadLine(); - int index; - if (int.TryParse(input, out index) && index <= res.servers.Length - 1 && index >= 0) - { - // 输入有效,退出循环 - server = res.servers[index]; - Console.WriteLine($"您选择的服务器为:{server.server_name}"); - break; - } - else - { - Console.WriteLine("输入有误,请重新输入"); - } - } - } - } - else - { - Console.WriteLine("您无可用的服务器"); - NewKey(_logger); - return; - } - - var client = servicesProvider.GetRequiredService(); - - client.Login(() => - { - - Connecter _client = null; - - try - { - _client = new Connecter(server.ip, server.bind_port); - _client.Connect(); - } - catch (Exception ex) - { - _logger.Error(ex.Message); - _client.Socket.Close(); - throw; - } - - // 登录 - _client.Send(new Message { MessageType = MessageType.C_LogIn, Content = new LogInByKeyMassage { key = key, server_id = server.server_id } }); - - return _client; - }, new SuiDaoServer { ServerAddr = server.ip, ServerPort = server.bind_port }); - } - else - { - Console.WriteLine(jobj["errorMsg"].ToString()); - NewKey(_logger); - } - } - - private static void Config(ServiceCollection service) - { - service.AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton(); - } - - public static void AppendTextToFile(string filename, string inputStr) - { - var dir = Path.GetDirectoryName(filename); - if (!Directory.Exists(dir)) - Directory.CreateDirectory(dir); - - using (FileStream fsw = new FileStream(filename, FileMode.Append)) - { - byte[] writeBytes = Encoding.UTF8.GetBytes(inputStr); - fsw.Write(writeBytes, 0, writeBytes.Length); - fsw.Close(); - } - } - } -} diff --git a/SuiDao.Client/SuiDao.Client.csproj b/SuiDao.Client/SuiDao.Client.csproj deleted file mode 100644 index bd9565d..0000000 --- a/SuiDao.Client/SuiDao.Client.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - Exe - netcoreapp3.1 - - - - - - - - - - - diff --git a/SuiDao.Server/Handlers/SuiDaoConfigHandler.cs b/SuiDao.Server/Handlers/SuiDaoConfigHandler.cs deleted file mode 100644 index 3571502..0000000 --- a/SuiDao.Server/Handlers/SuiDaoConfigHandler.cs +++ /dev/null @@ -1,64 +0,0 @@ -using FastTunnel.Core.Core; -using FastTunnel.Core.Exceptions; -using FastTunnel.Core.Handlers; -using FastTunnel.Core.Models; -using Newtonsoft.Json.Linq; -using SuiDao.Client; -using SuiDao.Client.Models; -using System; -using System.Collections.Generic; -using System.Net.Sockets; - -namespace SuiDao.Server -{ - public class SuiDaoConfigHandler : IConfigHandler - { - public LogInMassage GetConfig(JObject content) - { - - var logMsg = content.ToObject(); - var res = HttpHelper.PostAsJson("https://api1.suidao.io/api/Client/GetTunnelByKey", $"{{ \"key\":\"{logMsg.key}\",\"server_id\":{logMsg.server_id}}}").Result; - - var jobj = JObject.Parse(res); - if ((bool)jobj["success"] == true) - { - var tunnels = jobj["data"].ToObject>(); - var Webs = new List(); - var SSH = new List(); - - foreach (var tunnel in tunnels) - { - if (tunnel.app_type == 1) // web - { - Webs.Add(new WebConfig - { - LocalIp = tunnel.local_ip, - LocalPort = tunnel.local_port, - SubDomain = tunnel.sub_domain - }); - } - else if (tunnel.app_type == 2) - { - SSH.Add(new SSHConfig - { - LocalIp = tunnel.local_ip, - LocalPort = tunnel.local_port, - RemotePort = tunnel.remote_port, - Protocol = Protocol.TCP - }); - } - } - - return new LogInMassage - { - SSH = SSH, - Webs = Webs, - }; - } - else - { - throw new APIErrorException(jobj["errorMsg"].ToString()); - } - } - } -} diff --git a/SuiDao.Server/Model/Appsettings.cs b/SuiDao.Server/Model/Appsettings.cs deleted file mode 100644 index 1704ed3..0000000 --- a/SuiDao.Server/Model/Appsettings.cs +++ /dev/null @@ -1,13 +0,0 @@ -using FastTunnel.Core.Config; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace SuiDao.Server -{ - public class Appsettings - { - public ServerConfig ServerSettings { get; set; } - } -} diff --git a/SuiDao.Server/Model/Tunnel.cs b/SuiDao.Server/Model/Tunnel.cs deleted file mode 100644 index 6bef074..0000000 --- a/SuiDao.Server/Model/Tunnel.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace SuiDao.Server -{ - public class Tunnel - { - public int app_type { get; set; } - - /// - /// 用户别名 - /// - public string name { get; set; } - - public string sub_domain { get; set; } - - public string local_ip { get; set; } - - public int local_port { get; set; } - - public int remote_port { get; set; } - } -} diff --git a/SuiDao.Server/Program.cs b/SuiDao.Server/Program.cs deleted file mode 100644 index a9ce273..0000000 --- a/SuiDao.Server/Program.cs +++ /dev/null @@ -1,80 +0,0 @@ -using FastTunnel.Core.Config; -using FastTunnel.Core.Core; -using FastTunnel.Core.Handlers; -using FastTunnel.Core.Handlers.Server; -using FastTunnel.Core.Host; -using FastTunnel.Core.Logger; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using NLog; -using System; -using System.IO; -using System.Threading; - -namespace SuiDao.Server -{ - public class Program - { - static Appsettings appsettings; - - static void Main(string[] args) - { - LogManager.Configuration = NlogConfig.getNewConfig(); - var logger = LogManager.GetCurrentClassLogger(); - logger.Debug("===== FastTunnel Server Start ====="); - - try - { - var servicesProvider = new Host().Config(Config).Build(); - Run(servicesProvider); - } - catch (Exception ex) - { - // NLog: catch any exception and log it. - logger.Error(ex); - Console.WriteLine(ex); - } - finally - { - // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) - LogManager.Shutdown(); - } - } - - private static ServerConfig implementationFactory(IServiceProvider arg) - { - if (appsettings == null) - { - var conf = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json", true, true) - .Build(); - - appsettings = conf.Get(); - } - - return appsettings.ServerSettings; - } - - private static void Config(ServiceCollection service) - { - service.AddSingleton() - .AddSingleton(implementationFactory) - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton(); - } - - private static void Run(IServiceProvider servicesProvider) - { - var server = servicesProvider.GetRequiredService(); - server.Run(); - - while (true) - { - Thread.Sleep(10000 * 60); - } - } - } -} diff --git a/SuiDao.Server/Properties/PublishProfiles/FolderProfile.pubxml b/SuiDao.Server/Properties/PublishProfiles/FolderProfile.pubxml deleted file mode 100644 index 47d90a6..0000000 --- a/SuiDao.Server/Properties/PublishProfiles/FolderProfile.pubxml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - FileSystem - Release - Any CPU - netcoreapp3.1 - bin\Release\netcoreapp3.1\publish\ - false - - \ No newline at end of file diff --git a/SuiDao.Server/Properties/PublishProfiles/FolderProfile.pubxml.user b/SuiDao.Server/Properties/PublishProfiles/FolderProfile.pubxml.user deleted file mode 100644 index 312c6e3..0000000 --- a/SuiDao.Server/Properties/PublishProfiles/FolderProfile.pubxml.user +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/SuiDao.Server/SuiDao.Server.csproj b/SuiDao.Server/SuiDao.Server.csproj deleted file mode 100644 index dd46eda..0000000 --- a/SuiDao.Server/SuiDao.Server.csproj +++ /dev/null @@ -1,23 +0,0 @@ - - - - Exe - netcoreapp3.1 - - - - - - - - - - - - - - Always - - - - diff --git a/SuiDao.Server/SuiDao.Server.csproj.user b/SuiDao.Server/SuiDao.Server.csproj.user deleted file mode 100644 index 9179783..0000000 --- a/SuiDao.Server/SuiDao.Server.csproj.user +++ /dev/null @@ -1,7 +0,0 @@ - - - - <_LastSelectedProfileId>D:\GitHub\FastTunnel\SuiDao.Server\Properties\PublishProfiles\FolderProfile.pubxml - false - - \ No newline at end of file diff --git a/SuiDao.Server/appsettings.json b/SuiDao.Server/appsettings.json deleted file mode 100644 index f98b00a..0000000 --- a/SuiDao.Server/appsettings.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - }, - "ServerSettings": { - "BindAddr": "0.0.0.0", - "BindPort": 2271, - - // 自定义域名 - "Domain": "sd.suidao.io", - - // 服务监听的端口号, 访问自定义域名站点时url为 http://{SubDomain}.{Domain}:{ProxyPort_HTTP}/ - "ProxyPort_HTTP": 2270, - "HasNginxProxy": true - } -} \ No newline at end of file diff --git a/publish.cmd b/publish.cmd index a2aacc3..91bffd3 100644 --- a/publish.cmd +++ b/publish.cmd @@ -1,6 +1,6 @@ @echo off -for /d %%p in (FastTunnel.Client,FastTunnel.Server,SuiDao.Client,SuiDao.Server) do ( +for /d %%p in (FastTunnel.Client,FastTunnel.Server) do ( CD ./%%p for %%I in (win-x64,osx-x64,linux-x64) do (