Exemplo n.º 1
0
        private bool execADCmd()
        {
            bool Disabled = (!cbEnabled.Checked);

            if (adHelper.OU != tbOU.Text)
            {
                adHelper.OU = tbOU.Text.Trim();
            }
            ADUserDetail user = new ADUserDetail(tbUser.Text, Disabled, tbFirst.Text, tbLast.Text, tbEmail.Text, tbPwd.Text);
            string       cmd  = (string)cbCommand.SelectedItem;
            string       err  = "";

            switch (cmd.ToLower())
            {
            case "add":
                adHelper.AddUserByLogin(user, ref err);
                break;

            case "delete":
                adHelper.DeleteUserByLogin(user, ref err);
                break;

            case "disable":
                adHelper.DisableUserByLogin(user, ref err);
                break;

            case "enable":
                adHelper.EnableUserByLogin(user, ref err);
                break;

            case "import":
                break;

            case "update":
                adHelper.UpdateUserByLogin(user, false, ref err);
                break;

            case "list":
                List <ADUserDetail> userList = adHelper.GetUsers();
                if (userList.Count <= 0)
                {
                    rtbMsg.AppendText("No users found.");
                    return(false);
                }
                foreach (ADUserDetail u in userList)
                {
                    rtbMsg.AppendText("Username: "******", Disabled=" + u.AccountDisabled.ToString() + ", FirstName=" + u.FirstName + ",LastName=" + u.LastName + ", Email=" + u.EmailAddress + "\r\n");
                    rtbMsg.AppendText("===================================================================================================================\r\n");
                }
                break;

            default:
                MessageBox.Show("Unknown command.");
                return(false);
            }

            rtbMsg.AppendText("Successfully completed " + cmd + "!");
            return(true);
        }
Exemplo n.º 2
0
        private void ProcessRequest(object o)
        {
            bool             logErr = false;
            bool             fatal  = false;
            bool             status = false;
            string           err    = "";
            ADUserDetail     adUser = null;
            UserManagerEvent e      = o as UserManagerEvent;

            if (e == null)
            {
                err = "ProcessRequest, UserManagerEvent argument is empty, OU " + m_OU_Filter;
                int Event_id = 6012;
                EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category);
            }

            if (e.UserId <= 0)
            {
                e.UserId = 0;
            }

            if (e.RequestType == Common.UserMgrCommandType.Unknown)
            {
                err = "UserManagerEvent RequestType is Unknown, ReqType=" + e.RequestType;
                int Event_id = 6014;
                EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category);
            }
            if (e.RequestId <= 0)
            {
                err = "UserManagerEvent RequestId is invalid, RequestId=" + e.RequestId.ToString();
                int Event_id = 6015;
                EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category);
            }
            try
            {
                if ((e.RequestType != Common.UserMgrCommandType.ImportUsers) &&
                    (e.RequestType != Common.UserMgrCommandType.StartImport) &&
                    (e.RequestType != Common.UserMgrCommandType.StopImport))
                {
                    if (e.ADUser == null)
                    {
                        err = "Received invalid UserManagerEvent RequestType, ReqType=" + e.RequestType + ", OU=" + m_OU_Filter;
                        int Event_id = 6016;
                        EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category);
                    }

                    adUser = new ADUserDetail(e.ADUser.Username, !e.ADUser.Enabled, e.ADUser.Firstname, e.ADUser.Lastname, e.ADUser.Email, e.ADUser.Password);
                }
                if (SetUpADHelper(ref err) == false)
                {
                    int Event_id = 6017;
                    EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category);
                }
                switch (e.RequestType)
                {
                case Common.UserMgrCommandType.CreateUser:
                    status = m_adHelper.AddUserByLogin(adUser, false, ref err);
                    break;

                case Common.UserMgrCommandType.DeleteUser:
                    status = m_adHelper.DeleteUserByLogin(adUser, ref err);
                    break;

                case Common.UserMgrCommandType.DisableUser:
                    status = m_adHelper.DisableUserByLogin(adUser, ref err);
                    break;

                case Common.UserMgrCommandType.EnableUser:
                    status = m_adHelper.EnableUserByLogin(adUser, ref err);
                    break;

                case Common.UserMgrCommandType.ImportUsers:
                    status = ImportADUsers(e.UserId, e.RequestId, ref err);
                    break;

                case Common.UserMgrCommandType.StartImport:
                    //status = StartImport();
                    break;

                case Common.UserMgrCommandType.StopImport:
                    //status = StopImport();
                    break;
                }
                if (status == false)
                {
                    int Event_id = 6018;
                    EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category);
                }
            }
            catch (Exception ex)
            {
                err = "Failed to  " + e.RequestType.ToString() + ", OU " + m_OU_Filter + ", Exception:" + ex.Message;
                int Event_id = 6019;
                EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category);
            }
            finally
            {
                if (logErr)
                {
                    int Event_id = 6020;
                    EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category);
                }
                string errMsg = "";
                UpdateRequest(e.UserId, e.RequestId, e.RequestType, status, err, ref errMsg);
            }
        }