public ConnectionTreeModel Load()
        {
            var connector               = DatabaseConnectorFactory.SqlDatabaseConnectorFromSettings();
            var dataProvider            = new SqlDataProvider(connector);
            var metaDataRetriever       = new SqlDatabaseMetaDataRetriever();
            var databaseVersionVerifier = new SqlDatabaseVersionVerifier(connector);
            var cryptoProvider          = new LegacyRijndaelCryptographyProvider();

            var metaData = metaDataRetriever.GetDatabaseMetaData(connector) ??
                           HandleFirstRun(metaDataRetriever, connector);
            var decryptionKey = GetDecryptionKey(metaData);

            if (!decryptionKey.Any())
            {
                throw new Exception("Could not load SQL connections");
            }

            databaseVersionVerifier.VerifyDatabaseVersion(metaData.ConfVersion);
            var dataTable      = dataProvider.Load();
            var deserializer   = new DataTableDeserializer(cryptoProvider, decryptionKey.First());
            var connectionTree = deserializer.Deserialize(dataTable);

            ApplyLocalConnectionProperties(connectionTree.RootNodes.First(i => i is RootNodeInfo));
            return(connectionTree);
        }
Beispiel #2
0
        public override void SaveSettings()
        {
            Settings.Default.SingleClickOnConnectionOpensIt      = chkSingleClickOnConnectionOpensIt.Checked;
            Settings.Default.SingleClickSwitchesToOpenConnection = chkSingleClickOnOpenedConnectionSwitchesToIt.Checked;
            Settings.Default.SetHostnameLikeDisplayName          = chkHostnameLikeDisplayName.Checked;

            Settings.Default.RdpReconnectionCount = (int)numRdpReconnectionCount.Value;

            Settings.Default.ConRDPOverallConnectionTimeout = (int)numRDPConTimeout.Value;

            Settings.Default.AutoSaveEveryMinutes = (int)numAutoSave.Value;
            if (Settings.Default.AutoSaveEveryMinutes > 0)
            {
                frmMain.Default.tmrAutoSave.Interval = Convert.ToInt32(Settings.Default.AutoSaveEveryMinutes * 60000);
                frmMain.Default.tmrAutoSave.Enabled  = true;
            }
            else
            {
                frmMain.Default.tmrAutoSave.Enabled = false;
            }

            if (radCredentialsNoInfo.Checked)
            {
                // ReSharper disable once StringLiteralTypo
                Settings.Default.EmptyCredentials = "noinfo";
            }
            else if (radCredentialsWindows.Checked)
            {
                Settings.Default.EmptyCredentials = "windows";
            }
            else if (radCredentialsCustom.Checked)
            {
                Settings.Default.EmptyCredentials = "custom";
            }

            Settings.Default.DefaultUsername = txtCredentialsUsername.Text;
            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();

            Settings.Default.DefaultPassword = cryptographyProvider.Encrypt(txtCredentialsPassword.Text, Runtime.EncryptionKey);
            Settings.Default.DefaultDomain   = txtCredentialsDomain.Text;

            if (radCloseWarnAll.Checked)
            {
                Settings.Default.ConfirmCloseConnection = (int)ConfirmCloseEnum.All;
            }
            if (radCloseWarnMultiple.Checked)
            {
                Settings.Default.ConfirmCloseConnection = (int)ConfirmCloseEnum.Multiple;
            }
            if (radCloseWarnExit.Checked)
            {
                Settings.Default.ConfirmCloseConnection = (int)ConfirmCloseEnum.Exit;
            }
            if (radCloseWarnNever.Checked)
            {
                Settings.Default.ConfirmCloseConnection = (int)ConfirmCloseEnum.Never;
            }

            Settings.Default.Save();
        }
Beispiel #3
0
        private void UpdateRootNodeTable(RootNodeInfo rootTreeNode, SqlDatabaseConnector sqlDatabaseConnector)
        {
            var    cryptographyProvider = new LegacyRijndaelCryptographyProvider();
            string strProtected;

            if (rootTreeNode != null)
            {
                if (rootTreeNode.Password)
                {
                    _password    = Convert.ToString(rootTreeNode.PasswordString).ConvertToSecureString();
                    strProtected = cryptographyProvider.Encrypt("ThisIsProtected", _password);
                }
                else
                {
                    strProtected = cryptographyProvider.Encrypt("ThisIsNotProtected", _password);
                }
            }
            else
            {
                strProtected = cryptographyProvider.Encrypt("ThisIsNotProtected", _password);
            }

            var sqlQuery = new SqlCommand("DELETE FROM tblRoot", sqlDatabaseConnector.SqlConnection);

            sqlQuery.ExecuteNonQuery();

            sqlQuery = new SqlCommand("INSERT INTO tblRoot (Name, Export, Protected, ConfVersion) VALUES(\'" + MiscTools.PrepareValueForDB(rootTreeNode.Name) + "\', 0, \'" + strProtected + "\'," + ConnectionsFileInfo.ConnectionFileVersion.ToString(CultureInfo.InvariantCulture) + ")", sqlDatabaseConnector.SqlConnection);
            sqlQuery.ExecuteNonQuery();
        }
        private void SerializeRootNodeInfo(RootNodeInfo rootNodeInfo)
        {
            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();

            _xmlTextWriter.WriteStartElement("Connections"); // Do not localize
            _xmlTextWriter.WriteAttributeString("Name", "", rootNodeInfo.Name);
            _xmlTextWriter.WriteAttributeString("Export", "", Convert.ToString(Export));

            if (Export)
            {
                _xmlTextWriter.WriteAttributeString("Protected", "", cryptographyProvider.Encrypt("ThisIsNotProtected", _password));
            }
            else
            {
                if (rootNodeInfo.Password)
                {
                    _password = rootNodeInfo.PasswordString.ConvertToSecureString();
                    _xmlTextWriter.WriteAttributeString("Protected", "", cryptographyProvider.Encrypt("ThisIsProtected", _password));
                }
                else
                {
                    _xmlTextWriter.WriteAttributeString("Protected", "", cryptographyProvider.Encrypt("ThisIsNotProtected", _password));
                }
            }

            _xmlTextWriter.WriteAttributeString("ConfVersion", "", ConnectionsFileInfo.ConnectionFileVersion.ToString(CultureInfo.InvariantCulture));
        }
Beispiel #5
0
        public override void SaveSettings()
        {
            base.SaveSettings();

            Settings.Default.CheckForUpdatesOnStartup = chkCheckForUpdatesOnStartup.Checked;
            if (cboUpdateCheckFrequency.SelectedItem.ToString() == Language.strUpdateFrequencyDaily)
            {
                Settings.Default.CheckForUpdatesFrequencyDays = 1;
            }
            else if (cboUpdateCheckFrequency.SelectedItem.ToString() == Language.strUpdateFrequencyWeekly)
            {
                Settings.Default.CheckForUpdatesFrequencyDays = 7;
            }
            else if (cboUpdateCheckFrequency.SelectedItem.ToString() == Language.strUpdateFrequencyMonthly)
            {
                Settings.Default.CheckForUpdatesFrequencyDays = 31;
            }

            Settings.Default.UpdateUseProxy     = chkUseProxyForAutomaticUpdates.Checked;
            Settings.Default.UpdateProxyAddress = txtProxyAddress.Text;
            Settings.Default.UpdateProxyPort    = (int)numProxyPort.Value;

            Settings.Default.UpdateProxyUseAuthentication = chkUseProxyAuthentication.Checked;
            Settings.Default.UpdateProxyAuthUser          = txtProxyUsername.Text;
            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();

            Settings.Default.UpdateProxyAuthPass = cryptographyProvider.Encrypt(txtProxyPassword.Text, Runtime.EncryptionKey);

            Settings.Default.Save();
        }
