コード例 #1
0
        public bool AddUrlReservations(bool shouldOpenFirewallPorts = false)
        {
            Logger.Info("[Topshelf.Nancy] Adding URL Reservations");

            var user = GetUser();

            foreach (var prefix in GetPrefixes())
            {
                var result = NetSh.AddUrlAcl(prefix, user);
                if (result.ResultCode == NetShResultCode.Error)
                {
                    Logger.Error(string.Format("[Topshelf.Nancy] Error deleting URL Reservation with command: netsh {0}. {1}", result.CommandRan, result.Message));
                    return(false);
                }

                if (result.ResultCode == NetShResultCode.UrlReservationAlreadyExists)
                {
                    Logger.Warn("[Topshelf.Nancy] Could not add URL Reservation becuase it already exists. Treating as a success.");
                    return(true);
                }
            }

            Logger.Info("[Topshelf.Nancy] URL Reservations added");

            return(true);
        }
コード例 #2
0
        public bool AddUrlReservations(bool shouldOpenFirewallPorts = false)
        {
            var prefixes = GetPrefixes().ToList();

            LogUrlReservations(prefixes);

            var user = GetUser();

            foreach (var prefix in prefixes)
            {
                var result = NetSh.AddUrlAcl(prefix, user);
                if (result.ResultCode == NetShResultCode.Error)
                {
                    var message = string.Format("[Topshelf.Nancy] Error adding URL Reservation {0} with command: netsh {1}. {2}", prefix, result.CommandRan, result.Message);
                    Logger.Error(message);
                    return(false);
                }

                if (result.ResultCode == NetShResultCode.UrlReservationAlreadyExists)
                {
                    var message = string.Format("[Topshelf.Nancy] Could not add URL Reservation {0} because it already exists. Treating as a success.", prefix);
                    Logger.Warn(message);
                    return(true);
                }
            }

            Logger.Info("[Topshelf.Nancy] URL Reservations added");

            return(true);
        }
コード例 #3
0
        public bool TryDeleteUrlReservations()
        {
            Logger.Info("[Topshelf.Nancy] Deleting URL Reservations");

            foreach (var prefix in GetPrefixes())
            {
                var result = NetSh.DeleteUrlAcl(prefix);

                if (result.ResultCode == NetShResultCode.Error)
                {
                    var message = string.Format("[Topshelf.Nancy] Error deleting URL Reservation {0} with command: netsh {1}. {2}", prefix, result.CommandRan, result.Message);
                    Logger.Error(message);
                    return(false);
                }

                if (result.ResultCode == NetShResultCode.UrlReservationDoesNotExist)
                {
                    var message = string.Format("[Topshelf.Nancy] Could not delete URL Reservation {0} because it does not exist. Treating as a success.", prefix);
                    Logger.Warn(message);
                }
            }

            Logger.Info("[Topshelf.Nancy] URL Reservations deleted");

            return(true);
        }
コード例 #4
0
        public bool OpenFirewallPorts(IEnumerable <int> ports, string firewallRuleName)
        {
            Logger.Info("[Topshelf.Nancy] Opening firewall ports");

            var user = GetUser();

            var portList = string.Join(",", ports);

            var result = NetSh.OpenFirewallPorts(portList, user, firewallRuleName);

            if (result.ResultCode == NetShResultCode.Error)
            {
                Logger.Error(string.Format("[Topshelf.Nancy] Error opening firewall port: netsh {0}. {1}", result.CommandRan, result.Message));
                return(false);
            }

            Logger.Info(string.Format("[Topshelf.Nancy] Firewall ports opened: {0}", portList));
            return(true);
        }