mirror of
https://github.com/FastTunnel/FastTunnel.git
synced 2025-02-08 02:39:29 +08:00
api
This commit is contained in:
parent
0ea598a134
commit
236c5d78ed
17
FastTunnel.Api/Controllers/BaseController.cs
Normal file
17
FastTunnel.Api/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.Api.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class BaseController : ControllerBase
|
||||
{
|
||||
protected ApiResponse ApiResponse = new ApiResponse();
|
||||
}
|
||||
}
|
77
FastTunnel.Api/Controllers/SystemController.cs
Normal file
77
FastTunnel.Api/Controllers/SystemController.cs
Normal file
|
@ -0,0 +1,77 @@
|
|||
using FastTunnel.Core.Client;
|
||||
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.Api.Controllers
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
16
FastTunnel.Api/FastTunnel.Api.csproj
Normal file
16
FastTunnel.Api/FastTunnel.Api.csproj
Normal file
|
@ -0,0 +1,16 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FastTunnel.Core\FastTunnel.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
25
FastTunnel.Api/Models/ApiResponse.cs
Normal file
25
FastTunnel.Api/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,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user