Beispiel #6
0
        public override void LoadSettings()
        {
            base.SaveSettings();

            chkCheckForUpdatesOnStartup.Checked = Convert.ToBoolean(Settings.Default.CheckForUpdatesOnStartup);
            cboUpdateCheckFrequency.Enabled     = chkCheckForUpdatesOnStartup.Checked;
            cboUpdateCheckFrequency.Items.Clear();
            var nDaily   = cboUpdateCheckFrequency.Items.Add(Language.strUpdateFrequencyDaily);
            var nWeekly  = cboUpdateCheckFrequency.Items.Add(Language.strUpdateFrequencyWeekly);
            var nMonthly = cboUpdateCheckFrequency.Items.Add(Language.strUpdateFrequencyMonthly);

            if (Settings.Default.CheckForUpdatesFrequencyDays < 1)
            {
                chkCheckForUpdatesOnStartup.Checked   = false;
                cboUpdateCheckFrequency.SelectedIndex = nDaily;
            } // Daily
            else if (Settings.Default.CheckForUpdatesFrequencyDays == 1)
            {
                cboUpdateCheckFrequency.SelectedIndex = nDaily;
            } // Weekly
            else if (Settings.Default.CheckForUpdatesFrequencyDays == 7)
            {
                cboUpdateCheckFrequency.SelectedIndex = nWeekly;
            } // Monthly
            else if (Settings.Default.CheckForUpdatesFrequencyDays == 31)
            {
                cboUpdateCheckFrequency.SelectedIndex = nMonthly;
            }
            else
            {
                var nCustom =
                    cboUpdateCheckFrequency.Items.Add(string.Format(Language.strUpdateFrequencyCustom,
                                                                    Settings.Default.CheckForUpdatesFrequencyDays));
                cboUpdateCheckFrequency.SelectedIndex = nCustom;
            }

            chkUseProxyForAutomaticUpdates.Checked = Convert.ToBoolean(Settings.Default.UpdateUseProxy);
            pnlProxyBasic.Enabled = Convert.ToBoolean(Settings.Default.UpdateUseProxy);
            txtProxyAddress.Text  = Convert.ToString(Settings.Default.UpdateProxyAddress);
            numProxyPort.Value    = Convert.ToDecimal(Settings.Default.UpdateProxyPort);

            chkUseProxyAuthentication.Checked = Convert.ToBoolean(Settings.Default.UpdateProxyUseAuthentication);
            pnlProxyAuthentication.Enabled    = Convert.ToBoolean(Settings.Default.UpdateProxyUseAuthentication);
            txtProxyUsername.Text             = Convert.ToString(Settings.Default.UpdateProxyAuthUser);
            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();

            txtProxyPassword.Text = cryptographyProvider.Decrypt(Convert.ToString(Settings.Default.UpdateProxyAuthPass), Runtime.EncryptionKey);

            btnTestProxy.Enabled = Convert.ToBoolean(Settings.Default.UpdateUseProxy);

#if PORTABLE
            foreach (Control Control in Controls)
            {
                if (Control != lblUpdatesExplanation)
                {
                    Control.Visible = false;
                }
            }
#endif
        }
Beispiel #7
0
 private string GetPassword(string password, string userName, string domain, string host)
 {
     if (string.IsNullOrEmpty(password))
     {
         if (Settings.Default.EmptyCredentials == "custom")
         {
             if (Settings.Default.DefaultPassword != "")
             {
                 var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
                 password = cryptographyProvider.Decrypt(Settings.Default.DefaultPassword, Runtime.EncryptionKey);
             }
         }
         if (Settings.Default.EmptyCredentials == "admpwd")
         {
             if (domain == ".")
             {
                 password = AdmPwd.PDSUtils.PdsWrapper.GetLocalAdminPassword(null, host, false, false).Password;
             }
             else
             {
                 password = AdmPwd.PDSUtils.PdsWrapper.GetManagedAccountPassword(domain, userName, false).Password;
             }
         }
     }
     return(password);
 }
Beispiel #8
0
        public static void SaveConnections(bool Update = false)
        {
            if (!IsConnectionsFileLoaded)
            {
                return;
            }

            try
            {
                if (Update && Settings.Default.UseSQLServer == false)
                {
                    return;
                }

                if (SQLConnProvider != null)
                {
                    SQLConnProvider.Disable();
                }

                ConnectionsSaver conS = new ConnectionsSaver();

                if (!Settings.Default.UseSQLServer)
                {
                    conS.ConnectionFileName = GetStartupConnectionFileName();
                }

                conS.ConnectionList = ConnectionList;
                conS.ContainerList  = ContainerList;
                conS.Export         = false;
                conS.SaveSecurity   = new Security.Save();
                conS.RootTreeNode   = Windows.treeForm.tvConnections.Nodes[0];

                if (Settings.Default.UseSQLServer)
                {
                    conS.SaveFormat      = ConnectionsSaver.Format.SQL;
                    conS.SQLHost         = Convert.ToString(Settings.Default.SQLHost);
                    conS.SQLDatabaseName = Convert.ToString(Settings.Default.SQLDatabaseName);
                    conS.SQLUsername     = Convert.ToString(Settings.Default.SQLUser);
                    var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
                    conS.SQLPassword = cryptographyProvider.Decrypt(Convert.ToString(Settings.Default.SQLPass), GeneralAppInfo.EncryptionKey);
                }

                conS.SaveConnections();

                if (Settings.Default.UseSQLServer)
                {
                    LastSqlUpdate = DateTime.Now;
                }
            }
            catch (Exception ex)
            {
                MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.strConnectionsFileCouldNotBeSaved + Environment.NewLine + ex.Message);
            }
            finally
            {
                SQLConnProvider?.Enable();
            }
        }
Beispiel #9
0
        private void GetSqlConnectionDataFromSettings()
        {
            _sqlHost     = mRemoteNG.Settings.Default.SQLHost;
            _sqlCatalog  = mRemoteNG.Settings.Default.SQLDatabaseName;
            _sqlUsername = mRemoteNG.Settings.Default.SQLUser;
            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();

            _sqlPassword = cryptographyProvider.Decrypt(mRemoteNG.Settings.Default.SQLPass, Runtime.EncryptionKey);
        }
        public static SqlDatabaseConnector SqlDatabaseConnectorFromSettings()
        {
            var sqlHost              = mRemoteNG.Settings.Default.SQLHost;
            var sqlCatalog           = mRemoteNG.Settings.Default.SQLDatabaseName;
            var sqlUsername          = mRemoteNG.Settings.Default.SQLUser;
            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
            var sqlPassword          = cryptographyProvider.Decrypt(mRemoteNG.Settings.Default.SQLPass, Runtime.EncryptionKey);

            return(new SqlDatabaseConnector(sqlHost, sqlCatalog, sqlUsername, sqlPassword));
        }
Beispiel #11
0
        public override void LoadSettings()
        {
            base.SaveSettings();

            chkCheckForUpdatesOnStartup.Checked = Convert.ToBoolean(Settings.Default.CheckForUpdatesOnStartup);
            cboUpdateCheckFrequency.Enabled     = chkCheckForUpdatesOnStartup.Checked;
            cboUpdateCheckFrequency.Items.Clear();
            var nDaily   = cboUpdateCheckFrequency.Items.Add(Language.strUpdateFrequencyDaily);
            var nWeekly  = cboUpdateCheckFrequency.Items.Add(Language.strUpdateFrequencyWeekly);
            var nMonthly = cboUpdateCheckFrequency.Items.Add(Language.strUpdateFrequencyMonthly);

            if (Settings.Default.CheckForUpdatesFrequencyDays < 1)
            {
                chkCheckForUpdatesOnStartup.Checked   = false;
                cboUpdateCheckFrequency.SelectedIndex = nDaily;
            } // Daily
            else
            {
                switch (Settings.Default.CheckForUpdatesFrequencyDays)
                {
                case 1:
                    cboUpdateCheckFrequency.SelectedIndex = nDaily;
                    break;

                case 7:
                    cboUpdateCheckFrequency.SelectedIndex = nWeekly;
                    break;

                case 31:
                    cboUpdateCheckFrequency.SelectedIndex = nMonthly;
                    break;

                default:
                    var nCustom =
                        cboUpdateCheckFrequency.Items.Add(string.Format(Language.strUpdateFrequencyCustom,
                                                                        Settings.Default.CheckForUpdatesFrequencyDays));
                    cboUpdateCheckFrequency.SelectedIndex = nCustom;
                    break;
                }
            }

            chkUseProxyForAutomaticUpdates.Checked = Convert.ToBoolean(Settings.Default.UpdateUseProxy);
            pnlProxyBasic.Enabled = Convert.ToBoolean(Settings.Default.UpdateUseProxy);
            txtProxyAddress.Text  = Convert.ToString(Settings.Default.UpdateProxyAddress);
            numProxyPort.Value    = Convert.ToDecimal(Settings.Default.UpdateProxyPort);

            chkUseProxyAuthentication.Checked = Convert.ToBoolean(Settings.Default.UpdateProxyUseAuthentication);
            pnlProxyAuthentication.Enabled    = Convert.ToBoolean(Settings.Default.UpdateProxyUseAuthentication);
            txtProxyUsername.Text             = Convert.ToString(Settings.Default.UpdateProxyAuthUser);
            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();

            txtProxyPassword.Text = cryptographyProvider.Decrypt(Convert.ToString(Settings.Default.UpdateProxyAuthPass), Runtime.EncryptionKey);

            btnTestProxy.Enabled = Convert.ToBoolean(Settings.Default.UpdateUseProxy);
        }
