Ejemplo n.º 1
0
        protected void btnSave_Click(Object Sender, EventArgs e)
        {
            int intResourceWorkflow = Int32.Parse(lblResourceWorkflow.Text);
            int intResourceParent   = oResourceRequest.GetWorkflowParent(intResourceWorkflow);

            oResourceRequest.UpdateWorkflowName(intResourceWorkflow, txtCustom.Text, intProfile);
            ds = oResourceRequest.Get(intResourceParent);
            int    intRequest = Int32.Parse(ds.Tables[0].Rows[0]["requestid"].ToString());
            int    intItem    = Int32.Parse(ds.Tables[0].Rows[0]["itemid"].ToString());
            int    intStatus  = Int32.Parse(oResourceRequest.GetWorkflow(intResourceWorkflow, "status"));
            double dblHours   = double.Parse(lblUsed.Text);
            double dblTime    = 5.00 / 60.00;

            foreach (RepeaterItem ri in rptView.Items)
            {
                CheckBox chkDelete = (CheckBox)ri.FindControl("chkDelete");
                if (chkDelete.Checked == true)
                {
                    Label          lblId          = (Label)ri.FindControl("lblId");
                    Label          lblPath        = (Label)ri.FindControl("lblPath");
                    Label          lblEnvironment = (Label)ri.FindControl("lblEnvironment");
                    Variables      oVariable      = new Variables(Int32.Parse(lblEnvironment.Text));
                    DirectoryEntry oEntry         = new DirectoryEntry(lblPath.Text, oVariable.Domain() + "\\" + oVariable.ADUser(), oVariable.ADPassword());
                    AD             oAD            = new AD(intProfile, dsn, Int32.Parse(lblEnvironment.Text));
                    if (oAD.Exists(oEntry))
                    {
                        oAD.Enable(oEntry, false);
                    }
                    dblHours += dblTime;
                    oADObject.UpdateDomainAccount(Int32.Parse(lblId.Text), intProfile);
                }
            }
            // Delete objects over a month old
            ds = oADObject.GetDomainAccountsDisabled(DateTime.Today.AddMonths(-1));
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                int            _environment = Int32.Parse(dr["environment"].ToString());
                Variables      oVariable    = new Variables(_environment);
                DirectoryEntry oEntry       = new DirectoryEntry(dr["path"].ToString(), oVariable.Domain() + "\\" + oVariable.ADUser(), oVariable.ADPassword());
                AD             oAD          = new AD(intProfile, dsn, _environment);
                if (oAD.Exists(oEntry) && oAD.IsDisabled(oEntry) == true)
                {
                    oAD.Delete(oEntry);
                    oADObject.UpdateDomainAccountDisabled(Int32.Parse(dr["adid"].ToString()), -1);
                }
                else
                {
                    oADObject.UpdateDomainAccountDisabled(Int32.Parse(dr["adid"].ToString()), -10);
                }
            }
            double dblTotal = double.Parse(oResourceRequest.GetWorkflow(intResourceWorkflow, "allocated"));
            double dblUsed  = oResourceRequest.GetWorkflowUsed(intResourceWorkflow);

            dblHours = (dblHours - dblUsed);
            if (dblHours > 0.00)
            {
                oResourceRequest.UpdateWorkflowHours(intResourceWorkflow, dblHours);
            }
            Response.Redirect(Request.Path + "?rrid=" + intResourceWorkflow.ToString() + "&save=true");
        }
        protected void btnApprove_Click(Object Sender, EventArgs e)
        {
            oResourceRequest.UpdateWorkflowHours(intResourceWorkflow);
            DataSet ds             = oAccountRequest.GetMaintenance(intRequest, intItem, intNumber);
            int     intUser        = oRequest.GetUser(intRequest);
            DataSet dsParameters   = oAccountRequest.GetMaintenanceParameters(intRequest, intItem, intNumber);
            string  strMaintenance = ds.Tables[0].Rows[0]["maintenance"].ToString();
            string  strUser        = ds.Tables[0].Rows[0]["username"].ToString();
            int     intDomain      = Int32.Parse(ds.Tables[0].Rows[0]["domain"].ToString());
            Domains oDomain        = new Domains(intProfile, dsn);

            intDomain = Int32.Parse(oDomain.Get(intDomain, "environment"));
            AD             oAD       = new AD(intProfile, dsn, intDomain);
            Variables      oVariable = new Variables(intDomain);
            DirectoryEntry oEntry    = oAD.UserSearch(strUser);

            if (oEntry != null)
            {
                switch (strMaintenance)
                {
                case "DISABLE":
                    // Account Disable
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Disable", oAD.Enable(oEntry, false), "Account " + strUser + " was successfully disabled", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "UNLOCK":
                    // Account Unlock
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Unlock", oAD.Unlock(oEntry), "Account " + strUser + " was successfully unlocked", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "ENABLE":
                    // Account Enable
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Enable", oAD.Enable(oEntry, true), "Account " + strUser + " was successfully enabled", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "EMAIL":
                    // Account Email
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Email", oAD.CreateMailbox(oEntry), "Account " + strUser + " was successfully created a mailbox", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "MOVE":
                    // Account Move
                    string strPath = dsParameters.Tables[0].Rows[0]["value"].ToString();
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Move", oAD.MoveAccount(oEntry, strPath), "Account " + strUser + " was successfully moved", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "PASSWORD":
                    // Account Password Change
                    Encryption oEncrypt    = new Encryption();
                    string     strPassword = dsParameters.Tables[0].Rows[0]["value"].ToString();
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Password Change", oAD.SetPassword(oEntry, oEncrypt.Decrypt(strPassword, "adpass")), "The password for account " + strUser + " was successfully changed", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "COPY":
                    // Account Copy
                    string strID    = txtID.Text;
                    string strFirst = txtFirst.Text;
                    string strLast  = txtLast.Text;
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Copy", oAD.CreateUser(strID, strFirst, strLast, txtPassword.Text, "", "Created by ClearView - " + DateTime.Now.ToShortDateString(), oVariable.UserOU()), "Account " + strUser + " was successfully copied", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    foreach (ListItem oList in chkGroups.Items)
                    {
                        if (oList.Selected == true)
                        {
                            oRequest.AddResult(intRequest, intItem, intNumber, "Group Membership", oAD.JoinGroup(strID, oList.Value, 0), "Account " + strUser + " was successfully added to the group " + oList.Value, intEnvironment, (oService.Get(intService, "notify_client") == "1"), "");
                        }
                    }
                    break;

                case "DELETE":
                    // Account Deletion
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Deletion", oAD.Delete(oEntry), "Account " + strUser + " was successfully deleted", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "RENAME":
                    // Account Rename
                    string strI = txtID.Text;
                    string strF = txtFirst.Text;
                    string strL = txtLast.Text;
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Rename", oAD.Rename(oEntry, strI, strF, strL), "Account " + strUser + " was successfully renamed", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;
                }
            }
            oAccountRequest.UpdateMaintenance(intRequest, intItem, intNumber, 1, txtComments.Text);
            Complete();
        }
Ejemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            RequestItems    oRequestItem    = new RequestItems(intProfile, dsn);
            RequestFields   oRequestField   = new RequestFields(intProfile, dsn);
            ServiceRequests oServiceRequest = new ServiceRequests(intProfile, dsn);
            Services        oService        = new Services(intProfile, dsn);
            int             intRequest      = Int32.Parse(Request.QueryString["rid"]);
            string          strStatus       = oServiceRequest.Get(intRequest, "checkout");
            DataSet         dsItems         = oRequestItem.GetForms(intRequest);
            int             intItem         = 0;
            int             intService      = 0;
            int             intNumber       = 0;

            if (dsItems.Tables[0].Rows.Count > 0)
            {
                bool boolBreak = false;
                foreach (DataRow drItem in dsItems.Tables[0].Rows)
                {
                    if (boolBreak == true)
                    {
                        break;
                    }
                    if (drItem["done"].ToString() == "0")
                    {
                        intItem    = Int32.Parse(drItem["itemid"].ToString());
                        intService = Int32.Parse(drItem["serviceid"].ToString());
                        intNumber  = Int32.Parse(drItem["number"].ToString());
                        boolBreak  = true;
                    }
                    if (intItem > 0 && (strStatus == "1" || strStatus == "2"))
                    {
                        bool          boolSuccess = true;
                        StringBuilder sbResult    = new StringBuilder(oService.GetName(intService) + " Completed");
                        StringBuilder sbError     = new StringBuilder(oService.GetName(intService) + " Error");

                        // ********* BEGIN PROCESSING **************
                        AccountRequest oAccountRequest = new AccountRequest(intProfile, dsn);
                        Requests       oRequest        = new Requests(intProfile, dsn);
                        Users          oUser           = new Users(intProfile, dsn);
                        DataSet        ds      = oAccountRequest.GetMaintenance(intRequest, intItem, intNumber);
                        Domains        oDomain = new Domains(intProfile, dsn);
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            string         strUser      = ds.Tables[0].Rows[0]["username"].ToString();
                            int            intDomain    = Int32.Parse(ds.Tables[0].Rows[0]["domain"].ToString());
                            int            intEnv       = Int32.Parse(oDomain.Get(intDomain, "environment"));
                            int            intUser      = oRequest.GetUser(intRequest);
                            DataSet        dsParameters = oAccountRequest.GetMaintenanceParameters(intRequest, intItem, intNumber);
                            AD             oAD          = new AD(intProfile, dsn, intEnv);
                            DirectoryEntry oEntry       = oAD.UserSearch(strUser);

                            if (oEntry == null)
                            {
                                sbResult = new StringBuilder();
                            }
                            else
                            {
                                sbError = new StringBuilder();

                                string strFirstOld = "";
                                if (oEntry.Properties.Contains("givenname") == true)
                                {
                                    strFirstOld = oEntry.Properties["givenname"].Value.ToString();
                                }
                                string strLastOld = "";
                                if (oEntry.Properties.Contains("sn") == true)
                                {
                                    strLastOld = oEntry.Properties["sn"].Value.ToString();
                                }
                                string strFirstNew        = dsParameters.Tables[0].Rows[0]["value"].ToString();
                                string strLastNew         = dsParameters.Tables[0].Rows[1]["value"].ToString();
                                string strEnable          = dsParameters.Tables[0].Rows[2]["value"].ToString();
                                string strUnlock          = dsParameters.Tables[0].Rows[3]["value"].ToString();
                                string strGroupsRequested = dsParameters.Tables[0].Rows[4]["value"].ToString();
                                if (strFirstOld != strFirstNew || strLastOld != strLastNew)
                                {
                                    if (strFirstOld != strFirstNew && strLastOld != strLastNew)
                                    {
                                        oEntry.Properties["givenname"].Value   = strFirstNew;
                                        oEntry.Properties["sn"].Value          = strLastNew;
                                        oEntry.Properties["displayname"].Value = strLastNew + ", " + strFirstNew;
                                        oEntry.CommitChanges();
                                        sbResult.Append("<p>The first name and last name for account ");
                                        sbResult.Append(strUser);
                                        sbResult.Append(" was successfully updated</p>");
                                    }
                                    else if (strFirstOld != strFirstNew)
                                    {
                                        oEntry.Properties["givenname"].Value   = strFirstNew;
                                        oEntry.Properties["displayname"].Value = strLastNew + ", " + strFirstNew;
                                        oEntry.CommitChanges();
                                        sbResult.Append("<p>The first name for account ");
                                        sbResult.Append(strUser);
                                        sbResult.Append(" was successfully updated</p>");
                                    }
                                    else
                                    {
                                        oEntry.Properties["sn"].Value          = strLastNew;
                                        oEntry.Properties["displayname"].Value = strLastNew + ", " + strFirstNew;
                                        oEntry.CommitChanges();
                                        sbResult.Append("<p>The last name for account ");
                                        sbResult.Append(strUser);
                                        sbResult.Append(" was successfully updated</p>");
                                    }
                                }
                                if (strEnable == "1")
                                {
                                    strEnable = oAD.Enable(oEntry, true);
                                    if (strEnable == "")
                                    {
                                        sbResult.Append("<p>The user account ");
                                        sbResult.Append(strUser);
                                        sbResult.Append(" was successfully enabled</p>");
                                    }
                                    else
                                    {
                                        sbError.Append("<p>The user account ");
                                        sbError.Append(strUser);
                                        sbError.Append(" was NOT successfully enabled</p>");
                                    }
                                }
                                if (strUnlock == "1")
                                {
                                    strUnlock = oAD.Unlock(oEntry);
                                    if (strUnlock == "")
                                    {
                                        sbResult.Append("<p>The user account ");
                                        sbResult.Append(strUser);
                                        sbResult.Append(" was successfully unlocked</p>");
                                    }
                                    else
                                    {
                                        sbError.Append("<p>The user account ");
                                        sbError.Append(strUser);
                                        sbError.Append(" was NOT successfully unlocked</p>");
                                    }
                                }

                                string   strGroupsExist = oAD.GetGroups(oEntry);
                                string[] strGroupRequested;
                                string[] strGroupExist;
                                char[]   strSplit = { ';' };
                                strGroupRequested = strGroupsRequested.Split(strSplit);
                                strGroupExist     = strGroupsExist.Split(strSplit);

                                // Add Groups
                                for (int ii = 0; ii < strGroupRequested.Length; ii++)
                                {
                                    if (strGroupRequested[ii].Trim() != "")
                                    {
                                        bool boolExist = false;
                                        for (int jj = 0; jj < strGroupExist.Length; jj++)
                                        {
                                            if (strGroupExist[jj].Trim() != "" && strGroupRequested[ii].Trim() == strGroupExist[jj].Trim())
                                            {
                                                boolExist = true;
                                                break;
                                            }
                                        }
                                        if (boolExist == false)
                                        {
                                            // Add the group
                                            string strJoin = oAD.JoinGroup(strUser, strGroupRequested[ii].Trim(), 0);
                                            if (strJoin == "")
                                            {
                                                sbResult.Append("<p>The user ");
                                                sbResult.Append(strUser);
                                                sbResult.Append(" was successfully joined to the group ");
                                                sbResult.Append(strGroupRequested[ii].Trim());
                                                sbResult.Append("</p>");
                                            }
                                            else
                                            {
                                                sbError.Append("<p>The user ");
                                                sbError.Append(strUser);
                                                sbError.Append(" was NOT successfully joined to the group ");
                                                sbError.Append(strGroupRequested[ii].Trim());
                                                sbError.Append(" : ");
                                                sbError.Append(strJoin);
                                                sbError.Append("</p>");
                                            }
                                        }
                                    }
                                }
                                // Remove Groups
                                for (int ii = 0; ii < strGroupExist.Length; ii++)
                                {
                                    if (strGroupExist[ii].Trim() != "")
                                    {
                                        bool boolExist = false;
                                        for (int jj = 0; jj < strGroupRequested.Length; jj++)
                                        {
                                            if (strGroupRequested[jj].Trim() != "" && strGroupExist[ii].Trim() == strGroupRequested[jj].Trim())
                                            {
                                                boolExist = true;
                                                break;
                                            }
                                        }
                                        if (boolExist == false)
                                        {
                                            // Remove the group
                                            string strJoin = oAD.RemoveGroup(strUser, strGroupExist[ii].Trim());
                                            if (strJoin == "")
                                            {
                                                sbResult.Append("<p>The user ");
                                                sbResult.Append(strUser);
                                                sbResult.Append(" was successfully removed from the group ");
                                                sbResult.Append(strGroupExist[ii].Trim());
                                                sbResult.Append("</p>");
                                            }
                                            else
                                            {
                                                sbError.Append("<p>The user ");
                                                sbError.Append(strUser);
                                                sbError.Append(" was NOT successfully removed from the group ");
                                                sbError.Append(strGroupExist[ii].Trim());
                                                sbError.Append(" : ");
                                                sbError.Append(strJoin);
                                                sbError.Append("</p>");
                                            }
                                        }
                                    }
                                }
                                oRequest.AddResult(intRequest, intItem, intNumber, "Account Modification", sbError.ToString(), sbResult.ToString(), intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                            }
                        }

                        if (sbResult.ToString() == "")
                        {
                            boolSuccess = false;
                        }

                        // ******** END PROCESSING **************
                        if (oService.Get(intService, "automate") == "1" && boolSuccess == true)
                        {
                            strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_check.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + sbResult.ToString() + "</td></tr></table>";
                        }
                        else
                        {
                            if (boolSuccess == false)
                            {
                                strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_error.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + sbError.ToString() + "</td></tr></table>";
                            }
                            else
                            {
                                strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_check.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + oService.GetName(intService) + " Submitted</td></tr></table>";
                            }
                        }
                        oRequestItem.UpdateFormDone(intRequest, intItem, intNumber, 1);
                    }
                }
            }
        }