mirror of
https://github.com/FastTunnel/FastTunnel.git
synced 2025-02-08 02:39:29 +08:00
增加几个接口
This commit is contained in:
parent
5de80de148
commit
2a3a7323eb
17
FastTunnel.Server/Controllers/BaseController.cs
Normal file
17
FastTunnel.Server/Controllers/BaseController.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using FastTunnel.Server.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FastTunnel.Server.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class BaseController : ControllerBase
|
||||
{
|
||||
protected ApiResponse ApiResponse = new ApiResponse();
|
||||
}
|
||||
}
|
78
FastTunnel.Server/Controllers/SystemController.cs
Normal file
78
FastTunnel.Server/Controllers/SystemController.cs
Normal file
|
@ -0,0 +1,78 @@
|
|||
using FastTunnel.Core.Client;
|
||||
using FastTunnel.Server.Controllers;
|
||||
using FastTunnel.Server.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FastTunnel.Server
|
||||
{
|
||||
public class SystemController : BaseController
|
||||
{
|
||||
FastTunnelServer fastTunnelServer;
|
||||
|
||||
public SystemController(FastTunnelServer fastTunnelServer)
|
||||
{
|
||||
this.fastTunnelServer = fastTunnelServer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前等待响应的请求数
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public ApiResponse GetResponseTempCount()
|
||||
{
|
||||
ApiResponse.data = fastTunnelServer.ResponseTasks.Count;
|
||||
return ApiResponse;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前映射的所有站点信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public ApiResponse GetAllWebList()
|
||||
{
|
||||
ApiResponse.data = fastTunnelServer.WebList.Select(x => new { x.Key, x.Value.WebConfig.LocalIp, x.Value.WebConfig.LocalPort });
|
||||
return ApiResponse;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取服务端配置信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public ApiResponse GetServerOption()
|
||||
{
|
||||
ApiResponse.data = fastTunnelServer.ServerOption;
|
||||
return ApiResponse;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有端口转发映射列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public ApiResponse GetAllForwardList()
|
||||
{
|
||||
ApiResponse.data = fastTunnelServer.ForwardList.Select(x => new { x.Key, x.Value.SSHConfig.LocalIp, x.Value.SSHConfig.LocalPort, x.Value.SSHConfig.RemotePort });
|
||||
|
||||
return ApiResponse;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前客户端在线数量
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public ApiResponse GetOnlineClientCount()
|
||||
{
|
||||
ApiResponse.data = fastTunnelServer.ConnectedClientCount;
|
||||
return ApiResponse;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,6 +12,8 @@
|
|||
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0-preview.4.21253.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="6.0.0-preview.4.21253.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="5.0.3" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.1.5" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.1.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
25
FastTunnel.Server/Models/ApiResponse.cs
Normal file
25
FastTunnel.Server/Models/ApiResponse.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FastTunnel.Server.Models
|
||||
{
|
||||
public class ApiResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 错误码
|
||||
/// 0 成功,其他为失败
|
||||
/// </summary>
|
||||
public ErrorCodeEnum errorCode { get; set; }
|
||||
|
||||
public string errorMessage { get; set; }
|
||||
|
||||
public object data { get; set; }
|
||||
}
|
||||
|
||||
public enum ErrorCodeEnum
|
||||
{
|
||||
NONE = 0,
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Hosting;
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace FastTunnel.Server
|
||||
{
|
||||
|
@ -19,6 +20,12 @@ namespace FastTunnel.Server
|
|||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddControllers();
|
||||
services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v2", new OpenApiInfo { Title = "FastTunel.Api", Version = "v2" });
|
||||
});
|
||||
|
||||
// -------------------FastTunnel START------------------
|
||||
services.AddFastTunnelServer(Configuration.GetSection("ServerSettings"));
|
||||
// -------------------FastTunnel END--------------------
|
||||
|
@ -29,6 +36,9 @@ namespace FastTunnel.Server
|
|||
{
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v2/swagger.json", "FastTunel.WebApi v2"));
|
||||
}
|
||||
|
||||
// -------------------FastTunnel START------------------
|
||||
|
@ -40,7 +50,7 @@ namespace FastTunnel.Server
|
|||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapReverseProxy();
|
||||
//endpoints.MapControllers();
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user