Esempio n. 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="html">HTML string</param>
        private void GetDomains(string html)
        {
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(html);

            string token = string.Empty;

            HtmlNodeCollection nodes;

            try
            {
                nodes = doc.DocumentNode.SelectNodes("//input[contains(@name,\"records\")]");
            }
            catch
            {
                return;
            }

            if (nodes == null || nodes.Count.Equals(0))
                return;

            foreach (HtmlNode link in nodes)
            {

                string[] splitted = link.Attributes["name"].Value.Split('[');

                string id = splitted[1].Replace("]", "");
                SubDomain currentDomain = SubDomains.Where(d => d.ID.Equals(id)).FirstOrDefault();

                if (currentDomain == null)
                {
                    currentDomain = new SubDomain();
                    currentDomain.ID = id;
                    SubDomains.Add(currentDomain);
                }

                string filter = splitted[2].Replace("]", "");

                switch (filter)
                {
                    case "line":
                        currentDomain.Line = link.Attributes["value"].Value;
                        break;
                    case "ttl":
                        currentDomain.TTL = link.Attributes["value"].Value;
                        break;
                    case "value":
                        currentDomain.Value = link.Attributes["value"].Value;
                        break;
                    case "name":
                        currentDomain.Name = link.Attributes["value"].Value;
                        break;
                    case "type":
                        currentDomain.Type = link.Attributes["value"].Value;
                        break;
                }

            }
        }
Esempio n. 2
0
        public void BeginAdd()
        {
            foreach (Domain dom in Domains)
            {
                logger.Info("Adding domains for " + dom.Name);

                SubDomains = new List<SubDomain>();

                List<SubDomain> TempDomains = new List<SubDomain>();

                for (var i = 0; i < DomainsToAdd.Count; i++)
                {
                    SubDomain subToAdd = new SubDomain();
                    subToAdd.ID = i.ToString();
                    subToAdd.Name = DomainsToAdd[i].ToUpper();
                    TempDomains.Add(subToAdd);
                }

                if (TempDomains.Count > 0)
                    logger.Info("Found " + TempDomains.Count.ToString() + " to add");
                else
                {
                    logger.Info("0 subdomains found in config file");
                    return;
                }

                //Get a new token to wonnect with
                CurrentToken = GetToken(_tokenURL, null, "/html/body/section/div/div/input");

                if (!string.IsNullOrEmpty(CurrentToken))
                {
                    //Connect to FreeNom with provided credentials
                    DoLogin(dom);

                    //Get subdomains
                    GetDomains(HTMLToParse);

                    if (SubDomains.Count > 0)
                    {
                        logger.Info("Found " + SubDomains.Count.ToString() + " existing domains, start filtering");

                        List<SubDomain> filteredDomains = new List<SubDomain>();

                        for (var i = 0; i < TempDomains.Count; i++)
                        {
                            bool temp = SubDomains.Where(s => s.Name.Equals(TempDomains[i].Name)).Any();

                            if (!temp)
                            {
                                filteredDomains.Add(TempDomains[i]);
                            }
                        }

                        SubDomains = filteredDomains;
                    }

                    //Update subdomains
                    if (SubDomains.Count > 1)
                    {
                        logger.Info(SubDomains.Count.ToString() + " subdomains to add");

                        //UpdateData();
                        AddDomains(dom);
                    }
                    else
                    {
                        logger.Info("All subdomains allready exists");
                    }

                    //Logout from FreeNom
                    Logout();
                }
            }
        }