/* * <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 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 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; } }
public EucaConfigForm() { try { string installLocation = (string)EucaUtil.GetRegistryValue(Registry.LocalMachine, EUCALYPTUS_REGISTRY_PATH, "InstallLocation"); EucaLogger.LogLocation = string.Format("{0}\\eucalog.txt", installLocation); } catch (Exception e) { MessageBox.Show(string.Format("Unexpected exception thrown: {0}", e.Message)); return; } InitializeComponent(); // using (System.Drawing.Bitmap bm = new System.Drawing.Bitmap(EucaConstant.ProgramRoot+"\\euca.png")) // this.Icon = System.Drawing.Icon.FromHandle(bm.GetHicon()); InitPanel(); }
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); } }
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; } }
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); } }
private void buttonApply_Click(object sender, EventArgs e) { string adAddr = textBoxADAddress.Text; if (adAddr != null && adAddr.Length == 0) { adAddr = null; } string adUsername = textBoxADUsername.Text; if (adUsername != null && adUsername.Length == 0) { adUsername = null; } string adPassword = textBoxADPassword.Text; if (adPassword != null && adPassword.Length == 0) { adPassword = null; } string adPasswordConfirm = textBoxPwdConfirm.Text; if (adPasswordConfirm != null && adPasswordConfirm.Length == 0) { adPasswordConfirm = null; } string adOu = textBoxADOU.Text; if (adOu != null && adOu.Length == 0) { adOu = null; } if (!(adAddr == null && adUsername == null && adPassword == null && adOu == null)) {// user has put something in the config window if (adAddr == null || adUsername == null || adPassword == null) { MessageBox.Show("AD address, username, and password are required to enable AD join"); return; } } else { MessageBox.Show("AD address, username, and password are required to enable AD join"); return; } if (adPassword != adPasswordConfirm) { MessageBox.Show("Passwords do not match!"); return; } bool updated = false; if (adAddr.Trim() != (string)EucaServiceLibraryUtil.GetSvcRegistryValue("ADAddress")) { EucaServiceLibraryUtil.SetSvcRegistryValue("ADAddress", adAddr.Trim()); updated = true; } if (adUsername.Trim() != (string)EucaServiceLibraryUtil.GetSvcRegistryValue("ADUsername")) { EucaServiceLibraryUtil.SetSvcRegistryValue("ADUsername", adUsername.Trim()); updated = true; } //encrypt AD password properly if (adPassword.Trim() != (string)EucaServiceLibraryUtil.GetSvcRegistryValue("ADPassword")) { string data = EucaUtil.Encrypt(adPassword.Trim()); EucaServiceLibraryUtil.SetSvcRegistryValue("ADPassword", data); updated = true; } if (adOu != null) { if (adOu.Trim() != (string)EucaServiceLibraryUtil.GetSvcRegistryValue("ADOU")) { EucaServiceLibraryUtil.SetSvcRegistryValue("ADOU", adOu.Trim()); updated = true; } } if (updated) { MessageBox.Show("AD information is updated succesfully"); buttonApply.Enabled = false; } else { MessageBox.Show("No change has been saved"); } }
static int Main(string[] args) { if (args.Length < 1) { return(-1); } if (args[0].ToLower() == "-unjoindom") { 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"); Console.WriteLine("EucaCLI: The instance is not a member of any domain"); return(-1); } /* string adAddress = null, adUsername = null, adPassword = null; * object tmp = EucaUtil.GetRegistryValue("ADAddress"); * if (tmp != null) * adAddress = (string)tmp; * tmp = EucaUtil.GetRegistryValue("ADUsername"); * if (tmp != null) * adUsername = (string)tmp; * tmp = EucaUtil.GetRegistryValue("ADPassword"); * if (tmp != null) * adPassword = (string)tmp; * * if (adUsername == null || adPassword == null || adAddress == null) * { * Console.WriteLine("EucaCLI: Username/password/ADaddress is not found"); * return -1; * } * * if (!adUsername.Contains("\\")) * adUsername = string.Format("{0}\\{1}", adAddress, adUsername); * * adPassword = EucaUtil.Decrypt(adPassword);*/ ManagementBaseObject paramIn = comObj.GetMethodParameters("UnjoinDomainOrWorkgroup"); paramIn["Password"] = null; 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) { Console.WriteLine("SUCCESS"); string hostnameFile = EucaConstant.ProgramRoot + "\\hostname"; if (System.IO.File.Exists(hostnameFile)) { try { System.IO.File.Delete(hostnameFile); } catch (Exception) {; } } return(0); } else { Console.WriteLine(string.Format("EucaCLI: Could not detach the instance: exit code={0}", retVal)); return(-1); } } } catch (Exception ie) { Console.WriteLine("EucaCLI: Can't detach the instance from the domain (exception thrown)"); return(-1); } } else if (args[0].ToLower() == "-setdom") { try { string uname = args[1].Trim(); string passwd = args[2].Trim(); if (uname == null || passwd == null) { Console.WriteLine("EucaCLI: uname and passwd is null"); return(-1); } string passwdEnc = EucaUtil.Encrypt(passwd); EucaServiceLibraryUtil.SetSvcRegistryValue("ADUsername", uname); EucaServiceLibraryUtil.SetSvcRegistryValue("ADPassword", passwdEnc); Console.WriteLine("SUCCESS"); return(0); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); return(-1); } } else { Console.WriteLine("Unknown parameter"); return(-1); } }