Beispiel #12
0
        public override void LoadSettings()
        {
            base.SaveSettings();

            chkSingleClickOnConnectionOpensIt.Checked =
                Convert.ToBoolean(Settings.Default.SingleClickOnConnectionOpensIt);
            chkSingleClickOnOpenedConnectionSwitchesToIt.Checked =
                Convert.ToBoolean(Settings.Default.SingleClickSwitchesToOpenConnection);
            chkHostnameLikeDisplayName.Checked = Convert.ToBoolean(Settings.Default.SetHostnameLikeDisplayName);

            numRdpReconnectionCount.Value = Convert.ToDecimal(Settings.Default.RdpReconnectionCount);

            numRDPConTimeout.Value = Convert.ToDecimal(Settings.Default.ConRDPOverallConnectionTimeout);

            numAutoSave.Value = Convert.ToDecimal(Settings.Default.AutoSaveEveryMinutes);

            // ReSharper disable once StringLiteralTypo
            if (Settings.Default.EmptyCredentials == "noinfo")
            {
                radCredentialsNoInfo.Checked = true;
            }
            else if (Settings.Default.EmptyCredentials == "windows")
            {
                radCredentialsWindows.Checked = true;
            }
            else if (Settings.Default.EmptyCredentials == "custom")
            {
                radCredentialsCustom.Checked = true;
            }

            txtCredentialsUsername.Text = Convert.ToString(Settings.Default.DefaultUsername);
            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();

            txtCredentialsPassword.Text = cryptographyProvider.Decrypt(Convert.ToString(Settings.Default.DefaultPassword), Runtime.EncryptionKey);
            txtCredentialsDomain.Text   = Convert.ToString(Settings.Default.DefaultDomain);

            if (Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.Never)
            {
                radCloseWarnNever.Checked = true;
            }
            else if (Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.Exit)
            {
                radCloseWarnExit.Checked = true;
            }
            else if (Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.Multiple)
            {
                radCloseWarnMultiple.Checked = true;
            }
            else
            {
                radCloseWarnAll.Checked = true;
            }
        }
Beispiel #13
0
        public static void SaveConnections(bool update = false)
        {
            if (ConnectionTreeModel == null)
            {
                return;
            }

            try
            {
                if (update && Settings.Default.UseSQLServer == false)
                {
                    return;
                }

                RemoteConnectionsSyncronizer?.Disable();

                var connectionsSaver = new ConnectionsSaver();

                if (!Settings.Default.UseSQLServer)
                {
                    connectionsSaver.ConnectionFileName = GetStartupConnectionFileName();
                }

                connectionsSaver.Export              = false;
                connectionsSaver.SaveFilter          = new SaveFilter();
                connectionsSaver.ConnectionTreeModel = ConnectionTreeModel;

                if (Settings.Default.UseSQLServer)
                {
                    connectionsSaver.SaveFormat      = ConnectionsSaver.Format.SQL;
                    connectionsSaver.SQLHost         = Convert.ToString(Settings.Default.SQLHost);
                    connectionsSaver.SQLDatabaseName = Convert.ToString(Settings.Default.SQLDatabaseName);
                    connectionsSaver.SQLUsername     = Convert.ToString(Settings.Default.SQLUser);
                    var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
                    connectionsSaver.SQLPassword = cryptographyProvider.Decrypt(Convert.ToString(Settings.Default.SQLPass), EncryptionKey);
                }

                connectionsSaver.SaveConnections();

                if (Settings.Default.UseSQLServer)
                {
                    LastSqlUpdate = DateTime.Now;
                }
            }
            catch (Exception ex)
            {
                MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.strConnectionsFileCouldNotBeSaved + Environment.NewLine + ex.Message);
            }
            finally
            {
                RemoteConnectionsSyncronizer?.Enable();
            }
        }
Beispiel #14
0
        public void SetProxySettings()
        {
            var shouldWeUseProxy     = Settings.Default.UpdateUseProxy;
            var proxyAddress         = Settings.Default.UpdateProxyAddress;
            var port                 = Settings.Default.UpdateProxyPort;
            var useAuthentication    = Settings.Default.UpdateProxyUseAuthentication;
            var username             = Settings.Default.UpdateProxyAuthUser;
            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
            var password             = cryptographyProvider.Decrypt(Settings.Default.UpdateProxyAuthPass, GeneralAppInfo.EncryptionKey);

            SetProxySettings(shouldWeUseProxy, proxyAddress, port, useAuthentication, username, password);
        }
Beispiel #15
0
        public override void LoadSettings()
        {
            base.SaveSettings();

            chkUseSQLServer.Checked = Settings.Default.UseSQLServer;
            txtSQLServer.Text       = Settings.Default.SQLHost;
            txtSQLDatabaseName.Text = Settings.Default.SQLDatabaseName;
            txtSQLUsername.Text     = Settings.Default.SQLUser;
            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();

            txtSQLPassword.Text = cryptographyProvider.Decrypt(Settings.Default.SQLPass, Runtime.EncryptionKey);
        }
        private string DecryptCompleteFile()
        {
            var sRd = new StreamReader(ConnectionFileName);
            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
            var strCons = "";

            strCons = sRd.ReadToEnd();
            sRd.Close();

            if (string.IsNullOrEmpty(strCons))
            {
                return("");
            }
            var  strDecr = "";
            bool notDecr;

            if (strCons.Contains("<?xml version=\"1.0\" encoding=\"utf-8\"?>"))
            {
                strDecr = strCons;
                return(strDecr);
            }

            try
            {
                strDecr = cryptographyProvider.Decrypt(strCons, _pW);
                notDecr = strDecr == strCons;
            }
            catch (Exception)
            {
                notDecr = true;
            }

            if (notDecr)
            {
                if (Authenticate(strCons, true))
                {
                    strDecr = cryptographyProvider.Decrypt(strCons, _pW);
                    notDecr = false;
                }

                if (notDecr == false)
                {
                    return(strDecr);
                }
            }
            else
            {
                return(strDecr);
            }

            return("");
        }
