diff --git a/CoreAgent.Domain/Helpers/LinuxWsResponseParser.cs b/CoreAgent.Domain/Helpers/LinuxWsResponseParser.cs new file mode 100644 index 0000000..a437b47 --- /dev/null +++ b/CoreAgent.Domain/Helpers/LinuxWsResponseParser.cs @@ -0,0 +1,69 @@ +using System.Text.RegularExpressions; + +namespace CoreAgent.Domain.Helpers; + +/// +/// Linux WebSocket响应日志解析器 +/// +public static class LinuxWsResponseParser +{ + private static readonly Regex _regexWs = new Regex(@"\{(?:[^{}]*|\{(?:[^{}]*|\{[^{}]*\})*\})*\}"); + + /// + /// 解析Linux WebSocket响应日志 + /// + /// 输入日志字符串 + /// 解析后的日志内容 + public static string ParseWsResultLogs(this string input) + { + try + { + return GetContentBetweenOuterCurlyBraces(input); + } + catch (Exception ex) + { + string msg = ex.Message; + return "Parse Logs Data Is null"; + } + } + + private static string GetContentBetweenOuterCurlyBraces(string input) + { + int openBraceIndex = input.IndexOf('{'); + if (openBraceIndex == -1) + { + return string.Empty; // 没有找到'{' + } + + int closeBraceIndex = FindMatchingCloseBrace(input, openBraceIndex); + if (closeBraceIndex == -1) + { + return string.Empty; // 没有找到匹配的'}' + } + + // 提取并返回内容 + return input.Substring(openBraceIndex, closeBraceIndex - openBraceIndex + 1); + } + + private static int FindMatchingCloseBrace(string input, int openBraceIndex) + { + int braceDepth = 1; // 从第一个'{'开始,深度为1 + for (int i = openBraceIndex + 1; i < input.Length; i++) + { + if (input[i] == '{') + { + braceDepth++; // 遇到'{',深度增加 + } + else if (input[i] == '}') + { + braceDepth--; // 遇到'}',深度减少 + if (braceDepth == 0) + { + return i; // 找到匹配的'}',返回其索引 + } + } + } + + return -1; // 没有找到匹配的'}' + } +} \ No newline at end of file diff --git a/CoreAgent.Domain/Models/System/AppSettings.cs b/CoreAgent.Domain/Models/System/AppSettings.cs index 86c9c54..43ac941 100644 --- a/CoreAgent.Domain/Models/System/AppSettings.cs +++ b/CoreAgent.Domain/Models/System/AppSettings.cs @@ -19,4 +19,9 @@ public class AppSettings /// MME配置目录路径 /// public string MmeConfigDirectory { get; set; } = "/root/mme/config/"; + + /// + /// WebSocket JavaScript文件路径 + /// + public string WebSocketJsPath { get; set; } = "/root/enb/doc/ws.js"; } \ No newline at end of file diff --git a/CoreAgent.Infrastructure/Command/Executors/LinuxCommandExecutor.cs b/CoreAgent.Infrastructure/Command/Executors/LinuxCommandExecutor.cs index 4939a23..5dc9b30 100644 --- a/CoreAgent.Infrastructure/Command/Executors/LinuxCommandExecutor.cs +++ b/CoreAgent.Infrastructure/Command/Executors/LinuxCommandExecutor.cs @@ -91,12 +91,8 @@ public class LinuxCommandExecutor : BaseCommandExecutor throw new ArgumentException("命令不能为空", nameof(command)); } - // 使用双引号包裹整个命令,只对必要的特殊字符进行转义 - var escapedCommand = command - .Replace("\"", "\\\"") - .Replace("`", "\\`") - .Replace("\\", "\\\\"); - + // 使用双引号包裹整个命令,只对双引号进行转义 + var escapedCommand = command.Replace("\"", "\\\""); return $"-c \"{escapedCommand}\""; } } \ No newline at end of file