Exemplo n.º 1
0
        protected void btnApprove_Click(Object Sender, EventArgs e)
        {
            oResourceRequest.UpdateWorkflowHours(intResourceWorkflow);
            DataSet ds             = oGroupRequest.GetMaintenance(intRequest, intItem, intNumber);
            int     intUser        = oRequest.GetUser(intRequest);
            DataSet dsParameters   = oGroupRequest.GetMaintenanceParameters(intRequest, intItem, intNumber);
            string  strMaintenance = ds.Tables[0].Rows[0]["maintenance"].ToString();
            string  strGroup       = ds.Tables[0].Rows[0]["name"].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.GroupSearch(strGroup);

            if (oEntry != null)
            {
                switch (strMaintenance)
                {
                case "MOVE":
                    // Group Move
                    string strPath = dsParameters.Tables[0].Rows[0]["value"].ToString();
                    oRequest.AddResult(intRequest, intItem, intNumber, "Group Move", oAD.MoveGroup(oEntry, strPath), "Group " + strGroup + " was successfully moved", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "COPY":
                    // Group Copy
                    string strID     = txtID.Text;
                    string strScope2 = dsParameters.Tables[0].Rows[1]["value"].ToString();
                    if (strScope2 == "Domain Local")
                    {
                        strScope2 = "DLG";
                    }
                    if (strScope2 == "Global")
                    {
                        strScope2 = "GG";
                    }
                    if (strScope2 == "Universal")
                    {
                        strScope2 = "UG";
                    }
                    string strType2 = dsParameters.Tables[0].Rows[2]["value"].ToString();
                    if (strType2 == "Security")
                    {
                        strType2 = "S";
                    }
                    if (strType2 == "Distribution")
                    {
                        strType2 = "D";
                    }
                    oRequest.AddResult(intRequest, intItem, intNumber, "Group Copy", oAD.CreateGroup(strID, "", "Created by ClearView - " + DateTime.Now.ToShortDateString(), oVariable.GroupOU(), strScope2, strType2), "Group " + strGroup + " was successfully copied", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    foreach (ListItem oList in chkUsers.Items)
                    {
                        if (oList.Selected == true)
                        {
                            oRequest.AddResult(intRequest, intItem, intNumber, "Group Membership", oAD.JoinGroup(oList.Value, strID, 0), "Account " + oList.Value + " was successfully added to the group " + strGroup, intEnvironment, (oService.Get(intService, "notify_client") == "1"), "");
                        }
                    }
                    break;

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

                case "RENAME":
                    // Group Rename
                    string strI = txtID.Text;
                    oRequest.AddResult(intRequest, intItem, intNumber, "Group Rename", oAD.Rename(oEntry, strI, "", ""), "Group " + strGroup + " was successfully renamed", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "CHANGE":
                    // Group Change
                    string strScope3 = dsParameters.Tables[0].Rows[0]["value"].ToString();
                    if (strScope3 == "Domain Local")
                    {
                        strScope3 = "DLG";
                    }
                    if (strScope3 == "Global")
                    {
                        strScope3 = "GG";
                    }
                    if (strScope3 == "Universal")
                    {
                        strScope3 = "UG";
                    }
                    string strType3 = dsParameters.Tables[0].Rows[1]["value"].ToString();
                    if (strType3 == "Security")
                    {
                        strType3 = "S";
                    }
                    if (strType3 == "Distribution")
                    {
                        strType3 = "D";
                    }
                    oRequest.AddResult(intRequest, intItem, intNumber, "Group Change", oAD.Change(oEntry, strScope3, strType3), "Group " + strGroup + " was successfully changed", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;
                }
            }
            else if (strMaintenance == "CREATE")
            {
                // Group Creation
                string strScope1 = dsParameters.Tables[0].Rows[0]["value"].ToString();
                if (strScope1 == "Domain Local")
                {
                    strScope1 = "DLG";
                }
                if (strScope1 == "Global")
                {
                    strScope1 = "GG";
                }
                if (strScope1 == "Universal")
                {
                    strScope1 = "UG";
                }
                string strType1 = dsParameters.Tables[0].Rows[1]["value"].ToString();
                if (strType1 == "Security")
                {
                    strType1 = "S";
                }
                if (strType1 == "Distribution")
                {
                    strType1 = "D";
                }
                oRequest.AddResult(intRequest, intItem, intNumber, "Group Creation", oAD.CreateGroup(txtID.Text, "", "Created by ClearView - " + DateTime.Now.ToShortDateString(), oVariable.GroupOU(), strScope1, strType1), "Group " + strGroup + " was successfully created", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
            }
            oGroupRequest.UpdateMaintenance(intRequest, intItem, intNumber, 1, txtComments.Text);
            Complete();
        }
Exemplo n.º 2
0
        public void Process(int _requestid, int _itemid, int _number, int _id, string _server, string _password, int _environment)
        {
            Requests  oRequest  = new Requests(user, dsn);
            Variables oVariable = new Variables(_environment);
            Users     oUser     = new Users(user, dsn);
            DataSet   ds        = Get(_id);

            if (ds.Tables[0].Rows.Count > 0)
            {
                DateTime _now      = DateTime.Now;
                string   strUnique = _now.Day.ToString() + _now.Month.ToString() + _now.Year.ToString() + _now.Hour.ToString() + _now.Minute.ToString() + _now.Second.ToString() + _now.Millisecond.ToString();
                string   strXID    = ds.Tables[0].Rows[0]["xid"].ToString().ToUpper();
                int      intUser   = oUser.GetId(strXID);
                int      intDomain = Int32.Parse(ds.Tables[0].Rows[0]["domain"].ToString());
                Domains  oDomain   = new Domains(user, dsn);
                if (oDomain.Get(intDomain, "account_setup") == "1" || oDomain.Get(intDomain, "account_maintenance") == "1")
                {
                    intDomain = Int32.Parse(oDomain.Get(intDomain, "environment"));
                    Variables oVar      = new Variables(intDomain);
                    AD        oAD       = new AD(user, dsn, intDomain);
                    string    strFName  = oUser.Get(intUser, "fname");
                    string    strLName  = oUser.Get(intUser, "lname");
                    string    strResult = "";
                    string    strID     = strXID;
                    string    strAction = "";
                    //string strNotify = "<p><a href=\"javascript:void(0);\" class=\"bold\" onclick=\"ShowAccountDetail('divAccount_" + strUnique + "');\">Account " + strXID.ToUpper() + " in " + oVar.Name() + "</a><br/>";
                    //strNotify += "<div id=\"divAccount_" + strUnique + "\" style=\"display:none\"><table cellpadding=\"2\" cellspacing=\"2\" border=\"0\" style=\"" + oVariable.DefaultFontStyle() + "\">";
                    string strNotify = "<p><table cellpadding=\"2\" cellspacing=\"2\" border=\"0\" style=\"" + oVariable.DefaultFontStyle() + "\">";
                    strNotify += "<tr><td><b><u>Account &quot;" + strXID.ToUpper() + "&quot; in " + oVar.Name() + "</u></b></td></tr>";
                    // Add User
                    if (intDomain != (int)CurrentEnvironment.CORPDMN && intDomain != (int)CurrentEnvironment.PNCNT_PROD)
                    {
                        strID = "E" + strID.Substring(1);
                        if (oAD.Search(strID, false) != null)
                        {
                            strAction = " already existed";
                        }
                        else
                        {
                            strID = "T" + strID.Substring(1);
                            if (oAD.Search(strID, false) != null)
                            {
                                strAction = " already existed";
                            }
                            else if (oDomain.Get(intDomain, "account_maintenance") == "1")
                            {
                                strResult = oAD.CreateUser(strID, strFName, strLName, _password, "", "Created by ClearView - " + DateTime.Now.ToShortDateString(), "");
                                strAction = " was created";
                            }
                            else
                            {
                                strResult = "Cannot create accounts in this domain";
                            }
                        }
                    }
                    else
                    {
                        if (oAD.Search(strID, false) != null)
                        {
                            strAction = " already existed";
                        }
                        else if (oDomain.Get(intDomain, "account_maintenance") == "1")
                        {
                            strResult = oAD.CreateUser(strID, strFName, strLName, _password, "", "Created by ClearView - " + DateTime.Now.ToShortDateString(), "");
                            strAction = " was created";
                        }
                        else
                        {
                            strResult = "Cannot create accounts in this domain";
                        }
                    }
                    if (strResult == "")
                    {
                        strNotify += "<tr><td>The account " + strID + strAction + " for " + strFName + " " + strLName + " in " + oVar.Name() + "</td></tr>";
                        // Local Groups
                        string strLocal = ds.Tables[0].Rows[0]["localgroups"].ToString();
                        if (strLocal != "")
                        {
                            string[] strGroups;
                            char[]   strSplit = { ';' };
                            strGroups = strLocal.Split(strSplit);
                            DirectoryEntry oAccount = new DirectoryEntry("WinNT://" + oVar.Domain() + "/" + strID + ",user", oVar.Domain() + "\\" + oVar.ADUser(), oVar.ADPassword());
                            DirectoryEntry oServer  = new DirectoryEntry("WinNT://" + oVar.Domain() + "/" + _server + ",computer", oVar.Domain() + "\\" + oVar.ADUser(), oVar.ADPassword());
                            for (int ii = 0; ii < strGroups.Length; ii++)
                            {
                                if (strGroups[ii].Trim() != "")
                                {
                                    try
                                    {
                                        DirectoryEntry oGroup = oServer.Children.Find(strGroups[ii]);
                                        oGroup.Invoke("Add", new object[] { oAccount.Path });
                                        strNotify += "<tr><td>The account " + strID + " was successfully added to the local group " + strGroups[ii] + "</td></tr>";
                                    }
                                    catch
                                    {
                                        strNotify += "<tr><td>There was a problem adding the account " + strID + " to the local group " + strGroups[ii] + "</td></tr>";
                                    }
                                }
                            }
                        }
                        // Global Groups
                        string strGlobal = ds.Tables[0].Rows[0]["adgroups"].ToString();
                        if (strGlobal != "")
                        {
                            string[] strGroups;
                            char[]   strSplit = { ';' };
                            strGroups = strGlobal.Split(strSplit);
                            for (int ii = 0; ii < strGroups.Length; ii++)
                            {
                                if (strGroups[ii].Trim() != "")
                                {
                                    if (oAD.Search(strGroups[ii], false) == null)
                                    {
                                        strResult = oAD.CreateGroup(strGroups[ii], "", "Created by ClearView - " + DateTime.Now.ToShortDateString(), "", "GG", "S");
                                        if (strResult == "")
                                        {
                                            strNotify += "<tr><td>The group " + strGroups[ii] + " was successfully created in " + oVar.Name() + "</td></tr>";
                                        }
                                        else
                                        {
                                            strNotify += "<tr><td>There was a problem creating the group " + strGroups[ii] + " in " + oVar.Name() + "</td></tr>";
                                        }
                                    }
                                    else
                                    {
                                        strResult  = "";
                                        strNotify += "<tr><td>The group " + strGroups[ii] + " already exists in " + oVar.Name() + "</td></tr>";
                                    }
                                    if (strResult == "")
                                    {
                                        strResult = oAD.JoinGroup(strID, strGroups[ii], 0);
                                        if (strResult == "")
                                        {
                                            strNotify += "<tr><td>The account " + strID + " was successfully added to the domain group " + strGroups[ii] + "</td></tr>";
                                        }
                                        else
                                        {
                                            strNotify += "<tr><td>There was a problem adding the account " + strID + " to the domain group " + strGroups[ii] + "</td></tr>";
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        strNotify += "<tr><td>There was a problem creating an account for " + strFName + " " + strLName + " in " + oVar.Name() + " - ERROR: " + strResult + "</td></tr>";
                    }
                    strNotify += "</table></p>";
                    //strNotify += "</table></div></p>";
                    Complete(_id);
                    oRequest.AddResult(_requestid, _itemid, _number, strNotify);
                }
            }
        }
Exemplo n.º 3
0
        private void ServiceTick()
        {
            try
            {
                string  strServer = Environment.MachineName;
                DataSet ds        = oWorkstation.GetRemoteVirtuals(strServer);
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int    intID          = Int32.Parse(dr["id"].ToString());
                    int    intEnvironment = Int32.Parse(dr["environment"].ToString());
                    string strINI         = @"\\citrixfile.ntl-city.com\flexcfg$\vwcfg\VW.INI";
                    if (intEnvironment != 4)
                    {
                        strINI = @"\\citrixfiletest.tstctr.ntl-city.net\flexcfg$\vwcfg\VW.INI";
                    }
                    string strImageScan = @"\\citrixfile.ntl-city.com\flexcfg$\vwcfg\BuildScripts\VWH_IMAGESCAN_SECURITY.vbs";
                    if (intEnvironment != 4)
                    {
                        strImageScan = @"\\citrixfiletest.tstctr.ntl-city.net\flexcfg$\vwcfg\BuildScripts\VWH_IMAGESCAN_SECURITY.vbs";
                    }
                    AD     oAD              = new AD(0, "", intEnvironment);
                    int    intAnswer        = Int32.Parse(dr["answerid"].ToString());
                    string strHost          = dr["hostname"].ToString();
                    string strVirtualDir    = dr["virtualdir"].ToString();
                    string strZipPath       = dr["gzippath"].ToString();
                    string strImage         = dr["image"].ToString();
                    string strName          = dr["name"].ToString();
                    string strSerial        = dr["serial"].ToString();
                    int    intStep          = Int32.Parse(dr["step"].ToString());
                    int    intRam           = Int32.Parse(dr["ram"].ToString());
                    string strManager       = dr["manager"].ToString();
                    string strGroupRemote   = "GSGu_WKS" + strName + "RemoteA";
                    string strGroupRemote2K = "GSGu_WKS" + strName + "Remote2K";
                    string strGroupAdmin    = "GSGu_WKS" + strName + "Adm";
                    string strGroupW        = "GSGw_" + strName;
                    string strResult        = "";
                    string strVBS           = strScripts + "scripts\\" + intID + ".vbs";
                    string strVBSImageScan  = strScripts + "scripts\\" + intID + "_imagescan.vbs";
                    bool   bool2000         = (strName.ToUpper().StartsWith("T2K") == true || strName.ToUpper().StartsWith("W2K") == true);
                    if (intStep > 0)
                    {
                        Type   typeVSClass           = typeof(VMVirtualServerClass);
                        Type   typeDCOM              = Type.GetTypeFromCLSID(typeVSClass.GUID, strHost, true);
                        object objDCOM               = Activator.CreateInstance(typeDCOM);
                        VMVirtualServerClass oServer = (VMVirtualServerClass)System.Runtime.InteropServices.Marshal.CreateWrapperOfType(objDCOM, typeVSClass);
                        switch (intStep)
                        {
                        case -1:
                            // Rebuild Workstation
                            if (intLogging > 0)
                            {
                                oLog.WriteEntry(String.Format("Starting rebuild of workstation " + strName), EventLogEntryType.Information);
                            }
                            VMVirtualMachine oMachineDown = oServer.FindVirtualMachine(strName);
                            if (oMachineDown.State != VMVMState.vmVMState_TurningOff && oMachineDown.State != VMVMState.vmVMState_TurnedOff)
                            {
                                oMachineDown.TurnOff();
                            }
                            if (oMachineDown.State == VMVMState.vmVMState_TurnedOff)
                            {
                                string strDirectory = strVirtualDir + "\\" + strName;
                                Directory.Delete(strDirectory);
                                oWorkstation.NextRemoteVirtual(intID);
                                oWorkstation.NextRemoteVirtual(intID);
                                oWorkstation.NextRemoteVirtual(intID);
                                oWorkstation.NextRemoteVirtual(intID);
                            }
                            break;

                        case 1:         // Step 1 - Selecting Host
                            // Should be taken care of when adding remote workstation
                            break;

                        case 2:         // Step 2 - Configuring Accounts
                            // User intervention required
                            break;

                        case 3:         // Step 3 - Initiating Build
                            if (Directory.Exists(strVirtualDir + "\\" + strName) == false)
                            {
                                Directory.CreateDirectory(strVirtualDir + "\\" + strName);
                            }
                            oWorkstation.NextRemoteVirtual(intID);
                            break;

                        case 4:         // Step 4 - Building VHD
                            if (strZipPath == "")
                            {
                                Zip oZip = new Zip();
                                oZip.ExtractZipFile(strImage, strVirtualDir + "\\" + strName);
                                oWorkstation.NextRemoteVirtual(intID);
                            }
                            else
                            {
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format("Starting step to create VHD for " + strName), EventLogEntryType.Information);
                                }
                                string strDirectory = strVirtualDir + "\\" + strName + "\\";
                                string strFile      = strDirectory + "DriveCXP.vhd";
                                if (bool2000 == true)
                                {
                                    strFile = strDirectory + "DriveC2K.vhd";
                                }
                                string strRename = strDirectory + "DriveCXP.rename";
                                if (bool2000 == true)
                                {
                                    strRename = strDirectory + "DriveC2K.rename";
                                }
                                if (Process.GetProcessesByName("gzip").GetLength(0) == 0)
                                {
                                    // GZIP not running - check to see if we have already extracted this file
                                    if (File.Exists(strFile))
                                    {
                                        // File exists - let's move on
                                        oWorkstation.NextRemoteVirtual(intID);
                                    }
                                    else
                                    {
                                        // Add code to only run if between 9PM and 6AM
                                        if (boolProduction == false || DateTime.Now.Hour >= 21 || DateTime.Now.Hour <= 6)
                                        {
                                            if (intLogging > 0)
                                            {
                                                oLog.WriteEntry(String.Format("Beginning extraction of VHD for " + strName), EventLogEntryType.Information);
                                            }
                                            // File does not exist, begin unzip
                                            StreamWriter oWriter = new StreamWriter(strVBS);
                                            oWriter.WriteLine("Dim objShell");
                                            oWriter.WriteLine("Set objShell = CreateObject(\"WScript.Shell\")");
                                            // FORMAT: objShell.Run("cmd.exe /c F:\WXP_SysPrep\gzip -d -k -c ""F:\WXP_SysPrep\WXP Pro SP2 CORPTEST.vhd.gz"" > R:\vsfiles\LUN01\WXP\TESTHEALY\DriveCXP.vhd")
                                            oWriter.WriteLine("objShell.Run(\"cmd.exe /c " + strZipPath + " -d -k -c \"\"" + strImage + "\"\" > " + strFile + "\")");
                                            oWriter.WriteLine("Set objShell = Nothing");
                                            oWriter.Flush();
                                            oWriter.Close();
                                            ILaunchScript oScript = new SimpleLaunchWsh(strVBS, "", true) as ILaunchScript;
                                            oScript.Launch();
                                            if (intLogging > 0)
                                            {
                                                oLog.WriteEntry(String.Format("FINISHED extraction of VHD for " + strName), EventLogEntryType.Information);
                                            }
                                        }
                                        else if (intLogging > 0)
                                        {
                                            oLog.WriteEntry(String.Format("Waiting until 9PM to start extraction of VHD for " + strName), EventLogEntryType.Information);
                                        }
                                    }
                                }
                                else if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format("GZIP already running - will not create VHD for " + strName), EventLogEntryType.Information);
                                }
                            }
                            break;

                        case 5:         // Step 5 - Creating Virtual Machine
                            oServer.CreateVirtualMachine(strName, strVirtualDir + "\\" + strName);
                            oWorkstation.NextRemoteVirtual(intID);
                            //    break;
                            //case 6:   // Step 6 - Modifying RAM
                            VMVirtualMachine oMachine = oServer.FindVirtualMachine(strName);
                            oMachine.Memory = intRam;
                            oMachine.ShutdownActionOnQuit = VMShutdownAction.vmShutdownAction_Shutdown;
                            oWorkstation.NextRemoteVirtual(intID);
                            //    break;
                            //case 7:   // Step 7 - Adding CD Drive
                            oMachine.AddDVDROMDrive(VMDriveBusType.vmDriveBusType_IDE, 1, 0);
                            oWorkstation.NextRemoteVirtual(intID);
                            //    break;
                            //case 8:   // Step 8 - Connecting Virtual Disks
                            VMSCSIController oSCSI = oMachine.AddSCSIController();
                            oSCSI.Configure(false, 7);
                            if (bool2000 == true)
                            {
                                oMachine.AddHardDiskConnection(strVirtualDir + "\\" + strName + "\\DriveC2K.vhd", VMDriveBusType.vmDriveBusType_SCSI, 0, 0);
                            }
                            else
                            {
                                oMachine.AddHardDiskConnection(strVirtualDir + "\\" + strName + "\\DriveCXP.vhd", VMDriveBusType.vmDriveBusType_SCSI, 0, 0);
                            }
                            oWorkstation.NextRemoteVirtual(intID);
                            break;

                        case 9:         // Step 9 - Configuring Network
                            VMVirtualMachine oMachineNetwork = oServer.FindVirtualMachine(strName);
                            foreach (VMNetworkAdapter oAdap in oMachineNetwork.NetworkAdapters)
                            {
                                foreach (VMVirtualNetwork oNet in oServer.VirtualNetworks)
                                {
                                    if (oNet.Name.ToUpper() == strNetwork.ToUpper())
                                    {
                                        oAdap.AttachToVirtualNetwork(oNet);
                                    }
                                }
                            }
                            oWorkstation.NextRemoteVirtual(intID);
                            break;

                        case 10:        // Step 10 - Updating Serial Number
                            VMVirtualMachine oMachineSerial = oServer.FindVirtualMachine(strName);
                            oMachineSerial.BaseBoardSerialNumber = strSerial;
                            oMachineSerial.ChassisSerialNumber   = strSerial;
                            oMachineSerial.BIOSSerialNumber      = strSerial;
                            oWorkstation.NextRemoteVirtual(intID);
                            break;

                        case 11:        // Step 11 - Creating AD groups
                            // Create RemoteA group in OUg_Resources/OUc_WksMgmt (not for Windows 2000 workstations)
                            if (bool2000 == false)
                            {
                                strResult = oAD.CreateGroup(strGroupRemote, "Remote access group for virtual workstation", "Requires approval from one of the following:" + Environment.NewLine + "               " + strManager, "OU=OUc_WksMgmt,OU=OUg_Resources,", "GG", "S");
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                            }
                            else
                            {
                                strResult = oAD.CreateGroup(strGroupRemote2K, "Remote access group for virtual workstation", "Requires approval from one of the following:" + Environment.NewLine + "               " + strManager, "OU=OUc_WksMgmt,OU=OUg_Resources,", "GG", "S");
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                            }
                            if (intEnvironment != (int)CurrentEnvironment.CORPDMN && intEnvironment != (int)CurrentEnvironment.PNCNT_PROD)     // Not Production
                            {
                                // Create Adm group in OUc_Orgs/OUg_Admins
                                strResult = oAD.CreateGroup(strGroupAdmin, "Virtual Workstation; " + strManager, "", "OU=OUg_Admins,OU=OUc_Orgs,", "GG", "S");
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                                // Create GSGw group in OUg_Resources
                                strResult = oAD.CreateGroup(strGroupW, "Virtual Workstation; " + strManager, "", "OU=OUg_Resources,", "GG", "S");
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                                // Create Workstation Object in OUc_DmnCptrs/OUc_Wksts/OUw_Standard
                                strResult = oAD.CreateWorkstation(strName, "Virtual Workstation; " + strManager, "", "OU=OUw_Standard,OU=OUc_Wksts,OU=OUc_DmnCptrs,");
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                                // Add workstation to GSGw group
                                strResult = oAD.JoinGroup(strName, strGroupW, 0);
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                            }
                            oWorkstation.NextRemoteVirtual(intID);
                            break;

                        case 12:
                            // Step 12 - Adding AD accounts
                            DataSet dsAccounts = oWorkstation.GetRemoteAccounts(strName);
                            foreach (DataRow drAccount in dsAccounts.Tables[0].Rows)
                            {
                                string strID = drAccount["xid"].ToString();
                                if (intEnvironment != (int)CurrentEnvironment.CORPDMN && intEnvironment != (int)CurrentEnvironment.PNCNT_PROD)     // Not Production
                                {
                                    strID = "E" + strID.Substring(1);
                                    if (oAD.Search(strID, false) == null)
                                    {
                                        strID = "T" + strID.Substring(1);
                                        if (oAD.Search(strID, false) == null)
                                        {
                                            strResult = oAD.CreateUser(strID, strID, strID, "Abcd1234", "", "", "");
                                            if (strResult.Trim() != "")
                                            {
                                                oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                            }
                                            if (intLogging > 0)
                                            {
                                                oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                            }
                                        }
                                    }
                                    if (drAccount["admin"].ToString() == "1")
                                    {
                                        strResult = oAD.JoinGroup(strID, strGroupAdmin, 0);
                                        if (strResult.Trim() != "")
                                        {
                                            oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                        }
                                        if (intLogging > 0)
                                        {
                                            oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                        }
                                    }
                                }
                                if (drAccount["remote"].ToString() == "1")
                                {
                                    if (bool2000 == false)
                                    {
                                        strResult = oAD.JoinGroup(strID, strGroupRemote, 0);
                                        if (strResult.Trim() != "")
                                        {
                                            oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                        }
                                        if (intLogging > 0)
                                        {
                                            oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                        }
                                    }
                                    else
                                    {
                                        strResult = oAD.JoinGroup(strID, strGroupRemote2K, 0);
                                        if (strResult.Trim() != "")
                                        {
                                            oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                        }
                                        if (intLogging > 0)
                                        {
                                            oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                        }
                                    }
                                }
                            }
                            oWorkstation.NextRemoteVirtual(intID);
                            break;

                        case 13:
                            // Step 13 - Starting Machine
                            VMVirtualMachine oMachineStart = oServer.FindVirtualMachine(strName);
                            oMachineStart.Startup();
                            oWorkstation.NextRemoteVirtual(intID);
                            // Update INI File
                            DataSet dsINI = oWorkstation.GetRemoteAccounts(strName);
                            foreach (DataRow drINI in dsINI.Tables[0].Rows)
                            {
                                string strID = drINI["xid"].ToString();
                                if (intEnvironment != (int)CurrentEnvironment.CORPDMN && intEnvironment != (int)CurrentEnvironment.PNCNT_PROD)     // Not Production
                                {
                                    strID = "E" + strID.Substring(1);
                                    if (oAD.Search(strID, false) == null)
                                    {
                                        strID = "T" + strID.Substring(1);
                                    }
                                }
                                if (drINI["remote"].ToString() == "1")
                                {
                                    // FORMAT: EMJY13C=TXPVM001,XP,OHCLEVWH4004
                                    bool         boolAdd = true;
                                    string       strLine = strID + "=" + strName + "," + (bool2000 ? "2000" : "XP") + "," + strHost;
                                    StreamReader oINIr   = new StreamReader(strINI);
                                    while (oINIr.Peek() != -1)
                                    {
                                        string strCompare = oINIr.ReadLine();
                                        if (strCompare == strLine)
                                        {
                                            boolAdd = false;
                                            break;
                                        }
                                    }
                                    oINIr.Close();
                                    if (boolAdd == true)
                                    {
                                        StreamWriter oINI = new StreamWriter(strINI, true);
                                        oINI.WriteLine(strLine);
                                        oINI.Flush();
                                        oINI.Close();
                                    }
                                }
                            }
                            break;

                        case 14:
                            // Step 14 - ZEUS
                            break;

                        case 15:
                            // Step 15 - Installing Applications
                            break;

                        case 16:
                            // Step 16 - Complete Request
                            // Run ImageScan script
                            File.Copy(strImageScan, strVBSImageScan, true);
                            ILaunchScript oScriptImageScan = new SimpleLaunchWsh(strVBSImageScan, "", true) as ILaunchScript;
                            oScriptImageScan.Launch();
                            // Delete Files
                            if (File.Exists(strVBS) == true)
                            {
                                File.Delete(strVBS);
                            }
                            if (File.Exists(strVBSImageScan) == true)
                            {
                                File.Delete(strVBSImageScan);
                            }
                            // Reboot the workstation
                            VMVirtualMachine oMachineRestart = oServer.FindVirtualMachine(strName);
                            oMachineRestart.Reset();
                            oWorkstation.UpdateRemoteVirtualCompleted(intID);
                            break;
                        }
                    }
                }


                ds = oWorkstation.GetRemoteVirtualDecoms(strServer);
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int    intID          = Int32.Parse(dr["id"].ToString());
                    int    intEnvironment = Int32.Parse(dr["environment"].ToString());
                    string strINI         = @"\\citrixfile.ntl-city.com\flexcfg$\vwcfg\VW.INI";
                    if (intEnvironment != 4)
                    {
                        strINI = @"\\citrixfiletest.tstctr.ntl-city.net\flexcfg$\vwcfg\VW.INI";
                    }
                    string strINITemp = @"\\citrixfile.ntl-city.com\flexcfg$\vwcfg\VW_TEMP.INI";
                    if (intEnvironment != 4)
                    {
                        strINITemp = @"\\citrixfiletest.tstctr.ntl-city.net\flexcfg$\vwcfg\VW_TEMP.INI";
                    }
                    AD     oAD                    = new AD(0, "", intEnvironment);
                    string strVirtualDir          = dr["virtualdir"].ToString();
                    string strName                = dr["name"].ToString();
                    string strGroupRemote         = "GSGu_WKS" + strName + "RemoteA";
                    string strGroupRemote2K       = "GSGu_WKS" + strName + "Remote2K";
                    string strGroupAdmin          = "GSGu_WKS" + strName + "Adm";
                    string strGroupW              = "GSGw_" + strName;
                    string strResult              = "";
                    bool   bool2000               = (strName.ToUpper().StartsWith("T2K") == true || strName.ToUpper().StartsWith("W2K") == true);
                    Type   typeVSClass            = typeof(VMVirtualServerClass);
                    Type   typeDCOM               = Type.GetTypeFromCLSID(typeVSClass.GUID, strServer, true);
                    object objDCOM                = Activator.CreateInstance(typeDCOM);
                    VMVirtualServerClass oServer  = (VMVirtualServerClass)System.Runtime.InteropServices.Marshal.CreateWrapperOfType(objDCOM, typeVSClass);
                    VMVirtualMachine     oMachine = oServer.FindVirtualMachine(strName);
                    if (oMachine.State == VMVMState.vmVMState_TurnedOff)
                    {
                        // Remove Workstation
                        oServer.DeleteVirtualMachine(oMachine);
                        if (intLogging > 0)
                        {
                            oLog.WriteEntry("Workstation " + strName + " has been deleted", EventLogEntryType.Information);
                        }
                        // Delete Folder
                        DeleteDirectory(strVirtualDir + "\\" + strName);
                        if (intLogging > 0)
                        {
                            oLog.WriteEntry("The directory for workstation " + strName + " has been deleted", EventLogEntryType.Information);
                        }
                        // Delete AD Objects
                        DirectoryEntry oGroup;
                        if (bool2000 == false)
                        {
                            oGroup = oAD.GroupSearch(strGroupRemote);
                            if (oGroup != null)
                            {
                                strResult = oAD.Delete(oGroup);
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                            }
                        }
                        else
                        {
                            oGroup = oAD.GroupSearch(strGroupRemote2K);
                            if (oGroup != null)
                            {
                                strResult = oAD.Delete(oGroup);
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                            }
                        }
                        if (intEnvironment != (int)CurrentEnvironment.CORPDMN && intEnvironment != (int)CurrentEnvironment.PNCNT_PROD) // Not Production
                        {
                            oGroup = oAD.GroupSearch(strGroupAdmin);
                            if (oGroup != null)
                            {
                                strResult = oAD.Delete(oGroup);
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                            }
                            oGroup = oAD.GroupSearch(strGroupW);
                            if (oGroup != null)
                            {
                                strResult = oAD.Delete(oGroup);
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                            }
                            SearchResultCollection oComputers = oAD.ComputerSearch(strName);
                            if (oComputers.Count > 0)
                            {
                                oGroup = oComputers[0].GetDirectoryEntry();
                                if (oGroup != null)
                                {
                                    strResult = oAD.Delete(oGroup);
                                    if (strResult.Trim() != "")
                                    {
                                        oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                    }
                                    if (intLogging > 0)
                                    {
                                        oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                    }
                                }
                            }
                        }
                        if (intLogging > 0)
                        {
                            oLog.WriteEntry("The AD groups for workstation " + strName + " have been deleted", EventLogEntryType.Information);
                        }
                        // Update the INI File
                        string       strCompare = "=" + strName + "," + (bool2000 ? "2000" : "XP") + "," + strServer;
                        StreamWriter oINI       = new StreamWriter(strINITemp, true);
                        StreamReader oINIr      = new StreamReader(strINI);
                        while (oINIr.Peek() != -1)
                        {
                            string strLine = oINIr.ReadLine();
                            if (strLine.EndsWith(strCompare) == false)
                            {
                                oINI.WriteLine(strLine);
                            }
                        }
                        oINIr.Close();
                        oINI.Flush();
                        oINI.Close();
                        if (File.Exists(strINI) == true)
                        {
                            File.Delete(strINI);
                        }
                        File.Copy(strINITemp, strINI, true);
                        if (File.Exists(strINITemp) == true)
                        {
                            File.Delete(strINITemp);
                        }
                        if (intLogging > 0)
                        {
                            oLog.WriteEntry("The INI file [" + strINI + "] was updated", EventLogEntryType.Information);
                        }
                        oWorkstation.UpdateRemoteVirtualDecomCompleted(intID);
                        if (intLogging > 0)
                        {
                            oLog.WriteEntry("The workstation " + strName + " has been decommissioned", EventLogEntryType.Information);
                        }
                    }
                    else if (oMachine.State != VMVMState.vmVMState_TurningOff)
                    {
                        oMachine.TurnOff();
                        if (intLogging > 0)
                        {
                            oLog.WriteEntry("The workstation " + strName + " is turning off", EventLogEntryType.Information);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                oLog.WriteEntry(String.Format(ex.Message) + " [" + System.Environment.UserName + "]", EventLogEntryType.Error);
            }
        }
Exemplo n.º 4
0
        //public async Task<bool> CheckExist(string UserCode)
        //{
        //    return await AD.CheckUser(UserCode);
        //}

        public bool Interact(EspackUser User)
        {
            try {
                AD.EC.ServerName = ServerName;

                if (User.Flags.Contains("DIS"))
                {
                    User.ServiceCommands.Add(new ServiceCommand()
                    {
                        Command = AD.UpdateUser(User.Name, User.Surname, User.UserCode, User.Password, User.Email, User.Sede.COD3, User.Position, User.Area, User.Sede.COD3Description)
                    });
                    User.ServiceCommands.Add(new ServiceCommand()
                    {
                        Command = AD.DisableUser(User.UserCode)
                    });
                    return(true);
                }
                // insert or update the user
                User.ServiceCommands.Add(new ServiceCommand()
                {
                    Command = AD.InteractUser(User.Name, User.Surname, User.UserCode, User.Password, User.Email, User.Sede.COD3, User.Position, User.Area, User.Sede.COD3Description)
                });
                // create the OU if not exists
                User.ServiceCommands.Add(new ServiceCommand()
                {
                    Command = AD.CreateOrganizationalUnit(User.Sede.COD3, User.Sede.COD3Description, AD.DefaultPath)
                });
                // move to the OU if not there
                User.ServiceCommands.Add(new ServiceCommand()
                {
                    Command = AD.MoveUserToOU(User.UserCode, User.Sede.COD3)
                });
                // remove from non present flag groups
                foreach (var f in Flags)
                {
                    if (!User.Flags.Contains(f.Key))
                    {
                        User.ServiceCommands.Add(new ServiceCommand()
                        {
                            Command = AD.RemoveUserFromGroup(User.UserCode, f.Value, AD.DefaultPath)
                        });
                    }
                }
                // add to flag groups
                if (User.Flags != null)
                {
                    foreach (var f in User.Flags)
                    {
                        User.ServiceCommands.Add(new ServiceCommand()
                        {
                            Command = AD.CreateGroup(Flags[f], Flags[f], "Security", AD.DefaultPath)
                        });
                        User.ServiceCommands.Add(new ServiceCommand()
                        {
                            Command = AD.AddUserToGroup(User.UserCode, Flags[f], GroupPath: AD.DefaultPath)
                        });
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 5
0
        protected void btn2_Click(object sender, EventArgs e)
        {
            // Create ADM Active Directory Group
            Variables oVariable = new Variables(intEnvironment);

            if (intOrganization > 0)
            {
                DataSet dsOrganization = oOrganization.Get(intOrganization);
                if (dsOrganization.Tables[0].Rows.Count > 0)
                {
                    if (strOrganizationCode != "")
                    {
                        //int intCustodian = Int32.Parse(dsOrganization.Tables[0].Rows[0]["userid"].ToString());
                        int intCustodian = 0;
                        Int32.TryParse(oForecast.GetAnswer(intAnswer, "appowner"), out intCustodian);
                        if (intCustodian > 0)
                        {
                            // BEGIN PROCESSING
                            // Create DLG OUg_<mnemonic> groups
                            string strMnemonicGroupDLG = "OUg_" + strMnemonicCode;
                            if (oAD.SearchOU(strMnemonicGroupDLG) == null)
                            {
                                string strResultMnemonic = oAD.CreateOU(strMnemonicGroupDLG, "", "OU=OUc_Resources,");
                                if (strResultMnemonic == "")
                                {
                                    strResult += "The OU " + strMnemonicGroupDLG + " was successfully created in " + oVar.Name() + "<br/>";
                                }
                                else
                                {
                                    strError = "There was a problem creating the OU ~ " + strMnemonicGroupDLG + " in " + oVar.Name();
                                }
                            }
                            else
                            {
                                strResult += "The OU " + strMnemonicGroupDLG + " already exists in " + oVar.Name() + "<br/>";
                            }

                            if (strError == "")
                            {
                                // Assume the GG OU exists and continue creating
                                string   strGroupDescription = "Custodian: " + oUser.GetFullName(intCustodian) + " (" + oUser.GetName(intCustodian) + "), LOB-" + strOrganizationCode + ", MIS-" + strMnemonicCode + " " + strMnemonicName;
                                string[] strGroups           = oVariable.PNC_AD_Groups();

                                for (int ii = 0; ii < strGroups.Length && strError == ""; ii++)
                                {
                                    //string strNameDLG = "DLG_URA_" + strOrganizationCode + "_" + strMnemonicCode + "_" + strGroups[ii];
                                    string strNameDLG = "GSLfsaSP_" + strMnemonicCode + "_" + strGroups[ii];
                                    //string strNameGG = "GG_URA_" + strOrganizationCode + "_" + strMnemonicCode + "_" + strGroups[ii];
                                    string strNameGG = "GSGu_" + strMnemonicCode + "_" + strGroups[ii];

                                    if (strError == "")
                                    {
                                        if (oAD.Search(strNameDLG, false) == null)
                                        {
                                            string strResultDLG = oAD.CreateGroup(strNameDLG, strGroupDescription, "", "OU=" + strMnemonicGroupDLG + ",OU=OUc_Resources,", "DLG", "S");
                                            if (strResultDLG == "")
                                            {
                                                strResult += "The group " + strNameDLG + " was successfully created in " + oVar.Name() + "<br/>";
                                            }
                                            else
                                            {
                                                strError = "There was a problem creating the group ~ " + strNameDLG + " in " + oVar.Name();
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            strResult += "The group " + strNameDLG + " already exists in " + oVar.Name() + "<br/>";
                                        }
                                    }

                                    if (strError == "")
                                    {
                                        if (oAD.Search(strNameGG, false) == null)
                                        {
                                            string strResultGG = oAD.CreateGroup(strNameGG, strGroupDescription, "", "OU=OUg_Applications,OU=OUc_AccessGroups,", "GG", "S");
                                            if (strResultGG == "")
                                            {
                                                strResult += "The group " + strNameGG + " was successfully created in " + oVar.Name() + "<br/>";
                                            }
                                            else
                                            {
                                                strError = "There was a problem creating the group ~ " + strNameGG + " in " + oVar.Name();
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            strResult += "The group " + strNameGG + " already exists in " + oVar.Name() + "<br/>";
                                        }
                                    }

                                    if (strError == "")
                                    {
                                        // Add the GG to the DLG
                                        string strResultJoin = oAD.JoinGroup(strNameGG, strNameDLG, 0);
                                        if (strResultJoin == "")
                                        {
                                            strResult += "The global group " + strNameGG + " was successfully added to the domain local group " + strNameDLG + " in " + oVar.Name() + "<br/>";
                                        }
                                        else
                                        {
                                            strError = "There was a problem adding the global group ~ " + strNameGG + " to the domain local group " + strNameDLG + " in " + oVar.Name();
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            strError = "The organization is not configured for Active Directory Group naming (CUSTODIAN / USERID is blank) ~ (" + dsOrganization.Tables[0].Rows[0]["name"].ToString() + ")";
                        }
                    }
                    else
                    {
                        strError = "The organization is not configured for Active Directory Group naming (CODE is blank) ~ (" + dsOrganization.Tables[0].Rows[0]["name"].ToString() + ")";
                    }
                }
                else
                {
                    strError = "Invalid Organization";
                }
            }
            else
            {
                strError = "There is no organization specified for this project";
            }
            int intStep = 6;

            //oOnDemand.UpdateStepDoneServer(intServer, intStep, strResult, 0, false, true);

            Response.Write("<p><b>RESULT...</b></p><p>" + strResult + "</p>");
            Response.Write("<p><b>ERROR...</b></p><p>" + strError + "</p>");
        }