Beispiel #17
0
        public override void SaveSettings()
        {
            base.SaveSettings();

            mRemoteNG.Settings.Default.UseSQLServer    = chkUseSQLServer.Checked;
            mRemoteNG.Settings.Default.SQLHost         = txtSQLServer.Text;
            mRemoteNG.Settings.Default.SQLDatabaseName = txtSQLDatabaseName.Text;
            mRemoteNG.Settings.Default.SQLUser         = txtSQLUsername.Text;
            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();

            mRemoteNG.Settings.Default.SQLPass = cryptographyProvider.Encrypt(txtSQLPassword.Text, GeneralAppInfo.EncryptionKey);
            ReinitializeSqlUpdater();
        }
        private Optional <SecureString> GetDecryptionKey(SqlConnectionListMetaData metaData)
        {
            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
            var cipherText           = metaData.Protected;
            var authenticator        = new PasswordAuthenticator(cryptographyProvider, cipherText, AuthenticationRequestor);
            var authenticated        = authenticator.Authenticate(new RootNodeInfo(RootNodeType.Connection).DefaultPassword.ConvertToSecureString());

            if (authenticated)
            {
                return(authenticator.LastAuthenticatedPassword);
            }
            return(Optional <SecureString> .Empty);
        }
        public string DecryptConnections(string xml)
        {
            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();

            if (string.IsNullOrEmpty(xml))
            {
                return("");
            }
            if (xml.Contains("<?xml version=\"1.0\" encoding=\"utf-8\"?>"))
            {
                return(xml);
            }

            var  strDecr = "";
            bool notDecr;

            try
            {
                strDecr = cryptographyProvider.Decrypt(xml, Runtime.EncryptionKey);
                notDecr = strDecr == xml;
            }
            catch (Exception)
            {
                notDecr = true;
            }

            if (notDecr)
            {
                if (Authenticate(xml, true))
                {
                    strDecr = cryptographyProvider.Decrypt(xml, Runtime.EncryptionKey);
                    notDecr = false;
                }

                if (notDecr == false)
                {
                    return(strDecr);
                }
            }
            else
            {
                return(strDecr);
            }

            return("");
        }
Beispiel #20
0
        private void EncryptCompleteFile()
        {
            var streamReader         = new StreamReader(ConnectionFileName);
            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();

            var fileContents = streamReader.ReadToEnd();

            streamReader.Close();

            if (string.IsNullOrEmpty(fileContents))
            {
                return;
            }
            var streamWriter = new StreamWriter(ConnectionFileName);

            streamWriter.Write(cryptographyProvider.Encrypt(fileContents, _password));
            streamWriter.Close();
        }
        public void WriteDatabaseMetaData(RootNodeInfo rootTreeNode, SqlDatabaseConnector sqlDatabaseConnector)
        {
            var    cryptographyProvider = new LegacyRijndaelCryptographyProvider();
            string strProtected;

            if (rootTreeNode != null)
            {
                if (rootTreeNode.Password)
                {
                    var password = rootTreeNode.PasswordString.ConvertToSecureString();
                    strProtected = cryptographyProvider.Encrypt("ThisIsProtected", password);
                }
                else
                {
                    strProtected = cryptographyProvider.Encrypt("ThisIsNotProtected", Runtime.EncryptionKey);
                }
            }
            else
            {
                strProtected = cryptographyProvider.Encrypt("ThisIsNotProtected", Runtime.EncryptionKey);
            }

            var sqlQuery = new SqlCommand("DELETE FROM tblRoot", sqlDatabaseConnector.SqlConnection);

            sqlQuery.ExecuteNonQuery();

            if (rootTreeNode != null)
            {
                sqlQuery =
                    new SqlCommand(
                        "INSERT INTO tblRoot (Name, Export, Protected, ConfVersion) VALUES(\'" +
                        MiscTools.PrepareValueForDB(rootTreeNode.Name) + "\', 0, \'" + strProtected + "\'," +
                        ConnectionsFileInfo.ConnectionFileVersion.ToString(CultureInfo.InvariantCulture) + ")",
                        sqlDatabaseConnector.SqlConnection);
                sqlQuery.ExecuteNonQuery();
            }
            else
            {
                Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, $"UpdateRootNodeTable: rootTreeNode was null. Could not insert!");
            }
        }
        private bool Authenticate(string value, bool compareToOriginalValue, RootNodeInfo rootInfo = null)
        {
            var passwordName         = "";
            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();

            passwordName = Language.strSQLServer.TrimEnd(':');


            if (compareToOriginalValue)
            {
                while (cryptographyProvider.Decrypt(value, _pW) == value)
                {
                    _pW = Tools.MiscTools.PasswordDialog(passwordName, false);
                    if (_pW.Length == 0)
                    {
                        return(false);
                    }
                }
            }
            else
            {
                while (cryptographyProvider.Decrypt(value, _pW) != "ThisIsProtected")
                {
                    _pW = Tools.MiscTools.PasswordDialog(passwordName, false);
                    if (_pW.Length == 0)
                    {
                        return(false);
                    }
                }

                if (rootInfo == null)
                {
                    return(true);
                }
                rootInfo.Password       = true;
                rootInfo.PasswordString = _pW.ConvertToUnsecureString();
            }

            return(true);
        }
        private bool ConnectionsFileIsAuthentic(RootNodeInfo rootInfo)
        {
            if (!(_confVersion > 1.3))
            {
                return(true);
            }
            var protectedString               = _xmlDocument.DocumentElement.Attributes["Protected"].Value;
            var cryptographyProvider          = new LegacyRijndaelCryptographyProvider();
            var connectionsFileIsNotEncrypted = cryptographyProvider.Decrypt(protectedString, _pW) == "ThisIsNotProtected";

            if (connectionsFileIsNotEncrypted)
            {
                return(true);
            }
            if (Authenticate(protectedString, false, rootInfo))
            {
                return(true);
            }
            mRemoteNG.Settings.Default.LoadConsFromCustomLocation = false;
            mRemoteNG.Settings.Default.CustomConsPath             = "";
            RootTreeNode.Remove();
            return(false);
        }
Beispiel #24
0
        public override bool Connect()
        {
            try
            {
                _isPuttyNg = PuttyTypeDetector.GetPuttyType() == PuttyTypeDetector.PuttyType.PuttyNg;

                PuttyProcess = new Process
                {
                    StartInfo =
                    {
                        UseShellExecute = false,
                        FileName        = PuttyPath
                    }
                };

                var arguments = new CommandLineArguments {
                    EscapeForShell = false
                };

                arguments.Add("-load", InterfaceControl.Info.PuttySession);

                if (!(InterfaceControl.Info is PuttySessionInfo))
                {
                    arguments.Add("-" + PuttyProtocol);

                    if (PuttyProtocol == Putty_Protocol.ssh)
                    {
                        var username = "";
                        var password = "";

                        if (!string.IsNullOrEmpty(InterfaceControl.Info?.Username))
                        {
                            username = InterfaceControl.Info.Username;
                        }
                        else
                        {
                            // ReSharper disable once SwitchStatementMissingSomeCases
                            switch (Settings.Default.EmptyCredentials)
                            {
                            case "windows":
                                username = Environment.UserName;
                                break;

                            case "custom":
                                username = Settings.Default.DefaultUsername;
                                break;
                            }
                        }

                        if (!string.IsNullOrEmpty(InterfaceControl.Info?.Password))
                        {
                            password = InterfaceControl.Info.Password;
                        }
                        else
                        {
                            if (Settings.Default.EmptyCredentials == "custom")
                            {
                                var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
                                password = cryptographyProvider.Decrypt(Settings.Default.DefaultPassword,
                                                                        Runtime.EncryptionKey);
                            }
                        }

                        arguments.Add("-" + (int)PuttySSHVersion);

                        if (!Force.HasFlag(ConnectionInfo.Force.NoCredentials))
                        {
                            if (!string.IsNullOrEmpty(username))
                            {
                                arguments.Add("-l", username);
                            }

                            if (!string.IsNullOrEmpty(password))
                            {
                                arguments.Add("-pw", password);
                            }
                        }
                    }

                    arguments.Add("-P", InterfaceControl.Info.Port.ToString());
                    arguments.Add(InterfaceControl.Info.Hostname);
                }

                if (_isPuttyNg)
                {
                    arguments.Add("-hwndparent", InterfaceControl.Handle.ToString());
                }

                PuttyProcess.StartInfo.Arguments = arguments.ToString();

                PuttyProcess.EnableRaisingEvents = true;
                PuttyProcess.Exited += ProcessExited;

                PuttyProcess.Start();
                PuttyProcess.WaitForInputIdle(Settings.Default.MaxPuttyWaitTime * 1000);

                var startTicks = Environment.TickCount;
                while (PuttyHandle.ToInt32() == 0 &
                       Environment.TickCount < startTicks + Settings.Default.MaxPuttyWaitTime * 1000)
                {
                    if (_isPuttyNg)
                    {
                        PuttyHandle = NativeMethods.FindWindowEx(
                            InterfaceControl.Handle, new IntPtr(0), null, null);
                    }
                    else
                    {
                        PuttyProcess.Refresh();
                        PuttyHandle = PuttyProcess.MainWindowHandle;
                    }

                    if (PuttyHandle.ToInt32() == 0)
                    {
                        Thread.Sleep(0);
                    }
                }

                if (!_isPuttyNg)
                {
                    NativeMethods.SetParent(PuttyHandle, InterfaceControl.Handle);
                }

                Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.strPuttyStuff, true);
                Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg,
                                                    string.Format(Language.strPuttyHandle, PuttyHandle), true);
                Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg,
                                                    string.Format(Language.strPuttyTitle, PuttyProcess.MainWindowTitle),
                                                    true);
                Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg,
                                                    string.Format(Language.strPuttyParentHandle,
                                                                  InterfaceControl.Parent.Handle), true);

                Resize(this, new EventArgs());
                base.Connect();
                return(true);
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg,
                                                    Language.strPuttyConnectionFailed + Environment.NewLine +
                                                    ex.Message);
                return(false);
            }
        }
