Skip to content

Commit f6eb426

Browse files
authored
Merge pull request #63 from Botinoc/dev
(Fortinet) Fixes errors with config parsing
2 parents c99a5cd + 4bde0ed commit f6eb426

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

FortinetMigration/FortiGateParser.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Newtonsoft.Json;
44
using MigrationBase;
55
using System.Text;
6+
using System.Text.RegularExpressions;
67

78
namespace FortiGateMigration
89
{
@@ -19,16 +20,30 @@ public FortiGateParser()
1920
{
2021
_fgCommandsList = new List<FgCommand>();
2122
}
22-
23+
2324
#region Override Methods
2425

2526
protected override void ParseVersion(object versionProvider)
2627
{
2728
string versionLine = versionProvider.ToString();
2829

29-
int indVersionDash = versionLine.IndexOf("-", "#config-version=".Length) + 1; //add 1 because we need to cut w/o colon
30+
Regex regex = new Regex(@"[0-9][.][0-9]");
31+
32+
MatchCollection matches = regex.Matches(versionLine);
33+
34+
if (matches.Count > 0)
35+
{
36+
int indVersionDash = versionLine.IndexOf(matches[0].Value, "#config-version=".Length);
3037

31-
VendorVersion = versionLine.Substring(indVersionDash, versionLine.IndexOf(":") - indVersionDash);
38+
VendorVersion = versionLine.Substring(indVersionDash, versionLine.IndexOf(":") - indVersionDash);
39+
}
40+
else
41+
{
42+
43+
int indVersionDash = versionLine.IndexOf("-", "#config-version=".Length) + 1; //add 1 because we need to cut w/o colon
44+
45+
VendorVersion = versionLine.Substring(indVersionDash, versionLine.IndexOf(":") - indVersionDash);
46+
}
3247
}
3348

3449
public override void Parse(string filename)
@@ -87,6 +102,11 @@ private void ParseCommands(string filename)
87102
commandName = line;
88103
}
89104

105+
if (commandName == "end\"")
106+
{
107+
commandName = "end";
108+
};
109+
90110
FgCommandExt fgCommandExtT = null;
91111

92112
switch (commandName)

0 commit comments

Comments
 (0)