private void SetNetworkInterfaceValues(NetworkInterface networkInterface, string interfaceName)
        {
            SetupIpv4Interface(interfaceName, networkInterface);
            SetupIpv6Interface(interfaceName, networkInterface);

            if (networkInterface.dns != null && networkInterface.dns.Length > 0)
            {
                CleanseDnsForSetup(interfaceName);
                SetupDns(interfaceName, networkInterface);
            }

            _executableProcessQueue.Go();

            SetInterfaceName(networkInterface, interfaceName, 0);
        }
        private void SetNetworkInterfaceValues(NetworkInterface networkInterface, string interfaceName)
        {
            CleanseInterfaceForSetup(interfaceName);
            SetupInterface(interfaceName, networkInterface);

            if (networkInterface.dns != null && networkInterface.dns.Length > 0)
            {
                CleanseDnsForSetup(interfaceName);
                SetupDns(interfaceName, networkInterface);
            }

            if (interfaceName != networkInterface.label)
            {
                _executableProcessQueue.Enqueue("netsh", String.Format("interface set interface name=\"{0}\" newname=\"{1}\"", interfaceName, networkInterface.label));
            }

            _executableProcessQueue.Go();
        }
Exemplo n.º 3
0
        public void Execute(ProviderData providerData, List <string> userMetadata)
        {
            string logMessage = string.Format(" Provider Data Deserialzed : {0}", new Json <ProviderData>().Serialize(providerData));

            _logger.Log(logMessage);

            if (CheckRoleNameMatch(providerData, userMetadata))
            {
                if (providerData.white_List_Ips.Count > 0)
                {
                    var command = string.Empty;
                    if (_netshFirewallRuleNameAvailable.IsRuleAvailable(Constants.SoftwareFirewallRuleName))
                    {
                        command = string.Format(
                            "advfirewall firewall set rule name=\"{0}\" new enable=yes remoteip={1}",
                            Constants.SoftwareFirewallRuleName, string.Join(",", providerData.white_List_Ips.ToArray()));
                    }
                    else
                    {
                        command =
                            string.Format(
                                "advfirewall firewall add rule name=\"{0}\" enable=yes dir=in profile=public,private,domain localip=any remoteip={1} protocol=tcp localport=445 remoteport=any edge=no action=allow",
                                Constants.SoftwareFirewallRuleName,
                                string.Join(",", providerData.white_List_Ips.ToArray()));
                    }
                    _executableProcessQueue.Enqueue("netsh", command);
                    _executableProcessQueue.Go();
                }
                else
                {
                    _logger.Log("White List Ips not available. Firewall rules will not be added/updated.");
                }
            }
            else
            {
                _logger.Log(string.Format("Role Names did not match. Roles names from provider data {0}. Role names from configuration {1}. UserMetadata:{2}",
                                          string.Join(",", providerData.roles.ToArray()), string.Join(",", GetFirewallRoles().ToArray()), string.Join(",", userMetadata.ToArray())));
            }
        }
        public void Execute(Network network)
        {
            IList <NetworkRoute> routes = new List <NetworkRoute>();
            var publicGateway           = "";

            foreach (var networkInterface in network.Interfaces.Values)
            {
                if (networkInterface.label.ToLower() == "public")
                {
                    publicGateway = networkInterface.gateway;
                }
                if (networkInterface.routes == null || networkInterface.routes.Length < 1)
                {
                    continue;
                }

                foreach (var route in networkInterface.routes)
                {
                    if (routes.Contains(route))
                    {
                        continue;
                    }
                    routes.Add(route);
                }
            }

            _logger.Log("Routes Found: " + routes.Count);

            DeleteExistingPersistentRoutesRoutes();
            _executableProcessQueue.Enqueue("route", String.Format("-p add 0.0.0.0 mask 0.0.0.0 {0} metric 2", publicGateway));

            foreach (var route in routes)
            {
                _executableProcessQueue.Enqueue("route", String.Format("-p add {0} mask {1} {2} metric 10", route.route, route.netmask, route.gateway));
            }

            _executableProcessQueue.Go();
        }