Exemplo n.º 1
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            vmEntry entry = new vmEntry();
            entry.vmName = textBoxName.Text;
            entry.vmFile = textBoxFile.Text;
            entry.snapshotName = textBoxSnapshotname.Text;
            entry.indexNum = vmList.Count+1;
            entry.busy = false;

            vmList.Add(entry);
            this.Dispose();
            vmUI.shouldSelect = vmList.Count-1;
            vmUI.updateList();
        }
Exemplo n.º 2
0
        public byte[] CreateNewUserInVM(vmEntry entry)
        {
            bool done = false;

            byte[] request = new byte[CLIENT_REQ_LEN];
            request[0] = CREATE_NEW_USER;

            byte[] clientResp = null;

            /* Process the request in clientData */
            Client vmClient = new Client();
            Debug.WriteLine("Connecting to VM ");

                if ((entry.busy == false) && vmClient.ConnectToVM(entry.vmName))//"129.49.16.93"))//""192.168.20.174"))
                {
                    Debug.WriteLine("Sending Request to VM");
                    clientResp = vmClient.sendReqToVM(request);

                    if (clientResp.Length > RESP_LEN_OFFSET)
                    {

                        entry.timestamp = DateTime.Now;
                        string[] temp = System.Text.Encoding.ASCII.GetString(clientResp).Split(':');

                        if (temp.Length == 3)
                        {

                            entry.username = temp[1].ToString();
                            entry.password = temp[2].ToString();
                        }

                        entry.busy = true;

                        WriteEntryToReg(entry);
                        done = true;
                    }
                }

            return clientResp;
        }
Exemplo n.º 3
0
        private void WriteEntryToReg(vmEntry entry)
        {
            try
            {
                ownWrite = true;
                Debug.WriteLine("Opening Registry");

                RegistryKey key = Registry.LocalMachine.CreateSubKey(regDir);
                int vmNumber;
                string tempVMFile, tempVMTimestamp, tempVMUsername, tempVMPassword;

                if (key != null)
                {

                    tempVMUsername = vmUsername + entry.indexNum;
                    tempVMPassword = vmPassword + entry.indexNum;
                    tempVMTimestamp = vmTimestamp + entry.indexNum;

                    key.SetValue(tempVMTimestamp, entry.timestamp.ToString());
                    key.SetValue(tempVMUsername, entry.username);
                    key.SetValue(tempVMPassword, entry.password);

                    key.Close();
                }
                ownWrite = false;
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception while adding entry to Reg " + e.Message);
            }
        }
