增加全局项目配置&增加对未登录的代理提示

This commit is contained in:
SpringHgui 2021-08-22 12:18:11 +08:00
parent 5c0f276b89
commit 86a0a990e8
11 changed files with 206 additions and 59 deletions

7
Directory.Build.props Normal file
View File

@ -0,0 +1,7 @@
<Project>
<PropertyGroup>
<Version>2.0.1</Version>
<Nullable>enable</Nullable>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>

View File

@ -1,8 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
<Version>1.0.0</Version>
<PackageProjectUrl>https://github.com/FastTunnel/FastTunnel/tree/v2/FastTunnel.Api</PackageProjectUrl>
<RepositoryUrl>https://github.com/FastTunnel/FastTunnel/tree/v2/FastTunnel.Api</RepositoryUrl>

View File

@ -2,7 +2,6 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
@ -21,12 +20,6 @@
<None Update="log4net.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="uninstall.bat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="install.bat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ProjectExtensions>

View File

@ -85,7 +85,7 @@ namespace FastTunnel.Core.Client
_logger.LogInformation($"正在连接服务端 {Server.ServerAddr}:{Server.ServerPort}");
await socket.ConnectAsync(
new Uri($"ws://{Server.ServerAddr}:{Server.ServerPort}"), cancellationToken);
new Uri($"{Server.Protocol}://{Server.ServerAddr}:{Server.ServerPort}"), cancellationToken);
_logger.LogDebug("连接服务端成功");
@ -151,13 +151,6 @@ namespace FastTunnel.Core.Client
public void Stop(CancellationToken cancellationToken)
{
_logger.LogInformation("===== FastTunnel Client Stoping =====");
if (socket == null)
return;
if (socket.State == WebSocketState.Connecting)
return;
socket.CloseAsync(WebSocketCloseStatus.Empty, string.Empty, cancellationToken);
}
}
}

View File

@ -18,6 +18,8 @@ namespace FastTunnel.Core.Config
public class SuiDaoServer
{
public string Protocol { get; set; } = "ws";
public string ServerAddr { get; set; }
public int ServerPort { get; set; }

View File

@ -14,6 +14,11 @@ using FastTunnel.Core.Filters;
using Microsoft.AspNetCore.Mvc.Filters;
using FastTunnel.Core.Models;
using FastTunnel.Core.Handlers.Server;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Options;
using System.Threading.Tasks;
using System.Threading;
using Microsoft.AspNetCore.Http;
namespace FastTunnel.Core
{
@ -71,5 +76,24 @@ namespace FastTunnel.Core
app.Use(clientHandler.Handle);
app.Use(swapHandler.Handle);
}
public static void MapFastTunnelServer(this IEndpointRouteBuilder endpoints)
{
endpoints.MapReverseProxy();
endpoints.MapFallback(context =>
{
var options = context.RequestServices.GetRequiredService<IOptionsMonitor<DefaultServerConfig>>();
var host = context.Request.Host.Host;
if (!host.EndsWith(options.CurrentValue.WebDomain) || host.Equals(options.CurrentValue.WebDomain))
{
context.Response.StatusCode = 404;
return Task.CompletedTask;
}
context.Response.StatusCode = 200;
context.Response.WriteAsync(TunnelResource.Page_NotFound, CancellationToken.None);
return Task.CompletedTask;
});
}
}
}

View File

@ -1,10 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net5.0</TargetFramework>
<ApplicationIcon />
<StartupObject />
<PackageProjectUrl>https://github.com/SpringHgui/FastTunnel</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Copyright>FastTunnel</Copyright>
@ -18,7 +14,6 @@
<RepositoryType>git</RepositoryType>
<PackageTags>FastTunnel.Core</PackageTags>
<PackageReleaseNotes>FastTunnel.Core</PackageReleaseNotes>
<Version>2.0.1</Version>
</PropertyGroup>
<ItemGroup>
@ -52,7 +47,7 @@
<ItemGroup>
<EmbeddedResource Update="TunnelResource.resx">
<Generator>ResXFileCodeGenerator</Generator>
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>TunnelResource.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

View File

