Example #1
0
        private void btnGrantRights_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtUserID.Text))
            {
                Util.MsgBox.Info("User ID cannot be blank when granting rights.");
                return;
            }

            user.UserID = txtUserID.Text.Trim(); //Update UserID in case user has changed it.
            ToggleRadioControls(false);
            ToggleButtonsOnOff(false);

            try
            {
                adTasksGrant = new AdTasks(targ);
                //If Production environment query Active Directory
                //for user's full name and verify the ID exists.
                if (isProdEnv)
                {
                    adTasksGrant.FindUserActiveD();
                    if (!user.UserIDExists) //User not found in AD, cannot proceed.
                    {
                        StatusReport(2);    //cancelling...
                        return;
                    }
                }
                //Found user in AD, let's see if they already have
                //admin rights on the host machine.
                adTasksGrant.CheckExistingRights(false, false);
                remoteTasksGrant = new RemoteTasks(targ);
            }
            catch (Exception)
            {
                ClearForm(false);
                return;
            }


            bool result = MsgBoxConfirmRights();

            if (result)
            {
                if (!user.AdminRightsExist)
                {
                    adTasksGrant.GrantRights(timeSpan);       //Add user to the Administrators group on Host.
                }
                remoteTasksGrant.CreateRemovalTask(timeSpan); //Create Scheduled task to remove rights.
                eventLogs.LogAction(timeSpan, AdTasks.ADD);   //Create a log file
                StatusReport(1);
                CopyToClipboard();                            //Attempts to copy contents of txtConsole to clipboard.
            }
            else
            {
                StatusReport(2); //cancelling...
            }
            ToggleRadioControls(true);
            ToggleButtonsAndHostIP(true, true);
            ToggleButtonsOnOff(true);
            ClearForm(false);
        }
