Browse Source

现在X撒大大

feature/MultiClientLog
root 1 month ago
parent
commit
d638969429
  1. 109
      LTEMvcApp/Controllers/IpGroupController.cs
  2. 31
      LTEMvcApp/Views/Home/Index.cshtml

109
LTEMvcApp/Controllers/IpGroupController.cs

@ -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;
}
}

31
LTEMvcApp/Views/Home/Index.cshtml

@ -196,14 +196,7 @@
<tr>
<td>@group.Ip</td>
<td>@group.Port</td>
<td>
<select class="form-control form-control-sm network-config-select"
data-ip="@group.Ip"
data-port="@group.Port"
onchange="updateGroupKey('@group.Ip', this.value)">
<option value="">加载中...</option>
</select>
</td>
<td>@group.Key</td>
<td class="apn-cell" data-ip="@group.Ip">
<!-- 异步加载 -->
</td>
@ -514,28 +507,6 @@
});
}
function updateGroupKey(ip, key) {
// 发送AJAX请求保存到服务器
$.ajax({
url: '/api/ipgroup/key',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({ ip: ip, key: key }),
success: function(response) {
console.log('IP组Key保存成功:', response);
// 可以显示一个小的成功提示
showToast('Key保存成功', 'success');
// 更新对应的apn、band、comment列
updateNetworkConfigDisplay(ip, key);
},
error: function(xhr) {
console.error('IP组Key保存失败:', xhr.responseText);
showToast('Key保存失败', 'error');
}
});
}
function updateNetworkConfigDisplay(ip, key) {
// 获取当前行的端口信息
var row = $('tr').filter(function() {

Loading…
Cancel
Save