diff --git a/LTEMvcApp/Controllers/HomeController.cs b/LTEMvcApp/Controllers/HomeController.cs index edc352f..997e92a 100644 --- a/LTEMvcApp/Controllers/HomeController.cs +++ b/LTEMvcApp/Controllers/HomeController.cs @@ -10,11 +10,13 @@ public class HomeController : Controller { private readonly ILogger _logger; private readonly WebSocketManagerService _webSocketManager; + private readonly HttpClientService _httpClientService; - public HomeController(ILogger logger, WebSocketManagerService webSocketManager) + public HomeController(ILogger logger, WebSocketManagerService webSocketManager, HttpClientService httpClientService) { _logger = logger; _webSocketManager = webSocketManager; + _httpClientService = httpClientService; } public IActionResult Index() @@ -36,9 +38,37 @@ public class HomeController : Controller var ipGroups = ProcessIpGroups(allTestClients); ViewBag.IpGroups = ipGroups; + // 网络配置将通过JavaScript异步加载,不阻塞页面渲染 + ViewBag.NetworkConfigs = new List(); + return View(); } + /// + /// 获取网络配置 + /// + private async Task> GetNetworkConfigs(string ip, string port) + { + try + { + var apiUrl = $"http://{ip}:{port}/api/v1/NetworkConfig"; + var response = await _httpClientService.GetAsync(apiUrl); + + if (response.IsSuccess) + { + return response.Data; + } + + _logger.LogWarning("获取网络配置失败: {Response}", response); + return new List(); + } + catch (Exception ex) + { + _logger.LogError(ex, "获取网络配置异常: {Ip}:{Port}", ip, port); + return new List(); + } + } + /// /// 处理IP分组数据 /// @@ -255,4 +285,13 @@ public class HomeController : Controller { return View(); } + + public IActionResult NetworkConfig() + { + // 获取所有测试客户端配置和状态 + var allTestClients = _webSocketManager.GetAllTestClientsWithState(); + var ipGroups = ProcessIpGroups(allTestClients); + ViewBag.IpGroups = ipGroups; + return View(); + } } diff --git a/LTEMvcApp/Controllers/IpGroupController.cs b/LTEMvcApp/Controllers/IpGroupController.cs index 1bcacbd..260b592 100644 --- a/LTEMvcApp/Controllers/IpGroupController.cs +++ b/LTEMvcApp/Controllers/IpGroupController.cs @@ -161,6 +161,74 @@ namespace LTEMvcApp.Controllers return NotFound($"未找到IP地址为 {ip} 的Key配置"); } } + + /// + /// 获取网络配置列表 + /// + /// IP地址 + /// 端口 + /// 网络配置列表 + [HttpGet("network-config")] + public async Task GetNetworkConfigs([FromQuery] string ip, [FromQuery] string port) + { + try + { + var apiUrl = $"http://{ip}:{port}/api/v1/NetworkConfig"; + _logger.LogInformation("获取网络配置: {ApiUrl}", apiUrl); + + var response = await _httpClientService.GetAsync(apiUrl); + + _logger.LogInformation("网络配置获取成功"); + return Ok(response); + } + catch (Exception ex) + { + _logger.LogError(ex, "获取网络配置失败: {Ip}:{Port}", ip, port); + return BadRequest($"获取网络配置失败: {ex.Message}"); + } + } + + /// + /// 添加网络配置(转发) + /// + [HttpPost("network-config")] + public async Task AddNetworkConfig([FromQuery] string ip, [FromQuery] string port, [FromBody] object config) + { + if (string.IsNullOrEmpty(ip) || string.IsNullOrEmpty(port)) + return BadRequest("ip和port不能为空"); + try + { + var apiUrl = $"http://{ip}:{port}/api/v1/NetworkConfig"; + var response = await _httpClientService.PostJsonAsync(apiUrl, config); + return Content(response, "application/json"); + } + catch (Exception ex) + { + _logger.LogError(ex, "添加网络配置失败: {Ip}:{Port}", ip, port); + return BadRequest($"添加网络配置失败: {ex.Message}"); + } + } + + /// + /// 删除网络配置(转发) + /// + [HttpDelete("network-config/{configKey}")] + public async Task DeleteNetworkConfig(string configKey, [FromQuery] string ip, [FromQuery] string port) + { + if (string.IsNullOrEmpty(ip) || string.IsNullOrEmpty(port)) + return BadRequest("ip和port不能为空"); + try + { + var apiUrl = $"http://{ip}:{port}/api/v1/NetworkConfig/{configKey}"; + var response = await _httpClientService.DeleteAsync(apiUrl); + return Content(response, "application/json"); + } + catch (Exception ex) + { + _logger.LogError(ex, "删除网络配置失败: {Ip}:{Port}", ip, port); + return BadRequest($"删除网络配置失败: {ex.Message}"); + } + } } /// diff --git a/LTEMvcApp/Models/NetworkConfig.cs b/LTEMvcApp/Models/NetworkConfig.cs new file mode 100644 index 0000000..8dd48f5 --- /dev/null +++ b/LTEMvcApp/Models/NetworkConfig.cs @@ -0,0 +1,50 @@ +namespace LTEMvcApp.Models +{ + /// + /// 网络配置响应 + /// + public class NetworkConfigResponse + { + public List Data { get; set; } = new(); + public bool IsSuccess { get; set; } + public string Message { get; set; } = string.Empty; + public string ErrorCode { get; set; } = string.Empty; + public int StatusCode { get; set; } + } + + /// + /// 网络配置 + /// + public class NetworkConfig + { + /// + /// 配置键 + /// + public string ConfigKey { get; set; } = string.Empty; + + /// + /// RAN配置路径 + /// + public string RagConfig { get; set; } = string.Empty; + + /// + /// 核心或IMS配置 + /// + public List CoreOrImsConfigs { get; set; } = new(); + + /// + /// APN + /// + public string Apn { get; set; } = string.Empty; + + /// + /// 频段列表 + /// + public List Band { get; set; } = new(); + + /// + /// 注释 + /// + public string Comment { 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 92105e5..3901b3c 100644 --- a/LTEMvcApp/Views/Home/Index.cshtml +++ b/LTEMvcApp/Views/Home/Index.cshtml @@ -178,11 +178,14 @@ - - - + + + + + + - + @@ -194,10 +197,21 @@ + + + } @@ -333,8 +352,121 @@ + + + @section Scripts { } diff --git a/LTEMvcApp/Views/Home/NetworkConfig.cshtml b/LTEMvcApp/Views/Home/NetworkConfig.cshtml new file mode 100644 index 0000000..c773e09 --- /dev/null +++ b/LTEMvcApp/Views/Home/NetworkConfig.cshtml @@ -0,0 +1,160 @@ +@{ + ViewData["Title"] = "网络配置管理"; + var ip = Context.Request.Query["ip"].ToString(); + var port = Context.Request.Query["port"].ToString(); +} + +
+

网络配置管理 @ip:@port

+
+
+ +
+
+
+ +
+
+ + + + +@section Scripts { + +} \ No newline at end of file
AgentIPAgentPortKeyAgentIPAgentPortKeyapnbandcomment 状态操作操作
@group.Ip @group.Port - + + + + + + + @if (group.State == "运行") @@ -214,12 +228,17 @@ } - - 启动网络 - - - 停止网络 - +