Beispiel #25
0
        private void SetCredentials()
        {
            try
            {
                if (((int)Force & (int)Connection.ConnectionInfo.Force.NoCredentials) == (int)Connection.ConnectionInfo.Force.NoCredentials)
                {
                    return;
                }

                string _user = this._Info.Username;
                string _pass = this._Info.Password;
                string _dom  = this._Info.Domain;

                if (string.IsNullOrEmpty(_user))
                {
                    if ((string)mRemoteNG.Settings.Default.EmptyCredentials == "windows")
                    {
                        _ICAClient.Username = Environment.UserName;
                    }
                    else if ((string)mRemoteNG.Settings.Default.EmptyCredentials == "custom")
                    {
                        _ICAClient.Username = mRemoteNG.Settings.Default.DefaultUsername;
                    }
                }
                else
                {
                    _ICAClient.Username = _user;
                }

                if (string.IsNullOrEmpty(_pass))
                {
                    if ((string)mRemoteNG.Settings.Default.EmptyCredentials == "custom")
                    {
                        if (mRemoteNG.Settings.Default.DefaultPassword != "")
                        {
                            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
                            _ICAClient.SetProp("ClearPassword", cryptographyProvider.Decrypt(Settings.Default.DefaultPassword, GeneralAppInfo.EncryptionKey));
                        }
                    }
                }
                else
                {
                    _ICAClient.SetProp("ClearPassword", _pass);
                }

                if (string.IsNullOrEmpty(_dom))
                {
                    if ((string)mRemoteNG.Settings.Default.EmptyCredentials == "windows")
                    {
                        _ICAClient.Domain = Environment.UserDomainName;
                    }
                    else if ((string)mRemoteNG.Settings.Default.EmptyCredentials == "custom")
                    {
                        _ICAClient.Domain = mRemoteNG.Settings.Default.DefaultDomain;
                    }
                }
                else
                {
                    _ICAClient.Domain = _dom;
                }
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg, Language.strIcaSetCredentialsFailed + Environment.NewLine + ex.Message, true);
            }
        }
        private string GetVariableReplacement(string variable, string original)
        {
            var replacement = "";

            if (_connectionInfo == null)
            {
                return(replacement);
            }
            switch (variable.ToLowerInvariant())
            {
            case "name":
                replacement = _connectionInfo.Name;
                break;

            case "hostname":
                replacement = _connectionInfo.Hostname;
                break;

            case "port":
                replacement = Convert.ToString(_connectionInfo.Port);
                break;

            case "username":
                replacement = _connectionInfo.Username;
                if (string.IsNullOrEmpty(replacement))
                {
                    if (Settings.Default.EmptyCredentials == "windows")
                    {
                        replacement = Environment.UserName;
                    }
                    else if (Settings.Default.EmptyCredentials == "custom")
                    {
                        replacement = Settings.Default.DefaultUsername;
                    }
                }
                break;

            case "password":
                replacement = _connectionInfo.Password;
                if (string.IsNullOrEmpty(replacement) && Settings.Default.EmptyCredentials == "custom")
                {
                    replacement = new LegacyRijndaelCryptographyProvider()
                                  .Decrypt(Convert.ToString(Settings.Default.DefaultPassword),
                                           Runtime.EncryptionKey);
                }
                break;

            case "domain":
                replacement = _connectionInfo.Domain;
                if (string.IsNullOrEmpty(replacement))
                {
                    if (Settings.Default.EmptyCredentials == "windows")
                    {
                        replacement = Environment.UserDomainName;
                    }
                    else if (Settings.Default.EmptyCredentials == "custom")
                    {
                        replacement = Settings.Default.DefaultDomain;
                    }
                }
                break;

            case "description":
                replacement = _connectionInfo.Description;
                break;

            case "macaddress":
                replacement = _connectionInfo.MacAddress;
                break;

            case "userfield":
                replacement = _connectionInfo.UserField;
                break;

            default:
                return(original);
            }
            return(replacement);
        }
Beispiel #27
0
        private void SetCredentials()
        {
            try
            {
                if ((Force & ConnectionInfo.Force.NoCredentials) == ConnectionInfo.Force.NoCredentials)
                {
                    return;
                }

                string userName = _connectionInfo.Username;
                string password = _connectionInfo.Password;
                string domain   = _connectionInfo.Domain;

                if (string.IsNullOrEmpty(userName))
                {
                    if (Settings.Default.EmptyCredentials == "windows")
                    {
                        _rdpClient.UserName = Environment.UserName;
                    }
                    else if (Settings.Default.EmptyCredentials == "custom")
                    {
                        _rdpClient.UserName = Convert.ToString(Settings.Default.DefaultUsername);
                    }
                }
                else
                {
                    _rdpClient.UserName = userName;
                }

                if (string.IsNullOrEmpty(password))
                {
                    if (Settings.Default.EmptyCredentials == "custom")
                    {
                        if (Settings.Default.DefaultPassword != "")
                        {
                            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
                            _rdpClient.AdvancedSettings2.ClearTextPassword = cryptographyProvider.Decrypt(Convert.ToString(Settings.Default.DefaultPassword), App.Info.GeneralAppInfo.EncryptionKey);
                        }
                    }
                }
                else
                {
                    _rdpClient.AdvancedSettings2.ClearTextPassword = password;
                }

                if (string.IsNullOrEmpty(domain))
                {
                    if (Settings.Default.EmptyCredentials == "windows")
                    {
                        _rdpClient.Domain = Environment.UserDomainName;
                    }
                    else if (Settings.Default.EmptyCredentials == "custom")
                    {
                        _rdpClient.Domain = Convert.ToString(Settings.Default.DefaultDomain);
                    }
                }
                else
                {
                    _rdpClient.Domain = domain;
                }
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddExceptionStackTrace(Language.strRdpSetCredentialsFailed, ex);
            }
        }
