예제 #1
0
 private void setpicpw()
 {
     Console.WriteLine("Opening DirXML... ");
     if (AuditSec.settings.picpw != null && AuditSec.settings.picpw.Length == 0)
     {
         AuditSec.settings.picpw = null;
     }
     UsersInfo.getDIRXMLAttributes(UserPrincipal.Current.SamAccountName);
 }
예제 #2
0
 static Image getPicture(string user)
 {
     if (PictureCache.Contains(user))
     {
         return((Image)PictureCache[user]);
     }
     else
     {
         return((Image)(PictureCache[user] = UsersInfo.Resize(UsersInfo.getUserPicture(user), 67, 90)));
     }
 }
예제 #3
0
        private void worker_DoWork(object sender, DoWorkEventArgs args)
        {
            BackgroundWorker w  = sender as BackgroundWorker;
            DirectoryEntry   de = (DirectoryEntry)args.Argument;

            Cursor.Current = Cursors.WaitCursor;


            w.ReportProgress(0, "Pre-Installation Phase");
            w.ReportProgress(0, "================================================================================");

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox1.Text + "...");
            string machine     = de.Properties["cn"].Value.ToString().ToUpper();
            string description = de.Properties["description"].Count > 0 ?
                                 de.Properties["description"][0].ToString() : "";
            string installed = ""; try

            {
                DateTime i = de.Properties["whenCreated"].Count > 0 ?
                             DateTime.ParseExact(de.Properties["whenCreated"][0].ToString(),
                                                 "dd/MM/yyyy HH:mm:ss", new CultureInfo("en-US"), DateTimeStyles.None)
                    : new DateTime();
                installed = "Installed on " + String.Format(new CultureInfo("en-US"), "{0:d-MMM-yyyy}", i);
            }
            catch (Exception ee) { Console.WriteLine(ee.ToString()); }
            w.ReportProgress(0, machine + " (" + description + ")");
            w.ReportProgress(0, installed);
            w.ReportProgress(1, CheckState.Checked);

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox2.Text + "...");
            w.ReportProgress(2, UsersInfo.isEnabledAD(de) ?
                             CheckState.Checked : CheckState.Unchecked);

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox3.Text + "...");
            try
            {
                w.ReportProgress(0, "Path=" + de.Path.ToUpper().Replace("LDAP://CN=", "")
                                 .Replace("OU=", "").Replace("DC=", "").Replace(",", "."));
                w.ReportProgress(3, System.Text.RegularExpressions.Regex.IsMatch(de.Path,
                                                                                 "LDAP://([A-Za-z.]+/)*CN=[A-Z]+[0-9]+,OU=Workstations,OU=[A-Z ]+,OU=[A-Z]+,DC=[A-Z]+,DC=MYCOMPANY,DC=INT",
                                                                                 System.Text.RegularExpressions.RegexOptions.IgnoreCase) ?
                                 CheckState.Checked : CheckState.Unchecked);
            }
            catch (Exception e)
            {
                w.ReportProgress(0, e.Message);
            }

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox4.Text + "...");
            Ping ping = new Ping(); PingReply reply;

            w.ReportProgress(0, "ping " + machine + "...");
            try
            {
                if ((reply = ping.Send(machine)).Status == IPStatus.Success)
                {
                    w.ReportProgress(0, "Reply from " + reply.Address);
                    w.ReportProgress(4, CheckState.Checked);
                }
                else
                {
                    w.ReportProgress(0, reply.Status);
                    w.ReportProgress(4, CheckState.Unchecked);
                }
            }
            catch (Exception e)
            {
                w.ReportProgress(0, e.Message);
                w.ReportProgress(4, CheckState.Unchecked);
            }

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox5.Text + "...");
            string fqdn = de.Properties["dNSHostName"].Value.ToString();

            w.ReportProgress(0, "ping " + fqdn + "...");
            try
            {
                if ((reply = ping.Send(fqdn)).Status == IPStatus.Success)
                {
                    w.ReportProgress(0, "Reply from " + reply.Address);
                    w.ReportProgress(5, CheckState.Checked);
                }
                else
                {
                    w.ReportProgress(0, reply.Status);
                    w.ReportProgress(5, CheckState.Unchecked);
                    w.ReportProgress(0, "\r\nFurther checks adjourned since computer not reachable.");
                    w.ReportProgress(0, "Computer description: " + description);
                    return;
                }
            }
            catch (Exception e)
            {
                w.ReportProgress(0, e.Message);
                w.ReportProgress(5, CheckState.Unchecked);
                w.ReportProgress(0, "\r\nFurther checks adjourned since computer not reachable.");
                w.ReportProgress(0, "Computer description: " + description);
                return;
            }

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox6.Text + "...");
            try
            {
                w.ReportProgress(6, Directory.Exists(@"\\" + machine + @"\admin$") ?
                                 CheckState.Checked : CheckState.Unchecked);
            }
            catch (Exception e)
            {
                w.ReportProgress(0, e.Message);
                w.ReportProgress(6, CheckState.Unchecked);
            }

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox7.Text + "...");
            //string admins = MachineInfo.getGroupMembers(machine, "administrators", null, null, false, false, parent == null ? "" : parent.adminsBox.Text);
            string admins = MachineInfo.getGroupMembers(machine, "administrators", null, null, false, false, AuditSec.defaultAdmins);

            w.ReportProgress(0, "Administrators: " + (admins == null ? "none" : admins.TrimEnd('\n').Replace("\n", ", ")));
            bool s1 = false, s2 = false;

            if (admins != null)
            {
                foreach (string u in admins.Split(new Char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    string user = u.Trim().ToUpper();
                    if (user.ToUpper().StartsWith("MYCOMPANY\\"))
                    {
                        s1 = true;
                    }
                    if (user.ToUpper().EndsWith("\\DOMAIN ADMINS"))
                    {
                        s2 = true;
                    }
                }
            }
            w.ReportProgress(7, s1 && s2 ?
                             CheckState.Checked : CheckState.Unchecked);

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox8.Text + "...");
            string freedisk = MachineInfo.getGB(machine);

            w.ReportProgress(8, freedisk != null ?
                             CheckState.Checked : CheckState.Unchecked);
            string users = MachineInfo.getCurrentUsers(machine);

            w.ReportProgress(0, "Currently logged users: " + (users == null ? "none." : users.TrimEnd('\n').Replace("\n", ", ")));

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox9.Text + "...");
            if (freedisk != null)
            {
                try
                {
                    w.ReportProgress(0, freedisk.Replace("\n", ""));
                    string f = freedisk.Replace("C: has ", "");
                    f = f.Substring(0, f.IndexOf("GB"));
                    w.ReportProgress(9, float.Parse(freedisk != null ? f.Trim() : "0") >= 5 ?
                                     CheckState.Checked : CheckState.Unchecked);
                }
                catch (Exception e)
                {
                    w.ReportProgress(0, freedisk.Replace("\n", "") + "---" + e.Message);
                }
            }
            else
            {
                w.ReportProgress(0, "The free disk space information is not available.");
                w.ReportProgress(9, CheckState.Unchecked);
            }

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox10.Text + "...");
            try
            {
                bool remregrun = MachineInfo.isServiceRunning(machine, "RemoteRegistry");
                if (!remregrun)
                {
                    MachineInfo.StartService(machine, "RemoteRegistry", 30000);
                }
                if (MachineInfo.isServiceRunning(machine, "RemoteRegistry"))
                {
                    RegistryKey HKLM = null;
                    bool        rrok = (HKLM = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, machine)) != null;
                    w.ReportProgress(10, rrok ?
                                     CheckState.Checked : CheckState.Unchecked);
                }
                else
                {
                    w.ReportProgress(10, CheckState.Unchecked);
                }
                if (!remregrun)
                {
                    MachineInfo.StopService(machine, "RemoteRegistry", 30000);
                }
            }
            catch (Exception e)
            {
                w.ReportProgress(0, e.Message);
                w.ReportProgress(10, CheckState.Unchecked);
            }

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox11.Text + "...");
            try
            {
                w.ReportProgress(11, Directory.Exists(@"\\" + machine + @"\admin$\system32\ccmsetup") ?
                                 CheckState.Checked : CheckState.Unchecked);
            }
            catch (Exception e)
            {
                w.ReportProgress(0, e.Message);
            }


            w.ReportProgress(0, "\r\n\r\nInstallation Phase");
            w.ReportProgress(0, "================================================================================");

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox12.Text + "...");
            w.ReportProgress(12, MachineInfo.isServicePresent(machine, "ccmsetup") &&
                             (MachineInfo.isServiceRunning(machine, "ccmsetup") ||
                              MachineInfo.StartService(machine, "ccmsetup", 30000)) ?
                             CheckState.Checked : CheckState.Unchecked);

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox13.Text + "...");
            w.ReportProgress(13, MachineInfo.isServicePresent(machine, "msiserver") &&
                             (MachineInfo.isServiceRunning(machine, "msiserver") ||
                              MachineInfo.StartService(machine, "msiserver", 30000)) ?
                             CheckState.Checked : CheckState.Unchecked);

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox14.Text + "...");
            w.ReportProgress(14, MachineInfo.isServicePresent(machine, "LanmanServer") &&
                             (MachineInfo.isServiceRunning(machine, "LanmanServer") ||
                              MachineInfo.StartService(machine, "LanmanServer", 30000)) ?
                             CheckState.Checked : CheckState.Unchecked);

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox15.Text + "...");
            w.ReportProgress(15, MachineInfo.isServicePresent(machine, "BITS") &&
                             (MachineInfo.isServiceRunning(machine, "BITS") ||
                              MachineInfo.StartService(machine, "BITS", 30000)) ?
                             CheckState.Checked : CheckState.Unchecked);

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox16.Text + "...");
            try
            {
                f16 = @"\\" + machine + @"\admin$\system32\ccmsetup\ccmsetup.log";
                f17 = @"\\" + machine + @"\admin$\system32\ccmsetup\client.msi.log";
                bool     f16e = File.Exists(f16);
                bool     f17e = File.Exists(f17);
                DateTime f16d = f16e ? File.GetLastWriteTime(f16) : new DateTime();
                DateTime f17d = f17e ? File.GetLastWriteTime(f17) : new DateTime();
                w.ReportProgress(16, new Object[] {
                    f16e&& f17e?CheckState.Checked: CheckState.Unchecked,
                    f16d, f17d
                });
                if (!f16e)
                {
                    w.ReportProgress(0, "ccmsetup.log not found!");
                }
                if (!f17e)
                {
                    w.ReportProgress(0, "client.msi.log not found!");
                }
            }
            catch (Exception e)
            {
                w.ReportProgress(0, e.Message);
            }

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox17.Text + "...");
            try
            {
                w.ReportProgress(17, Directory.Exists(@"\\" + machine + @"\admin$\system32\CCM") ?
                                 CheckState.Checked : CheckState.Unchecked);
            }
            catch (Exception e)
            {
                w.ReportProgress(0, e.Message);
            }



            w.ReportProgress(0, "\r\n\r\nPost-Installation Phase");
            w.ReportProgress(0, "================================================================================");

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox18.Text + "...");
            w.ReportProgress(18, MachineInfo.isServicePresent(machine, "CcmExec") &&
                             (MachineInfo.isServiceRunning(machine, "CcmExec") ||
                              MachineInfo.StartService(machine, "CcmExec", 30000)) ?
                             CheckState.Checked : CheckState.Unchecked);

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox19.Text + "...");
            MachineInfo.refreshManagementPoint(machine,
                                               report => { w.ReportProgress(0, report); return(true); },
                                               (check, MP) => { w.ReportProgress(19, new Object[] { check?CheckState.Checked: CheckState.Unchecked, MP }); return(true); });

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox20.Text + "...");
            MachineInfo.enableSMSAutoAssignment(machine,
                                                report => { w.ReportProgress(0, report); return(true); },
                                                (check, site) => { w.ReportProgress(20, new Object[] { check?CheckState.Checked: CheckState.Unchecked, site }); return(true); });

            if (w.CancellationPending)
            {
                return;
            }
            w.ReportProgress(0, "\r\nChecking: " + checkBox21.Text + "...");
            string21 = MachineInfo.getSMSComponents(machine,
                                                    report => { w.ReportProgress(0, report); return(true); },
                                                    check => { w.ReportProgress(21, check ? CheckState.Checked : CheckState.Unchecked); return(true); });



            w.ReportProgress(22, true);
            w.ReportProgress(23, true);
            w.ReportProgress(24, true);
            w.ReportProgress(25, true);
            w.ReportProgress(26, true);
            w.ReportProgress(27, true);
            w.ReportProgress(28, true);
            w.ReportProgress(29, true);

            w.ReportProgress(0, "");
            w.ReportProgress(0, "Final Client Health Check not implemented. Do it locally/remotely please.");
            w.ReportProgress(0, "================================================================================");
            w.ReportProgress(0, "All checks performed.");
            w.ReportProgress(0, "Computer description: " + description);
            w.ReportProgress(0, "Currently logged users: " + (users == null ? "none." : users.TrimEnd('\n').Replace("\n", ", ")));

            Cursor.Current = Cursors.Default;

            MessageBox.Show("Do it locally/remotely please.\n"
                            + "\nComputer description: " + description
                            + "\nCurrently logged users: " + (users == null ? "none." : users.TrimEnd('\n').Replace("\n", ", ")),
                            "Final Client Health Check");
            return;
        }
