|
|
@ -14,9 +14,6 @@ namespace LTEMvcApp.Controllers |
|
|
|
{ |
|
|
|
private readonly HttpClientService _httpClientService; |
|
|
|
private readonly ILogger<IpGroupController> _logger; |
|
|
|
|
|
|
|
// 存储IP组的Key配置
|
|
|
|
private static readonly Dictionary<string, string> _ipGroupKeys = new(); |
|
|
|
|
|
|
|
public IpGroupController(HttpClientService httpClientService, ILogger<IpGroupController> logger) |
|
|
|
{ |
|
|
@ -24,23 +21,6 @@ namespace LTEMvcApp.Controllers |
|
|
|
_logger = logger; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 保存IP组Key配置
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request">IP组Key请求</param>
|
|
|
|
/// <returns>操作结果</returns>
|
|
|
|
[HttpPost("key")] |
|
|
|
public ActionResult SaveIpGroupKey([FromBody] IpGroupKeyRequest request) |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(request.Ip)) |
|
|
|
return BadRequest("IP地址不能为空"); |
|
|
|
|
|
|
|
_ipGroupKeys[request.Ip] = request.Key ?? string.Empty; |
|
|
|
_logger.LogInformation("保存IP组Key: {Ip} -> {Key}", request.Ip, request.Key); |
|
|
|
|
|
|
|
return Ok(new { message = "IP组Key保存成功" }); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 启动IP组网络
|
|
|
|
/// </summary>
|
|
|
@ -55,16 +35,12 @@ namespace LTEMvcApp.Controllers |
|
|
|
if (string.IsNullOrEmpty(request.Port)) |
|
|
|
return BadRequest("端口不能为空"); |
|
|
|
|
|
|
|
// 检查Key是否已配置
|
|
|
|
if (!_ipGroupKeys.TryGetValue(request.Ip, out var key) || string.IsNullOrEmpty(key)) |
|
|
|
return BadRequest("请先配置网络Key"); |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
var apiUrl = $"http://{request.Ip}:{request.Port}/api/v1/CellularNetwork/start"; |
|
|
|
var command = new StartCellularNetworkCommand { Key = key }; |
|
|
|
var command = new StartCellularNetworkCommand { Key = request.Key }; |
|
|
|
|
|
|
|
_logger.LogInformation("启动IP组网络: {Ip}:{Port}, Key: {Key}", request.Ip, request.Port, key); |
|
|
|
_logger.LogInformation("启动IP组网络: {Ip}:{Port}, Key: {Key}", request.Ip, request.Port, request.Key); |
|
|
|
|
|
|
|
var response = await _httpClientService.PostJsonAsync(apiUrl, command); |
|
|
|
|
|
|
@ -92,16 +68,12 @@ namespace LTEMvcApp.Controllers |
|
|
|
if (string.IsNullOrEmpty(request.Port)) |
|
|
|
return BadRequest("端口不能为空"); |
|
|
|
|
|
|
|
// 检查Key是否已配置
|
|
|
|
if (!_ipGroupKeys.TryGetValue(request.Ip, out var key) || string.IsNullOrEmpty(key)) |
|
|
|
return BadRequest("请先配置网络Key"); |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
var apiUrl = $"http://{request.Ip}:{request.Port}/api/v1/CellularNetwork/stop"; |
|
|
|
var command = new StopCellularNetworkCommand { Key = key }; |
|
|
|
var command = new StopCellularNetworkCommand { Key = request.Key }; |
|
|
|
|
|
|
|
_logger.LogInformation("停止IP组网络: {Ip}:{Port}, Key: {Key}", request.Ip, request.Port, key); |
|
|
|
_logger.LogInformation("停止IP组网络: {Ip}:{Port}, Key: {Key}", request.Ip, request.Port, request.Key); |
|
|
|
|
|
|
|
var response = await _httpClientService.PostJsonAsync(apiUrl, command); |
|
|
|
|
|
|
@ -115,53 +87,6 @@ namespace LTEMvcApp.Controllers |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取IP组Key配置
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="ip">IP地址</param>
|
|
|
|
/// <returns>Key配置</returns>
|
|
|
|
[HttpGet("key/{ip}")] |
|
|
|
public ActionResult GetIpGroupKey(string ip) |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(ip)) |
|
|
|
return BadRequest("IP地址不能为空"); |
|
|
|
|
|
|
|
var key = _ipGroupKeys.TryGetValue(ip, out var value) ? value : string.Empty; |
|
|
|
return Ok(new { ip, key }); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取所有IP组Key配置
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>所有IP组Key配置</returns>
|
|
|
|
[HttpGet("keys")] |
|
|
|
public ActionResult GetAllIpGroupKeys() |
|
|
|
{ |
|
|
|
return Ok(_ipGroupKeys); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 删除IP组Key配置
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="ip">IP地址</param>
|
|
|
|
/// <returns>操作结果</returns>
|
|
|
|
[HttpDelete("key/{ip}")] |
|
|
|
public ActionResult DeleteIpGroupKey(string ip) |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(ip)) |
|
|
|
return BadRequest("IP地址不能为空"); |
|
|
|
|
|
|
|
if (_ipGroupKeys.Remove(ip)) |
|
|
|
{ |
|
|
|
_logger.LogInformation("删除IP组Key: {Ip}", ip); |
|
|
|
return Ok(new { message = "IP组Key删除成功" }); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
return NotFound($"未找到IP地址为 {ip} 的Key配置"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取网络配置列表
|
|
|
|
/// </summary>
|
|
|
@ -231,22 +156,6 @@ namespace LTEMvcApp.Controllers |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// IP组Key请求
|
|
|
|
/// </summary>
|
|
|
|
public class IpGroupKeyRequest |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// IP地址
|
|
|
|
/// </summary>
|
|
|
|
public string Ip { get; set; } = string.Empty; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Key值
|
|
|
|
/// </summary>
|
|
|
|
public string? Key { get; set; } |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 启动IP组请求
|
|
|
|
/// </summary>
|
|
|
@ -261,6 +170,11 @@ namespace LTEMvcApp.Controllers |
|
|
|
/// 端口
|
|
|
|
/// </summary>
|
|
|
|
public string Port { get; set; } = string.Empty; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Key值
|
|
|
|
/// </summary>
|
|
|
|
public string Key { get; set; } = string.Empty; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
@ -277,5 +191,10 @@ namespace LTEMvcApp.Controllers |
|
|
|
/// 端口
|
|
|
|
/// </summary>
|
|
|
|
public string Port { get; set; } = string.Empty; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Key值
|
|
|
|
/// </summary>
|
|
|
|
public string Key { get; set; } = string.Empty; |
|
|
|
} |
|
|
|
} |