Exemple #1
0
        private void AddDomainComputer(int _requestid, string _server, int _domain)
        {
            Variables oVariable             = new Variables(_domain);
            ADObject  oADObject             = new ADObject(0, dsn);
            AD        oAD                   = new AD(0, dsn, _domain);
            SearchResultCollection oResults = oAD.ComputerSearch(_server);

            foreach (SearchResult oResult in oResults)
            {
                string strPath = "";
                if (oResult.Properties.Contains("adspath") == true)
                {
                    strPath = oResult.Properties["adspath"][0].ToString();
                }
                string strDate = "";
                if (oResult.Properties.Contains("whencreated") == true)
                {
                    strDate = oResult.Properties["whencreated"][0].ToString();
                }
                oADObject.AddDomainAccount(_requestid, _domain, _server, strPath, _server + " is not a member of " + oVariable.Domain().ToUpper(), strDate);
            }
        }
Exemple #2
0
        private double LastLogin(int _search_domain, int _days, int _accounts, int _requestid)
        {
            double            dblHours  = 0.00;
            double            dblTime   = 5.00 / 60.00;
            ADObject          oADObject = new ADObject(0, dsn);
            Variables         oVariable = new Variables(_search_domain);
            DirectoryEntry    oEntry    = new DirectoryEntry(oVariable.primaryDC(dsn), oVariable.ADUser(), oVariable.ADPassword());
            DirectorySearcher oSearcher = new DirectorySearcher(oEntry);

            oSearcher.Filter = "(&(objectCategory=user)(|(sAMAccountName=t*)(|(sAMAccountName=e*)(sAMAccountName=x*))))";
            SearchResultCollection oResults = oSearcher.FindAll();

            foreach (SearchResult oResult in oResults)
            {
                if (_accounts > 0 && intCounter > _accounts)
                {
                    break;
                }
                if (oResult.Properties.Contains("sAMAccountName") == true)
                {
                    string strXid   = oResult.Properties["sAMAccountName"][0].ToString();
                    string strFName = "";
                    if (oResult.Properties.Contains("givenname") == true)
                    {
                        strFName = oResult.Properties["givenname"][0].ToString();
                    }
                    string strLName = "";
                    if (oResult.Properties.Contains("sn") == true)
                    {
                        strLName = oResult.Properties["sn"][0].ToString();
                    }
                    string strName = "";
                    if (strFName != "" || strLName != "")
                    {
                        strName = "(" + strFName + " " + strLName + ")";
                    }
                    string strPath = "";
                    if (oResult.Properties.Contains("adspath") == true)
                    {
                        strPath = oResult.Properties["adspath"][0].ToString();
                    }
                    DateTime dc1       = CheckDomain(1, _search_domain, strXid, _days);
                    DateTime dc2       = CheckDomain(2, _search_domain, strXid, _days);
                    DateTime dcGreater = new DateTime();
                    DateTime dcLess    = new DateTime();
                    if (dc1 > dc2)
                    {
                        dcGreater = dc1;
                        dcLess    = dc2;
                    }
                    else
                    {
                        dcGreater = dc2;
                        dcLess    = dc1;
                    }
                    TimeSpan oSpan     = DateTime.Today.Subtract(dcGreater);
                    TimeSpan oSpanLess = DateTime.Today.Subtract(dcLess);
                    if (oSpan.Days > _days)
                    {
                        string strDate = dcGreater.ToString();
                        oADObject.AddDomainAccount(_requestid, _search_domain, strXid.ToUpper() + strName, strPath, "Account has not logged in for " + oSpan.Days.ToString() + " days in " + oVariable.Name() + " (" + oSpanLess.Days.ToString() + " in other DC)", strDate);
                        intCounter++;
                        dblHours += dblTime;
                    }
                }
            }
            return(dblHours);
        }
Exemple #3
0
        private double CompareDomainAccounts(int _search_domain, int _searched_domain, string _account_preface, int _accounts, int _requestid)
        {
            double            dblHours  = 0.00;
            double            dblTime   = 5.00 / 60.00;
            Variables         vDev      = new Variables(_search_domain);
            Variables         vProd     = new Variables(_searched_domain);
            ADObject          oADObject = new ADObject(0, dsn);
            DirectoryEntry    oDev      = new DirectoryEntry(vDev.primaryDC(dsn), vDev.ADUser(), vDev.ADPassword());
            DirectoryEntry    oProd     = new DirectoryEntry(vProd.primaryDC(dsn), vProd.ADUser(), vProd.ADPassword());
            DirectorySearcher sDev      = new DirectorySearcher(oDev);

            sDev.Filter = "(&(objectCategory=user)(|(sAMAccountName=t*)(|(sAMAccountName=e*)(sAMAccountName=x*))))";
            SearchResultCollection resDevs = sDev.FindAll();

            foreach (SearchResult resDev in resDevs)
            {
                if (_accounts > 0 && intCounter > _accounts)
                {
                    break;
                }
                if (resDev.Properties.Contains("sAMAccountName") == true)
                {
                    string            strXid    = resDev.Properties["sAMAccountName"][0].ToString();
                    string            strNewXid = _account_preface + strXid.Substring(1);
                    DirectorySearcher sProd     = new DirectorySearcher(oProd);
                    sProd.Filter = "(&(objectCategory=user)(sAMAccountName=" + strNewXid + "))";
                    SearchResult resProd = sProd.FindOne();
                    if (resProd == null)
                    {
                        string strFName = "";
                        if (resDev.Properties.Contains("givenname") == true)
                        {
                            strFName = resDev.Properties["givenname"][0].ToString();
                        }
                        string strLName = "";
                        if (resDev.Properties.Contains("sn") == true)
                        {
                            strLName = resDev.Properties["sn"][0].ToString();
                        }
                        string strName = "";
                        if (strFName != "" || strLName != "")
                        {
                            strName = "(" + strFName + " " + strLName + ")";
                        }
                        string strPath = "";
                        if (resDev.Properties.Contains("adspath") == true)
                        {
                            strPath = resDev.Properties["adspath"][0].ToString();
                        }
                        string strDate = "";
                        if (resDev.Properties.Contains("whencreated") == true)
                        {
                            strDate = resDev.Properties["whencreated"][0].ToString();
                        }
                        oADObject.AddDomainAccount(_requestid, _search_domain, strNewXid.ToUpper() + strName, strPath, vDev.Name() + " account not found in " + vProd.Name() + "(" + strNewXid + ")", strDate);
                        intCounter++;
                        dblHours += dblTime;
                    }
                }
            }
            return(dblHours);
        }