Beispiel #1
0
 private bool DeactivateFirewallRules()
 {
     try
     {
         Firewall.RemoveRules("Removeo");
         HostsFile.RemoveDomainsFromHosts(Config.SystemHostsFile);
     }
     catch (Exception e)
     {
         lastError = e.Message;
         return(false);
     }
     return(true);
 }
Beispiel #2
0
        private bool ActivateFirewallRules()
        {
            try
            {
                Firewall.RemoveRules("Removeo");
                HostsFile.RemoveDomainsFromHosts(Config.SystemHostsFile);
                foreach (var option in new List <Config.BlockOption>(Config.BlockOptions.Where(opt => opt.Enabled))
                {
                    Config.CustomOption
                })
                {
                    if (File.Exists(option.IpFileName))
                    {
                        var ipv4 = Common.ReadUniqueIpv4(option.IpFileName);
                        // add ip rules
                        if (ipv4.Count > 0)
                        {
                            foreach (var chunk in Common.Split(ipv4, 1000))
                            {
                                var address = string.Join(",", chunk);
                                Firewall.AddRule("Removeo", address);
                            }
                        }
                    }

                    if (File.Exists(option.DomainsFileName))
                    {
                        var domains = File.ReadAllLines(option.DomainsFileName).Distinct().ToList();
                        // add domains to hosts file
                        if (domains.Count > 0)
                        {
                            HostsFile.AppendDomainsToHosts(Config.SystemHostsFile, domains);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                lastError = e.Message;
                return(false);
            }

            return(true);
        }