/// <summary>
        /// Delete a rule from the tracked objects.
        /// </summary>
        /// <param name="networkRule"></param>
        /// <exception cref="Exception"></exception>
        public void DeleteRule(NetworkRule networkRule)
        {
            // Build standard process options.
            var processOptions = NetworkBuilder.BuildProcessOptions("iptables");

            // Get local interface information
            var interfaceInformation = GetDefaultInterface();

            // Determine how to handle the rule.
            switch (networkRule.Type)
            {
            // MASQUERADE
            case NetworkRuleType.Masquerade:
                processOptions.Arguments = ("-D " + NetworkBuilder.BuildTemplate(NetworkRuleTemplates.MASQUERADE, networkRule, interfaceInformation)).Split(" ");
                break;

            // SNAT
            case NetworkRuleType.SourceNetworkAddressTranslation:
                processOptions.Arguments =
                    ("-D " + NetworkBuilder.BuildTemplate(NetworkRuleTemplates.SNAT, networkRule, interfaceInformation)).Split(" ");
                break;

            // Unhandled Exception
            default:
                _logger.LogError("Firewall environment was provided undefined rule type.");
                throw FirewallExceptions.UnhandledNetworkRuleException();
            }

            //TODO: Ask paul for help here. Not sure what we should do.
            _processRunner.Run(processOptions, null);

            // Forget the rule.
            _rules.Remove(networkRule);
        }
        /// <summary>
        /// Add a rule to track.
        /// </summary>
        /// <param name="networkRule"></param>
        /// <exception cref="Exception"></exception>
        public void AddRule(NetworkRule networkRule)
        {
            // Build standard process options.
            var commandOptions = NetworkBuilder.BuildProcessOptions("iptables");

            // Get local interface information
            var interfaceInformation = GetDefaultInterface();

            // Determine how to handle the rule.
            switch (networkRule.Type)
            {
            // MASQUERADE
            case NetworkRuleType.Masquerade:
                // Assign the argument.
                commandOptions.Arguments = ("-A " + NetworkBuilder.BuildTemplate(
                                                NetworkRuleTemplates.MASQUERADE,
                                                networkRule,
                                                interfaceInformation
                                                )
                                            )
                                           // Convert to string array.
                                           .Split(" ");

                // Tell the console
                _logger.LogInformation("Created MASQUERADE rule for {0}", networkRule.Network);
                break;

            // SNAT
            case NetworkRuleType.SourceNetworkAddressTranslation:
                // Assign the argument
                commandOptions.Arguments = ("-A " + NetworkBuilder.BuildTemplate(
                                                NetworkRuleTemplates.SNAT,
                                                networkRule,
                                                interfaceInformation
                                                )
                                            )
                                           // Convert to string array.
                                           .Split(" ");

                // Tell the console.
                _logger.LogInformation("Created SNAT rule for {0}", networkRule.Network);
                break;

            // Unhandled Exception
            default:
                _logger.LogError("Firewall environment was provided undefined rule type.");
                throw FirewallExceptions.UnhandledNetworkRuleException();
            }

            // Run the process.
            _processRunner.Run(commandOptions);

            // Track the rule.
            _rules.Add(networkRule);
        }
        /// <summary>
        /// Disable a SNAT Rule.
        /// </summary>
        /// <param name="networkRule"></param>
        /// <exception cref="Exception"></exception>
        public void DisableSourceNetworkAddressTranslation(NetworkRule networkRule)
        {
            // Check if we have the right rule.
            if (networkRule.Type != NetworkRuleType.SourceNetworkAddressTranslation)
            {
                throw FirewallExceptions.NetworkRuleMismatchException();
            }

            // Safely delete the rule.
            DeleteRule(networkRule);
        }
        /// <summary>
        /// Disable a MASQ rule.
        /// </summary>
        /// <param name="networkRule"></param>
        /// <exception cref="Exception"></exception>
        public void DisableMasquerade(NetworkRule networkRule)
        {
            // Check if we have the right rule.
            if (networkRule.Type != NetworkRuleType.Masquerade)
            {
                throw FirewallExceptions.NetworkRuleMismatchException();
            }

            // Delete the rule
            DeleteRule(networkRule);
        }
Exemple #5
0
 public BuildProjectCode(WIXSharpProject project)
 {
     Options = project.GetOptions();
     GlobalFileAssociations = project.GetGlobalFileAssociations();
     Registryvalues         = project.GetRegistryValues();
     FireExcept             = project.GetFirewallExceptions();
     Sourcefiles            = project.GetSourceFiles();
     Certs = project.GetCerts();
     EnvironmentVariables = project.GetEnvironmentVars();
     application          = project.GetApplication();
     users      = project.GetUsers();
     WElements  = project.GetElements();
     installdir = project.GetInstallDir();
     progfiles  = project.GetProgFiles();
     progmenu   = project.GetProgMenu();
 }
Exemple #6
0
 public BuildProjectCode(SetupOptions options, FileAssociations fileassoc, RegistryValues registryvalues, FirewallExceptions firewallexceptions, SourceFiles sourcefiles,
                         Certificates certs, EnvironmentVars envirvars, ApplicationInfo app, Users user, Elements elements, string dir, string files, string menu)
 {
     Options = options;
     GlobalFileAssociations = fileassoc;
     Registryvalues         = registryvalues;
     FireExcept             = firewallexceptions;
     Sourcefiles            = sourcefiles;
     Certs = certs;
     EnvironmentVariables = envirvars;
     application          = app;
     users      = user;
     WElements  = elements;
     installdir = dir;
     progfiles  = files;
     progmenu   = menu;
     addglobalfileassociations();
 }