Esempio n. 1
0
        /// <summary>
        /// Save sessions to the sessions.xml configuration file.
        /// </summary>
        public void SaveSessionsData(List <Dictionary <string, object> > sessions_data)
        {
            try
            {
                String filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                               "PuTTYStorm", "sessions.xml");

                if (!Directory.Exists(Path.Combine(Environment.GetFolderPath
                                                       (Environment.SpecialFolder.MyDocuments), "PuTTYStorm")))
                {
                    Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath
                                                               (Environment.SpecialFolder.MyDocuments), "PuTTYStorm"));
                }

                using (XmlWriter writer = XmlWriter.Create(filePath))
                {
                    writer.WriteStartDocument();
                    writer.WriteStartElement("Sessions");

                    foreach (Dictionary <string, object> dictionary in sessions_data)
                    {
                        if (dictionary["hostname"].ToString() != "" && dictionary["username"].ToString() != "")
                        {
                            writer.WriteStartElement("Session");

                            writer.WriteElementString("hostname", dictionary["hostname"].ToString());
                            writer.WriteElementString("username", dictionary["username"].ToString());
                            writer.WriteElementString("password", AESEncryptDecrypt.Encrypt(dictionary["password"].ToString()));
                            writer.WriteElementString("count", dictionary["c_count"].ToString());
                            writer.WriteElementString("group", dictionary["group"].ToString());
                            writer.WriteElementString("subgroup", dictionary["sub_group"].ToString());

                            writer.WriteEndElement();
                        }
                    }

                    writer.WriteEndElement();
                    writer.WriteEndDocument();
                    writer.Close();

                    if (writer.WriteState == WriteState.Closed)
                    {
                        GlobalVar.ConfigSavedSuccessfully = true;
                    }
                }
            }
            catch (Exception e)
            {
                GlobalVar.ConfigSavedSuccessfully = false;
                MessageBox.Show("Failed to save sessions! Try again! " + e.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }

            Backup_Sessions();
        }
