From b4690aae6b9f4573fe6048dcb68abc867c59e6b5 Mon Sep 17 00:00:00 2001
From: AnastasiaIBA <67756010+AnastasiaIBA@users.noreply.github.com>
Date: Fri, 3 Jul 2020 00:03:42 +0300
Subject: [PATCH 01/12] cherry-pick commit
baaedb1e48f3f26da0494b08b5cff943b063cc57 from the repo chkp-yaelg/SmartMove
---
SmartMove/CommandLine.cs | 48 ++++++++++++++++++++--------------------
1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/SmartMove/CommandLine.cs b/SmartMove/CommandLine.cs
index 725ea214..1c51e945 100644
--- a/SmartMove/CommandLine.cs
+++ b/SmartMove/CommandLine.cs
@@ -132,30 +132,30 @@ public int CheckOptionsValidity(CommandLine commandLine)
return 0;
}
if (!fullVendorsList.Contains(commandLine.Vendor))
- {
- Console.WriteLine("Specified vendor \"" + commandLine.Vendor + "\" is not available.", MessageTypes.Error);
+ {
+ Console.WriteLine("Specified vendor \"" + commandLine.Vendor + "\" is not available.", MessageTypes.Error);
Console.WriteLine("Available options are: CiscoASA, JuniperSRX, JuniperSSG, FortiNet, PaloAlto, Panorama", MessageTypes.Error);
- Console.WriteLine("For command help run \"SmartMove.exe -help\"", MessageTypes.Error);
- return 0;
- }
+ Console.WriteLine("For command help run \"SmartMove.exe -help\"", MessageTypes.Error);
+ return 0;
+ }
if (vendorsList1.Contains(commandLine.Vendor))
- {
+ {
if (commandLine.ConvertUserConfiguration == true)
- {
- Console.WriteLine("Option -u is not valid for vendor " + commandLine.Vendor + "!");
- Console.WriteLine("For command help run \"SmartMove.exe -help\"", MessageTypes.Error);
+ {
+ Console.WriteLine("Option -u is not valid for vendor " + commandLine.Vendor + "!");
+ Console.WriteLine("For command help run \"SmartMove.exe -help\"", MessageTypes.Error);
return 0;
}
-
+
if (commandLine.DontImportUnusedObjects == true)
- {
- Console.WriteLine("Option -i is not valid for vendor " + commandLine.Vendor + "!");
- Console.WriteLine("For command help run \"SmartMove.exe -help\"", MessageTypes.Error);
+ {
+ Console.WriteLine("Option -i is not valid for vendor " + commandLine.Vendor + "!");
+ Console.WriteLine("For command help run \"SmartMove.exe -help\"", MessageTypes.Error);
return 0;
- }
-
- }
- if (vendorsList2.Contains(commandLine.Vendor))
+ }
+
+ }
+ if (vendorsList2.Contains(commandLine.Vendor))
{
if (commandLine.ConvertUserConfiguration == true && commandLine.LdapAccountUnit == null)
{
@@ -163,7 +163,7 @@ public int CheckOptionsValidity(CommandLine commandLine)
Console.WriteLine("For command help run \"SmartMove.exe -help\"", MessageTypes.Error);
return 0;
}
-
+
}
if ((commandLine.vendor == "JuniperSRX" || commandLine.vendor == "PaloAlto") && !commandLine.configFileName.EndsWith(".xml"))
{
@@ -308,7 +308,7 @@ public CommandLine Parse(string[] args)
public void DoMigration(CommandLine commandLine)
{
- string fileName = Path.GetFileNameWithoutExtension(commandLine.ConfigFileName);
+ string fileName = Path.GetFileNameWithoutExtension(commandLine.ConfigFileName);
//Console.WriteLine("File name: " + fileName);
if (string.IsNullOrEmpty(commandLine.ConfigFileName) || string.IsNullOrEmpty(fileName))
@@ -373,7 +373,7 @@ public void DoMigration(CommandLine commandLine)
}
else
{
- vendorParser.Parse(ciscoFile);
+ vendorParser.Parse(ciscoFile);
}
}
catch (Exception ex)
@@ -485,12 +485,12 @@ public void DoMigration(CommandLine commandLine)
fgConverter.LDAPAccoutUnit = ldapAccountUnit;
vendorConverter = fgConverter;
break;
- case "PaloAlto":
+ case "PaloAlto":
PaloAltoConverter paConverter = new PaloAltoConverter();
paConverter.OptimizeConf = commandLine.DontImportUnusedObjects;
paConverter.ConvertUserConf = commandLine.ConvertUserConfiguration;
paConverter.LDAPAccoutUnit = ldapAccountUnit;
- vendorConverter = paConverter;
+ vendorConverter = paConverter;
break;
case "Panorama":
PanoramaConverter panoramaConverter = new PanoramaConverter();
@@ -513,7 +513,7 @@ public void DoMigration(CommandLine commandLine)
}
catch (Exception ex)
{
-
+
if (ex is InvalidDataException && ex.Message != null && ex.Message.Contains("Policy exceeds the maximum number"))
{
Console.WriteLine(String.Format("{1}{0}{2}{0}{3}", Environment.NewLine, "SmartMove is unable to convert the provided policy.",
@@ -522,7 +522,7 @@ public void DoMigration(CommandLine commandLine)
}
else
{
- Console.WriteLine(string.Format("Could not convert configuration file.\n\nMessage: {0}\nModule:\t{1}\nClass:\t{2}\nMethod:\t{3}", ex.Message, ex.Source, ex.TargetSite.ReflectedType.Name, ex.TargetSite.Name), MessageTypes.Error);
+ Console.WriteLine(string.Format("Could not convert configuration file.\n\nMessage: {0}\nModule:\t{1}\nClass:\t{2}\nMethod:\t{3}", ex.Message, ex.Source, ex.TargetSite.ReflectedType.Name, ex.TargetSite.Name), MessageTypes.Error);
}
return;
}
From ca520934ed4aa917cd028f3cff231fe21dd452b2 Mon Sep 17 00:00:00 2001
From: AnastasiaIBA <67756010+AnastasiaIBA@users.noreply.github.com>
Date: Thu, 2 Jul 2020 23:58:04 +0300
Subject: [PATCH 02/12] cherry-pick the commit
f5910e37c0a5f321cc04660fabf98dee00a034a4 from fork chkp-yaelg/SmartMove
---
SmartMove/MainWindow.xaml.cs | 8 ++++++++
SmartMove/SmartMove.csproj | 5 ++++-
SmartMove/packages.config | 4 ++++
3 files changed, 16 insertions(+), 1 deletion(-)
create mode 100644 SmartMove/packages.config
diff --git a/SmartMove/MainWindow.xaml.cs b/SmartMove/MainWindow.xaml.cs
index 95a741ca..595623ca 100644
--- a/SmartMove/MainWindow.xaml.cs
+++ b/SmartMove/MainWindow.xaml.cs
@@ -514,10 +514,12 @@ private async void Go_OnClick(object sender, RoutedEventArgs e)
if (string.IsNullOrEmpty(vendorParser.Version))
{
ShowMessage("Unspecified ASA version.\nCannot find ASA version for the selected configuration.\nThe configuration may not parse correctly.", MessageTypes.Warning);
+ return;
}
else if (vendorParser.MajorVersion < 8 || (vendorParser.MajorVersion == 8 && vendorParser.MinorVersion < 3))
{
ShowMessage("Unsupported ASA version (" + vendorParser.Version + ").\nThis tool supports ASA 8.3 and above configuration files.\nThe configuration may not parse correctly.", MessageTypes.Warning);
+ return;
}
break;
@@ -525,10 +527,12 @@ private async void Go_OnClick(object sender, RoutedEventArgs e)
if (string.IsNullOrEmpty(vendorParser.Version))
{
ShowMessage("Unspecified SRX version.\nCannot find SRX version for the selected configuration.\nThe configuration may not parse correctly.", MessageTypes.Warning);
+ return;
}
else if (vendorParser.MajorVersion < 12 || (vendorParser.MajorVersion == 12 && vendorParser.MinorVersion < 1))
{
ShowMessage("Unsupported SRX version (" + vendorParser.Version + ").\nThis tool supports SRX 12.1 and above configuration files.\nThe configuration may not parse correctly.", MessageTypes.Warning);
+ return;
}
break;
@@ -539,20 +543,24 @@ private async void Go_OnClick(object sender, RoutedEventArgs e)
if (string.IsNullOrEmpty(vendorParser.Version))
{
ShowMessage("Unspecified FortiGate version.\nCannot find FortiGate version for the selected configuration.\nThe configuration may not parse correctly.", MessageTypes.Warning);
+ return;
}
else if(vendorParser.MajorVersion < 5)
{
ShowMessage("Unsupported FortiGate version (" + vendorParser.Version + ").\nThis tool supports FortiGate 5.x and above configuration files.\nThe configuration may not parse correctly.", MessageTypes.Warning);
+ return;
}
break;
case Vendor.PaloAlto:
if (string.IsNullOrEmpty(vendorParser.Version))
{
ShowMessage("Unspecified PaloAlto version.\nCannot find PaloAlto PAN-OS version for the selected configuration.\nThe configuration may not parse correctly.", MessageTypes.Warning);
+ return;
}
else if (vendorParser.MajorVersion < 7)
{
ShowMessage("Unsupported PaloAlto version (" + vendorParser.Version + ").\nThis tool supports PaloAlto PAN-OS 7.x and above configuration files.\nThe configuration may not parse correctly.", MessageTypes.Warning);
+ return;
}
break;
case Vendor.PaloAltoPanorama:
diff --git a/SmartMove/SmartMove.csproj b/SmartMove/SmartMove.csproj
index 8f88ad71..6d509ed2 100644
--- a/SmartMove/SmartMove.csproj
+++ b/SmartMove/SmartMove.csproj
@@ -68,7 +68,9 @@
-
+
+ ..\packages\System.Windows.Interactivity.WPF.2.0.20525\lib\net40\System.Windows.Interactivity.dll
+
@@ -145,6 +147,7 @@
ResXFileCodeGenerator
Resources.Designer.cs
+
SettingsSingleFileGenerator
Settings.Designer.cs
diff --git a/SmartMove/packages.config b/SmartMove/packages.config
new file mode 100644
index 00000000..1f01b947
--- /dev/null
+++ b/SmartMove/packages.config
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
From 8f94dd64e65e1143fc60608e1f15d17abf9ee191 Mon Sep 17 00:00:00 2001
From: EnotRoma
Date: Tue, 8 Jun 2021 14:38:30 +0300
Subject: [PATCH 03/12] add duplicates for flags to console for source, target,
vendor, nat, domain, ldap
---
SmartMove/CommandLine.cs | 38 +++++++++++++++++++++++---------------
SmartMove/SmartMove.csproj | 6 ------
2 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/SmartMove/CommandLine.cs b/SmartMove/CommandLine.cs
index 1c51e945..667ce8ee 100644
--- a/SmartMove/CommandLine.cs
+++ b/SmartMove/CommandLine.cs
@@ -94,15 +94,15 @@ public int DisplayHelp()
{
Console.WriteLine("SmartMove command usage:");
Console.WriteLine();
- Console.WriteLine("SmartMove.exe [–f config_file_name] [-v vendor] [-t target_folder] [-d domain] [-n] [-u LDAP_Account_unit] [-i]");
+ Console.WriteLine("SmartMove.exe [–s config_file_name] [-v vendor] [-t target_folder] [-d domain] [-n] [-l LDAP_Account_unit] [-i]");
Console.WriteLine();
Console.WriteLine("Options:");
- Console.WriteLine("\t" + "-f" + "\t" + "full path to vendor configuration file");
- Console.WriteLine("\t" + "-v" + "\t" + "vendor for conversion (available options: CiscoASA, JuniperSRX, JuniperSSG, FortiNet, PaloAlto, Panorama)");
- Console.WriteLine("\t" + "-t" + "\t" + "migration output folder");
- Console.WriteLine("\t" + "-d" + "\t" + "domain name (for CiscoASA, JuniperSRX, JuniperSSG only)");
- Console.WriteLine("\t" + "-n" + "\t" + "convert NAT configuration");
- Console.WriteLine("\t" + "-u" + "\t" + "LDAP Account unit for convert user configuration option (for FortiNet, PaloAlto and Panorama only)");
+ Console.WriteLine("\t" + "-s | --source" + "\t" + "full path to vendor configuration file");
+ Console.WriteLine("\t" + "-v | --vendor" + "\t" + "vendor for conversion (available options: CiscoASA, JuniperSRX, JuniperSSG, FortiNet, PaloAlto, Panorama)");
+ Console.WriteLine("\t" + "-t | --target" + "\t" + "migration output folder");
+ Console.WriteLine("\t" + "-d | --domain" + "\t" + "domain name (for CiscoASA, JuniperSRX, JuniperSSG only)");
+ Console.WriteLine("\t" + "-n | --nat" + "\t" + "convert NAT configuration");
+ Console.WriteLine("\t" + "-l | --ldap" + "\t" + "LDAP Account unit for convert user configuration option (for FortiNet, PaloAlto and Panorama only)");
Console.WriteLine("\t" + "-i" + "\t" + "do not import unused objects (for FortiNet, PaloAlto and Panorama only)");
Console.WriteLine();
Console.WriteLine("Example:");
@@ -122,20 +122,20 @@ public int CheckOptionsValidity(CommandLine commandLine)
if (String.IsNullOrEmpty(commandLine.Vendor))
{
Console.WriteLine("Option -v is mandatory but not specified.", MessageTypes.Error);
- Console.WriteLine("For command help run \"SmartMove.exe -help\"", MessageTypes.Error);
+ Console.WriteLine("For command help run \"SmartMove.exe -h or --help\"", MessageTypes.Error);
return 0;
}
if (String.IsNullOrEmpty(commandLine.ConfigFileName))
{
Console.WriteLine("Option -f is mandatory but not specified.", MessageTypes.Error);
- Console.WriteLine("For command help run \"SmartMove.exe -help\"", MessageTypes.Error);
+ Console.WriteLine("For command help run \"SmartMove.exe -h or --help\"", MessageTypes.Error);
return 0;
}
if (!fullVendorsList.Contains(commandLine.Vendor))
{
Console.WriteLine("Specified vendor \"" + commandLine.Vendor + "\" is not available.", MessageTypes.Error);
Console.WriteLine("Available options are: CiscoASA, JuniperSRX, JuniperSSG, FortiNet, PaloAlto, Panorama", MessageTypes.Error);
- Console.WriteLine("For command help run \"SmartMove.exe -help\"", MessageTypes.Error);
+ Console.WriteLine("For command help run \"SmartMove.exe -h or --help\"", MessageTypes.Error);
return 0;
}
if (vendorsList1.Contains(commandLine.Vendor))
@@ -143,14 +143,14 @@ public int CheckOptionsValidity(CommandLine commandLine)
if (commandLine.ConvertUserConfiguration == true)
{
Console.WriteLine("Option -u is not valid for vendor " + commandLine.Vendor + "!");
- Console.WriteLine("For command help run \"SmartMove.exe -help\"", MessageTypes.Error);
+ Console.WriteLine("For command help run \"SmartMove.exe -h or --help\"", MessageTypes.Error);
return 0;
}
if (commandLine.DontImportUnusedObjects == true)
{
Console.WriteLine("Option -i is not valid for vendor " + commandLine.Vendor + "!");
- Console.WriteLine("For command help run \"SmartMove.exe -help\"", MessageTypes.Error);
+ Console.WriteLine("For command help run \"SmartMove.exe -h or --help\"", MessageTypes.Error);
return 0;
}
@@ -160,7 +160,7 @@ public int CheckOptionsValidity(CommandLine commandLine)
if (commandLine.ConvertUserConfiguration == true && commandLine.LdapAccountUnit == null)
{
Console.WriteLine("Value for option -u is not specified!");
- Console.WriteLine("For command help run \"SmartMove.exe -help\"", MessageTypes.Error);
+ Console.WriteLine("For command help run \"SmartMove.exe -h or --help\"", MessageTypes.Error);
return 0;
}
@@ -221,11 +221,14 @@ public string[] regenerateArgs(string commandLineString)
*/
public CommandLine Parse(string[] args)
{
+ //set default values
+
for (int i = 0; i < args.Length; i++)
{
switch (args[i])
{
- case "-f":
+ case "-s":
+ case "--source":
{
if (args[i] != args.Last() && !args[i + 1].StartsWith("-"))
{
@@ -249,6 +252,7 @@ public CommandLine Parse(string[] args)
break;
}
case "-v":
+ case "--vendor":
{
if (args[i] != args.Last() && !args[i + 1].StartsWith("-"))
this.vendor = args[i + 1];
@@ -257,6 +261,7 @@ public CommandLine Parse(string[] args)
break;
}
case "-t":
+ case "--target":
{
if (args[i] != args.Last() && !args[i + 1].StartsWith("-"))
this.targetFolder = args[i + 1];
@@ -265,6 +270,7 @@ public CommandLine Parse(string[] args)
break;
}
case "-d":
+ case "--domain":
{
if (args[i] != args.Last() && !args[i + 1].StartsWith("-"))
this.domain = args[i + 1];
@@ -273,11 +279,13 @@ public CommandLine Parse(string[] args)
break;
}
case "-n":
+ case "--nat":
{
this.convertNat = true;
break;
}
- case "-u":
+ case "-l":
+ case "--ldap":
{
if (args[i] != args.Last() && !args[i + 1].StartsWith("-"))
{
diff --git a/SmartMove/SmartMove.csproj b/SmartMove/SmartMove.csproj
index 6d509ed2..5c2b3e1f 100644
--- a/SmartMove/SmartMove.csproj
+++ b/SmartMove/SmartMove.csproj
@@ -59,12 +59,6 @@
..\packages\System.Windows.Interactivity.WPF.2.0.20525\lib\net40\Microsoft.Expression.Interactions.dll
-
- ..\packages\Microsoft.Xaml.Behaviors.Wpf.1.1.19\lib\net45\Microsoft.Xaml.Behaviors.dll
-
-
- ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll
-
From d4c77b1e6daadcebdf3b9d46573b3d91d57c1538 Mon Sep 17 00:00:00 2001
From: EnotRoma
Date: Tue, 8 Jun 2021 14:38:52 +0300
Subject: [PATCH 04/12] decorations for Command line (fix 5 spaces)
---
SmartMove/CommandLine.cs | 149 ++++++++++++++++++++-------------------
1 file changed, 75 insertions(+), 74 deletions(-)
diff --git a/SmartMove/CommandLine.cs b/SmartMove/CommandLine.cs
index 667ce8ee..4f2adb03 100644
--- a/SmartMove/CommandLine.cs
+++ b/SmartMove/CommandLine.cs
@@ -18,7 +18,7 @@ namespace SmartMove
/// Represents command line logic
///
class CommandLine
- {
+ {
private string[] arguments { get; set; }
public CommandLine(string[] args)
@@ -34,7 +34,7 @@ public string ConfigFileName
get { return configFileName; }
set { configFileName = value; }
}
-
+
//–v CiscoASA
private string vendor { get; set; }
public string Vendor
@@ -50,7 +50,7 @@ public string TargetFolder
get { return targetFolder; }
set { targetFolder = value; }
}
-
+
//-d domain
private string domain { get; set; }
public string Domain
@@ -132,30 +132,30 @@ public int CheckOptionsValidity(CommandLine commandLine)
return 0;
}
if (!fullVendorsList.Contains(commandLine.Vendor))
- {
- Console.WriteLine("Specified vendor \"" + commandLine.Vendor + "\" is not available.", MessageTypes.Error);
+ {
+ Console.WriteLine("Specified vendor \"" + commandLine.Vendor + "\" is not available.", MessageTypes.Error);
Console.WriteLine("Available options are: CiscoASA, JuniperSRX, JuniperSSG, FortiNet, PaloAlto, Panorama", MessageTypes.Error);
- Console.WriteLine("For command help run \"SmartMove.exe -h or --help\"", MessageTypes.Error);
- return 0;
- }
+ Console.WriteLine("For command help run \"SmartMove.exe -h or --help\"", MessageTypes.Error);
+ return 0;
+ }
if (vendorsList1.Contains(commandLine.Vendor))
- {
+ {
if (commandLine.ConvertUserConfiguration == true)
- {
- Console.WriteLine("Option -u is not valid for vendor " + commandLine.Vendor + "!");
- Console.WriteLine("For command help run \"SmartMove.exe -h or --help\"", MessageTypes.Error);
+ {
+ Console.WriteLine("Option -u is not valid for vendor " + commandLine.Vendor + "!");
+ Console.WriteLine("For command help run \"SmartMove.exe -h or --help\"", MessageTypes.Error);
return 0;
}
-
+
if (commandLine.DontImportUnusedObjects == true)
- {
- Console.WriteLine("Option -i is not valid for vendor " + commandLine.Vendor + "!");
- Console.WriteLine("For command help run \"SmartMove.exe -h or --help\"", MessageTypes.Error);
+ {
+ Console.WriteLine("Option -i is not valid for vendor " + commandLine.Vendor + "!");
+ Console.WriteLine("For command help run \"SmartMove.exe -h or --help\"", MessageTypes.Error);
return 0;
- }
-
- }
- if (vendorsList2.Contains(commandLine.Vendor))
+ }
+
+ }
+ if (vendorsList2.Contains(commandLine.Vendor))
{
if (commandLine.ConvertUserConfiguration == true && commandLine.LdapAccountUnit == null)
{
@@ -163,7 +163,7 @@ public int CheckOptionsValidity(CommandLine commandLine)
Console.WriteLine("For command help run \"SmartMove.exe -h or --help\"", MessageTypes.Error);
return 0;
}
-
+
}
if ((commandLine.vendor == "JuniperSRX" || commandLine.vendor == "PaloAlto") && !commandLine.configFileName.EndsWith(".xml"))
{
@@ -189,7 +189,7 @@ public int CheckOptionsValidity(CommandLine commandLine)
public string[] regenerateArgs(string commandLineString)
{
String[] args = null;
-
+
var parts = Regex.Matches(commandLineString, @"[\""].+?[\""]|[^ ]+")
.Cast()
.Select(m => m.Value)
@@ -197,7 +197,7 @@ public string[] regenerateArgs(string commandLineString)
parts.RemoveAt(0);
string buf;
- List finalArgs = new List ();
+ List finalArgs = new List();
foreach (var item in parts)
{
if (item.StartsWith("\"") && item.EndsWith("\""))
@@ -209,10 +209,10 @@ public string[] regenerateArgs(string commandLineString)
{
finalArgs.Add(item);
}
-
+
}
- args = finalArgs.ToArray();
-
+ args = finalArgs.ToArray();
+
return args;
}
@@ -220,34 +220,34 @@ public string[] regenerateArgs(string commandLineString)
* Parses input options and writes its values to ComamndLine class fields
*/
public CommandLine Parse(string[] args)
- {
- //set default values
+ {
- for (int i = 0; i < args.Length; i++)
- {
+ for (int i = 0; i < args.Length; i++)
+ {
switch (args[i])
{
case "-s":
case "--source":
{
if (args[i] != args.Last() && !args[i + 1].StartsWith("-"))
- {
+ {
if (args[i + 1].IndexOf("\\") != -1)
- {
+ {
this.ConfigFileName = args[i + 1];
}
else
{
this.configFileName = Directory.GetCurrentDirectory() + "\\" + args[i + 1];
-
+
}
//set default velue of target folder to cofig file directory
this.TargetFolder = this.ConfigFileName.Substring(0, this.ConfigFileName.LastIndexOf("\\"));
-
- } else
+
+ }
+ else
{
Console.WriteLine("Value for mandatory option -f is not specified! ", MessageTypes.Error);
- }
+ }
break;
}
@@ -256,15 +256,15 @@ public CommandLine Parse(string[] args)
{
if (args[i] != args.Last() && !args[i + 1].StartsWith("-"))
this.vendor = args[i + 1];
- else
- Console.WriteLine("Value for mandatory option -v is not specified! ", MessageTypes.Error);
+ else
+ Console.WriteLine("Value for mandatory option -v is not specified! ", MessageTypes.Error);
break;
}
case "-t":
case "--target":
{
if (args[i] != args.Last() && !args[i + 1].StartsWith("-"))
- this.targetFolder = args[i + 1];
+ this.targetFolder = args[i + 1];
else
Console.WriteLine("Value for target folder option -t is not specified. Default value will be set!", MessageTypes.Error);
break;
@@ -291,22 +291,23 @@ public CommandLine Parse(string[] args)
{
this.ldapAccountUnit = args[i + 1];
this.ConvertUserConfiguration = true;
- } else
+ }
+ else
{
this.ConvertUserConfiguration = true;
//Console.WriteLine("Value for option -u is not specified! ", MessageTypes.Error);
}
-
+
break;
}
case "-i":
{
this.dontImportUnusedObjects = true;
break;
- }
- }
- }
- return this;
+ }
+ }
+ }
+ return this;
}
/*
@@ -315,13 +316,13 @@ public CommandLine Parse(string[] args)
*/
public void DoMigration(CommandLine commandLine)
{
-
- string fileName = Path.GetFileNameWithoutExtension(commandLine.ConfigFileName);
+
+ string fileName = Path.GetFileNameWithoutExtension(commandLine.ConfigFileName);
//Console.WriteLine("File name: " + fileName);
- if (string.IsNullOrEmpty(commandLine.ConfigFileName) || string.IsNullOrEmpty(fileName))
+ if (string.IsNullOrEmpty(commandLine.ConfigFileName) || string.IsNullOrEmpty(fileName))
{
- Console.WriteLine("Configuration file is not selected.", MessageTypes.Error);
+ Console.WriteLine("Configuration file is not selected.", MessageTypes.Error);
return;
}
@@ -336,7 +337,7 @@ public void DoMigration(CommandLine commandLine)
Console.WriteLine("Configuration file name is restricted to 20 characters at most.", MessageTypes.Error);
return;
}
-
+
if (!Directory.Exists(commandLine.TargetFolder))
{
Console.WriteLine("Cannot find target folder for conversion output.", MessageTypes.Error);
@@ -345,9 +346,9 @@ public void DoMigration(CommandLine commandLine)
VendorParser vendorParser;
- switch (commandLine.Vendor)
+ switch (commandLine.Vendor)
{
- case "CiscoASA":
+ case "CiscoASA":
vendorParser = new CiscoParser();
break;
case "JuniperSRX":
@@ -359,8 +360,8 @@ public void DoMigration(CommandLine commandLine)
case "FortiNet":
vendorParser = new FortiGateParser();
break;
- case "PaloAlto":
- vendorParser = new PaloAltoParser();
+ case "PaloAlto":
+ vendorParser = new PaloAltoParser();
break;
case "Panorama":
vendorParser = new PanoramaParser();
@@ -370,10 +371,10 @@ public void DoMigration(CommandLine commandLine)
}
try
- {
+ {
string ciscoFile = commandLine.ConfigFileName;
Console.WriteLine("Parsing configuration file...");
-
+
if (commandLine.Vendor.Equals("Panorama"))
{
PanoramaParser panParser = (PanoramaParser)vendorParser;
@@ -381,11 +382,11 @@ public void DoMigration(CommandLine commandLine)
}
else
{
- vendorParser.Parse(ciscoFile);
+ vendorParser.Parse(ciscoFile);
}
}
catch (Exception ex)
- {
+ {
Console.WriteLine(string.Format("Could not parse configuration file.\n\nMessage: {0}\nModule:\t{1}\nClass:\t{2}\nMethod:\t{3}", ex.Message, ex.Source, ex.TargetSite.ReflectedType.Name, ex.TargetSite.Name), MessageTypes.Error);
return;
}
@@ -461,23 +462,23 @@ public void DoMigration(CommandLine commandLine)
}
#endregion
- string vendorFileName = Path.GetFileNameWithoutExtension(commandLine.ConfigFileName);
+ string vendorFileName = Path.GetFileNameWithoutExtension(commandLine.ConfigFileName);
string toolVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
-
- string targetFolder = commandLine.TargetFolder + "\\";
+
+ string targetFolder = commandLine.TargetFolder + "\\";
bool convertNat = commandLine.ConvertNat;
-
+
string ldapAccountUnit = commandLine.LdapAccountUnit;
-
+
vendorParser.Export(targetFolder + vendorFileName + ".json");
VendorConverter vendorConverter;
switch (commandLine.Vendor)
{
- case "CiscoASA":
+ case "CiscoASA":
vendorConverter = new CiscoConverter();
break;
case "JuniperSRX":
@@ -493,7 +494,7 @@ public void DoMigration(CommandLine commandLine)
fgConverter.LDAPAccoutUnit = ldapAccountUnit;
vendorConverter = fgConverter;
break;
- case "PaloAlto":
+ case "PaloAlto":
PaloAltoConverter paConverter = new PaloAltoConverter();
paConverter.OptimizeConf = commandLine.DontImportUnusedObjects;
paConverter.ConvertUserConf = commandLine.ConvertUserConfiguration;
@@ -512,7 +513,7 @@ public void DoMigration(CommandLine commandLine)
}
vendorConverter.Initialize(vendorParser, commandLine.ConfigFileName, toolVersion, targetFolder, commandLine.Domain);
-
+
try
{
Console.WriteLine("Conversion is in progress...");
@@ -521,7 +522,7 @@ public void DoMigration(CommandLine commandLine)
}
catch (Exception ex)
{
-
+
if (ex is InvalidDataException && ex.Message != null && ex.Message.Contains("Policy exceeds the maximum number"))
{
Console.WriteLine(String.Format("{1}{0}{2}{0}{3}", Environment.NewLine, "SmartMove is unable to convert the provided policy.",
@@ -530,17 +531,17 @@ public void DoMigration(CommandLine commandLine)
}
else
{
- Console.WriteLine(string.Format("Could not convert configuration file.\n\nMessage: {0}\nModule:\t{1}\nClass:\t{2}\nMethod:\t{3}", ex.Message, ex.Source, ex.TargetSite.ReflectedType.Name, ex.TargetSite.Name), MessageTypes.Error);
+ Console.WriteLine(string.Format("Could not convert configuration file.\n\nMessage: {0}\nModule:\t{1}\nClass:\t{2}\nMethod:\t{3}", ex.Message, ex.Source, ex.TargetSite.ReflectedType.Name, ex.TargetSite.Name), MessageTypes.Error);
}
return;
- }
-
- vendorConverter.ExportConfigurationAsHtml();
- vendorConverter.ExportPolicyPackagesAsHtml();
+ }
+
+ vendorConverter.ExportConfigurationAsHtml();
+ vendorConverter.ExportPolicyPackagesAsHtml();
if (commandLine.ConvertNat)
{
- vendorConverter.ExportNatLayerAsHtml();
- }
+ vendorConverter.ExportNatLayerAsHtml();
+ }
}
}
}
From 0583f8479ac589bcec2b8f34439d6dc7fb0c5bee Mon Sep 17 00:00:00 2001
From: EnotRoma
Date: Fri, 11 Jun 2021 12:10:44 +0300
Subject: [PATCH 05/12] * changed help page for console * added results of
conversion to the console * from the console ldap flag now by default is
empty string for disabling null reference exception during parsing (by the
example of UI code)
---
CiscoMigration/CiscoConverter.cs | 14 +-
FortinetMigration/FortiGateConverter.cs | 53 +++++---
JuniperMigration/JuniperConverter.cs | 11 +-
MigrationBase/VendorConverter.cs | 6 +-
NetScreenMigration/ScreenOSConverter.cs | 22 +++-
PaloAltoMigration/PaloAltoConverter.cs | 11 +-
PaloAltoMigration/PanoramaConverter.cs | 11 +-
SmartMove/CommandLine.cs | 167 +++++++++++++++++++-----
SmartMove/MainWindow.xaml.cs | 3 +-
SmartMove/Program.cs | 2 +-
10 files changed, 227 insertions(+), 73 deletions(-)
diff --git a/CiscoMigration/CiscoConverter.cs b/CiscoMigration/CiscoConverter.cs
index 00b23789..d1e22518 100644
--- a/CiscoMigration/CiscoConverter.cs
+++ b/CiscoMigration/CiscoConverter.cs
@@ -522,6 +522,7 @@ private static void GetServicePortRanges(string servicePort, out int from, out i
private IList _ciscoSshCommands;
private Cisco_Hostname _ciscoHostnameCommand;
private List _ciscoGlobalAclCommands = new List();
+ private string _outputFormat;
private List _cpPreorderedNatRules = new List();
@@ -4522,10 +4523,7 @@ private bool IsFirewallRuleMatchedByNATRule(CheckPoint_Zone parentLayerRuleZone,
return true;
}
- if (fwRule.Service.Count == 0)
- {
- // TODO: ???
- }
+ if (fwRule.Service.Count == 0) {}
else if (fwRule.Service.Count == 1 && fwRule.Service[0].Name == CheckPointObject.Any)
{
// There is only one service in FW rule and it is "any", no matter what NAT rule service is...
@@ -4683,18 +4681,19 @@ private string BuildInspectedRuleLinkTag(string ciscoClassMapName)
#region Public Methods
- public override void Initialize(VendorParser vendorParser, string vendorFilePath, string toolVersion, string targetFolder, string domainName)
+ public override void Initialize(VendorParser vendorParser, string vendorFilePath, string toolVersion, string targetFolder, string domainName, string outputFormat = "json")
{
_ciscoParser = (CiscoParser)vendorParser;
if (_ciscoParser == null)
{
throw new InvalidDataException("Unexpected!!!");
}
+ this._outputFormat = outputFormat;
- base.Initialize(vendorParser, vendorFilePath, toolVersion, targetFolder, domainName);
+ base.Initialize(vendorParser, vendorFilePath, toolVersion, targetFolder, domainName, outputFormat);
}
- public override void Convert(bool convertNat)
+ public override Dictionary Convert(bool convertNat)
{
RaiseConversionProgress(20, "Converting obects ...");
_cpObjects.Initialize(); // must be first!!!
@@ -4748,6 +4747,7 @@ public override void Convert(bool convertNat)
ConversionIncidentsCommandsCount = _conversionIncidents.GroupBy(error => error.LineNumber).Count();
CreateSmartConnector();
+ return new Dictionary() { { "warnings", ConversionIncidentCategoriesCount } };
}
public override int RulesInConvertedPackage()
diff --git a/FortinetMigration/FortiGateConverter.cs b/FortinetMigration/FortiGateConverter.cs
index 83de468f..53323429 100644
--- a/FortinetMigration/FortiGateConverter.cs
+++ b/FortinetMigration/FortiGateConverter.cs
@@ -19,6 +19,7 @@ public class FortiGateConverter : VendorConverter
public bool OptimizeConf { get; set; } //check if Optimized configuration is requested
public bool ConvertUserConf { get; set; } //check if User converion is requested
public string LDAPAccoutUnit { get; set; } //read LDAP Account Unit Name for gethering users
+ public string OutputFormat { get; set; } //json or text format for output file
#endregion
@@ -31,7 +32,7 @@ public class FortiGateConverter : VendorConverter
private List _errorsList = new List(); //storing conversion errors for config or each VDOM
private List _warningsList = new List(); //storing conversion warnings for config or each VDOM
- private Dictionary> _localMapperFgCp = new Dictionary>(); //storing map of FG names to CheckPoint objects
+ private Dictionary> _localMapperFgCp = new Dictionary>(); //storing map of FG names to CheckPoint objects
private Dictionary> _interfacesMapperFgCp = new Dictionary>(); //storing information about interfaces
@@ -83,14 +84,15 @@ public class FortiGateConverter : VendorConverter
#endregion
//Initialization method... stupid method because you must to initialize CheckPoint Objects Store in convert. (from Cisco converter)
- public override void Initialize(VendorParser vendorParser, string vendorFilePath, string toolVersion, string targetFolder, string domainName)
+ public override void Initialize(VendorParser vendorParser, string vendorFilePath, string toolVersion, string targetFolder, string domainName, string outputFormat = "json")
{
_fortiGateParser = (FortiGateParser)vendorParser;
if (_fortiGateParser == null)
{
throw new InvalidDataException("Unexpected!!!");
}
- base.Initialize(vendorParser, vendorFilePath, toolVersion, targetFolder, domainName);
+ OutputFormat = outputFormat;
+ base.Initialize(vendorParser, vendorFilePath, toolVersion, targetFolder, domainName, outputFormat);
}
protected override bool AddCheckPointObject(CheckPointObject cpObject)
@@ -477,7 +479,7 @@ public string BuildInspectedRuleInfo(string fortiClassMapName)
public void CreateCatalogObjects()
{
string filename = this.ObjectsHtmlFile;
-
+
using (var file = new StreamWriter(filename, false))
{
file.WriteLine("");
@@ -624,10 +626,11 @@ public void CreateCatalogWarnings()
}
//report about Errors
- public void CreateErrorsHtml(string vDomName)
+ public void CreateErrorsReport(string vDomName)
{
if (_errorsList.Count > 0)
{
+ // if (OutputFormat == "text") {
string filename = _targetFolder + "//" + vDomName + "_errors.html";
using (var file = new StreamWriter(filename, false))
@@ -653,11 +656,27 @@ public void CreateErrorsHtml(string vDomName)
file.WriteLine("");
file.WriteLine("