Exemplo n.º 4
0
        private void GetVMInfo()
        {
            try
            {
                vmList = new List<vmEntry>();

                Debug.WriteLine("Opening Registry");
                RegistryKey key = Registry.LocalMachine.OpenSubKey(regDir);
                string tempVMName, tempVMFile, tempVMSnapshot, tempVMUsername, tempVMPassword, tempVMTimestamp, fileConv;

                if (key != null)
                {
                    Debug.WriteLine("Successfully opened Registry");
                    if (key.GetValue(numVM) != null)
                    {
                        numVMs = Convert.ToInt32(key.GetValue(numVM).ToString());
                        if (key.GetValue(interval) != null)
                        {
                            numInterval = Convert.ToInt32(key.GetValue(interval).ToString());
                        }
                        if (key.GetValue(valid) != null)
                        {
                            numValid = Convert.ToInt32(key.GetValue(valid).ToString());
                        }
                        for (int i = 1; i <= numVMs; i++)
                        {
                            tempVMName = vmName + i;
                            tempVMFile = vmFile + i;
                            tempVMSnapshot = vmSnapshot + i;
                            tempVMUsername = vmUsername + i;
                            tempVMPassword = vmPassword + i;
                            tempVMTimestamp = vmTimestamp + i;

                            Debug.WriteLine("Temp VM String " + tempVMName + " " + tempVMFile + " " + tempVMSnapshot);

                            vmEntry entry = new vmEntry();
                            entry.indexNum = i;
                            if (key.GetValue(tempVMName) != null)
                            {
                                entry.vmName = key.GetValue(tempVMName).ToString();
                            }
                            if (key.GetValue(tempVMFile) != null)
                            {
                                fileConv = key.GetValue(tempVMFile).ToString();
                                fileConv = fileConv.Substring(1, fileConv.Length - 2);
                                entry.vmFile = Path.GetFullPath(fileConv);
                            }
                            if (key.GetValue(tempVMSnapshot) != null)
                            {
                                entry.snapshotName = key.GetValue(tempVMSnapshot).ToString();
                            }

                            if (key.GetValue(tempVMUsername) != null)
                            {
                                entry.username = key.GetValue(tempVMUsername).ToString();
                                entry.password = key.GetValue(tempVMPassword).ToString();
                                entry.timestamp = Convert.ToDateTime(key.GetValue(tempVMTimestamp).ToString());
                                entry.busy = true;
                            }
                            else
                            {

                                entry.busy = false;
                            }

                            vmList.Add(entry);
                        }
                    }
                    key.Close();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception while reading from reg " + e.Message);

            }
        }
Exemplo n.º 5
0
        private void DeleteEntryFromReg(vmEntry entry)
        {
            try
            {
                Debug.WriteLine("Opening Registry");
                RegistryKey key = Registry.LocalMachine.CreateSubKey(regDir);

                // int vmNumber;
                string tempVMTimestamp, tempUsername, tempPassword;

                if (key != null)
                {
                    if (key.GetValue(numVM) != null)
                    {

                        Debug.WriteLine("entry index in delete reg");

                        tempVMTimestamp = vmTimestamp + entry.indexNum;
                        tempUsername = vmUsername + entry.indexNum;
                        tempPassword = vmPassword + entry.indexNum;

                        key.DeleteValue(tempVMTimestamp);
                        key.DeleteValue(tempUsername);
                        key.DeleteValue(tempPassword);

                    }
                    key.Close();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception while deleting entry from Reg " + e.Message);

            }
        }
Exemplo n.º 6
0
        public void restoreVM(vmEntry entry)
        {
            string fileNameJoined;
            string [] tempVMFileArray = entry.vmFile.Split('\\');
            fileNameJoined = String.Join("\\\\", tempVMFileArray, 0, tempVMFileArray.Length);
            fileNameJoined = "\"" + fileNameJoined + "\"";

            try
            {

                /* Now restore the VM to a snapshot */
                string vmrun = "C:\\Program Files\\VMware\\VMware Workstation\\vmrun.exe";
                string command = " revertToSnapshot " + fileNameJoined + " " + entry.snapshotName;
                Debug.WriteLine("command " + command);
                //                        string command = " stop " + entry.vmPath;

                System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo(vmrun, command);
                procStartInfo.UseShellExecute = false;
                procStartInfo.RedirectStandardOutput = true;
                Debug.WriteLine("Dequeue3");

                // Now we create a process, assign its ProcessStartInfo and start it
                System.Diagnostics.Process proc = new System.Diagnostics.Process();

                proc.StartInfo = procStartInfo;
                proc.Start();
                string result = proc.StandardOutput.ReadToEnd();

                proc.WaitForExit();
                // Display the command output.
                Debug.WriteLine("Result " + result);

                Debug.WriteLine("Dequeue4");
                Debug.WriteLine("Dequeue1");

                System.Threading.Thread.Sleep(5000);
                command = " start " + fileNameJoined;
                procStartInfo = new System.Diagnostics.ProcessStartInfo(vmrun, command);

                procStartInfo.UseShellExecute = false;
                // Do not create the black window.
                procStartInfo.CreateNoWindow = false;
                procStartInfo.RedirectStandardOutput = true;

                proc.StartInfo = procStartInfo;
                proc.Start();
                result = proc.StandardOutput.ReadToEnd();
                proc.WaitForExit();

                Debug.WriteLine("Result2 " + result);

                Debug.WriteLine("Dequeue2");

                entry.busy = false;
                DeleteEntryFromReg(entry);
            }
            catch (Exception exc)
            {
                Debug.WriteLine("Exception while stopping VM " + exc.Message);
            }
        }
Exemplo n.º 7
0
        public vmEntry getEntryfromReg(int index)
        {
            string tempvmFile, temVMSnapshotName, tempVMName, tempUsername;
            vmEntry entry = new vmEntry();
            try
            {

                RegistryKey key = Registry.LocalMachine.CreateSubKey(regDir);

                if (key != null)
                {
                    if (key.GetValue(numVM) != null)
                    {
                        tempVMName = vmName + index;
                        tempvmFile = vmFile + index;
                        temVMSnapshotName = vmSnapshot + index;

                        if (key.GetValue(tempVMName) != null)
                        {
                            entry.vmName = key.GetValue(tempVMName).ToString();
                        }
                        if (key.GetValue(tempvmFile) != null)
                        {
                            entry.vmFile = key.GetValue(tempvmFile).ToString();
                        }
                        if (key.GetValue(temVMSnapshotName) != null)
                        {
                            entry.snapshotName = key.GetValue(temVMSnapshotName).ToString();
                        }

                 }
                }
                currentEntry = entry;
            }
            catch (Exception exe)
            {

            }

            return null;
        }