Beispiel #1
0
        // Whitelist/Blacklist
        public List <DomainFilter> GetDomainFilter(DnsBlockList.Lists List)
        {
            List <byte[]> args = new List <byte[]>();
            List <byte[]> ret  = RemoteExec("GetDomainFilter", args);

            return(ret != null?GetFilterList(ret[0]) : null);
        }
Beispiel #2
0
        public List <DomainFilter> GetDomainFilter(DnsBlockList.Lists List)
        {
            ListLock.EnterReadLock();
            var ret = GetDomainFilterList(List).Select(v => { return(v.Value.Item1); }).ToList();

            ListLock.ExitReadLock();
            return(ret);
        }
Beispiel #3
0
        public bool RemoveDomainFilter(DnsBlockList.Lists List, string Domain)
        {
            List <byte[]> args = new List <byte[]>();

            args.Add(PutStr(List));
            args.Add(PutStr(Domain));
            List <byte[]> ret = RemoteExec("RemoveDomainFilter", args);

            return(ret != null?GetBool(ret[0]) : false);
        }
Beispiel #4
0
        public bool UpdateDomainFilter(DnsBlockList.Lists List, DomainFilter Filter)
        {
            List <byte[]> args = new List <byte[]>();

            args.Add(PutStr(List));
            args.Add(PutDomainFilter(Filter));
            List <byte[]> ret = RemoteExec("UpdateDomainFilter", args);

            return(ret != null?GetBool(ret[0]) : false);
        }
Beispiel #5
0
        public bool RemoveDomainFilter(DnsBlockList.Lists List, string Domain)
        {
            Dictionary <string, Tuple <DomainFilter, Regex> > list = GetDomainFilterList(List);

            ListLock.EnterWriteLock();
            var ret = list.Remove(Domain);

            ListLock.ExitWriteLock();
            return(ret);
        }
        public void UpdateList(DnsBlockList.Lists ListType)
        {
            List <DomainFilter> Filters = App.client.GetDomainFilter(ListType);

            if (Filters == null)
            {
                return;
            }

            this.ListType = ListType;
            FilterList.Clear();
            foreach (var Filter in Filters)
            {
                AddItem(Filter);
            }
        }
Beispiel #7
0
        public bool UpdateDomainFilter(DnsBlockList.Lists List, DomainFilter Filter)
        {
            Dictionary <string, Tuple <DomainFilter, Regex> > list = GetDomainFilterList(List);

            ListLock.EnterWriteLock();
            Tuple <DomainFilter, Regex> KnownFilter;

            if (list.TryGetValue(Filter.Domain, out KnownFilter))
            {
                KnownFilter.Item1.Enabled = Filter.Enabled;
            }
            else
            {
                AddDomainFilterImpl(List, Filter);
            }
            ListLock.ExitWriteLock();
            return(true);
        }
Beispiel #8
0
        private void LoadList(XmlNode rootNode, DnsBlockList.Lists List)
        {
            foreach (XmlNode node in rootNode)
            {
                if (node.Name != "DomainFilter")
                {
                    continue;
                }

                DomainFilter domainFilter = new DomainFilter();
                foreach (XmlNode subNode in node)
                {
                    if (subNode.Name == "Domain")
                    {
                        domainFilter.Domain = subNode.InnerText;
                    }
                    else if (subNode.Name == "Enabled")
                    {
                        bool.TryParse(subNode.InnerText, out domainFilter.Enabled);
                    }
                    else if (subNode.Name == "Format")
                    {
                        Enum.TryParse(subNode.InnerText, out domainFilter.Format);
                    }
                    else if (subNode.Name == "HitCount")
                    {
                        int.TryParse(subNode.InnerText, out domainFilter.HitCount);
                    }
                    else if (subNode.Name == "LastHit")
                    {
                        DateTime dateTime;
                        if (DateTime.TryParse(subNode.InnerText, out dateTime))
                        {
                            domainFilter.LastHit = dateTime;
                        }
                    }
                }
                AddDomainFilterImpl(List, domainFilter);
            }
        }
Beispiel #9
0
        private void StoreList(XmlWriter writer, DnsBlockList.Lists List)
        {
            Dictionary <string, Tuple <DomainFilter, Regex> > list = GetDomainFilterList(List);

            foreach (var item in list.Values)
            {
                DomainFilter domainfilter = item.Item1;
                writer.WriteStartElement("DomainFilter");

                writer.WriteElementString("Domain", domainfilter.Domain);
                writer.WriteElementString("Enabled", domainfilter.Enabled.ToString());
                writer.WriteElementString("Format", domainfilter.Format.ToString());
                if (domainfilter.HitCount != 0)
                {
                    writer.WriteElementString("HitCount", domainfilter.HitCount.ToString());
                }
                if (domainfilter.LastHit != null)
                {
                    writer.WriteElementString("LastHit", domainfilter.LastHit.ToString());
                }

                writer.WriteEndElement();
            }
        }
Beispiel #10
0
        private bool AddDomainFilterImpl(DnsBlockList.Lists List, DomainFilter Filter)
        {
            // WARNING: ListLock must be locked for writing when entering this function.

            Dictionary <string, Tuple <DomainFilter, Regex> > list = GetDomainFilterList(List);

            try
            {
                Regex Matcher = null;
                if (Filter.Format == DomainFilter.Formats.RegExp)
                {
                    Matcher = new Regex(Filter.Domain);
                }
                else if (Filter.Format == DomainFilter.Formats.WildCard)
                {
                    Matcher = new Regex(Regex.Escape(Filter.Domain).Replace("\\*", ".*"));
                }
                list.Add(Filter.Domain, Tuple.Create(Filter, Matcher));
                return(true);
            }
            catch {
                return(false);
            }
        }
Beispiel #11
0
 public bool RemoveDomainFilter(DnsBlockList.Lists List, string Domain)
 {
     return(RemoteExec("RemoveDomainFilter", new object[2] {
         List, Domain
     }, false));
 }
Beispiel #12
0
 public bool UpdateDomainFilter(DnsBlockList.Lists List, DomainFilter Filter)
 {
     return(RemoteExec("UpdateDomainFilter", new object[2] {
         List, Filter
     }, false));
 }
Beispiel #13
0
 // Whitelist/Blacklist
 public List <DomainFilter> GetDomainFilter(DnsBlockList.Lists List)
 {
     return(RemoteExec <List <DomainFilter> >("GetDomainFilter", new object[1] {
         List
     }, null));
 }
Beispiel #14
0
        private Dictionary <string, Tuple <DomainFilter, Regex> > GetDomainFilterList(DnsBlockList.Lists List)
        {
            switch (List)
            {
            case Lists.Whitelist: return(Whitelist);

            case Lists.Blacklist: return(Blacklist);
            }
            return(null);
        }