diff --git a/.gitignore b/.gitignore index 8dbea78..21facb3 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ publish /SuiDao.Client/Properties/PublishProfiles/*.user /SuiDao.Client/*.user /SuiDao.Client/Properties/PublishProfiles/FolderProfile.pubxml +/FastTunnel.Core/*.user diff --git a/FastTunnel.Core/Core/SuiDaoServer.cs b/FastTunnel.Core/Core/SuiDaoServer.cs index 84bc595..11ac0af 100644 --- a/FastTunnel.Core/Core/SuiDaoServer.cs +++ b/FastTunnel.Core/Core/SuiDaoServer.cs @@ -67,7 +67,7 @@ namespace FastTunnel.Core.Core //接收消息 void ReceiveCustomer(Socket client, object _) { - _logger.LogDebug("新的HTTP请求"); + _logger.LogDebug("Receive HTTP Request"); try { @@ -121,17 +121,15 @@ namespace FastTunnel.Core.Core WebInfo web; if (!WebList.TryGetValue(domain, out web)) { - _logger.LogError($"客户端不存在:'{domain}'"); - _logger.LogDebug(words); - HandlerClientNotOnLine(client, domain, buffer); return; - + HandlerClientNotOnLine(client, domain, buffer); + return; } if (!web.Socket.Connected) { - _logger.LogError($"客户端已下线:'{domain}'"); WebList.Remove(domain); - HandlerClientNotOnLine(client, domain, buffer); return; + HandlerClientNotOnLine(client, domain, buffer); + return; } var msgid = Guid.NewGuid().ToString(); @@ -145,36 +143,28 @@ namespace FastTunnel.Core.Core Buffer = bytes }); + _logger.LogDebug($"OK"); web.Socket.Send(new Message { MessageType = MessageType.S_NewCustomer, Content = new NewCustomerMassage { MsgId = msgid, WebConfig = web.WebConfig } }); } catch (Exception ex) { _logger.LogError(ex); + client.Close(); } } private void HandlerClientNotOnLine(Socket clientsocket, string domain, byte[] buffer) { + _logger.LogDebug($"TunnelNotFound:'{domain}'"); string statusLine = "HTTP/1.1 200 OK\r\n"; string responseHeader = "Content-Type: text/html\r\n"; byte[] responseBody; var file = Path.Combine(AppContext.BaseDirectory, "Htmls", "TunnelNotFound.html"); if (File.Exists(file)) - { responseBody = FileHelper.GetBytesFromFile(file); - } else - { - responseBody = Encoding.UTF8.GetBytes(@" -

看到本页面表示当前隧道未登录,如果您是当前隧道地址的拥有者,请检查以下原因:

-
    -
  1. 是否创建了当前子域名的隧道
  2. -
  3. 是否在后台设置中禁用了当前隧道
  4. -
  5. 是否启动了客户端并登录成功
  6. -
"); - } - + responseBody = Encoding.UTF8.GetBytes(TunnelResource.NoTunnelPage); clientsocket.Send(Encoding.UTF8.GetBytes(statusLine)); clientsocket.Send(Encoding.UTF8.GetBytes(responseHeader)); diff --git a/FastTunnel.Core/FastTunnel.Core.csproj b/FastTunnel.Core/FastTunnel.Core.csproj index 0bdd7d5..214c2aa 100644 --- a/FastTunnel.Core/FastTunnel.Core.csproj +++ b/FastTunnel.Core/FastTunnel.Core.csproj @@ -28,9 +28,18 @@ - - Always - + + True + True + TunnelResource.resx + + + + + + ResXFileCodeGenerator + TunnelResource.Designer.cs + diff --git a/FastTunnel.Core/TunnelResource.Designer.cs b/FastTunnel.Core/TunnelResource.Designer.cs new file mode 100644 index 0000000..d9a01c9 --- /dev/null +++ b/FastTunnel.Core/TunnelResource.Designer.cs @@ -0,0 +1,84 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace FastTunnel.Core { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class TunnelResource { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal TunnelResource() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FastTunnel.Core.TunnelResource", typeof(TunnelResource).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 重写当前线程的 CurrentUICulture 属性 + /// 重写当前线程的 CurrentUICulture 属性。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// 查找类似 <!DOCTYPE html> + ///<html lang="en"> + /// + ///<head> + /// <meta charset="utf-8" /> + /// <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + /// <title>FastTunnel</title> + /// <link href="https://cdn.bootcss.com/twitter-bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"> + /// <style> + /// /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification + ///for details on configuring this project to bundle and minify static web assets. */ + /// + /// a.navbar-brand { [字符串的其余部分被截断]"; 的本地化字符串。 + /// + internal static string NoTunnelPage { + get { + return ResourceManager.GetString("NoTunnelPage", resourceCulture); + } + } + } +} diff --git a/FastTunnel.Core/TunnelResource.resx b/FastTunnel.Core/TunnelResource.resx new file mode 100644 index 0000000..fb0622b --- /dev/null +++ b/FastTunnel.Core/TunnelResource.resx @@ -0,0 +1,248 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + <!DOCTYPE html> +<html lang="en"> + +<head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>FastTunnel</title> + <link href="https://cdn.bootcss.com/twitter-bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"> + <style> + /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification +for details on configuring this project to bundle and minify static web assets. */ + + a.navbar-brand { + white-space: normal; + text-align: center; + word-break: break-all; + } + + /* Provide sufficient contrast against white background */ + a { + color: #0366d6; + } + + .btn-primary { + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; + } + + .nav-pills .nav-link.active, + .nav-pills .show>.nav-link { + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; + } + + /* Sticky footer styles +-------------------------------------------------- */ + html { + font-size: 14px; + } + + @media (min-width: 768px) { + html { + font-size: 16px; + } + } + + .border-top { + border-top: 1px solid #e5e5e5; + } + + .border-bottom { + border-bottom: 1px solid #e5e5e5; + } + + .box-shadow { + box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); + } + + button.accept-policy { + font-size: 1rem; + line-height: inherit; + } + + /* Sticky footer styles +-------------------------------------------------- */ + html { + position: relative; + min-height: 100%; + } + + body { + /* Margin bottom by footer height */ + margin-bottom: 60px; + } + + .footer { + position: absolute; + bottom: 0; + width: 100%; + white-space: nowrap; + line-height: 60px; + /* Vertically center the text there */ + } + </style> +</head> + +<body> + <header> + <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3"> + <div class="container"> + <a class="navbar-brand" src="https://suidao.io">FastTunnel</a> + <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" + aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> + <span class="navbar-toggler-icon"></span> + </button> + </div> + </nav> + </header> + <div class="container"> + <main role="main" class="pb-3"> + <div class="text-center"> + <h1 class="display-4">找不到隧道</h1> + <p>了解有关 <a target="_blank" href="https://github.com/SpringHgui/FastTunnel">FastTunel</a>的信息.</p> + </div> + + <blockquote style="padding-top: 4em;"> + <p class="lead">看到本页面表示当前隧道未登录,如果您是当前隧道地址的拥有者,请检查以下原因:</p> + </blockquote> + <ol> + <li class="lead">是否创建了当前子域名的隧道</li> + <li class="lead">是否在后台设置中禁用了当前隧道</li> + <li class="lead">是否启动了客户端并登录成功</li> + </ol> + </main> + </div> + + <footer class="border-top footer text-muted"> + <div class="container"> + <a href="https://github.com/SpringHgui/FastTunnel" target="_blank">© Power By FastTunnel</a> + </div> + </footer> +</body> + +</html> + + \ No newline at end of file diff --git a/SuiDao.Server/SuiDao.Server.csproj.user b/SuiDao.Server/SuiDao.Server.csproj.user index 13e2071..b8c3132 100644 --- a/SuiDao.Server/SuiDao.Server.csproj.user +++ b/SuiDao.Server/SuiDao.Server.csproj.user @@ -1,6 +1,6 @@  - <_LastSelectedProfileId>D:\GitHub\FastTunnel\SuiDao.Server\Properties\PublishProfiles\FolderProfile.pubxml + <_LastSelectedProfileId>G:\GitHub\FastTunnel\SuiDao.Server\Properties\PublishProfiles\FolderProfile.pubxml \ No newline at end of file