Esempio n. 2
0
        /// <summary>
        /// Get saved sessions from sessions.xml configuration file.
        /// </summary>
        /// <returns>Class with Lists of sessions conenction info</returns>
        public SavedConnectionInfo get_Sessions()
        {
            SavedConnectionInfo xml_connection_info = new SavedConnectionInfo();

            String filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                           "PuTTYStorm", "sessions.xml");

            try
            {
                using (XmlReader reader = XmlReader.Create(filePath))
                {
                    while (reader.Read())
                    {
                        if (reader.IsStartElement())
                        {
                            switch (reader.Name)
                            {
                            case "hostname":
                                if (reader.Read())
                                {
                                    xml_connection_info.hostnames.Add(reader.Value);
                                }
                                break;

                            case "username":
                                if (reader.Read())
                                {
                                    xml_connection_info.usernames.Add(reader.Value);
                                }
                                break;

                            case "password":
                                if (reader.Read())
                                {
                                    // Handle passwordless login
                                    if (reader.Value == " ")
                                    {
                                        xml_connection_info.passwords.Add(null);
                                    }
                                    else
                                    {
                                        xml_connection_info.passwords.Add(AESEncryptDecrypt.Decrypt(reader.Value));
                                    }
                                }
                                break;

                            case "count":
                                if (reader.Read())
                                {
                                    xml_connection_info.counts.Add(reader.Value);
                                }
                                break;

                            case "group":
                                if (reader.Read())
                                {
                                    if (reader.Value == " ")
                                    {
                                        xml_connection_info.groups.Add(null);
                                    }
                                    else
                                    {
                                        xml_connection_info.groups.Add(reader.Value);
                                    }
                                }
                                break;

                            case "subgroup":
                                if (reader.Read())
                                {
                                    if (reader.Value == " ")
                                    {
                                        xml_connection_info.sub_groups.Add(null);
                                    }
                                    else
                                    {
                                        xml_connection_info.sub_groups.Add(reader.Value);
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            } catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            return(xml_connection_info);
        }
Esempio n. 3
0
        /// <summary>
        /// Save private keys to the privatekeys.xml configuration file.
        /// </summary>
        public void Save_PrivateKeys(List <Panel> PrivateKeys)
        {
            String filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                           "PuTTYStorm", "privatekeys.xml");

            if (!Directory.Exists(Path.Combine(Environment.GetFolderPath
                                                   (Environment.SpecialFolder.MyDocuments), "PuTTYStorm")))
            {
                Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath
                                                           (Environment.SpecialFolder.MyDocuments), "PuTTYStorm"));
            }

            using (XmlWriter writer = XmlWriter.Create(filePath))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("PrivateKeys");

                foreach (Panel container in PrivateKeys)
                {
                    string pk_name  = null;
                    string pk_type  = null;
                    string pk_group = null;
                    string pk_pwd   = null;

                    foreach (Control control in container.Controls)
                    {
                        if (control.Name == "pk_name_label")
                        {
                            pk_name = control.Text;
                        }

                        if (control.Name == "pk_type_label")
                        {
                            pk_type = control.Text.Replace("Type: ", string.Empty);
                        }

                        if (control.Name == "pk_group_label")
                        {
                            pk_group = control.Text.Replace("Group: ", string.Empty);
                        }

                        if (control.Name == "private_keys_hidden_passphrase_textbox")
                        {
                            pk_pwd = control.Text;
                        }
                    }

                    if (pk_name != "")
                    {
                        writer.WriteStartElement("PrivateKey");

                        writer.WriteElementString("name", pk_name);
                        writer.WriteElementString("type", pk_type);
                        writer.WriteElementString("group", pk_group);
                        if (pk_pwd == "" || pk_pwd == null)
                        {
                            writer.WriteElementString("pwd", " ");
                        }
                        else
                        {
                            writer.WriteElementString("pwd", AESEncryptDecrypt.Encrypt(pk_pwd));
                        }

                        writer.WriteEndElement();
                    }
                }

                writer.WriteEndElement();
                writer.WriteEndDocument();
            }

            GetSavedSessions     saved_data  = new GetSavedSessions();
            SavedPrivatekeysInfo privatekeys = null;

            if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                         "PuTTYStorm", "privatekeys.xml")))
            {
                privatekeys = saved_data.get_PrivateKeys();
            }

            if (privatekeys.names.Count != 0)
            {
                Backup_PrivateKeys();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Get saved private keys from privatekeys.xml configuration file.
        /// </summary>
        /// <returns>Class with List of private keys</returns>
        public SavedPrivatekeysInfo get_PrivateKeys()
        {
            SavedPrivatekeysInfo xml_privatekeys_info = new SavedPrivatekeysInfo();

            String filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                           "PuTTYStorm", "privatekeys.xml");

            try
            {
                using (XmlReader reader = XmlReader.Create(filePath))
                {
                    while (reader.Read())
                    {
                        if (reader.IsStartElement())
                        {
                            switch (reader.Name)
                            {
                            case "name":
                                if (reader.Read())
                                {
                                    xml_privatekeys_info.names.Add(reader.Value);
                                }
                                break;

                            case "type":
                                if (reader.Read())
                                {
                                    xml_privatekeys_info.types.Add(reader.Value);
                                }
                                break;

                            case "group":
                                if (reader.Read())
                                {
                                    xml_privatekeys_info.groups.Add(reader.Value);
                                }
                                break;

                            case "pwd":
                                if (reader.Read())
                                {
                                    if (reader.Value == " ")
                                    {
                                        xml_privatekeys_info.pwds.Add(null);
                                    }
                                    else
                                    {
                                        xml_privatekeys_info.pwds.Add(AESEncryptDecrypt.Decrypt(reader.Value));
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            } catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            return(xml_privatekeys_info);
        }