mirror of
https://github.com/FastTunnel/FastTunnel.git
synced 2025-02-08 02:39:29 +08:00
Merge branch 'v2' into ui
# Conflicts: # FastTunnel.Server/Startup.cs
This commit is contained in:
commit
842346e46d
|
@ -39,8 +39,8 @@ namespace FastTunnel.Api.Controllers
|
|||
{
|
||||
if ((serverOptionsMonitor.CurrentValue?.Api?.Accounts?.Length ?? 0) == 0)
|
||||
{
|
||||
ApiResponse.errorCode = ErrorCodeEnum.NoAccount;
|
||||
ApiResponse.errorMessage = "账号或密码错误";
|
||||
ApiResponse.Success = false;
|
||||
ApiResponse.Message = "账号或密码错误";
|
||||
return ApiResponse;
|
||||
}
|
||||
|
||||
|
@ -51,8 +51,8 @@ namespace FastTunnel.Api.Controllers
|
|||
|
||||
if (account == null)
|
||||
{
|
||||
ApiResponse.errorCode = ErrorCodeEnum.NoAccount;
|
||||
ApiResponse.errorMessage = "账号或密码错误";
|
||||
ApiResponse.Success = false;
|
||||
ApiResponse.Message = "账号或密码错误";
|
||||
return ApiResponse;
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ namespace FastTunnel.Api.Controllers
|
|||
new Claim("Name", account.Name)
|
||||
};
|
||||
|
||||
ApiResponse.data = GenerateToken(
|
||||
ApiResponse.Data = GenerateToken(
|
||||
claims,
|
||||
serverOptionsMonitor.CurrentValue.Api.JWT.IssuerSigningKey,
|
||||
serverOptionsMonitor.CurrentValue.Api.JWT.Expires,
|
||||
|
|
|
@ -31,7 +31,7 @@ public class SystemController : BaseController
|
|||
[HttpGet]
|
||||
public ApiResponse GetResponseTempList()
|
||||
{
|
||||
ApiResponse.data = new
|
||||
ApiResponse.Data = new
|
||||
{
|
||||
Count = fastTunnelServer.ResponseTasks.Count,
|
||||
Rows = fastTunnelServer.ResponseTasks.Select(x => new
|
||||
|
@ -50,7 +50,7 @@ public class SystemController : BaseController
|
|||
[HttpGet]
|
||||
public ApiResponse GetAllWebList()
|
||||
{
|
||||
ApiResponse.data = new
|
||||
ApiResponse.Data = new
|
||||
{
|
||||
Count = fastTunnelServer.WebList.Count,
|
||||
Rows = fastTunnelServer.WebList.Select(x => new { x.Key, x.Value.WebConfig.LocalIp, x.Value.WebConfig.LocalPort })
|
||||
|
@ -66,7 +66,7 @@ public class SystemController : BaseController
|
|||
[HttpGet]
|
||||
public ApiResponse GetServerOption()
|
||||
{
|
||||
ApiResponse.data = fastTunnelServer.ServerOption;
|
||||
ApiResponse.Data = fastTunnelServer.ServerOption;
|
||||
return ApiResponse;
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class SystemController : BaseController
|
|||
[HttpGet]
|
||||
public ApiResponse GetAllForwardList()
|
||||
{
|
||||
ApiResponse.data = new
|
||||
ApiResponse.Data = new
|
||||
{
|
||||
Count = fastTunnelServer.ForwardList.Count,
|
||||
Rows = fastTunnelServer.ForwardList.Select(x => new { x.Key, x.Value.SSHConfig.LocalIp, x.Value.SSHConfig.LocalPort, x.Value.SSHConfig.RemotePort })
|
||||
|
@ -94,7 +94,7 @@ public class SystemController : BaseController
|
|||
[HttpGet]
|
||||
public ApiResponse GetOnlineClientCount()
|
||||
{
|
||||
ApiResponse.data = fastTunnelServer.ConnectedClientCount;
|
||||
ApiResponse.Data = fastTunnelServer.ConnectedClientCount;
|
||||
return ApiResponse;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,9 +25,9 @@ namespace FastTunnel.Api.Filters
|
|||
_logger.LogError(context.Exception, "【全局异常捕获】");
|
||||
var res = new ApiResponse()
|
||||
{
|
||||
errorCode = ErrorCodeEnum.Exception,
|
||||
data = null,
|
||||
errorMessage = context.Exception.Message,
|
||||
Success = false,
|
||||
Data = null,
|
||||
Message = context.Exception.Message,
|
||||
};
|
||||
|
||||
var result = new JsonResult(res) { StatusCode = 200 };
|
||||
|
|
|
@ -12,21 +12,12 @@ namespace FastTunnel.Server.Models
|
|||
/// 错误码
|
||||
/// 0 成功,其他为失败
|
||||
/// </summary>
|
||||
public ErrorCodeEnum errorCode { get; set; }
|
||||
public bool Success { get; set; }
|
||||
|
||||
public string errorMessage { get; set; }
|
||||
public string Message { get; set; }
|
||||
|
||||
public object data { get; set; }
|
||||
}
|
||||
public string Code { get; set; }
|
||||
|
||||
public enum ErrorCodeEnum
|
||||
{
|
||||
NONE = 0,
|
||||
|
||||
AuthError = 1,
|
||||
|
||||
Exception = 2,
|
||||
|
||||
NoAccount = 3,
|
||||
public object Data { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
"FastTunnel": {
|
||||
"Server": {
|
||||
// [必选] 服务端ip/域名(来自服务端配置文件的urls参数)
|
||||
"ServerAddr": "127.0.0.1",
|
||||
"ServerAddr": "suidao.bx.com.cn",
|
||||
// [必选] 服务端监听的通信端口(来自服务端配置文件的urls参数)
|
||||
"ServerPort": 1270
|
||||
},
|
||||
|
|
|
@ -67,8 +67,9 @@ public class FastTunnelClient : IFastTunnelClient
|
|||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex.Message);
|
||||
await Task.Delay(TimeSpan.FromSeconds(10), cancellationToken);
|
||||
}
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(10), cancellationToken);
|
||||
}
|
||||
|
||||
_logger.LogInformation("===== FastTunnel Client End =====");
|
||||
|
|
|
@ -71,7 +71,6 @@ public class TunnelClient
|
|||
await utility.ProcessLinesAsync(cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
private async void ProcessLine(ReadOnlySequence<byte> line, CancellationToken cancellationToken)
|
||||
{
|
||||
var cmd = Encoding.UTF8.GetString(line);
|
||||
|
@ -100,6 +99,7 @@ public class TunnelClient
|
|||
{
|
||||
try
|
||||
{
|
||||
fastTunnelServer.ForwardList.TryRemove(item.SSHConfig.RemotePort, out _);
|
||||
item.Listener.Stop();
|
||||
}
|
||||
catch { }
|
||||
|
|
84
FastTunnel.Server/Startup.cs
Normal file
84
FastTunnel.Server/Startup.cs
Normal file
|
@ -0,0 +1,84 @@
|
|||
// 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 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.Hosting;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System;
|
||||
using FastTunnel.Core.Config;
|
||||
using System.Text;
|
||||
using FastTunnel.Api.Filters;
|
||||
|
||||
#if DEBUG
|
||||
using Microsoft.OpenApi.Models;
|
||||
#endif
|
||||
|
||||
namespace FastTunnel.Server;
|
||||
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddAuthorization();
|
||||
|
||||
services.AddControllers();
|
||||
|
||||
#if DEBUG
|
||||
services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v2", new OpenApiInfo { Title = "FastTunel.Api", Version = "v2" });
|
||||
});
|
||||
#endif
|
||||
// -------------------FastTunnel STEP1 OF 3------------------
|
||||
services.AddFastTunnelServer(Configuration.GetSection("FastTunnel"));
|
||||
// -------------------FastTunnel STEP1 END-------------------
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
#if DEBUG
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v2/swagger.json", "FastTunel.WebApi v2"));
|
||||
#endif
|
||||
}
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
// -------------------FastTunnel STEP2 OF 3------------------
|
||||
app.UseFastTunnelServer();
|
||||
// -------------------FastTunnel STEP2 END-------------------
|
||||
|
||||
// app.UseStaticFiles();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
// -------------------FastTunnel STEP3 OF 3------------------
|
||||
endpoints.MapFastTunnelServer();
|
||||
// -------------------FastTunnel STEP3 END-------------------
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user