add page HostRequired

This commit is contained in:
SpringHgui 2020-07-03 14:26:52 +08:00
parent 2288f9cfac
commit 2904430b71
5 changed files with 334 additions and 48 deletions

View File

@ -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];

View File

@ -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));

View 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>

View File

@ -60,35 +60,6 @@ namespace FastTunnel.Core {
}
}
/// <summary>
/// 查找类似 &lt;!DOCTYPE html&gt;
///&lt;html lang=&quot;en&quot;&gt;
///
///&lt;head&gt;
/// &lt;meta charset=&quot;utf-8&quot; /&gt;
/// &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot; /&gt;
/// &lt;title&gt;FastTunnel&lt;/title&gt;
/// &lt;link href=&quot;https://cdn.bootcss.com/twitter-bootstrap/4.4.1/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;&gt;
/// &lt;style&gt;
/// .err-info {
/// margin-top: 120px;
/// }
///
/// /* Provide sufficient contrast against white background */
/// a {
/// color: #0366d6;
/// }
///
/// .btn-primary {
/// color: #fff;
/// background-color [字符串的其余部分被截断]&quot;; 的本地化字符串。
/// </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 [字符串的其余部分被截断]&quot;; 的本地化字符串。
/// </summary>
internal static string NoTunnelPage {
internal static string Page_HostRequired {
get {
return ResourceManager.GetString("NoTunnelPage", resourceCulture);
return ResourceManager.GetString("Page_HostRequired", resourceCulture);
}
}
/// <summary>
/// 查找类似 &lt;!DOCTYPE html&gt;
///&lt;html lang=&quot;en&quot;&gt;
///
///&lt;head&gt;
/// &lt;meta charset=&quot;utf-8&quot; /&gt;
/// &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot; /&gt;
/// &lt;title&gt;FastTunnel&lt;/title&gt;
/// &lt;link href=&quot;https://cdn.bootcss.com/twitter-bootstrap/4.4.1/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;&gt;
/// &lt;style&gt;
/// .err-info {
/// margin-top: 120px;
/// }
///
/// /* Provide sufficient contrast against white background */
/// a {
/// color: #0366d6;
/// }
///
/// .btn-primary {
/// color: #fff;
/// background-color [字符串的其余部分被截断]&quot;; 的本地化字符串。
/// </summary>
internal static string Page_NoSite {
get {
return ResourceManager.GetString("Page_NoSite", resourceCulture);
}
}
/// <summary>
/// 查找类似 &lt;!DOCTYPE html&gt;
///&lt;html lang=&quot;en&quot;&gt;
///
///&lt;head&gt;
/// &lt;meta charset=&quot;utf-8&quot; /&gt;
/// &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot; /&gt;
/// &lt;title&gt;FastTunnel&lt;/title&gt;
/// &lt;link href=&quot;https://cdn.bootcss.com/twitter-bootstrap/4.4.1/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;&gt;
/// &lt;style&gt;
/// .err-info {
/// margin-top: 120px;
/// }
///
/// /* Provide sufficient contrast against white background */
/// a {
/// color: #0366d6;
/// }
///
/// .btn-primary {
/// color: #fff;
/// background-color [字符串的其余部分被截断]&quot;; 的本地化字符串。
/// </summary>
internal static string Page_NoTunnel {
get {
return ResourceManager.GetString("Page_NoTunnel", resourceCulture);
}
}

View File

@ -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>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta charset="utf-8" /&gt;
&lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&gt;
&lt;title&gt;FastTunnel&lt;/title&gt;
&lt;link href="https://cdn.bootcss.com/twitter-bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"&gt;
&lt;style&gt;
.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&gt;.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 */
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class="container err-info"&gt;
&lt;main role="main" class="pb-3"&gt;
&lt;div class="text-center"&gt;
&lt;h1 class="display-4"&gt;Http请求必须使用域名访问&lt;/h1&gt;
&lt;p&gt;本页面的方法不能解决您的问题? 去github提交&lt;a target="_blank" href="https://github.com/SpringHgui/FastTunnel/issues"&gt;issue&lt;/a&gt;给软件作者.
&lt;/div&gt;
&lt;blockquote style="padding-top: 4em;"&gt;
&lt;p class="lead"&gt;您看到本页面表示您请求web服务的方式有误&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ol&gt;
&lt;li class="lead"&gt;HTTP请求不可使用ip+端口直接访问&lt;/li&gt;
&lt;li class="lead"&gt;请根据客户端提示的地址进行访问&lt;/li&gt;
&lt;li class="lead"&gt;HTTP协议的Host头不可省略&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote style="padding-top: 4em;"&gt;
&lt;p class="lead"&gt;提醒:当前软件处于开发阶段,客户端版本可能会更新频繁,如遇到客户端异常,请登录&lt;a target="_blank"
href="https://suidao.io"&gt;suidao.io&lt;/a&gt;下载最新的客户端重试。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/main&gt;
&lt;/div&gt;
&lt;footer class="border-top footer text-muted"&gt;
&lt;div class="container"&gt;
&lt;a href="https://github.com/SpringHgui/FastTunnel" target="_blank"&gt;© Power By FastTunnel&lt;/a&gt;
&lt;/div&gt;
&lt;/footer&gt;
&lt;/body&gt;
&lt;/html&gt;</value>
</data>
<data name="Page_NoSite" xml:space="preserve">
<value>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
@ -234,10 +353,7 @@
&lt;/html&gt;</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>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;