Beispiel #28
0
        private void SetCredentials()
        {
            try
            {
                if (Force.HasFlag(ConnectionInfo.Force.NoCredentials))
                {
                    return;
                }

                var user = _info?.Username ?? "";
                var pass = _info?.Password ?? "";
                var dom  = _info?.Domain ?? "";

                if (string.IsNullOrEmpty(user))
                {
                    if (Settings.Default.EmptyCredentials == "windows")
                    {
                        _icaClient.Username = Environment.UserName;
                    }
                    else if (Settings.Default.EmptyCredentials == "custom")
                    {
                        _icaClient.Username = Settings.Default.DefaultUsername;
                    }
                }
                else
                {
                    _icaClient.Username = user;
                }

                if (string.IsNullOrEmpty(pass))
                {
                    if (Settings.Default.EmptyCredentials == "custom")
                    {
                        if (Settings.Default.DefaultPassword != "")
                        {
                            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
                            _icaClient.SetProp("ClearPassword",
                                               cryptographyProvider.Decrypt(Settings.Default.DefaultPassword,
                                                                            Runtime.EncryptionKey));
                        }
                    }
                }
                else
                {
                    _icaClient.SetProp("ClearPassword", pass);
                }

                if (string.IsNullOrEmpty(dom))
                {
                    if (Settings.Default.EmptyCredentials == "windows")
                    {
                        _icaClient.Domain = Environment.UserDomainName;
                    }
                    else if (Settings.Default.EmptyCredentials == "custom")
                    {
                        _icaClient.Domain = Settings.Default.DefaultDomain;
                    }
                }
                else
                {
                    _icaClient.Domain = dom;
                }
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg,
                                                    Language.strIcaSetCredentialsFailed + Environment.NewLine +
                                                    ex.Message, true);
            }
        }
        private ConnectionInfo GetConnectionInfoFromXml(XmlNode xxNode)
        {
            var connectionInfo       = new ConnectionInfo();
            var cryptographyProvider = new LegacyRijndaelCryptographyProvider();

            try
            {
                var xmlnode = xxNode;
                if (_confVersion > 0.1) //0.2
                {
                    connectionInfo.Name             = xmlnode.Attributes["Name"].Value;
                    connectionInfo.Description      = xmlnode.Attributes["Descr"].Value;
                    connectionInfo.Hostname         = xmlnode.Attributes["Hostname"].Value;
                    connectionInfo.Username         = xmlnode.Attributes["Username"].Value;
                    connectionInfo.Password         = cryptographyProvider.Decrypt(xmlnode.Attributes["Password"].Value, _pW);
                    connectionInfo.Domain           = xmlnode.Attributes["Domain"].Value;
                    connectionInfo.DisplayWallpaper = bool.Parse(xmlnode.Attributes["DisplayWallpaper"].Value);
                    connectionInfo.DisplayThemes    = bool.Parse(xmlnode.Attributes["DisplayThemes"].Value);
                    connectionInfo.CacheBitmaps     = bool.Parse(xmlnode.Attributes["CacheBitmaps"].Value);

                    if (_confVersion < 1.1) //1.0 - 0.1
                    {
                        connectionInfo.Resolution = Convert.ToBoolean(xmlnode.Attributes["Fullscreen"].Value) ? ProtocolRDP.RDPResolutions.Fullscreen : ProtocolRDP.RDPResolutions.FitToWindow;
                    }
                }

                if (_confVersion > 0.2) //0.3
                {
                    if (_confVersion < 0.7)
                    {
                        if (Convert.ToBoolean(xmlnode.Attributes["UseVNC"].Value))
                        {
                            connectionInfo.Protocol = ProtocolType.VNC;
                            connectionInfo.Port     = Convert.ToInt32(xmlnode.Attributes["VNCPort"].Value);
                        }
                        else
                        {
                            connectionInfo.Protocol = ProtocolType.RDP;
                        }
                    }
                }
                else
                {
                    connectionInfo.Port     = (int)ProtocolRDP.Defaults.Port;
                    connectionInfo.Protocol = ProtocolType.RDP;
                }

                if (_confVersion > 0.3) //0.4
                {
                    if (_confVersion < 0.7)
                    {
                        if (Convert.ToBoolean(xmlnode.Attributes["UseVNC"].Value))
                        {
                            connectionInfo.Port = Convert.ToInt32(xmlnode.Attributes["VNCPort"].Value);
                        }
                        else
                        {
                            connectionInfo.Port = Convert.ToInt32(xmlnode.Attributes["RDPPort"].Value);
                        }
                    }

                    connectionInfo.UseConsoleSession = bool.Parse(xmlnode.Attributes["ConnectToConsole"].Value);
                }
                else
                {
                    if (_confVersion < 0.7)
                    {
                        if (Convert.ToBoolean(xmlnode.Attributes["UseVNC"].Value))
                        {
                            connectionInfo.Port = (int)ProtocolVNC.Defaults.Port;
                        }
                        else
                        {
                            connectionInfo.Port = (int)ProtocolRDP.Defaults.Port;
                        }
                    }
                    connectionInfo.UseConsoleSession = false;
                }

                if (_confVersion > 0.4) //0.5 and 0.6
                {
                    connectionInfo.RedirectDiskDrives = bool.Parse(xmlnode.Attributes["RedirectDiskDrives"].Value);
                    connectionInfo.RedirectPrinters   = bool.Parse(xmlnode.Attributes["RedirectPrinters"].Value);
                    connectionInfo.RedirectPorts      = bool.Parse(xmlnode.Attributes["RedirectPorts"].Value);
                    connectionInfo.RedirectSmartCards = bool.Parse(xmlnode.Attributes["RedirectSmartCards"].Value);
                }
                else
                {
                    connectionInfo.RedirectDiskDrives = false;
                    connectionInfo.RedirectPrinters   = false;
                    connectionInfo.RedirectPorts      = false;
                    connectionInfo.RedirectSmartCards = false;
                }

                if (_confVersion > 0.6) //0.7
                {
                    connectionInfo.Protocol = (ProtocolType)Tools.MiscTools.StringToEnum(typeof(ProtocolType), xmlnode.Attributes["Protocol"].Value);
                    connectionInfo.Port     = Convert.ToInt32(xmlnode.Attributes["Port"].Value);
                }

                if (_confVersion > 0.9) //1.0
                {
                    connectionInfo.RedirectKeys = bool.Parse(xmlnode.Attributes["RedirectKeys"].Value);
                }

                if (_confVersion > 1.1) //1.2
                {
                    connectionInfo.PuttySession = xmlnode.Attributes["PuttySession"].Value;
                }

                if (_confVersion > 1.2) //1.3
                {
                    connectionInfo.Colors        = (ProtocolRDP.RDPColors)Tools.MiscTools.StringToEnum(typeof(ProtocolRDP.RDPColors), xmlnode.Attributes["Colors"].Value);
                    connectionInfo.Resolution    = (ProtocolRDP.RDPResolutions)Tools.MiscTools.StringToEnum(typeof(ProtocolRDP.RDPResolutions), Convert.ToString(xmlnode.Attributes["Resolution"].Value));
                    connectionInfo.RedirectSound = (ProtocolRDP.RDPSounds)Tools.MiscTools.StringToEnum(typeof(ProtocolRDP.RDPSounds), Convert.ToString(xmlnode.Attributes["RedirectSound"].Value));
                }
                else
                {
                    switch (Convert.ToInt32(xmlnode.Attributes["Colors"].Value))
                    {
                    case 0:
                        connectionInfo.Colors = ProtocolRDP.RDPColors.Colors256;
                        break;

                    case 1:
                        connectionInfo.Colors = ProtocolRDP.RDPColors.Colors16Bit;
                        break;

                    case 2:
                        connectionInfo.Colors = ProtocolRDP.RDPColors.Colors24Bit;
                        break;

                    case 3:
                        connectionInfo.Colors = ProtocolRDP.RDPColors.Colors32Bit;
                        break;

                    case 4:
                        connectionInfo.Colors = ProtocolRDP.RDPColors.Colors15Bit;
                        break;
                    }

                    connectionInfo.RedirectSound = (ProtocolRDP.RDPSounds)Convert.ToInt32(xmlnode.Attributes["RedirectSound"].Value);
                }

                if (_confVersion > 1.2) //1.3
                {
                    connectionInfo.Inheritance = new ConnectionInfoInheritance(connectionInfo)
                    {
                        CacheBitmaps       = bool.Parse(xmlnode.Attributes["InheritCacheBitmaps"].Value),
                        Colors             = bool.Parse(xmlnode.Attributes["InheritColors"].Value),
                        Description        = bool.Parse(xmlnode.Attributes["InheritDescription"].Value),
                        DisplayThemes      = bool.Parse(xmlnode.Attributes["InheritDisplayThemes"].Value),
                        DisplayWallpaper   = bool.Parse(xmlnode.Attributes["InheritDisplayWallpaper"].Value),
                        Domain             = bool.Parse(xmlnode.Attributes["InheritDomain"].Value),
                        Icon               = bool.Parse(xmlnode.Attributes["InheritIcon"].Value),
                        Panel              = bool.Parse(xmlnode.Attributes["InheritPanel"].Value),
                        Password           = bool.Parse(xmlnode.Attributes["InheritPassword"].Value),
                        Port               = bool.Parse(xmlnode.Attributes["InheritPort"].Value),
                        Protocol           = bool.Parse(xmlnode.Attributes["InheritProtocol"].Value),
                        PuttySession       = bool.Parse(xmlnode.Attributes["InheritPuttySession"].Value),
                        RedirectDiskDrives = bool.Parse(xmlnode.Attributes["InheritRedirectDiskDrives"].Value),
                        RedirectKeys       = bool.Parse(xmlnode.Attributes["InheritRedirectKeys"].Value),
                        RedirectPorts      = bool.Parse(xmlnode.Attributes["InheritRedirectPorts"].Value),
                        RedirectPrinters   = bool.Parse(xmlnode.Attributes["InheritRedirectPrinters"].Value),
                        RedirectSmartCards = bool.Parse(xmlnode.Attributes["InheritRedirectSmartCards"].Value),
                        RedirectSound      = bool.Parse(xmlnode.Attributes["InheritRedirectSound"].Value),
                        Resolution         = bool.Parse(xmlnode.Attributes["InheritResolution"].Value),
                        UseConsoleSession  = bool.Parse(xmlnode.Attributes["InheritUseConsoleSession"].Value),
                        Username           = bool.Parse(xmlnode.Attributes["InheritUsername"].Value)
                    };
                    connectionInfo.Icon  = xmlnode.Attributes["Icon"].Value;
                    connectionInfo.Panel = xmlnode.Attributes["Panel"].Value;
                }
                else
                {
                    connectionInfo.Inheritance = new ConnectionInfoInheritance(connectionInfo);
                    if (Convert.ToBoolean(xmlnode.Attributes["Inherit"].Value))
                    {
                        connectionInfo.Inheritance.TurnOnInheritanceCompletely();
                    }
                    connectionInfo.Icon  = Convert.ToString(xmlnode.Attributes["Icon"].Value.Replace(".ico", ""));
                    connectionInfo.Panel = Language.strGeneral;
                }

                if (_confVersion > 1.4) //1.5
                {
                    connectionInfo.PleaseConnect = bool.Parse(xmlnode.Attributes["Connected"].Value);
                }

                if (_confVersion > 1.5) //1.6
                {
                    connectionInfo.ICAEncryptionStrength             = (ProtocolICA.EncryptionStrength)Tools.MiscTools.StringToEnum(typeof(ProtocolICA.EncryptionStrength), xmlnode.Attributes["ICAEncryptionStrength"].Value);
                    connectionInfo.Inheritance.ICAEncryptionStrength = bool.Parse(xmlnode.Attributes["InheritICAEncryptionStrength"].Value);
                    connectionInfo.PreExtApp              = xmlnode.Attributes["PreExtApp"].Value;
                    connectionInfo.PostExtApp             = xmlnode.Attributes["PostExtApp"].Value;
                    connectionInfo.Inheritance.PreExtApp  = bool.Parse(xmlnode.Attributes["InheritPreExtApp"].Value);
                    connectionInfo.Inheritance.PostExtApp = bool.Parse(xmlnode.Attributes["InheritPostExtApp"].Value);
                }

                if (_confVersion > 1.6) //1.7
                {
                    connectionInfo.VNCCompression               = (ProtocolVNC.Compression)Tools.MiscTools.StringToEnum(typeof(ProtocolVNC.Compression), xmlnode.Attributes["VNCCompression"].Value);
                    connectionInfo.VNCEncoding                  = (ProtocolVNC.Encoding)Tools.MiscTools.StringToEnum(typeof(ProtocolVNC.Encoding), Convert.ToString(xmlnode.Attributes["VNCEncoding"].Value));
                    connectionInfo.VNCAuthMode                  = (ProtocolVNC.AuthMode)Tools.MiscTools.StringToEnum(typeof(ProtocolVNC.AuthMode), xmlnode.Attributes["VNCAuthMode"].Value);
                    connectionInfo.VNCProxyType                 = (ProtocolVNC.ProxyType)Tools.MiscTools.StringToEnum(typeof(ProtocolVNC.ProxyType), xmlnode.Attributes["VNCProxyType"].Value);
                    connectionInfo.VNCProxyIP                   = xmlnode.Attributes["VNCProxyIP"].Value;
                    connectionInfo.VNCProxyPort                 = Convert.ToInt32(xmlnode.Attributes["VNCProxyPort"].Value);
                    connectionInfo.VNCProxyUsername             = xmlnode.Attributes["VNCProxyUsername"].Value;
                    connectionInfo.VNCProxyPassword             = cryptographyProvider.Decrypt(xmlnode.Attributes["VNCProxyPassword"].Value, _pW);
                    connectionInfo.VNCColors                    = (ProtocolVNC.Colors)Tools.MiscTools.StringToEnum(typeof(ProtocolVNC.Colors), xmlnode.Attributes["VNCColors"].Value);
                    connectionInfo.VNCSmartSizeMode             = (ProtocolVNC.SmartSizeMode)Tools.MiscTools.StringToEnum(typeof(ProtocolVNC.SmartSizeMode), xmlnode.Attributes["VNCSmartSizeMode"].Value);
                    connectionInfo.VNCViewOnly                  = bool.Parse(xmlnode.Attributes["VNCViewOnly"].Value);
                    connectionInfo.Inheritance.VNCCompression   = bool.Parse(xmlnode.Attributes["InheritVNCCompression"].Value);
                    connectionInfo.Inheritance.VNCEncoding      = bool.Parse(xmlnode.Attributes["InheritVNCEncoding"].Value);
                    connectionInfo.Inheritance.VNCAuthMode      = bool.Parse(xmlnode.Attributes["InheritVNCAuthMode"].Value);
                    connectionInfo.Inheritance.VNCProxyType     = bool.Parse(xmlnode.Attributes["InheritVNCProxyType"].Value);
                    connectionInfo.Inheritance.VNCProxyIP       = bool.Parse(xmlnode.Attributes["InheritVNCProxyIP"].Value);
                    connectionInfo.Inheritance.VNCProxyPort     = bool.Parse(xmlnode.Attributes["InheritVNCProxyPort"].Value);
                    connectionInfo.Inheritance.VNCProxyUsername = bool.Parse(xmlnode.Attributes["InheritVNCProxyUsername"].Value);
                    connectionInfo.Inheritance.VNCProxyPassword = bool.Parse(xmlnode.Attributes["InheritVNCProxyPassword"].Value);
                    connectionInfo.Inheritance.VNCColors        = bool.Parse(xmlnode.Attributes["InheritVNCColors"].Value);
                    connectionInfo.Inheritance.VNCSmartSizeMode = bool.Parse(xmlnode.Attributes["InheritVNCSmartSizeMode"].Value);
                    connectionInfo.Inheritance.VNCViewOnly      = bool.Parse(xmlnode.Attributes["InheritVNCViewOnly"].Value);
                }

                if (_confVersion > 1.7) //1.8
                {
                    connectionInfo.RDPAuthenticationLevel             = (ProtocolRDP.AuthenticationLevel)Tools.MiscTools.StringToEnum(typeof(ProtocolRDP.AuthenticationLevel), xmlnode.Attributes["RDPAuthenticationLevel"].Value);
                    connectionInfo.Inheritance.RDPAuthenticationLevel = bool.Parse(xmlnode.Attributes["InheritRDPAuthenticationLevel"].Value);
                }

                if (_confVersion > 1.8) //1.9
                {
                    connectionInfo.RenderingEngine             = (HTTPBase.RenderingEngine)Tools.MiscTools.StringToEnum(typeof(HTTPBase.RenderingEngine), xmlnode.Attributes["RenderingEngine"].Value);
                    connectionInfo.MacAddress                  = xmlnode.Attributes["MacAddress"].Value;
                    connectionInfo.Inheritance.RenderingEngine = bool.Parse(xmlnode.Attributes["InheritRenderingEngine"].Value);
                    connectionInfo.Inheritance.MacAddress      = bool.Parse(xmlnode.Attributes["InheritMacAddress"].Value);
                }

                if (_confVersion > 1.9) //2.0
                {
                    connectionInfo.UserField             = xmlnode.Attributes["UserField"].Value;
                    connectionInfo.Inheritance.UserField = bool.Parse(xmlnode.Attributes["InheritUserField"].Value);
                }

                if (_confVersion > 2.0) //2.1
                {
                    connectionInfo.ExtApp             = xmlnode.Attributes["ExtApp"].Value;
                    connectionInfo.Inheritance.ExtApp = bool.Parse(xmlnode.Attributes["InheritExtApp"].Value);
                }

                if (_confVersion > 2.1) //2.2
                {
                    // Get settings
                    connectionInfo.RDGatewayUsageMethod = (ProtocolRDP.RDGatewayUsageMethod)Tools.MiscTools.StringToEnum(typeof(ProtocolRDP.RDGatewayUsageMethod), Convert.ToString(xmlnode.Attributes["RDGatewayUsageMethod"].Value));
                    connectionInfo.RDGatewayHostname    = xmlnode.Attributes["RDGatewayHostname"].Value;
                    connectionInfo.RDGatewayUseConnectionCredentials = (ProtocolRDP.RDGatewayUseConnectionCredentials)Tools.MiscTools.StringToEnum(typeof(ProtocolRDP.RDGatewayUseConnectionCredentials), Convert.ToString(xmlnode.Attributes["RDGatewayUseConnectionCredentials"].Value));
                    connectionInfo.RDGatewayUsername = xmlnode.Attributes["RDGatewayUsername"].Value;
                    connectionInfo.RDGatewayPassword = cryptographyProvider.Decrypt(Convert.ToString(xmlnode.Attributes["RDGatewayPassword"].Value), _pW);
                    connectionInfo.RDGatewayDomain   = xmlnode.Attributes["RDGatewayDomain"].Value;

                    // Get inheritance settings
                    connectionInfo.Inheritance.RDGatewayUsageMethod = bool.Parse(xmlnode.Attributes["InheritRDGatewayUsageMethod"].Value);
                    connectionInfo.Inheritance.RDGatewayHostname    = bool.Parse(xmlnode.Attributes["InheritRDGatewayHostname"].Value);
                    connectionInfo.Inheritance.RDGatewayUseConnectionCredentials = bool.Parse(xmlnode.Attributes["InheritRDGatewayUseConnectionCredentials"].Value);
                    connectionInfo.Inheritance.RDGatewayUsername = bool.Parse(xmlnode.Attributes["InheritRDGatewayUsername"].Value);
                    connectionInfo.Inheritance.RDGatewayPassword = bool.Parse(xmlnode.Attributes["InheritRDGatewayPassword"].Value);
                    connectionInfo.Inheritance.RDGatewayDomain   = bool.Parse(xmlnode.Attributes["InheritRDGatewayDomain"].Value);
                }

                if (_confVersion > 2.2) //2.3
                {
                    // Get settings
                    connectionInfo.EnableFontSmoothing      = bool.Parse(xmlnode.Attributes["EnableFontSmoothing"].Value);
                    connectionInfo.EnableDesktopComposition = bool.Parse(xmlnode.Attributes["EnableDesktopComposition"].Value);

                    // Get inheritance settings
                    connectionInfo.Inheritance.EnableFontSmoothing      = bool.Parse(xmlnode.Attributes["InheritEnableFontSmoothing"].Value);
                    connectionInfo.Inheritance.EnableDesktopComposition = bool.Parse(xmlnode.Attributes["InheritEnableDesktopComposition"].Value);
                }

                if (_confVersion >= 2.4)
                {
                    connectionInfo.UseCredSsp             = bool.Parse(xmlnode.Attributes["UseCredSsp"].Value);
                    connectionInfo.Inheritance.UseCredSsp = bool.Parse(xmlnode.Attributes["InheritUseCredSsp"].Value);
                }

                if (_confVersion >= 2.5)
                {
                    connectionInfo.LoadBalanceInfo             = xmlnode.Attributes["LoadBalanceInfo"].Value;
                    connectionInfo.AutomaticResize             = bool.Parse(xmlnode.Attributes["AutomaticResize"].Value);
                    connectionInfo.Inheritance.LoadBalanceInfo = bool.Parse(xmlnode.Attributes["InheritLoadBalanceInfo"].Value);
                    connectionInfo.Inheritance.AutomaticResize = bool.Parse(xmlnode.Attributes["InheritAutomaticResize"].Value);
                }
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, string.Format(Language.strGetConnectionInfoFromXmlFailed, connectionInfo.Name, ConnectionFileName, ex.Message));
            }
            return(connectionInfo);
        }
