From f5eb8bcbe5afb36b17fa68ba45624bd0f6e291e6 Mon Sep 17 00:00:00 2001 From: ASemenchuk <59782501+Botinoc@users.noreply.github.com> Date: Tue, 26 Jul 2022 08:55:17 +0300 Subject: [PATCH 1/2] Cisco: fix bug with RefObjectName --- CiscoMigration/CiscoCommands.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CiscoMigration/CiscoCommands.cs b/CiscoMigration/CiscoCommands.cs index ee900ea..8834f2d 100644 --- a/CiscoMigration/CiscoCommands.cs +++ b/CiscoMigration/CiscoCommands.cs @@ -1846,6 +1846,7 @@ public override void Parse(CiscoCommand command, CiscoCommand prevCommand, Dicti } } + public class Cisco_AccessList : CiscoCommand { public enum ActionType { NA, Deny, Permit }; @@ -1907,6 +1908,9 @@ public SourceDest(List words) : this() if (words.Count > 1) { RefObjectName = words[1]; + var NameValidityRegex = @"[^A-Za-z0-9_.-]"; + RefObjectName = Validators.ChangeNameAccordingToRules(RefObjectName); + Regex.Replace(RefObjectName, NameValidityRegex, "_"); WordsCount = 2; } break; @@ -1916,6 +1920,9 @@ public SourceDest(List words) : this() if (words.Count > 1) { RefObjectName = InterfacePrefix + words[1]; + var NameValidityRegex = @"[^A-Za-z0-9_.-]"; + RefObjectName = Validators.ChangeNameAccordingToRules(RefObjectName); + Regex.Replace(RefObjectName, NameValidityRegex, "_"); WordsCount = 2; } break; From 8dd88ca834fd66c686d42aa06c1d1ebcfce4f807 Mon Sep 17 00:00:00 2001 From: ASemenchuk <59782501+Botinoc@users.noreply.github.com> Date: Wed, 27 Jul 2022 14:19:49 +0300 Subject: [PATCH 2/2] Cisco: fix network bug with 255.255.255.255 --- CiscoMigration/CiscoParser.cs | 37 +++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/CiscoMigration/CiscoParser.cs b/CiscoMigration/CiscoParser.cs index 5795811..871e81a 100644 --- a/CiscoMigration/CiscoParser.cs +++ b/CiscoMigration/CiscoParser.cs @@ -136,23 +136,47 @@ protected override void ParseVersion(object versionProvider) } } } + private void chengeLines(List newLines, int index, string ip) + { + if ((newLines[index - 1][0] == ' ' && !newLines[index - 1].Contains("description")) || (newLines[index + 1][0] == ' ' && !newLines[index + 1].Contains("description"))) + { + newLines[index] = " network-object host " + ip; + int inserIndex = index; + while (newLines[inserIndex][0] == ' ') + { + inserIndex -= 1; + } + newLines.Insert(inserIndex, "object network " + ip); + newLines.Insert(inserIndex+1, " host " + ip); + } + } private void ParseCommands(string filename) { string[] lines = File.ReadAllLines(filename, Encoding.GetEncoding("us-ascii", new EncoderReplacementFallback(""), new DecoderReplacementFallback(""))); ParsedLines = lines.Count(); + var newLines = lines.ToList(); + + for (var i = 0; i < newLines.Count; i++) + { + if (newLines[i].Contains("255.255.255.255") && newLines[i].Contains("network-object")) + chengeLines(newLines, i, newLines[i].Split(' ')[2]); + } + lines = newLines.ToArray(); + var parents = new Stack(); var flatList = new List(); - parents.Push(new Indentation(null, 0)); int prevIndentationLevel = 0; int lineId = 0; - + foreach (string line in lines) { lineId++; + + // Check for an empty line or line with just spaces. if (line.Trim().Length == 0) @@ -195,6 +219,11 @@ private void ParseCommands(string filename) prevIndentationLevel = command.IndentationLevel; flatList.Add(FindCommand(command)); + + if (line.Contains("g-ext-dns-leg")) + { + var gd = 3; + } } _ciscoCommands = flatList.BuildTree(); @@ -204,6 +233,10 @@ private void ParseCommands(string filename) { ParseWithChildren(command, prevCommand); prevCommand = command; + if (command.Text.Contains("g-ext-dns-leg")) + { + var gd = 3; + } } // Remove duplicates