Ejemplo n.º 1
0
        private async void Go_OnClick(object sender, RoutedEventArgs e)
        {
            string fileName = Path.GetFileNameWithoutExtension(ConfigFilePath.Text);

            if (string.IsNullOrEmpty(ConfigFilePath.Text) || string.IsNullOrEmpty(fileName))
            {
                ShowMessage("Configuration file is not selected.", MessageTypes.Error);
                return;
            }

            if (!File.Exists(ConfigFilePath.Text))
            {
                ShowMessage("Cannot find configuration file.", MessageTypes.Error);
                return;
            }

            if (fileName.Length > 20)
            {
                ShowMessage("Configuration file name is restricted to 20 characters at most.", MessageTypes.Error);
                return;
            }

            if (!Directory.Exists(TargetFolderPath.Text))
            {
                ShowMessage("Cannot find target folder for conversion output.", MessageTypes.Error);
                return;
            }

            if (ConvertUserConfiguration)
            {
                if (LDAPAccountUnit.Text.Trim().Equals("") || LDAPAccountUnit.Text.Trim().Contains(" "))
                {
                    ShowMessage("LDAP Account Unit field cannot be empty or containt space(s).", MessageTypes.Error);
                    return;
                }
            }

            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
            EnableDisableControls(false);
            ProgressPanel.Visibility = Visibility.Visible;
            ResultsPanel.Visibility  = Visibility.Collapsed;
            OutputPanel.Visibility   = Visibility.Visible;

            UpdateProgress(10, "Parsing configuration file ...");

            VendorParser vendorParser;

            switch (_supportedVendors.SelectedVendor)
            {
            case Vendor.CiscoASA:
                vendorParser = new CiscoParser();
                break;

            case Vendor.JuniperJunosOS:
                vendorParser = new JuniperParser();
                break;

            case Vendor.JuniperScreenOS:
                vendorParser = new ScreenOSParser();
                break;

            case Vendor.FortiGate:
                vendorParser = new FortiGateParser();
                break;

            case Vendor.PaloAlto:
                vendorParser = new PaloAltoParser();
                break;

            default:
                throw new InvalidDataException("Unexpected!!!");
            }

            try
            {
                string ciscoFile = ConfigFilePath.Text;
                await Task.Run(() => vendorParser.Parse(ciscoFile));
            }
            catch (Exception ex)
            {
                Mouse.OverrideCursor = null;
                EnableDisableControls(true);
                OutputPanel.Visibility = Visibility.Collapsed;
                ShowMessage(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;
            }

            switch (_supportedVendors.SelectedVendor)
            {
            case Vendor.CiscoASA:
                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);
                }
                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);
                }
                break;

            case Vendor.JuniperJunosOS:
                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);
                }
                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);
                }
                break;

            case Vendor.JuniperScreenOS:
                break;

            case Vendor.FortiGate:
                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);
                }
                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);
                }
                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);
                }
                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);
                }
                break;
            }

            string vendorFileName  = Path.GetFileNameWithoutExtension(ConfigFilePath.Text);
            string toolVersion     = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            string targetFolder    = TargetFolderPath.Text + "\\";
            bool   convertNat      = ConvertNATConfiguration;
            string ldapAccountUnit = LDAPAccountUnit.Text.Trim();

            vendorParser.Export(targetFolder + vendorFileName + ".json");

            VendorConverter vendorConverter;

            switch (_supportedVendors.SelectedVendor)
            {
            case Vendor.CiscoASA:
                vendorConverter = new CiscoConverter();
                break;

            case Vendor.JuniperJunosOS:
                vendorConverter = new JuniperConverter();
                break;

            case Vendor.JuniperScreenOS:
                vendorConverter = new ScreenOSConverter();
                break;

            case Vendor.FortiGate:
                FortiGateConverter fgConverter = new FortiGateConverter();
                fgConverter.OptimizeConf    = SkipUnusedObjectsConversion;
                fgConverter.ConvertUserConf = ConvertUserConfiguration;
                fgConverter.LDAPAccoutUnit  = ldapAccountUnit.Trim();
                vendorConverter             = fgConverter;
                break;

            case Vendor.PaloAlto:
                PaloAltoConverter paConverter = new PaloAltoConverter();
                paConverter.OptimizeConf    = SkipUnusedObjectsConversion;
                paConverter.ConvertUserConf = ConvertUserConfiguration;
                paConverter.LDAPAccoutUnit  = ldapAccountUnit.Trim();
                vendorConverter             = paConverter;
                break;

            default:
                throw new InvalidDataException("Unexpected!!!");
            }

            vendorConverter.Initialize(vendorParser, ConfigFilePath.Text, toolVersion, targetFolder, DomainName.Text);
            vendorConverter.ConversionProgress += OnConversionProgress;

            try
            {
                await Task.Run(() => vendorConverter.Convert(convertNat));
            }
            catch (Exception ex)
            {
                Mouse.OverrideCursor = null;
                EnableDisableControls(true);
                OutputPanel.Visibility = Visibility.Collapsed;
                ShowMessage(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;
            }

            UpdateProgress(90, "Exporting Check Point configuration ...");
            vendorConverter.ExportConfigurationAsHtml();
            vendorConverter.ExportPolicyPackagesAsHtml();
            if (ConvertNATConfiguration)
            {
                ConvertedNatPolicyLink.MouseUp -= Link_OnClick;
                vendorConverter.ExportNatLayerAsHtml();

                //check if the user asked for NAT policy and no rules found.
                if (vendorConverter.RulesInNatLayer() == 0)  // anly if 0 then we do not show NAT report.
                {
                    ConvertedNatPolicyLink.Style = (Style)ConvertedNatPolicyLink.FindResource("NormalTextBloclStyle");
                }
                else // otherwise it is single NAT report or Catalog for NAT reports (value = -1)
                {
                    ConvertedNatPolicyLink.Style    = (Style)ConvertedNatPolicyLink.FindResource("HyperLinkStyle");
                    ConvertedNatPolicyLink.MouseUp += Link_OnClick;
                }
            }
            UpdateProgress(100, "");

            vendorConverter.ConversionProgress -= OnConversionProgress;

            Mouse.OverrideCursor = null;
            EnableDisableControls(true);
            ProgressPanel.Visibility = Visibility.Collapsed;
            ResultsPanel.Visibility  = Visibility.Visible;

            ShowResults(vendorConverter, vendorParser.ParsedLines);
        }
