Example #1
0
        private void buildRaw(DirectoryEntry group)
        {
            var generator = new RawADGridGenerator();
            var result = generator.buildRawSegment(group);

            labelRawData.Text = result.ToString();
        }
Example #2
0
        protected void buildlookupComputer(string computername)
        {
            Session["adpath"] = null;
            var tmpName = computername;

            string domain = null;
            if (tmpName.Contains("\\")) {
                var tmp = tmpName.Split('\\');
                computername = tmp[1];

                if (!tmp[0].Equals("aau",StringComparison.CurrentCultureIgnoreCase)){
                    domain = tmp[0]+".aau.dk";
                }else {
                    domain = "aau.dk";
                }
            }

            if (domain == null){

                var de = new DirectoryEntry("GC://aau.dk");
                string filter = string.Format("(&(objectClass=computer)(cn={0}))", computername);

                var search = new DirectorySearcher(de);
                search.Filter = filter;
                search.PropertiesToLoad.Add("distinguishedName");

                var r = search.FindOne();

                if (r == null){ //Computer not found

                    ResultLabel.Text = "Computer Not Found";
                    return;
                }

                var distinguishedName = r.Properties["distinguishedName"][0].ToString();
                var split = distinguishedName.Split(',');

                var len = split.GetLength(0);
                domain = (split[len-3] + "." + split[len-2] + "." + split[len-1]).Replace("DC=","");

            }
            //XXX this is not safe computerName is a use attibute, they might be able to change the value of this

            var de2 = new DirectoryEntry("LDAP://"+domain);
            var search2 = new DirectorySearcher(de2);

            search2.PropertiesToLoad.Add("cn");

            //search.PropertiesToLoad.Add("ms-Mcs-AdmPwd");
            search2.PropertiesToLoad.Add("ms-Mcs-AdmPwdExpirationTime");
            search2.PropertiesToLoad.Add("memberOf");

            search2.Filter = string.Format("(&(objectClass=computer)(cn={0}))", computername);
            var resultLocal = search2.FindOne();

            labelDomain.Text = domain;

            if (resultLocal == null)
            { //Computer not found

                ResultLabel.Text = "Computer Not Found";
                return;
            }

            String adpath = resultLocal.Properties["ADsPath"][0].ToString();
            Session["adpath"] = adpath;

            logger.Info("User {0} requesed info about computer {1}", System.Web.HttpContext.Current.User.Identity.Name, adpath);

            if (resultLocal.Properties.Contains("ms-Mcs-AdmPwdExpirationTime"))
            {
                long rawDate = (long)resultLocal.Properties["ms-Mcs-AdmPwdExpirationTime"][0];
                DateTime expireDate = DateTime.FromFileTime(rawDate);
                labelPwdExpireDate.Text = expireDate.ToString();
            }
            else
            {
                labelPwdExpireDate.Text = "LAPS not Enabled";
            }

            var rawbuilder = new RawADGridGenerator();
            ResultLabelRaw.Text = rawbuilder.buildRawSegment(resultLocal.GetDirectoryEntry());

            buildBasicInfo(resultLocal.GetDirectoryEntry());

            var resourceID = getSCCMResourceIDFromComputerName(computername); //XXX use ad path to get right object in sccm, also dont get obsolite
            //XXX check resourceID
            buildSCCMInfo(resourceID);
            buildSCCMInventory(resourceID);

            buildGroupsSegments(resultLocal.GetDirectoryEntry());

            ResultDiv.Visible = true;

            if (!checkComputerOU(adpath))
            {
                MoveComputerOUdiv.Visible = true;
            }
        }
Example #3
0
        protected async void buildUserLookup(string adpath)
        {
            
            if (adpath != null)
            {

                var watch = System.Diagnostics.Stopwatch.StartNew();

                //Get the AD object 
                var userDE = new DirectoryEntry(adpath);

                //Save Session
                Session["adpath"] = adpath;

                //Async
                var task1 = buildBasicInfoSegment(userDE);
                var task2 = BuildSCSMSegment(userDE);

                //Build GUI
                var rawbuilder = new RawADGridGenerator();
                var rawsegment = rawbuilder.buildRawSegment(userDE);
                labelRawdata.Text = rawsegment;
                
                buildComputerInformation(userDE);
                buildWarningSegment(userDE);
                buildGroupsSegments(userDE);
                buildCalAgenda(userDE);
                buildLoginscript(userDE);

                await System.Threading.Tasks.Task.WhenAll(task1, task2);

                //Save user in session
                ResultDiv.Visible = true;
                errordiv.Visible = false;

                watch.Stop();
                System.Diagnostics.Debug.WriteLine("buildUserLookup took: "+  watch.ElapsedMilliseconds);
            }

        }