예제 #4
0
        private void lockedAccountTimer_Tick(object sender, EventArgs e)
        {
            statusLabel.Text = "Checking " + usersInfo.getUsersCount() + " user" + (usersInfo.getUsersCount() > 1 ? "s" : "") + "...";
            speak("Account checking...");
            //if (!running) return;
            foreach (Control control in actionsPanel.Controls)
            {
                if (control is Panel && ((Panel)control).Controls.Count > 0 && ((Panel)control).Controls[0] is Button)
                {
                    Panel  panel  = control as Panel;
                    Button button = ((Panel)control).Controls[0] as Button;
                    if (button.Text.StartsWith("UNLOCK"))
                    {
                        string desc     = button.Text.Split(new char[] { ':', '\'' })[1].Trim();
                        string user     = usersInfo.getUsernameFromDisplayname(desc);
                        bool   unlocked = UsersInfo.isUnlockedAD(usersInfo.getDirectoryentryFromUsername(user));
                        if (unlocked)
                        {
                            Invoke(new removeActionDelegate(removeAction), new Object[] { panel });
                        }
                    }
                    else if (button.Text.StartsWith("EXPIRING"))
                    {
                        string desc     = button.Text.Split(new char[] { ':', '\'' })[1].Trim();
                        string user     = usersInfo.getUsernameFromDisplayname(desc);
                        int    days     = UsersInfo.daysToExpiration(usersInfo.getDirectoryentryFromUsername(user), MAXDAYS);
                        bool   expiring = days < ALARMDAYS && days >= 0;
                        if (!expiring)
                        {
                            Invoke(new removeActionDelegate(removeAction), new Object[] { panel });
                        }
                    }
                }
            }
            int users_count = usersInfo.getUsersCount();

            var expiring_u = usersInfo.getExpiringUsers(MAXDAYS, ALARMDAYS).ToList().OrderByDescending(o => (int)o[1]).Select(o => new
            {
                days          = (int)o[1],
                user          = (string)o[0],
                desc          = usersInfo.getDisplaynameFromUsername((string)o[0]),
                decentralized = usersInfo.getDecentralizedFromUsername((string)o[0]),
                external      = usersInfo.getDirectoryentryFromUsername((string)o[0]).Path.ToUpper().Contains("OU=EXTERNAL,"),
                //de = usersInfo.getDirectoryentryFromUsername((string)o[0]).Path
            }).ToList(); foreach (var o in expiring_u)
            {
                if (SHOW_EXTERNAL || !o.external)
                {
                    actions.Insert(0, new Object[] { "EXPIRING: " + o.desc + "'s password is "
                                                     + (o.days == 0 ? "expired" : "expiring in " + o.days + " day" + (o.days > 1 ? "s" : ""))
                                                     + (o.decentralized || o.external ? "\n***" : "") + (o.decentralized ? " DECENTRALIZED" : "") + (o.external ? " EXTERNAL" : "") + (o.decentralized || o.external ? " ***" : ""),
                                                     "EXPIRING", o.user, o.decentralized, null });
                }
            }

            var locked_u = usersInfo.getLockedUsers().ToList().Select(u => new
            {
                user          = u,
                desc          = usersInfo.getDisplaynameFromUsername(u),
                decentralized = usersInfo.getDecentralizedFromUsername(u),
                external      = usersInfo.getDirectoryentryFromUsername(u).Path.ToUpper().Contains("/EXTERNAL")
            }).ToList(); foreach (var o in locked_u)

            {
                if (SHOW_EXTERNAL || !o.external)

                {
                    actions.Insert(0, new Object[] { "UNLOCK: " + o.desc + "'s account is locked"
                                                     + (o.decentralized || o.external ? "\n***" : "") + (o.decentralized ? " DECENTRALIZED" : "") + (o.external ? " EXTERNAL" : "") + (o.decentralized || o.external ? " ***" : ""),
                                                     "UNLOCK", o.user, o.decentralized, null });
                }
            }

            statusLabel.Text = "Check completed: " + users_count + " user" + (users_count > 1 ? "s" : "") + " verified. Locked: " + locked_u.Count + ". Expiring: " + expiring_u.Count + ".";
            int actions_count = locked_u.Count + expiring_u.Count;

            speak("Check completed. There are " + actions_count + " user" + (actions_count > 1 ? "s" : "") + " to look at, "
                  + locked_u.Count + (locked_u.Count > 1 ? " are " : " is ") + "locked and " + expiring_u.Count + (expiring_u.Count > 1 ? " are " : " is ") + "expiring.");
            Console.WriteLine("Timer getting job done!");
        }