@ -22,7 +22,7 @@ namespace FastTunnel.Core {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class TunnelResource {
public class TunnelResource {
private static global::System.Resources.ResourceManager resourceMan;
@ -36,7 +36,7 @@ namespace FastTunnel.Core {
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
public 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);
@ -51,7 +51,7 @@ namespace FastTunnel.Core {
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
public static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
@ -63,7 +63,7 @@ namespace FastTunnel.Core {
/// <summary>
/// Looks up a localized string similar to 服务端禁用了Forward.
/// </summary>
internal static string ForwardDisabled {
public static string ForwardDisabled {
get {
return ResourceManager.GetString("ForwardDisabled", resourceCulture);
}
@ -72,7 +72,7 @@ namespace FastTunnel.Core {
/// <summary>
/// Looks up a localized string similar to 您尚未创建任何隧道请登录https://suidao.io 创建后重试。.
/// </summary>
internal static string NoTunnel {
public static string NoTunnel {
get {
return ResourceManager.GetString("NoTunnel", resourceCulture);
}
@ -101,7 +101,7 @@ namespace FastTunnel.Core {
/// color: #fff;
/// background-color [rest of string was truncated]&quot;;.
/// </summary>
internal static string Page_HostRequired {
public static string Page_HostRequired {
get {
return ResourceManager.GetString("Page_HostRequired", resourceCulture);
}
@ -129,7 +129,7 @@ namespace FastTunnel.Core {
/// color: #fff;
/// background-color: [rest of string was truncated]&quot;;.
/// </summary>
internal static string Page_NoSite {
public static string Page_NoSite {
get {
return ResourceManager.GetString("Page_NoSite", resourceCulture);
}
@ -158,7 +158,7 @@ namespace FastTunnel.Core {
/// color: #fff;
/// background-color [rest of string was truncated]&quot;;.
/// </summary>
internal static string Page_NotAccessIps {
public static string Page_NotAccessIps {
get {
return ResourceManager.GetString("Page_NotAccessIps", resourceCulture);
}
@ -187,9 +187,38 @@ namespace FastTunnel.Core {
/// color: #fff;
/// background-color [rest of string was truncated]&quot;;.
/// </summary>
internal static string Page_Offline {
public static string Page_NotFound {
get {
return ResourceManager.GetString("Page_NoTunnel", resourceCulture);
return ResourceManager.GetString("Page_NotFund", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &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 [rest of string was truncated]&quot;;.
/// </summary>
public static string Page_Offline {
get {
return ResourceManager.GetString("Page_Offline", resourceCulture);
}
}
@ -213,7 +242,7 @@ namespace FastTunnel.Core {
///&lt;body&gt;
/// &lt;head [rest of string was truncated]&quot;;.
/// </summary>
internal static string Test {
public static string Test {
get {
return ResourceManager.GetString("Test", resourceCulture);
}
@ -222,7 +251,7 @@ namespace FastTunnel.Core {
/// <summary>
/// Looks up a localized string similar to \n=====隧道已建立成功,现在可以通过以下方式访问您的内网服务了=====\n{0}\n.
/// </summary>
internal static string TunnelLlist {
public static string TunnelLlist {
get {
return ResourceManager.GetString("TunnelLlist", resourceCulture);
}

View File

@ -471,7 +471,7 @@
&lt;/html&gt;</value>
</data>
<data name="Page_NoTunnel" xml:space="preserve">
<data name="Page_NotFund" xml:space="preserve">
<value>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
@ -585,6 +585,122 @@
&lt;/footer&gt;
&lt;/body&gt;
&lt;/html&gt;</value>
</data>
<data name="Page_Offline" 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;客户端已离线&lt;/h1&gt;
&lt;p&gt;登录遇到问题? 去github提交&lt;a target="_blank" href="https://github.com/SpringHgui/FastTunnel/issues"&gt;issue&lt;/a&gt;给软件作者.
&lt;/p&gt;
&lt;/div&gt;
&lt;blockquote style="padding-top: 4em;"&gt;
&lt;p class="lead"&gt;您看到本页面表示当前隧道尚未登录,如果您是当前隧道地址的拥有者,请检查以下原因:&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ol&gt;
&lt;li class="lead"&gt;是否创建了当前子域名的隧道&lt;/li&gt;
&lt;li class="lead"&gt;是否在后台设置中禁用了当前隧道&lt;/li&gt;
&lt;li class="lead"&gt;是否启动了客户端并登录成功&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>
<comment>客户端未登录</comment>
</data>

View File

@ -1,12 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>c508b25f-0a51-4bab-b64c-8a7e993f24f6</UserSecretsId>
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<Compile Remove="logs\**" />
<Content Remove="logs\**" />
@ -29,12 +22,6 @@
</ItemGroup>
<ItemGroup>
<None Update="uninstall.bat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="install.bat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="uninstall.bat">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
@ -42,8 +29,4 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties config_4appsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>
</Project>

View File

@ -1,10 +1,15 @@
using FastTunnel.Core;
using FastTunnel.Core.Config;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using System.Threading;
using System.Threading.Tasks;
namespace FastTunnel.Server
{
@ -26,9 +31,9 @@ namespace FastTunnel.Server
c.SwaggerDoc("v2", new OpenApiInfo { Title = "FastTunel.Api", Version = "v2" });
});
// -------------------FastTunnel START------------------
// -------------------FastTunnel STEP1 OF 3------------------
services.AddFastTunnelServer(Configuration.GetSection("ServerSettings"));
// -------------------FastTunnel END--------------------
// -------------------FastTunnel STEP1 END--------------------
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@ -41,16 +46,18 @@ namespace FastTunnel.Server
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v2/swagger.json", "FastTunel.WebApi v2"));
}
// -------------------FastTunnel START------------------
// -------------------FastTunnel STEP2 OF 3------------------
app.UseFastTunnelServer();
// -------------------FastTunnel END--------------------
// -------------------FastTunnel STEP2 END--------------------
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapReverseProxy();
endpoints.MapControllers();
// -------------------FastTunnel STEP3 OF 3------------------
endpoints.MapFastTunnelServer();
// -------------------FastTunnel STEP3 END--------------------
});
}
}