Ejemplo n.º 2
0
        private async void Go_OnClick(object sender, RoutedEventArgs e)
        {
            string fileName = Path.GetFileNameWithoutExtension(ConfigFilePath.Text);

            if (string.IsNullOrEmpty(ConfigFilePath.Text) || string.IsNullOrEmpty(fileName))
            {
                ShowMessage("Configuration file is not selected.", MessageTypes.Error);
                return;
            }

            if (!File.Exists(ConfigFilePath.Text))
            {
                ShowMessage("Cannot find configuration file.", MessageTypes.Error);
                return;
            }

            if (fileName.Length > 20)
            {
                ShowMessage("Configuration file name is restricted to 20 characters at most.", MessageTypes.Error);
                return;
            }

            if (!Directory.Exists(TargetFolderPath.Text))
            {
                ShowMessage("Cannot find target folder for conversion output.", MessageTypes.Error);
                return;
            }

            if (ConvertUserConfiguration)
            {
                if (LDAPAccountUnit.Text.Trim().Equals("") || LDAPAccountUnit.Text.Trim().Contains(" "))
                {
                    ShowMessage("LDAP Account Unit field cannot be empty or containt space(s).", MessageTypes.Error);
                    return;
                }
            }

            VendorParser vendorParser;

            switch (_supportedVendors.SelectedVendor)
            {
            case Vendor.CiscoASA:
                vendorParser = new CiscoParser();
                break;

            case Vendor.JuniperJunosOS:
                vendorParser = new JuniperParser();
                break;

            case Vendor.JuniperScreenOS:
                vendorParser = new ScreenOSParser();
                break;

            case Vendor.FortiGate:
                vendorParser = new FortiGateParser();
                break;

            case Vendor.PaloAlto:
                vendorParser = new PaloAltoParser();
                break;

            case Vendor.PaloAltoPanorama:
                string compressorsDirPath = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "compressors";
                string compressorZip      = Path.Combine(compressorsDirPath, "zip.exe");
                string compressorGtar     = Path.Combine(compressorsDirPath, "gtar.exe");
                string compressorGzip     = Path.Combine(compressorsDirPath, "gzip.exe");
                if (!File.Exists(compressorZip) || !File.Exists(compressorGtar) || !File.Exists(compressorGzip))
                {
                    ShowMessage(String.Format("{1}{0}{2}", Environment.NewLine, "The system cannot find the required files. ",
                                              "Please follow"), MessageTypes.Error, "these instructions", "https://github.com/CheckPointSW/SmartMove#smart-connector-and-paloalto-panorama-instructions");
                    return;
                }
                vendorParser = new PanoramaParser();
                break;

            default:
                throw new InvalidDataException("Unexpected!!!");
            }

            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
            EnableDisableControls(false);
            ProgressPanel.Visibility = Visibility.Visible;
            ResultsPanel.Visibility  = Visibility.Collapsed;
            OutputPanel.Visibility   = Visibility.Visible;

            UpdateProgress(10, "Parsing configuration file ...");

            string vendorFileName  = Path.GetFileNameWithoutExtension(ConfigFilePath.Text);
            string toolVersion     = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            string targetFolder    = TargetFolderPath.Text + "\\";
            bool   convertNat      = ConvertNATConfiguration;
            string ldapAccountUnit = LDAPAccountUnit.Text.Trim();

            try
            {
                string ciscoFile = ConfigFilePath.Text;
                switch (_supportedVendors.SelectedVendor)
                {
                case Vendor.PaloAltoPanorama:
                    PanoramaParser panParser = (PanoramaParser)vendorParser;
                    await Task.Run(() => panParser.ParseWithTargetFolder(ciscoFile, targetFolder));

                    break;

                default:
                    await Task.Run(() => vendorParser.Parse(ciscoFile));

                    break;
                }
            }
            catch (Exception ex)
            {
                Mouse.OverrideCursor = null;
                EnableDisableControls(true);
                OutputPanel.Visibility = Visibility.Collapsed;
                ShowMessage(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;
            }

            switch (_supportedVendors.SelectedVendor)
            {
            case Vendor.CiscoASA:
                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);
                }
                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);
                }
                break;

            case Vendor.JuniperJunosOS:
                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);
                }
                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);
                }
                break;

            case Vendor.JuniperScreenOS:
                break;

            case Vendor.FortiGate:
                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);
                }
                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);
                }
                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);
                }
                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);
                }
                break;

            case Vendor.PaloAltoPanorama:
                if (string.IsNullOrEmpty(vendorParser.Version))
                {
                    ShowMessage("Unspecified PaloAlto version.\nCannot find PaloAlto Panorama 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 Panorama 7.x and above configuration files.\nThe configuration may not parse correctly.", MessageTypes.Warning);
                    return;
                }
                break;
            }

            vendorParser.Export(targetFolder + vendorFileName + ".json");

            VendorConverter vendorConverter;

            switch (_supportedVendors.SelectedVendor)
            {
            case Vendor.CiscoASA:
                vendorConverter = new CiscoConverter();
                break;

            case Vendor.JuniperJunosOS:
                vendorConverter = new JuniperConverter();
                break;

            case Vendor.JuniperScreenOS:
                vendorConverter = new ScreenOSConverter();
                break;

            case Vendor.FortiGate:
                FortiGateConverter fgConverter = new FortiGateConverter();
                fgConverter.OptimizeConf    = SkipUnusedObjectsConversion;
                fgConverter.ConvertUserConf = ConvertUserConfiguration;
                fgConverter.LDAPAccoutUnit  = ldapAccountUnit.Trim();
                vendorConverter             = fgConverter;
                break;

            case Vendor.PaloAlto:
                PaloAltoConverter paConverter = new PaloAltoConverter();
                paConverter.OptimizeConf    = SkipUnusedObjectsConversion;
                paConverter.ConvertUserConf = ConvertUserConfiguration;
                paConverter.LDAPAccoutUnit  = ldapAccountUnit.Trim();
                vendorConverter             = paConverter;
                break;

            case Vendor.PaloAltoPanorama:
                PanoramaConverter panoramaConverter = new PanoramaConverter();
                panoramaConverter.OptimizeConf    = SkipUnusedObjectsConversion;
                panoramaConverter.ConvertUserConf = ConvertUserConfiguration;
                panoramaConverter.LDAPAccoutUnit  = ldapAccountUnit.Trim();
                vendorConverter = panoramaConverter;
                break;

            default:
                throw new InvalidDataException("Unexpected!!!");
            }

            vendorConverter.Initialize(vendorParser, ConfigFilePath.Text, toolVersion, targetFolder, DomainName.Text);
            vendorConverter.ConversionProgress += OnConversionProgress;

            try
            {
                await Task.Run(() => vendorConverter.Convert(convertNat));
            }
            catch (Exception ex)
            {
                Mouse.OverrideCursor = null;
                EnableDisableControls(true);
                OutputPanel.Visibility = Visibility.Collapsed;
                if (ex is InvalidDataException && ex.Message != null && ex.Message.Contains("Policy exceeds the maximum number"))
                {
                    ShowMessage(String.Format("{1}{0}{2}{0}{3}", Environment.NewLine, "SmartMove is unable to convert the provided policy.",
                                              "Reason: Policy exceeds the maximum number of supported policy layers.",
                                              "To assure the smooth conversion of your data, it is recommended to contact Check Point Professional Services by sending an e-mail to"),
                                MessageTypes.Error, "*****@*****.**", "mailto:[email protected]");
                }
                else
                {
                    ShowMessage(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;
            }

            UpdateProgress(90, "Exporting Check Point configuration ...");
            vendorConverter.ExportConfigurationAsHtml();
            vendorConverter.ExportPolicyPackagesAsHtml();
            if (ConvertNATConfiguration)
            {
                ConvertedNatPolicyLink.MouseUp -= Link_OnClick;
                vendorConverter.ExportNatLayerAsHtml();

                //check if the user asked for NAT policy and no rules found.
                if (vendorConverter.RulesInNatLayer() == 0)  // anly if 0 then we do not show NAT report.
                {
                    ConvertedNatPolicyLink.Style = (Style)ConvertedNatPolicyLink.FindResource("NormalTextBloclStyle");
                }
                else // otherwise it is single NAT report or Catalog for NAT reports (value = -1)
                {
                    ConvertedNatPolicyLink.Style    = (Style)ConvertedNatPolicyLink.FindResource("HyperLinkStyle");
                    ConvertedNatPolicyLink.MouseUp += Link_OnClick;
                }
            }
            UpdateProgress(100, "");

            vendorConverter.ConversionProgress -= OnConversionProgress;

            Mouse.OverrideCursor = null;
            EnableDisableControls(true);
            ProgressPanel.Visibility = Visibility.Collapsed;
            ResultsPanel.Visibility  = Visibility.Visible;

            ShowResults(vendorConverter, vendorParser.ParsedLines);
        }