Example #1
0
        private void buttonRDPermissionApply_Click(object sender, EventArgs e)
        {
            /// compare user/group list in registry with the list in GUI
            ///
            string[] users = new string[listBoxRDPermission.Items.Count];
            int      i     = 0;

            foreach (string s in listBoxRDPermission.Items)
            {
                users[i++] = s.Trim();
            }

            try
            {
                ClearRDPermissionUserRegistry();
                AddRDPermissionUsers(users);
                MessageBox.Show("Remote desktop permission updated successfully");
            }
            catch (Exception ex)
            {
                MessageBox.Show("[FAILED] Couldn't save users/groups to the Windows registry!");
                EucaLogger.Exception("Couldn't save users/groups to the Windows registry", ex);
                return;
            }
            buttonRDPermissionApply.Enabled = false;
        }
Example #2
0
        // text = Forget
        private void buttonClear_Click(object sender, EventArgs e)
        {
            DialogResult answer = MessageBox.Show("Do you want to remove all AD records from the system?",
                                                  "AD clean-up", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (answer == DialogResult.No)
            {
                return;
            }
            try
            {
                EucaServiceLibraryUtil.DeleteSvcRegistryValue("ADAddress");
                EucaServiceLibraryUtil.DeleteSvcRegistryValue("ADUsername");
                EucaServiceLibraryUtil.DeleteSvcRegistryValue("ADPassword");
                EucaServiceLibraryUtil.DeleteSvcRegistryValue("ADOU");

                textBoxADAddress.Text  = "";
                textBoxADUsername.Text = "";
                textBoxADPassword.Text = "";
                textBoxADOU.Text       = "";
                buttonApply.Enabled    = false;

                MessageBox.Show("Active Directory information is cleared");
            }
            catch (Exception ie)
            {
                EucaLogger.Exception("Can't forget the AD information", ie);
            }
        }
Example #3
0
        /* this method is deprecated */
        private void buttonUnregister_Click(object sender, EventArgs e)
        {
            try
            {
                bool   partOfDomain = false;
                string domain       = null;
                using (ManagementObject comObj = WMIUtil.QueryLocalWMI("Select * from win32_computersystem"))
                {
                    partOfDomain = (bool)comObj["PartOfDomain"];
                    domain       = (string)comObj["Domain"];
                    if (!partOfDomain)
                    {// this must be a bug, because the button shouldn't be activated if the instance isn't a domain member
                        MessageBox.Show("This instance is not a member of any domain");
                        return;
                    }

                    DialogResult answer = MessageBox.Show(string.Format("Detach this instance from domain({0})?", domain),
                                                          "Detach from domain", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (answer == DialogResult.No)
                    {
                        return;
                    }

                    ManagementBaseObject paramIn = comObj.GetMethodParameters("UnjoinDomainOrWorkgroup");

                    paramIn["Password"]       = null;         // this won't delete computer record from AD controller
                    paramIn["UserName"]       = null;
                    paramIn["FUnjoinOptions"] = (UInt32)0x00; // Default, no option

                    ManagementBaseObject paramOut = comObj.InvokeMethod("UnjoinDomainOrWorkgroup", paramIn, null);
                    UInt32 retVal = (UInt32)paramOut["ReturnValue"];
                    if (retVal == 0)
                    {
                        EucaLogger.Info("The instance was successfully detached from the domain");
                        MessageBox.Show("The instance was successfully detached from the domain");
                        string hostnameFile = EucaConstant.ProgramRoot + "\\hostname";
                        if (File.Exists(hostnameFile))
                        {
                            try{ File.Delete(hostnameFile); }
                            catch (Exception)   {; }
                        }
                        System.Environment.Exit(0);
                    }
                    else
                    {
                        EucaLogger.Warning(string.Format("Could not detach the instance: exit code={0}", retVal));
                        MessageBox.Show(string.Format("Could not detach the instance: exit code={0}", retVal));
                        return;
                    }
                }
            }
            catch (Exception ie)
            {
                EucaLogger.Exception("Can't detach the instance from the domain", ie);
            }
        }
Example #4
0
        /****
        * Contents in the unzipped directory
        * script: script file to be handled by ScriptHandler
        * powershell: powershell file to be handled by ScriptHandler
        * eucalyptus: eucalyptus file to be handled by EucalyptusParameterHandler
        * include: include file to be handled by IncludeHandler
        * and any other resource files to be used by script/powershell handlers (exe, dll, etc)
        ****/
        override protected void Handle()
        {
            if (!Directory.Exists(UnzippedDir))
            {
                EucaLogger.Error(String.Format("Can't find the unzipped directory {0}", UnzippedDir));
                return;
            }
            else if (File.Exists(UserDataFile))
            {
                try
                {
                    EucaFileUtil.Unzip(UnzippedDir, UserDataFile);
                }
                catch (Exception ex)
                {
                    EucaLogger.Exception(String.Format("Failed to unzip {0} into {1}", UserDataFile, UnzippedDir), ex);
                    return;
                }
            }

            foreach (String filePath in Directory.GetFiles(UnzippedDir))
            {
                String          fileName = Path.GetFileName(filePath).ToLower();
                UserDataHandler handler  = null;
                if (fileName.Equals("script") || fileName.Equals("powershell"))
                {
                    handler = new ScriptHandler();
                }
                else if (fileName.Equals("eucalyptus"))
                {
                    handler = new EucalyptusParameterHandler();
                }
                else if (fileName.Equals("include"))
                {
                    handler = new IncludeHandler();
                }
                else
                {
                    EucaLogger.Debug(String.Format("unknown file: {0}", fileName));
                    continue;
                }

                try
                {
                    handler.HandleUserData(filePath);
                    EucaLogger.Debug(String.Format("Successfully handled the contents in {0}", fileName));
                }
                catch (Exception ex)
                {
                    EucaLogger.Exception(String.Format("failed to handle the file {0}", fileName), ex);
                }
            }
        }
 public static void SetSvcRegistryValue(string key, object value)
 {
     if (key == null || value == null)
     {
         return;
     }
     try
     {
         Com.Eucalyptus.SystemsUtil.SetRegistryValue(Registry.LocalMachine,
                                                     new string[] { "SOFTWARE", "Eucalyptus Systems", "Eucalyptus" }, key, value, false);
     }
     catch (Exception e)
     {
         EucaLogger.Exception("Could not set registry value", e);
     }
 }
        /*
         * <include>
         *    http://myhost/user-data1
         *    http://myhost/user-data2
         * </include>
         *
         */
        override protected void Handle()
        {
            var urls      = this.AsMultiLinesWithoutTag;
            var validUrls = urls.Where(url =>
                                       url.ToLower().StartsWith("http://"));
            List <String> localUserData = new List <String>();

            foreach (String url in validUrls)
            {
                String filePath = String.Format("{0}\\{1}.txt",
                                                CloudInit.CloudInitDirectory, Guid.NewGuid().ToString().Substring(0, 8));
                try{
                    EucaUtil.Curl(url, filePath);
                    localUserData.Add(filePath);
                }catch (Exception ex) {
                    EucaLogger.Exception(String.Format("Failed to download from the include url {0}", url), ex);
                    continue;
                }
            }

            foreach (String userDataFile in localUserData)
            {
                UserDataHandler handler = null;
                try
                {
                    handler = UserDataHandlerFactory.Instance.GetHandler(userDataFile);
                }
                catch (Exception ex)
                {
                    EucaLogger.Exception("Unable to find the right handler for include file", ex);
                }

                try
                {
                    handler.HandleUserData(userDataFile);
                }
                catch (Exception ex)
                {
                    EucaLogger.Exception("Failed to handle the user data", ex);
                }
            }

            foreach (String userDataFile in localUserData)
            {
                File.Delete(userDataFile);
            }
        }
 public static object GetSvcRegistryValue(string key)
 {
     if (key == null)
     {
         return(null);
     }
     try
     {
         return(Com.Eucalyptus.SystemsUtil.GetRegistryValue(Registry.LocalMachine,
                                                            new string[] { "SOFTWARE", "Eucalyptus Systems", "Eucalyptus" }, key));
     }
     catch (Exception e)
     {
         EucaLogger.Exception("Could not retrieve registry value", e);
         return(null);
     }
 }
 public static void DeleteSvcRegistryValue(string key)
 {
     if (key == null)
     {
         return;
     }
     try
     {
         Com.Eucalyptus.SystemsUtil.DeleteRegistryValue(Registry.LocalMachine,
                                                        new string[] { "SOFTWARE", "Eucalyptus Systems", "Eucalyptus" }, key);
     }
     catch (Exception e)
     {
         EucaLogger.Exception("Could not delete registry value", e);
         return;
     }
 }
Example #9
0
        public void Init()
        {
            string userDataFile = null;

            try
            {
                userDataFile = CloudInit.CloudInitDirectory + "\\user-data";
                EucaUtil.GetUserData(userDataFile);
                if (!File.Exists(userDataFile))
                {
                    throw new EucaException("User data file not found");
                }
                if ((new FileInfo(userDataFile)).Length <= 0)
                {
                    throw new EucaException("Invalid user data file");
                }
            }
            catch (Exception ex)
            {
                EucaLogger.Debug("Unable to download the user-data");
                throw ex;
            }

            // detect the contents
            UserDataHandler handler = null;

            try
            {
                handler = UserDataHandlerFactory.Instance.GetHandler(userDataFile);
            }
            catch (Exception ex)
            {
                EucaLogger.Exception("Unable to find the handler for matching user-data contents", ex);
                return;
            }
            // invoke handler
            try
            {
                handler.HandleUserData(userDataFile);
            }
            catch (Exception e)
            {
                EucaLogger.Exception("User data handler threw exception", e);
            }
            // return
        }
        private void ExecutePowershell(String powershellFile)
        {
            String exec = "powershell.exe";
            String args = String.Format("-NonInteractive -File {0}", powershellFile);

            EucaLogger.Debug(String.Format("Executing {0} {1}", exec, args));
            try
            {
                Win32_CommandResult result = SystemsUtil.SpawnProcessAndWait(exec, args);
                EucaLogger.Debug(String.Format("Execution finished with exit code={0}", result.ExitCode));
                EucaLogger.Debug(String.Format("Stdout: {0}", result.Stdout));
                EucaLogger.Debug(String.Format("Stderr: {0}", result.Stderr));
            }
            catch (Exception ex)
            {
                EucaLogger.Exception("Execution failed", ex);
            }
        }
        private void ExecuteCommandLine(String scriptFile)
        {
            String exec = "cmd.exe";
            String args = String.Format("/c {0}", scriptFile);

            EucaLogger.Debug(String.Format("Executing {0} {1}", exec, args));
            try
            {
                Win32_CommandResult result = SystemsUtil.SpawnProcessAndWait(exec, args);
                EucaLogger.Debug(String.Format("Execution finished with exit code={0}", result.ExitCode));
                EucaLogger.Debug(String.Format("Stdout: {0}", result.Stdout));
                EucaLogger.Debug(String.Format("Stderr: {0}", result.Stderr));
            }
            catch (Exception ex)
            {
                EucaLogger.Exception("Execution failed", ex);
            }
        }
Example #12
0
 private void buttonAnswerFile_Click(object sender, EventArgs e)
 {
     try
     {
         string answerPath = this.SysprepAnswerFile;
         if (!File.Exists(answerPath))
         {
             MessageBox.Show(string.Format("Sysprep answer file is not found ({0})", answerPath));
             return;
         }
         Win32_CommandResult result = EucaUtil.SpawnProcessAndWait("notepad.exe", answerPath);
     }
     catch (Exception ie) {
         MessageBox.Show(string.Format("Unexpected exception thrown: {0}", ie.Message), "WARNING");
         EucaLogger.Exception("Unexpected exception thrown while opening sysprep answer file", ie);
         return;
     }
 }
        /*
         * <eucalyptus>
         * key1:value1
         * key2:value2
         * </eucalytpus>
         *
         * <eucalyptus> key1:value1, key2:value2 </eucalyptus>
         */
        override protected void Handle()
        {
            var keyValues = this.AsMultiLinesWithoutTag
                            .Where(line => line.Split(':').Length == 2)
                            .Select(line => new KeyValuePair <String, String>(line.Split(':')[0], line.Split(':')[1]));

            foreach (var kv in keyValues)
            {
                try
                {
                    SetEucaRegistryValue(kv.Key, kv.Value);
                    EucaLogger.Debug(String.Format("Eucalyptus registry updated: {0}-{1}", kv.Key, kv.Value));
                }
                catch (Exception e)
                {
                    EucaLogger.Exception("Could not set registry value", e);
                }
            }
        }
Example #14
0
        private void checkBoxFormatDrives_CheckedChanged(object sender, EventArgs e)
        {
            bool formatDrive = this.checkBoxFormatDrives.Checked;

            try
            {
                if (formatDrive)
                {
                    EucaUtil.SetRegistryValue(Registry.LocalMachine, EUCALYPTUS_REGISTRY_PATH, "FormatDrives", 1, false);
                }
                else
                {
                    EucaUtil.SetRegistryValue(Registry.LocalMachine, EUCALYPTUS_REGISTRY_PATH, "FormatDrives", 0, false);
                }
            }
            catch (Exception ie)
            {
                EucaLogger.Exception("Couldn't set registry value for 'FormatDrives'", ie);
            }
        }
Example #15
0
        private void buttonSysprep_Click(object sender, EventArgs e)
        {
            //   IMPLEMENT_SYS_PREP;
            try
            {
                DialogResult answer = MessageBox.Show("Sysprep should be performed only when you are finished with VM setup. Do you want to run the sysprep now?",
                                                      "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (answer == DialogResult.No)
                {
                    return;
                }

                string answerPath = this.SysprepAnswerFile;
                if (answerPath == null)
                {
                    MessageBox.Show("Sysprep is not supported on this Windows version. Please check with the administration manual to find the supported OS",
                                    "WARNING");
                    return;
                }

                if (!File.Exists(answerPath))
                {
                    MessageBox.Show(string.Format("Sysprep answer file is not found ({0})", answerPath));
                    return;
                }

                string sysprepDest = string.Format("C:\\{0}", (new FileInfo(answerPath)).Name);
                if (File.Exists(sysprepDest))
                {
                    File.Delete(sysprepDest);
                }

                File.Copy(answerPath, sysprepDest);
                string sysprepExec = string.Format("{0}\\sysprep\\sysprep.exe",
                                                   Environment.GetFolderPath(Environment.SpecialFolder.System));

                string arg = string.Format("/generalize /oobe /quit /unattend:\"{0}\"", sysprepDest);
                EucaLogger.Debug("sysprep argument: " + arg);

                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.UseShellExecute = true;

                Win32_CommandResult result = EucaUtil.SpawnProcessAndWait(sysprepExec, arg);
                if (result.ExitCode != 0)
                {
                    MessageBox.Show(string.Format("Sysprep returned exit code: {0}", result.ExitCode));
                    EucaLogger.Debug(string.Format("Sysprep exit code: {0}, stdout: {1}, stderr: {2}", result.ExitCode, result.Stdout, result.Stderr));
                    return;
                }
                else
                {
                    MessageBox.Show("Sysprep finished successfully. You can shutdown the VM and register it with Eucalyptus front-end.");
                    System.Environment.Exit(0);
                }
            }
            catch (Exception ie)
            {
                MessageBox.Show(string.Format("Unexpected exception thrown: {0}", ie.Message), "WARNING");
                EucaLogger.Exception("Unexpected exception thrown while running sysprep", ie);
                return;
            }
        }
Example #16
0
        private void InitPanel()
        {
            /// check if the instance is a member of an AD
            ///
            bool   partOfDomain = false;
            string domain       = null;

            try
            {
                using (ManagementObject comObj = WMIUtil.QueryLocalWMI("Select * from win32_computersystem"))
                {
                    partOfDomain = (bool)comObj["PartOfDomain"];
                    domain       = (string)comObj["Domain"];
                }

                if (partOfDomain)
                {
                    labelADStatus.Text = string.Format("domain member of {0}", domain);
                    // buttonUnregister.Enabled = true;
                    // buttonUnregister.Visible = true;
                }
                else
                {
                    labelADStatus.Text = "not a member of a domain";
                }
            }
            catch (Exception e)
            {
                EucaLogger.Exception("Can't determine if the host is a part of domain", e);
                labelADStatus.Text = "error-AD status could not be determined";
            }

            object tmp = EucaServiceLibraryUtil.GetSvcRegistryValue("ADAddress");

            if (tmp != null)
            {
                _adConfig.ADAddress = (string)tmp;
            }
            tmp = EucaServiceLibraryUtil.GetSvcRegistryValue("ADUsername");
            if (tmp != null)
            {
                _adConfig.ADUsername = (string)tmp;
            }
            tmp = EucaServiceLibraryUtil.GetSvcRegistryValue("ADPassword");
            {
                if (tmp != null)
                {
                    _adConfig.ADPassword = EucaUtil.Decrypt((string)tmp);
                }
            }
            tmp = EucaServiceLibraryUtil.GetSvcRegistryValue("ADOU");
            if (tmp != null)
            {
                _adConfig.ADOU = (string)tmp;
            }

            if (_adConfig.ADAddress != null)
            {
                textBoxADAddress.Text = _adConfig.ADAddress;
            }
            if (_adConfig.ADUsername != null)
            {
                textBoxADUsername.Text = _adConfig.ADUsername;
            }
            if (_adConfig.ADPassword != null)
            {
                textBoxADPassword.Text = _adConfig.ADPassword;
            }
            if (_adConfig.ADOU != null)
            {
                textBoxADOU.Text = _adConfig.ADOU;
            }


            /// bring up the list of users/groups that has RD permission on the image
            string[] rdPermissionUsers = null;
            try
            {
                rdPermissionUsers = this.GetRDPermissionUsers();
            }
            catch (Exception e) {
                EucaLogger.Exception("Could not enumerate RD users/groups from registry", e);
            }

            if (rdPermissionUsers != null)
            {
                foreach (string name in rdPermissionUsers)
                {
                    listBoxRDPermission.Items.Add(name);
                }
            }
            buttonApply.Enabled = false;

            try
            {
                int selected = (int)EucaUtil.GetRegistryValue(Registry.LocalMachine, EUCALYPTUS_REGISTRY_PATH, "FormatDrives");
                if (selected == 1)
                {
                    checkBoxFormatDrives.Checked = true;
                }
                else
                {
                    checkBoxFormatDrives.Checked = false;
                }
            }
            catch (Exception e)
            {
                EucaLogger.Exception("Couldn't check 'FormatDrives' option from registry", e);
            }
        }