Example #2
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            connection.HostIP = txtIP.Text.Trim();
            Util.ConnectionTest.TestWmi(targDev);
            int cmdChoice = comboBox2.SelectedIndex;

            var         execute = (Command)cmdChoice;
            RemoteTasks r;
            AdTasks     ad;

            string[] vpnScope =
            {
                "10.40.244", "10.32.244",
                "10.40.245", "10.32.245",
                "10.40.246", "10.32.246"
            };

            bool isVpn = vpnScope.Any(s => txtIP.Text.Contains(s));

            Cursor.Current = Cursors.WaitCursor;

            switch (execute)
            {
            case Command.RightsExist:

                #region Check for Exsisting Rights (Script)

                user.AdminRightsExist = false;
                if (txtIP.Text == string.Empty || txtUser.Text == string.Empty)
                {
                    MessageBox.Show("IP & ID Cannot be blank");
                }
                else if (Util.ConnectionTest.IsHostAlive(txtIP.Text))
                {
                    user.UserID       = txtUser.Text;
                    connection.HostIP = txtIP.Text;

                    ad = new AdTasks(targDev);
                    connection.IsWmiActive = false;     //DevTools Only
                    ad.CheckLocale();
                    ad.CheckExistingRights(NoComboAdd, DevOutputFalse);

                    targDev.mainForm.WriteToConsole(user.AdminRightsExist ? "Rights Exist." : "Rights DO NOT Exist.");
                }

                #endregion

                break;

            case Command.RightsExistWmi:

                #region Check for Existing Rights(WMI)

                user.AdminRightsExist = false;
                if (txtIP.Text == string.Empty || txtUser.Text == string.Empty)
                {
                    MessageBox.Show("IP & ID Cannot be blank");
                }
                else if (Util.ConnectionTest.IsHostAlive(txtIP.Text))
                {
                    if (isVpn)
                    {
                        MessageBox.Show("Fuction does not work with VPN clients.");
                        return;
                    }

                    user.UserID       = txtUser.Text;
                    connection.HostIP = txtIP.Text;

                    ad = new AdTasks(targDev);
                    r  = new RemoteTasks(targDev);

                    r.GetHostInfo();
                    ad.CheckLocale();
                    ad.CheckExistingRights(NoComboAdd, DevOutputFalse);


                    targDev.mainForm.WriteToConsole(user.AdminRightsExist ? "Rights Exist." : "Rights DO NOT Exist.");
                }
                else
                {
                    MessageBox.Show("Host is not Online.");
                }

                #endregion

                break;

            case Command.UserExists:

                #region Check if User Esists in AD

                if (Util.ValidationCheck.isTestEnvironment())
                {
                    MessageBox.Show("Function does not work in TEST Environment");
                    return;
                }
                if (txtUser.Text == string.Empty)
                {
                    MessageBox.Show("IP & ID Cannot be blank");
                }
                else
                {
                    user.UserID = txtUser.Text;

                    ad = new AdTasks(targDev);
                    ad.FindUserActiveD();
                }

                #endregion

                break;

            case Command.ListAdmins:

                #region List all Admins on Host

                if (txtIP.Text == string.Empty)
                {
                    MessageBox.Show("IP cannot be blank");
                }
                else
                {
                    connection.HostIP      = txtIP.Text;
                    connection.IsWmiActive = false;     //DevTools Only
                    ad = new AdTasks(targDev);
                    ad.CheckLocale();
                    ad.CheckExistingRights(NoComboAdd, DevOutputTrue);
                }

                #endregion

                break;

            case Command.ListAdminsWmi:

                #region List all Admins on Host(WMI)

                if (txtIP.Text == string.Empty)
                {
                    MessageBox.Show("IP cannot be blank");
                }
                else
                {
                    if (isVpn)
                    {
                        MessageBox.Show("Fuction does not work with VPN clients.");
                        return;
                    }
                    connection.HostIP = txtIP.Text;

                    ad = new AdTasks(targDev);
                    r  = new RemoteTasks(targDev);
                    ad.CheckLocale();
                    r.GetHostInfo();
                    ad.CheckExistingRights(NoComboAdd, DevOutputTrue);
                }

                #endregion

                break;

            case Command.AddTestAdmins:

                //To use create a file named AddAdmin.bat in the System32 dir.
                //add a line for each user you want to add admin rights for
                //ex. NET LOCALGROUP ADMINISTRATORS {USERID} /ADD
                #region Add Test Admins
                if (!File.Exists(@"c:\windows\system32\AddAdmin.bat"))
                {
                    MessageBox.Show(@"File ""AddAdmin.bat"" does not exist.");
                }
                else
                {
                    const string args = "/c AddAdmin.bat";
                    Util.Tools.RunProcess(args, false);
                    MessageBox.Show("--Added test users--");
                }

                #endregion

                break;

            case Command.GetInfoByScripts:

                #region Get Info By Scripts

                if (txtIP.Text == string.Empty)
                {
                    MessageBox.Show("IP cannot be blank.");
                }
                else
                {
                    connection.HostIP = txtIP.Text;

                    r = new RemoteTasks(targDev);
                    r.GetHostInfo(DevOutputTrue);

                    targDev.mainForm.WriteToConsole(string.Format(
                                                        "==========================={0}" +
                                                        "GetInfoByScripts{0}" +
                                                        "==========================={0}" +
                                                        "Current User: {1}{0}" +
                                                        "Computer Name: {2}{0}" +
                                                        "Local Time: {3}{0}" +
                                                        "===========================",
                                                        Environment.NewLine,
                                                        user.CurrentUser,
                                                        connection.HostName,
                                                        targDev.host.removalTask.HostTime));
                }

                #endregion

                break;

            case Command.GetInfoByWmi:

                #region Get Info By WMI

                if (txtIP.Text == string.Empty)
                {
                    MessageBox.Show("IP cannot be blank.");
                }
                else
                {
                    if (isVpn)
                    {
                        MessageBox.Show("Fuction does not work with VPN clients.");
                        return;
                    }

                    connection.HostIP = txtIP.Text;
                    r = new RemoteTasks(targDev);
                    r.GetHostInfo(DevOutputTrue);
                    targDev.mainForm.WriteToConsole(string.Format(
                                                        "==========================={0}" +
                                                        "GetInfoByWMI{0}" +
                                                        "==========================={0}" +
                                                        "Current User: {1}{0}" +
                                                        "Computer Name: {2}{0}" +
                                                        "Local Time: {3}{0}" +
                                                        "===========================",
                                                        Environment.NewLine,
                                                        user.CurrentUser,
                                                        connection.HostName,
                                                        targDev.host.removalTask.HostTime));
                }

                #endregion

                break;
            }

            Cursor.Current = Cursors.Default;
        }