mirror of
https://github.com/FastTunnel/FastTunnel.git
synced 2025-02-08 02:39:29 +08:00
add page HostRequired
This commit is contained in:
parent
2288f9cfac
commit
2904430b71
|
@ -107,6 +107,9 @@ namespace FastTunnel.Core.Core
|
|||
if (collection.Count == 0)
|
||||
{
|
||||
_logger.LogError($"Host异常:{words}");
|
||||
|
||||
// 返回错误页
|
||||
HandlerHostRequired(client);
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
@ -117,6 +120,14 @@ namespace FastTunnel.Core.Core
|
|||
_logger.LogDebug(Host.Replace("\r", ""));
|
||||
var domain = Host.Split(":")[1].Trim();
|
||||
|
||||
// 判断是否为ip
|
||||
if (IsIpDomian(domain))
|
||||
{
|
||||
// 返回错误页
|
||||
HandlerHostRequired(client);
|
||||
return;
|
||||
}
|
||||
|
||||
WebInfo web;
|
||||
if (!WebList.TryGetValue(domain, out web))
|
||||
{
|
||||
|
@ -152,23 +163,39 @@ namespace FastTunnel.Core.Core
|
|||
}
|
||||
}
|
||||
|
||||
private void HandlerClientNotOnLine(Socket clientsocket, string domain, byte[] buffer)
|
||||
private bool IsIpDomian(string domain)
|
||||
{
|
||||
_logger.LogDebug($"TunnelNotFound:'{domain}'");
|
||||
return Regex.IsMatch(domain, @"^\d.\d.\d.\d.\d$");
|
||||
}
|
||||
|
||||
private void HandlerHostRequired(Socket client)
|
||||
{
|
||||
_logger.LogDebug($"### HostRequired:'{client.RemoteEndPoint}'");
|
||||
string statusLine = "HTTP/1.1 200 OK\r\n";
|
||||
string responseHeader = "Content-Type: text/html\r\n";
|
||||
|
||||
//var file = Path.Combine(AppContext.BaseDirectory, "Htmls", "TunnelNotFound.html");
|
||||
//if (File.Exists(file))
|
||||
// responseBody = FileHelper.GetBytesFromFile(file);
|
||||
byte[] responseBody = Encoding.UTF8.GetBytes(TunnelResource.Page_HostRequired);
|
||||
|
||||
byte[] responseBody = Encoding.UTF8.GetBytes(TunnelResource.NoTunnelPage);
|
||||
client.Send(Encoding.UTF8.GetBytes(statusLine));
|
||||
client.Send(Encoding.UTF8.GetBytes(responseHeader));
|
||||
client.Send(Encoding.UTF8.GetBytes("\r\n"));
|
||||
client.Send(responseBody);
|
||||
client.Close();
|
||||
}
|
||||
|
||||
clientsocket.Send(Encoding.UTF8.GetBytes(statusLine));
|
||||
clientsocket.Send(Encoding.UTF8.GetBytes(responseHeader));
|
||||
clientsocket.Send(Encoding.UTF8.GetBytes("\r\n"));
|
||||
clientsocket.Send(responseBody);
|
||||
clientsocket.Close();
|
||||
private void HandlerClientNotOnLine(Socket client, 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 = Encoding.UTF8.GetBytes(TunnelResource.Page_NoTunnel);
|
||||
|
||||
client.Send(Encoding.UTF8.GetBytes(statusLine));
|
||||
client.Send(Encoding.UTF8.GetBytes(responseHeader));
|
||||
client.Send(Encoding.UTF8.GetBytes("\r\n"));
|
||||
client.Send(responseBody);
|
||||
client.Close();
|
||||
}
|
||||
|
||||
byte[] buffer = new byte[1024 * 1024];
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace FastTunnel.Core.Handlers.Client
|
|||
string statusLine = "HTTP/1.1 200 OK\r\n";
|
||||
string responseHeader = "Content-Type: text/html\r\n";
|
||||
byte[] responseBody;
|
||||
responseBody = Encoding.UTF8.GetBytes(TunnelResource.NoSite);
|
||||
responseBody = Encoding.UTF8.GetBytes(TunnelResource.Page_NoSite);
|
||||
|
||||
connecter.Send(Encoding.UTF8.GetBytes(statusLine));
|
||||
connecter.Send(Encoding.UTF8.GetBytes(responseHeader));
|
||||
|
|
114
FastTunnel.Core/Htmls/HostReqired.html
Normal file
114
FastTunnel.Core/Htmls/HostReqired.html
Normal file
|
@ -0,0 +1,114 @@
|
|||
<!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>
|
||||
.err-info {
|
||||
margin-top: 120px;
|
||||
}
|
||||
|
||||
/* 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>
|
||||
<div class="container err-info">
|
||||
<main role="main" class="pb-3">
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Http请求必须使用域名访问</h1>
|
||||
<p>本页面的方法不能解决您的问题? 去github提交<a target="_blank" href="https://github.com/SpringHgui/FastTunnel/issues">issue</a>给软件作者.
|
||||
</div>
|
||||
|
||||
<blockquote style="padding-top: 4em;">
|
||||
<p class="lead">您看到本页面表示您请求web服务的方式有误:</p>
|
||||
</blockquote>
|
||||
<ol>
|
||||
<li class="lead">HTTP请求不可使用ip+端口直接访问</li>
|
||||
<li class="lead">请根据客户端提示的地址进行访问</li>
|
||||
<li class="lead">HTTP协议的Host头不可省略</li>
|
||||
</ol>
|
||||
<blockquote style="padding-top: 4em;">
|
||||
<p class="lead">提醒:当前软件处于开发阶段,客户端版本可能会更新频繁,如遇到客户端异常,请登录<a target="_blank"
|
||||
href="https://suidao.io">suidao.io</a>下载最新的客户端重试。</p>
|
||||
</blockquote>
|
||||
</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>
|
91
FastTunnel.Core/TunnelResource.Designer.cs
generated
91
FastTunnel.Core/TunnelResource.Designer.cs
generated
|
@ -60,35 +60,6 @@ namespace FastTunnel.Core {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 <!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>
|
||||
/// .err-info {
|
||||
/// margin-top: 120px;
|
||||
/// }
|
||||
///
|
||||
/// /* Provide sufficient contrast against white background */
|
||||
/// a {
|
||||
/// color: #0366d6;
|
||||
/// }
|
||||
///
|
||||
/// .btn-primary {
|
||||
/// color: #fff;
|
||||
/// background-color [字符串的其余部分被截断]"; 的本地化字符串。
|
||||
/// </summary>
|
||||
internal static string NoSite {
|
||||
get {
|
||||
return ResourceManager.GetString("NoSite", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 您尚未创建任何隧道,请登录https://suidao.io 创建后重试。 的本地化字符串。
|
||||
/// </summary>
|
||||
|
@ -121,9 +92,67 @@ namespace FastTunnel.Core {
|
|||
/// color: #fff;
|
||||
/// background-color [字符串的其余部分被截断]"; 的本地化字符串。
|
||||
/// </summary>
|
||||
internal static string NoTunnelPage {
|
||||
internal static string Page_HostRequired {
|
||||
get {
|
||||
return ResourceManager.GetString("NoTunnelPage", resourceCulture);
|
||||
return ResourceManager.GetString("Page_HostRequired", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 <!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>
|
||||
/// .err-info {
|
||||
/// margin-top: 120px;
|
||||
/// }
|
||||
///
|
||||
/// /* Provide sufficient contrast against white background */
|
||||
/// a {
|
||||
/// color: #0366d6;
|
||||
/// }
|
||||
///
|
||||
/// .btn-primary {
|
||||
/// color: #fff;
|
||||
/// background-color [字符串的其余部分被截断]"; 的本地化字符串。
|
||||
/// </summary>
|
||||
internal static string Page_NoSite {
|
||||
get {
|
||||
return ResourceManager.GetString("Page_NoSite", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 <!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>
|
||||
/// .err-info {
|
||||
/// margin-top: 120px;
|
||||
/// }
|
||||
///
|
||||
/// /* Provide sufficient contrast against white background */
|
||||
/// a {
|
||||
/// color: #0366d6;
|
||||
/// }
|
||||
///
|
||||
/// .btn-primary {
|
||||
/// color: #fff;
|
||||
/// background-color [字符串的其余部分被截断]"; 的本地化字符串。
|
||||
/// </summary>
|
||||
internal static string Page_NoTunnel {
|
||||
get {
|
||||
return ResourceManager.GetString("Page_NoTunnel", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -117,7 +117,126 @@
|
|||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="NoSite" xml:space="preserve">
|
||||
<data name="NoTunnel" xml:space="preserve">
|
||||
<value>您尚未创建任何隧道,请登录https://suidao.io 创建后重试。</value>
|
||||
</data>
|
||||
<data name="Page_HostRequired" xml:space="preserve">
|
||||
<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>
|
||||
.err-info {
|
||||
margin-top: 120px;
|
||||
}
|
||||
|
||||
/* 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>
|
||||
<div class="container err-info">
|
||||
<main role="main" class="pb-3">
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Http请求必须使用域名访问</h1>
|
||||
<p>本页面的方法不能解决您的问题? 去github提交<a target="_blank" href="https://github.com/SpringHgui/FastTunnel/issues">issue</a>给软件作者.
|
||||
</div>
|
||||
|
||||
<blockquote style="padding-top: 4em;">
|
||||
<p class="lead">您看到本页面表示您请求web服务的方式有误:</p>
|
||||
</blockquote>
|
||||
<ol>
|
||||
<li class="lead">HTTP请求不可使用ip+端口直接访问</li>
|
||||
<li class="lead">请根据客户端提示的地址进行访问</li>
|
||||
<li class="lead">HTTP协议的Host头不可省略</li>
|
||||
</ol>
|
||||
<blockquote style="padding-top: 4em;">
|
||||
<p class="lead">提醒:当前软件处于开发阶段,客户端版本可能会更新频繁,如遇到客户端异常,请登录<a target="_blank"
|
||||
href="https://suidao.io">suidao.io</a>下载最新的客户端重试。</p>
|
||||
</blockquote>
|
||||
</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></value>
|
||||
</data>
|
||||
<data name="Page_NoSite" xml:space="preserve">
|
||||
<value><!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
|
@ -234,10 +353,7 @@
|
|||
</html></value>
|
||||
<comment>内网服务未开启</comment>
|
||||
</data>
|
||||
<data name="NoTunnel" xml:space="preserve">
|
||||
<value>您尚未创建任何隧道,请登录https://suidao.io 创建后重试。</value>
|
||||
</data>
|
||||
<data name="NoTunnelPage" xml:space="preserve">
|
||||
<data name="Page_NoTunnel" xml:space="preserve">
|
||||
<value><!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user