mirror of
https://github.com/FastTunnel/FastTunnel.git
synced 2025-02-08 02:39:29 +08:00
增加隧道不存在时的提示页
This commit is contained in:
parent
731e5c43fc
commit
4fb36b00ee
|
@ -14,6 +14,9 @@ using System.Threading.Tasks;
|
|||
using Microsoft.Extensions.Logging;
|
||||
using FastTunnel.Core.Handlers;
|
||||
using FastTunnel.Core.Handlers.Server;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using FastTunnel.Core.Helper;
|
||||
using System.IO;
|
||||
|
||||
namespace FastTunnel.Core.Core
|
||||
{
|
||||
|
@ -120,14 +123,15 @@ namespace FastTunnel.Core.Core
|
|||
{
|
||||
_logger.LogError($"客户端不存在:'{domain}'");
|
||||
_logger.LogDebug(words);
|
||||
return;
|
||||
HandlerClientNotOnLine(client, domain, buffer); return;
|
||||
|
||||
}
|
||||
|
||||
if (!web.Socket.Connected)
|
||||
{
|
||||
_logger.LogError($"客户端已下线:'{domain}'");
|
||||
WebList.Remove(domain);
|
||||
return;
|
||||
HandlerClientNotOnLine(client, domain, buffer); return;
|
||||
}
|
||||
|
||||
var msgid = Guid.NewGuid().ToString();
|
||||
|
@ -149,6 +153,36 @@ namespace FastTunnel.Core.Core
|
|||
}
|
||||
}
|
||||
|
||||
private void HandlerClientNotOnLine(Socket clientsocket, string domain, byte[] buffer)
|
||||
{
|
||||
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(@"
|
||||
<p>看到本页面表示当前隧道未登录,如果您是当前隧道地址的拥有者,请检查以下原因:</p>
|
||||
<ol>
|
||||
<li>是否创建了当前子域名的隧道</li>
|
||||
<li>是否在后台设置中禁用了当前隧道</li>
|
||||
<li>是否启动了客户端并登录成功</li>
|
||||
</ol>");
|
||||
}
|
||||
|
||||
|
||||
clientsocket.Send(Encoding.UTF8.GetBytes(statusLine));
|
||||
clientsocket.Send(Encoding.UTF8.GetBytes(responseHeader));
|
||||
clientsocket.Send(Encoding.UTF8.GetBytes("\r\n"));
|
||||
clientsocket.Send(responseBody);
|
||||
clientsocket.Close();
|
||||
}
|
||||
|
||||
byte[] buffer = new byte[1024 * 1024];
|
||||
|
||||
public void ReceiveClient(Socket client, object _)
|
||||
|
@ -174,9 +208,9 @@ namespace FastTunnel.Core.Core
|
|||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"client 退出登录");
|
||||
_logger.LogError($"接收客户端异常 -> 退出登录 {ex.Message}");
|
||||
if (client.Connected)
|
||||
{
|
||||
client.Close();
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0" />
|
||||
|
@ -26,4 +27,10 @@
|
|||
<PackageReference Include="NLog.Extensions.Logging" Version="1.6.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Htmls\TunnelNotFound.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
27
FastTunnel.Core/Helper/FileHelper.cs
Normal file
27
FastTunnel.Core/Helper/FileHelper.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace FastTunnel.Core.Helper
|
||||
{
|
||||
public static class FileHelper
|
||||
{
|
||||
public static byte[] GetBytesFromFile(string fileName)
|
||||
{
|
||||
if (!File.Exists(fileName))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
FileInfo fi = new FileInfo(fileName);
|
||||
byte[] buff = new byte[fi.Length];
|
||||
|
||||
FileStream fs = fi.OpenRead();
|
||||
fs.Read(buff, 0, Convert.ToInt32(fs.Length));
|
||||
fs.Close();
|
||||
|
||||
return buff;
|
||||
}
|
||||
}
|
||||
}
|
126
FastTunnel.Core/Htmls/TunnelNotFound.html
Normal file
126
FastTunnel.Core/Htmls/TunnelNotFound.html
Normal file
|
@ -0,0 +1,126 @@
|
|||
<!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>
|
|
@ -72,6 +72,10 @@ namespace FastTunnel.Core
|
|||
|
||||
if (!chanel.Send.Connected)
|
||||
break;
|
||||
|
||||
var str = Encoding.UTF8.GetString(result, 0, num);
|
||||
Console.Write(str);
|
||||
|
||||
chanel.Send.Send(result, num, SocketFlags.None);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
@ -9,5 +9,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
|
|||
<Platform>Any CPU</Platform>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<PublishDir>bin\Release\netcoreapp3.1\publish\</PublishDir>
|
||||
<SelfContained>false</SelfContained>
|
||||
</PropertyGroup>
|
||||
</Project>
|
|
@ -9,5 +9,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
|
|||
<Platform>Any CPU</Platform>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<PublishDir>bin\Release\netcoreapp3.1\publish\</PublishDir>
|
||||
<SelfContained>false</SelfContained>
|
||||
</PropertyGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user