Beispiel #30
0
        public static void SaveSettings()
        {
            try
            {
                var with1           = frmMain.Default;
                var windowPlacement = new WindowPlacement(frmMain.Default);
                if (with1.WindowState == FormWindowState.Minimized & windowPlacement.RestoreToMaximized)
                {
                    with1.Opacity     = 0;
                    with1.WindowState = FormWindowState.Maximized;
                }

                mRemoteNG.Settings.Default.MainFormLocation = with1.Location;
                mRemoteNG.Settings.Default.MainFormSize     = with1.Size;

                if (with1.WindowState != FormWindowState.Normal)
                {
                    mRemoteNG.Settings.Default.MainFormRestoreLocation = with1.RestoreBounds.Location;
                    mRemoteNG.Settings.Default.MainFormRestoreSize     = with1.RestoreBounds.Size;
                }

                mRemoteNG.Settings.Default.MainFormState = with1.WindowState;

                if (with1.Fullscreen != null)
                {
                    mRemoteNG.Settings.Default.MainFormKiosk = with1.Fullscreen.Value;
                }

                mRemoteNG.Settings.Default.FirstStart    = false;
                mRemoteNG.Settings.Default.ResetPanels   = false;
                mRemoteNG.Settings.Default.ResetToolbars = false;
                mRemoteNG.Settings.Default.NoReconnect   = false;

                mRemoteNG.Settings.Default.ExtAppsTBLocation = with1.tsExternalTools.Location;
                if (with1.tsExternalTools.Parent != null)
                {
                    mRemoteNG.Settings.Default.ExtAppsTBParentDock = with1.tsExternalTools.Parent.Dock.ToString();
                }
                mRemoteNG.Settings.Default.ExtAppsTBVisible  = with1.tsExternalTools.Visible;
                mRemoteNG.Settings.Default.ExtAppsTBShowText = with1.cMenToolbarShowText.Checked;

                mRemoteNG.Settings.Default.QuickyTBLocation = with1.tsQuickConnect.Location;
                if (with1.tsQuickConnect.Parent != null)
                {
                    mRemoteNG.Settings.Default.QuickyTBParentDock = with1.tsQuickConnect.Parent.Dock.ToString();
                }
                mRemoteNG.Settings.Default.QuickyTBVisible = with1.tsQuickConnect.Visible;

                var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
                mRemoteNG.Settings.Default.ConDefaultPassword =
                    cryptographyProvider.Encrypt(Convert.ToString(mRemoteNG.Settings.Default.ConDefaultPassword), EncryptionKey);

                mRemoteNG.Settings.Default.Save();

                SavePanelsToXML();
                SaveExternalAppsToXML();
            }
            catch (Exception ex)
            {
                MessageCollector.AddExceptionStackTrace("Saving settings failed", ex);
            }
        }