mirror of
https://github.com/FastTunnel/FastTunnel.git
synced 2025-02-08 02:39:29 +08:00
1
This commit is contained in:
parent
98ecb29407
commit
c923bd41a7
|
@ -1,7 +1,5 @@
|
|||
<Project>
|
||||
<PropertyGroup>
|
||||
<Version>3.0.0-Beta.1.22511</Version>
|
||||
<TargetFrameworks>net6.0</TargetFrameworks>
|
||||
<PackageProjectUrl>https://github.com/SpringHgui/FastTunnel</PackageProjectUrl>
|
||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||
<Copyright>FastTunnel</Copyright>
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.4" />
|
||||
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.17.0" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.17.0" />
|
||||
</ItemGroup>
|
||||
|
|
80
FastTunnel.Api/FastTunnelApiHostingStartup.cs
Normal file
80
FastTunnel.Api/FastTunnelApiHostingStartup.cs
Normal file
|
@ -0,0 +1,80 @@
|
|||
// Licensed under the Apache License, Version 2.0 (the "License").
|
||||
// You may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE
|
||||
// Copyright (c) 2019 Gui.H
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FastTunnel.Api;
|
||||
using FastTunnel.Api.Filters;
|
||||
using FastTunnel.Core.Config;
|
||||
using FastTunnel.Core.Extensions;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
[assembly: HostingStartup(typeof(FastTunnelApiHostingStartup))]
|
||||
|
||||
namespace FastTunnel.Api;
|
||||
|
||||
public class FastTunnelApiHostingStartup : IHostingStartup
|
||||
{
|
||||
public void Configure(IWebHostBuilder builder)
|
||||
{
|
||||
Debug.WriteLine("FastTunnelApiHostingStartup Configured");
|
||||
|
||||
builder.ConfigureServices((webHostBuilderContext, services) =>
|
||||
{
|
||||
services.AddControllers();
|
||||
services.AddAuthorization();
|
||||
var serverOptions = webHostBuilderContext.Configuration.GetSection("FastTunnel").Get<DefaultServerConfig>();
|
||||
if (serverOptions.Api?.JWT != null)
|
||||
{
|
||||
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
.AddJwtBearer(options =>
|
||||
{
|
||||
options.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuer = false,
|
||||
ValidateAudience = false,
|
||||
ValidateLifetime = true,
|
||||
ClockSkew = TimeSpan.FromSeconds(serverOptions.Api.JWT.ClockSkew),
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidAudience = serverOptions.Api.JWT.ValidAudience,
|
||||
ValidIssuer = serverOptions.Api.JWT.ValidIssuer,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(serverOptions.Api.JWT.IssuerSigningKey))
|
||||
};
|
||||
|
||||
options.Events = new JwtBearerEvents
|
||||
{
|
||||
OnChallenge = async context =>
|
||||
{
|
||||
context.HandleResponse();
|
||||
|
||||
context.Response.ContentType = "application/json;charset=utf-8";
|
||||
context.Response.StatusCode = StatusCodes.Status200OK;
|
||||
|
||||
await context.Response.WriteAsync(new
|
||||
{
|
||||
errorCode = 1,
|
||||
errorMessage = context.Error ?? "Token is Required"
|
||||
}.ToJson());
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
services.AddSingleton<CustomExceptionFilterAttribute>();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,34 +1,36 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<Version>3.0.0-Beta.1.22511</Version>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<OutputType>Exe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="7.0.0-preview.3.22175.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="7.0.0-preview.3.22175.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FastTunnel.Core\FastTunnel.Core.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FastTunnel.Core\FastTunnel.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="install.bat">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="uninstall.bat">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="install.bat">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="uninstall.bat">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties appsettings_1json__JsonSchema="" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties appsettings_1json__JsonSchema="" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Version>3.0.0-Beta.1.22511</Version>
|
||||
<TargetFrameworks>net6.0</TargetFrameworks>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
|
|
@ -44,7 +44,7 @@ public class FastTunelProtocol
|
|||
ReadOnlySequence<byte> readableBuffer;
|
||||
while (true)
|
||||
{
|
||||
result = await _input.ReadAsync();
|
||||
result = await _input.ReadAsync(context.ConnectionClosed);
|
||||
var tempBuffer = readableBuffer = result.Buffer;
|
||||
|
||||
SequencePosition? position = null;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Version>3.0.0-Beta.1.22511</Version>
|
||||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
|
||||
|
@ -15,16 +15,15 @@
|
|||
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.0-preview.3.22175.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FastTunnel.Core\FastTunnel.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="README.md">
|
||||
<None Include="..\README.md">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FastTunnel.Core\FastTunnel.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,166 +0,0 @@
|
|||
<div align="center">
|
||||
|
||||
<img src="images/logo.png" width="150" align=center />
|
||||
|
||||
## FastTunnel
|
||||
[![License](https://img.shields.io/badge/license-Apache%202-green.svg)](https://www.apache.org/licenses/LICENSE-2.0)
|
||||
[![Build status](https://github.com/anjoy8/blog.core/workflows/.NET%20Core/badge.svg)](https://github.com/SpringHgui/FastTunnel/actions)
|
||||
[![Nuget](https://img.shields.io/nuget/v/FastTunnel.Core)](https://www.nuget.org/packages/FastTunnel.Core/)
|
||||
[![Nuget](https://img.shields.io/nuget/dt/FastTunnel.Core)](https://www.nuget.org/packages/FastTunnel.Core/)
|
||||
|
||||
[README](README.md) | [中文文档](README_zh.md)
|
||||
|
||||
***This project supports any commercial and secondary development activities, but seriously despises plagiarizing and copying the code, implementation scheme or architecture of this project and repackaging them into their own open source works.***
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
## What is FastTunnel?
|
||||
- FastTunnel is a high-performance cross-platform intranet penetration tool. With it, you can expose intranet services to the public network for yourself or anyone to access.
|
||||
- Unlike other penetration tools, the FastTunnel project is committed to creating an easy-to-extensible and easy-to-maintain intranet penetration framework.
|
||||
- You can build your own penetration application by referencing the nuget package of `FastTunnel.Core`, and target the business extension functions you need.
|
||||
|
||||
|
||||
***
|
||||
|
||||
Official website : https://suidao.io
|
||||
|
||||
The penetration platform developed based on this framework, if you need intranet penetration, you can register and use it directly, eliminating the cost of building and maintaining yourself.
|
||||
But do not use this service for important items.
|
||||
|
||||
OpenSource:
|
||||
|
||||
GitHub : [FastTunnel](https://github.com/SpringHgui/FastTunnel)
|
||||
Gitee: [FastTunnel](https://gitee.com/Hgui/FastTunnel)
|
||||
|
||||
**If helpful, click on ⭐Star to support this project, please submit an issue if you have needs and bugs, and welcome coder to PR**
|
||||
|
||||
## Get GVP
|
||||
|
||||
![img1](images/gvp.png)
|
||||
***
|
||||
|
||||
## What can FastTunel do?
|
||||
- [x] Remote intranet computer Windows/Linux/Mac
|
||||
- [x] Use a custom domain name to access intranet web services (usually used for WeChat development)
|
||||
- [x] Port forwarding/port mapping, access services provided by any port on the intranet mysql, redis, ftp, etc.
|
||||
- [ ] p2p penetration
|
||||
- [x] Support binding multiple domain names to access intranet services
|
||||
- [x] Support domain name whitelist restriction
|
||||
- [x] Support client identity verification
|
||||
|
||||
## Quickstart
|
||||
1. Download the corresponding program on the [releases](https://github.com/SpringHgui/FastTunnel/releases) page
|
||||
2. Modify the client and server configuration files according to your needs`appsettings.json`
|
||||
3. Run FastTunnel.Server
|
||||
4. Run FastTunnel.Cient
|
||||
|
||||
## Install FastTunel.Sever using Docker Engine
|
||||
Configuration files and log files are mounted through volume. If this image has been run before, docker may not update to the latest image. Please delete the existing image manually, and then execute the following command
|
||||
|
||||
```
|
||||
docker run --detach \
|
||||
--publish 1270:1270 --publish 1271:1271 \
|
||||
--name FastTunnel \
|
||||
--restart always \
|
||||
--volume /var/FastTunnel/config:/app/config \
|
||||
--volume /var/FastTunnel/Logs:/app/Logs \
|
||||
springhgui/fasttunnel:latest
|
||||
```
|
||||
## Run on Linux/Mac os?
|
||||
#### Windows
|
||||
Double click directly `FastTunnel.Client.exe` to run
|
||||
#### Linux
|
||||
`chmod +x FastTunnel.Client`
|
||||
`./FastTunnel.Client`
|
||||
#### Mac
|
||||
click directly `FastTunnel.Client` to run
|
||||
|
||||
## Configuration example
|
||||
### 1. Use a custom domain name to access intranet web services
|
||||
- For example, you have a server with a public IP address of `110.110.110.110`, and you have a domain name with a top-level domain name of `abc.com`, you want to visit a website on the intranet by visiting `test.abc.com`
|
||||
- You need to add a DNS resolution for the domain name address, the type is `A`, the name is `*`, and the ipv4 address is `110.110.110.110`, so that all domain names of `*.abc.com` will point to `110.110.110.110`’s server, because the default http port of `FastTunnel` is 1270, so you need to visit`http://test.abc.com:1270`
|
||||
|
||||
- #### If you don't want to bring the port number every time you visit, you can use `nginx` forwarding.
|
||||
```
|
||||
http {
|
||||
# add resolver
|
||||
resolver 8.8.8.8;
|
||||
|
||||
# set *.abc.com to 1270 port
|
||||
server {
|
||||
server_name *.abc.com;
|
||||
location / {
|
||||
proxy_pass http://$host:1270;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
|
||||
# 可选
|
||||
error_log /var/log/nginx/error_ft.log error;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- If the domain name configured on the server is `ft.suidao.io`, then access the local site through the subdomain name `test.ft.suidao.io:1270`, the IIS configuration is as follows:
|
||||
![img1](images/iis-web.png)
|
||||
|
||||
### 2. Remote intranet computer Windows/Linux/Mac
|
||||
|
||||
The client configuration is as follows, there are two hosts in the intranet, and the ip is as follows:
|
||||
appsettings.json
|
||||
```
|
||||
"ClientSettings": {
|
||||
"Common": {
|
||||
"ServerAddr": "xxx.xxx.xxx.xxx",
|
||||
"ServerPort": 1271
|
||||
},
|
||||
"SSH": [
|
||||
{
|
||||
"LocalIp": "192.168.0.100", // linux pc
|
||||
"LocalPort": 22, // ssh default port
|
||||
"RemotePort": 12701
|
||||
},
|
||||
{
|
||||
"LocalIp": "192.168.0.101", // windows pc
|
||||
"LocalPort": 3389, // windows default port for Remote
|
||||
"RemotePort": 12702
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
#### remote intranet linux host by ssh (ip:192.168.0.100)
|
||||
|
||||
Assuming that the user name of the intranet host is root, the server ip is x.x.x.x, and the two hosts that access the intranet are as follows
|
||||
```
|
||||
ssh -oPort=12701 root@x.x.x.x
|
||||
```
|
||||
|
||||
#### remote desktop Windows host by mstsc (ip:192.168.0.101)
|
||||
#### Controlled terminal setting
|
||||
- Open cmd and enter the command `sysdm.cpl` in the pop-up dialog box and select Allow remote connection to this computer
|
||||
|
||||
![img1](images/setallow.png)
|
||||
#### Control terminal settings
|
||||
- Open cmd and enter the command `mstsc`, open the remote dialog box, enter `x.x.x.x:12701` in the computer input box of the dialog box, and then specify the user name and password to remote the windows host of the intranet
|
||||
![img1](images/remote.png)
|
||||
|
||||
## Development/PR
|
||||
- install `vs2019` last version
|
||||
- install `.net5` or higher `https://dotnet.microsoft.com/download/dotnet/5.0`
|
||||
- add `test.test.cc 127.0.0.1` in system host file
|
||||
- run fasttunnel.server
|
||||
- run fasttunnel.client
|
||||
|
||||
## contributors
|
||||
<a href = "https://github.com/FastTunnel/FastTunnel/graphs/contributors">
|
||||
<img src = "https://contrib.rocks/image?repo=FastTunnel/FastTunnel"/>
|
||||
</a>
|
||||
|
||||
## Join QQ Group
|
||||
|
||||
<div align="center"><img src="images/qqgroup.png" width="150" align=center /></div>
|
||||
|
||||
## License
|
||||
Apache License 2.0
|
|
@ -1,6 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0</TargetFrameworks>
|
||||
<Version>3.0.0-Beta.1.22511</Version>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ public class Program
|
|||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder.UseKestrel();
|
||||
webHostBuilder.UseSetting(WebHostDefaults.HostingStartupAssembliesKey, "FastTunnel.Hosting");
|
||||
webHostBuilder.UseSetting(WebHostDefaults.HostingStartupAssembliesKey, "FastTunnel.Api;FastTunnel.Hosting");
|
||||
|
||||
webHostBuilder.ConfigureAppConfiguration((hostingContext, config) =>
|
||||
{
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
-->
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<DeleteExistingFiles>False</DeleteExistingFiles>
|
||||
<ExcludeApp_Data>False</ExcludeApp_Data>
|
||||
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
|
||||
<DeleteExistingFiles>false</DeleteExistingFiles>
|
||||
<ExcludeApp_Data>false</ExcludeApp_Data>
|
||||
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
|
||||
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
|
||||
<LastUsedPlatform>Any CPU</LastUsedPlatform>
|
||||
<PublishProvider>FileSystem</PublishProvider>
|
||||
<PublishUrl>bin\Release\net5.0\publish\</PublishUrl>
|
||||
<PublishUrl>bin\Release\net6.0\publish\</PublishUrl>
|
||||
<WebPublishMethod>FileSystem</WebPublishMethod>
|
||||
<_TargetId>Folder</_TargetId>
|
||||
</PropertyGroup>
|
||||
</Project>
|
|
@ -1,20 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
-->
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<DeleteExistingFiles>False</DeleteExistingFiles>
|
||||
<ExcludeApp_Data>False</ExcludeApp_Data>
|
||||
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
|
||||
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
|
||||
<LastUsedPlatform>Any CPU</LastUsedPlatform>
|
||||
<PublishProvider>FileSystem</PublishProvider>
|
||||
<PublishUrl>bin\Release\net5.0\publish\</PublishUrl>
|
||||
<WebPublishMethod>FileSystem</WebPublishMethod>
|
||||
<SiteUrlToLaunchAfterPublish />
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<ProjectGuid>def2e322-9075-4c3f-9967-7eaf0ee28ceb</ProjectGuid>
|
||||
<SelfContained>false</SelfContained>
|
||||
</PropertyGroup>
|
||||
</Project>
|
|
@ -1,16 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
-->
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<DeleteExistingFiles>False</DeleteExistingFiles>
|
||||
<ExcludeApp_Data>False</ExcludeApp_Data>
|
||||
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
|
||||
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
|
||||
<LastUsedPlatform>Any CPU</LastUsedPlatform>
|
||||
<PublishProvider>FileSystem</PublishProvider>
|
||||
<PublishUrl>bin\Release\net5.0\publish\</PublishUrl>
|
||||
<WebPublishMethod>FileSystem</WebPublishMethod>
|
||||
</PropertyGroup>
|
||||
</Project>
|
|
@ -35,45 +35,6 @@ public class Startup
|
|||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
.AddJwtBearer(options =>
|
||||
{
|
||||
var serverOptions = Configuration.GetSection("FastTunnel").Get<DefaultServerConfig>();
|
||||
|
||||
options.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuer = false,
|
||||
ValidateAudience = false,
|
||||
ValidateLifetime = true,
|
||||
ClockSkew = TimeSpan.FromSeconds(serverOptions.Api.JWT.ClockSkew),
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidAudience = serverOptions.Api.JWT.ValidAudience,
|
||||
ValidIssuer = serverOptions.Api.JWT.ValidIssuer,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(serverOptions.Api.JWT.IssuerSigningKey))
|
||||
};
|
||||
|
||||
options.Events = new JwtBearerEvents
|
||||
{
|
||||
OnChallenge = async context =>
|
||||
{
|
||||
context.HandleResponse();
|
||||
|
||||
context.Response.ContentType = "application/json;charset=utf-8";
|
||||
context.Response.StatusCode = StatusCodes.Status200OK;
|
||||
|
||||
await context.Response.WriteAsync(new
|
||||
{
|
||||
errorCode = 1,
|
||||
errorMessage = context.Error ?? "Token is Required"
|
||||
}.ToJson());
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
services.AddAuthorization();
|
||||
|
||||
services.AddControllers();
|
||||
|
||||
#if DEBUG
|
||||
services.AddSwaggerGen(c =>
|
||||
{
|
||||
|
@ -109,7 +70,7 @@ public class Startup
|
|||
endpoints.MapControllers();
|
||||
endpoints.MapFallback(async (HttpContext ctx) =>
|
||||
{
|
||||
await ctx.Response.Body.WriteAsync(Encoding.UTF8.GetBytes("hello~"));
|
||||
await ctx.Response.Body.WriteAsync(Encoding.UTF8.GetBytes("404~"));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
// Trace Debug Information Warning Error
|
||||
"Default": "Debug",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"EnableFileLog": false
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
// Trace Debug Information Warning Error
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
|
||||
// 是否启用文件日志输出
|
||||
"EnableFileLog": false,
|
||||
"FastTunnel": {
|
||||
// Http&客户端通讯端口
|
||||
"BasePort": 1270,
|
||||
|
||||
// 可选,绑定的根域名,
|
||||
// 客户端需配置SubDomain,实现 ${SubDomain}.${WebDomain}访问内网的站点,注意:需要通过域名访问网站时必选。
|
||||
"WebDomain": "test.cc",
|
||||
|
||||
// 可选,访问白名单,为空时:所有人有权限访问,不为空时:不在白名单的ip拒绝。
|
||||
"WebAllowAccessIps": [ "192.168.0.101" ],
|
||||
|
||||
// 可选,是否开启端口转发代理,禁用后不处理Forward类型端口转发.默认false。
|
||||
"EnableForward": true,
|
||||
|
||||
// 可选,当不为空时,客户端也必须携带Tokens中的任意一个token,否则拒绝登录。
|
||||
"Tokens": [ "TOKEN_FOR_CLIENT_AUTHENTICATION" ],
|
||||
|
||||
/**
|
||||
* 访问api接口的JWT配置
|
||||
*/
|
||||
"Api": {
|
||||
"JWT": {
|
||||
"ClockSkew": 10,
|
||||
"ValidAudience": "https://suidao.io",
|
||||
"ValidIssuer": "FastTunnel",
|
||||
"IssuerSigningKey": "This is IssuerSigningKey",
|
||||
"Expires": 120
|
||||
},
|
||||
"Accounts": [
|
||||
{
|
||||
"Name": "admin",
|
||||
"Password": "admin123"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ color 0e
|
|||
@echo ==================================
|
||||
@echo 提醒:请右键本文件,用管理员方式打开。
|
||||
@echo ==================================
|
||||
@echo Start Install FastTunnel.Server
|
||||
@echo Start Install ./../FastTunnel.Server
|
||||
|
||||
sc create FastTunnel.Server binPath=%~dp0\FastTunnel.Server.exe start= auto
|
||||
sc description FastTunnel.Server "FastTunnel-开源内网穿透服务,仓库地址:https://github.com/SpringHgui/FastTunnel star项目以支持作者"
|
||||
|
|
|
@ -4,7 +4,7 @@ color 0e
|
|||
@echo ==================================
|
||||
@echo 提醒:请右键本文件,用管理员方式打开。
|
||||
@echo ==================================
|
||||
@echo Start Remove FastTunnel.Server
|
||||
@echo Start Remove ./../FastTunnel.Server
|
||||
|
||||
Net stop FastTunnel.Server
|
||||
sc delete FastTunnel.Server
|
||||
|
|
Loading…
Reference in New Issue
Block a user