diff --git a/LTEMvcApp/Controllers/IpGroupController.cs b/LTEMvcApp/Controllers/IpGroupController.cs index 260b592..e4cd03a 100644 --- a/LTEMvcApp/Controllers/IpGroupController.cs +++ b/LTEMvcApp/Controllers/IpGroupController.cs @@ -14,9 +14,6 @@ namespace LTEMvcApp.Controllers { private readonly HttpClientService _httpClientService; private readonly ILogger _logger; - - // 存储IP组的Key配置 - private static readonly Dictionary _ipGroupKeys = new(); public IpGroupController(HttpClientService httpClientService, ILogger logger) { @@ -24,23 +21,6 @@ namespace LTEMvcApp.Controllers _logger = logger; } - /// - /// 保存IP组Key配置 - /// - /// IP组Key请求 - /// 操作结果 - [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保存成功" }); - } - /// /// 启动IP组网络 /// @@ -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 } } - /// - /// 获取IP组Key配置 - /// - /// IP地址 - /// Key配置 - [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 }); - } - - /// - /// 获取所有IP组Key配置 - /// - /// 所有IP组Key配置 - [HttpGet("keys")] - public ActionResult GetAllIpGroupKeys() - { - return Ok(_ipGroupKeys); - } - - /// - /// 删除IP组Key配置 - /// - /// IP地址 - /// 操作结果 - [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配置"); - } - } - /// /// 获取网络配置列表 /// @@ -231,22 +156,6 @@ namespace LTEMvcApp.Controllers } } - /// - /// IP组Key请求 - /// - public class IpGroupKeyRequest - { - /// - /// IP地址 - /// - public string Ip { get; set; } = string.Empty; - - /// - /// Key值 - /// - public string? Key { get; set; } - } - /// /// 启动IP组请求 /// @@ -261,6 +170,11 @@ namespace LTEMvcApp.Controllers /// 端口 /// public string Port { get; set; } = string.Empty; + + /// + /// Key值 + /// + public string Key { get; set; } = string.Empty; } /// @@ -277,5 +191,10 @@ namespace LTEMvcApp.Controllers /// 端口 /// public string Port { get; set; } = string.Empty; + + /// + /// Key值 + /// + public string Key { get; set; } = string.Empty; } } \ No newline at end of file diff --git a/LTEMvcApp/Views/Home/Index.cshtml b/LTEMvcApp/Views/Home/Index.cshtml index 3901b3c..72acea5 100644 --- a/LTEMvcApp/Views/Home/Index.cshtml +++ b/LTEMvcApp/Views/Home/Index.cshtml @@ -196,14 +196,7 @@ @group.Ip @group.Port - - - + @group.Key @@ -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() {