コード例 #1
0
        private void ValidateConnectionFileVersion()
        {
            if (_xmlDocument.DocumentElement.HasAttribute("ConfVersion"))
            {
                _confVersion = Convert.ToDouble(_xmlDocument.DocumentElement.Attributes["ConfVersion"].Value.Replace(",", "."),
                                                CultureInfo.InvariantCulture);
            }
            else
            {
                Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, Language.strOldConffile);
            }

            const double maxSupportedConfVersion = 2.5;

            if (!(_confVersion > maxSupportedConfVersion))
            {
                return;
            }
            CTaskDialog.ShowTaskDialogBox(
                frmMain.Default,
                Application.ProductName,
                "Incompatible connection file format",
                $"The format of this connection file is not supported. Please upgrade to a newer version of {Application.ProductName}.",
                string.Format("{1}{0}File Format Version: {2}{0}Highest Supported Version: {3}", Environment.NewLine,
                              ConnectionFileName, _confVersion, maxSupportedConfVersion),
                "",
                "",
                "",
                "",
                ETaskDialogButtons.Ok,
                ESysIcons.Error,
                ESysIcons.Error
                );
            throw (new Exception($"Incompatible connection file format (file format version {_confVersion})."));
        }
コード例 #2
0
        private void frmMain_Shown(object sender, EventArgs e)
        {
#if !PORTABLE
            if (!Settings.Default.CheckForUpdatesAsked)
            {
                string[] commandButtons =
                {
                    Language.strAskUpdatesCommandRecommended, Language.strAskUpdatesCommandCustom,
                    Language.strAskUpdatesCommandAskLater
                };

                CTaskDialog.ShowTaskDialogBox(this, GeneralAppInfo.ProductName, Language.strAskUpdatesMainInstruction, string.Format(Language.strAskUpdatesContent, GeneralAppInfo.ProductName),
                                              "", "", "", "", string.Join(" | ", commandButtons), ETaskDialogButtons.None, ESysIcons.Question, ESysIcons.Question);

                if (CTaskDialog.CommandButtonResult == 0 | CTaskDialog.CommandButtonResult == 1)
                {
                    Settings.Default.CheckForUpdatesAsked = true;
                }

                if (CTaskDialog.CommandButtonResult != 1)
                {
                    return;
                }

                using (var optionsForm = new frmOptions(Language.strTabUpdates))
                {
                    optionsForm.ShowDialog(this);
                }

                return;
            }

            if (!Settings.Default.CheckForUpdatesOnStartup)
            {
                return;
            }

            DateTime nextUpdateCheck = Convert.ToDateTime(
                Settings.Default.CheckForUpdatesLastCheck.Add(
                    TimeSpan.FromDays(Convert.ToDouble(Settings.Default.CheckForUpdatesFrequencyDays))));

            if (!Settings.Default.UpdatePending && DateTime.UtcNow <= nextUpdateCheck)
            {
                return;
            }
            if (!IsHandleCreated)
            {
                CreateHandle();                   // Make sure the handle is created so that InvokeRequired returns the correct result
            }
            Startup.Instance.CheckForUpdate();
#endif
        }
コード例 #3
0
 private void ShowIncompatibleVersionDialogBox()
 {
     CTaskDialog.ShowTaskDialogBox(
         frmMain.Default,
         Application.ProductName,
         "Incompatible connection file format",
         $"The format of this connection file is not supported. Please upgrade to a newer version of {Application.ProductName}.",
         string.Format("{1}{0}File Format Version: {2}{0}Highest Supported Version: {3}", Environment.NewLine, ConnectionFileName, _confVersion, MaxSupportedConfVersion),
         "",
         "",
         "",
         "",
         ETaskDialogButtons.Ok,
         ESysIcons.Error,
         ESysIcons.Error
         );
 }
コード例 #4
0
        //Refernce: https://bitbucket.org/geckofx/geckofx-33.0/issues/90/invalid-security-certificate-error-on
        internal static void GeckoBrowser_NSSError(object sender, GeckoNSSErrorEventArgs e)
        {
            /* some messages say "Certificate", some say "certificate"
             * I'm guessing that this is going to be a localization issue...
             * Log a message so we can try to find a better solution if problems are reported in the future...
             */
            if (!e.Message.ToLower().Contains("certificate"))
            {
                Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, $"Unhandled NSSError: {e.Message}");
                e.Handled = false;
                return;
            }

            string[] commandButtons =
            {
                Language.strHttpsInsecureAllowOnce,     // 0
                Language.strHttpsInsecureAllowAlways,   // 1
                Language.strHttpsInsecureDontAllow      // 2
            };

            CTaskDialog.ShowTaskDialogBox(null, GeneralAppInfo.ProductName, Language.strHttpsInsecurePromptTitle,
                                          string.Format(Language.strHttpsInsecurePrompt, e.Uri.AbsoluteUri), "", "", "", "",
                                          string.Join(" | ", commandButtons), ETaskDialogButtons.None, ESysIcons.Question, ESysIcons.Question);

            var allow     = false;
            var temporary = true;

            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (CTaskDialog.CommandButtonResult)
            {
            case 0:
                allow     = true;
                temporary = true;
                break;

            case 1:
                allow     = true;
                temporary = false;
                break;

            case 2:
                allow     = false;
                temporary = true;     // just to be safe
                break;
            }

            if (!allow)
            {
                Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, $"User did not allow navigation to {e.Uri.AbsoluteUri} with an insecure certificate: {e.Message}");
                return;
            }

            /* "temporary == false" (aka always) might not work:
             * https://bitbucket.org/geckofx/geckofx-45.0/issues/152/remembervalidityoverride-doesnt-save-in
             * However, my testing was successful in Gecko 45.0.22
             */
            CertOverrideService.GetService().RememberValidityOverride(e.Uri, e.Certificate,
                                                                      CertOverride.Mismatch | CertOverride.Time | CertOverride.Untrusted, temporary);

            e.Handled = true;
            ((GeckoWebBrowser)sender).Navigate(e.Uri.AbsoluteUri);
        }
コード例 #5
0
ファイル: Runtime.cs プロジェクト: fmcontrib/mrng-jumphost
        /// <summary>
        ///
        /// </summary>
        /// <param name="withDialog">
        /// Should we show the file selection dialog to allow the user to select
        /// a connection file
        /// </param>
        public static void LoadConnections(bool withDialog = false)
        {
            var connectionFileName = "";

            try
            {
                // disable sql update checking while we are loading updates
                ConnectionsService.RemoteConnectionsSyncronizer?.Disable();

                if (withDialog)
                {
                    var loadDialog = DialogFactory.BuildLoadConnectionsDialog();
                    if (loadDialog.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    connectionFileName            = loadDialog.FileName;
                    Settings.Default.UseSQLServer = false;
                    Settings.Default.Save();
                }
                else if (!Settings.Default.UseSQLServer)
                {
                    connectionFileName = ConnectionsService.GetStartupConnectionFileName();
                }

                ConnectionsService.LoadConnections(Settings.Default.UseSQLServer, false, connectionFileName);

                if (Settings.Default.UseSQLServer)
                {
                    ConnectionsService.LastSqlUpdate = DateTime.Now;
                }

                // re-enable sql update checking after updates are loaded
                ConnectionsService.RemoteConnectionsSyncronizer?.Enable();
            }
            catch (Exception ex)
            {
                if (Settings.Default.UseSQLServer)
                {
                    MessageCollector.AddExceptionMessage(Language.strLoadFromSqlFailed, ex);
                    var commandButtons = string.Join("|", Language.strCommandTryAgain, Language.strCommandOpenConnectionFile, string.Format(Language.strCommandExitProgram, Application.ProductName));
                    CTaskDialog.ShowCommandBox(Application.ProductName, Language.strLoadFromSqlFailed, Language.strLoadFromSqlFailedContent, MiscTools.GetExceptionMessageRecursive(ex), "", "", commandButtons, false, ESysIcons.Error, ESysIcons.Error);
                    switch (CTaskDialog.CommandButtonResult)
                    {
                    case 0:
                        LoadConnections(withDialog);
                        return;

                    case 1:
                        Settings.Default.UseSQLServer = false;
                        LoadConnections(true);
                        return;

                    default:
                        Application.Exit();
                        return;
                    }
                }
                if (ex is FileNotFoundException && !withDialog)
                {
                    MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoadedNew, connectionFileName), ex, MessageClass.InformationMsg);

                    string[] commandButtons =
                    {
                        Language.ConfigurationCreateNew,
                        Language.ConfigurationCustomPath,
                        Language.ConfigurationImportFile,
                        Language.strMenuExit
                    };

                    var answered = false;
                    while (!answered)
                    {
                        try
                        {
                            CTaskDialog.ShowTaskDialogBox(
                                GeneralAppInfo.ProductName,
                                Language.ConnectionFileNotFound,
                                "", "", "", "", "",
                                string.Join(" | ", commandButtons),
                                ETaskDialogButtons.None,
                                ESysIcons.Question,
                                ESysIcons.Question);

                            switch (CTaskDialog.CommandButtonResult)
                            {
                            case 0:
                                ConnectionsService.NewConnectionsFile(connectionFileName);
                                answered = true;
                                break;

                            case 1:
                                LoadConnections(true);
                                answered = true;
                                break;

                            case 2:
                                ConnectionsService.NewConnectionsFile(connectionFileName);
                                Import.ImportFromFile(ConnectionsService.ConnectionTreeModel.RootNodes[0]);
                                answered = true;
                                break;

                            case 3:
                                Application.Exit();
                                answered = true;
                                break;
                            }
                        }
                        catch (Exception exc)
                        {
                            MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoadedNew, connectionFileName), exc, MessageClass.InformationMsg);
                        }
                    }
                    return;
                }

                MessageCollector.AddExceptionStackTrace(string.Format(Language.strConnectionsFileCouldNotBeLoaded, connectionFileName), ex);
                if (connectionFileName != ConnectionsService.GetStartupConnectionFileName())
                {
                    LoadConnections(withDialog);
                }
                else
                {
                    MessageBox.Show(FrmMain.Default,
                                    string.Format(Language.strErrorStartupConnectionFileLoad, Environment.NewLine, Application.ProductName, ConnectionsService.GetStartupConnectionFileName(), MiscTools.GetExceptionMessageRecursive(ex)),
                                    @"Could not load startup file.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.Exit();
                }
            }
        }
コード例 #6
0
        public void LoadFromSql()
        {
            if (Windows.treeForm == null || Windows.treeForm.tvConnections == null)
            {
                return;
            }
            if (Windows.treeForm.tvConnections.InvokeRequired)
            {
                Windows.treeForm.tvConnections.Invoke(new LoadFromSqlDelegate(LoadFromSql));
                return;
            }

            try
            {
                Runtime.IsConnectionsFileLoaded = false;
                _sqlConnection = !string.IsNullOrEmpty(DatabaseUsername) ? new SqlConnection("Data Source=" + DatabaseHost + ";Initial Catalog=" + DatabaseName + ";User Id=" + DatabaseUsername + ";Password="******"Data Source=" + DatabaseHost + ";Initial Catalog=" + DatabaseName + ";Integrated Security=True");

                _sqlConnection.Open();
                _sqlQuery      = new SqlCommand("SELECT * FROM tblRoot", _sqlConnection);
                _sqlDataReader = _sqlQuery.ExecuteReader(CommandBehavior.CloseConnection);
                _sqlDataReader.Read();

                if (_sqlDataReader.HasRows == false)
                {
                    Runtime.SaveConnections();
                    _sqlQuery      = new SqlCommand("SELECT * FROM tblRoot", _sqlConnection);
                    _sqlDataReader = _sqlQuery.ExecuteReader(CommandBehavior.CloseConnection);
                    _sqlDataReader.Read();
                }

                _confVersion = Convert.ToDouble(_sqlDataReader["confVersion"], CultureInfo.InvariantCulture);
                const double maxSupportedSchemaVersion = 2.5;
                if (_confVersion > maxSupportedSchemaVersion)
                {
                    CTaskDialog.ShowTaskDialogBox(
                        frmMain.Default,
                        Application.ProductName,
                        "Incompatible database schema",
                        $"The database schema on the server is not supported. Please upgrade to a newer version of {Application.ProductName}.",
                        string.Format("Schema Version: {1}{0}Highest Supported Version: {2}", Environment.NewLine, _confVersion, maxSupportedSchemaVersion),
                        "",
                        "",
                        "",
                        "",
                        ETaskDialogButtons.Ok,
                        ESysIcons.Error,
                        ESysIcons.Error
                        );
                    throw (new Exception($"Incompatible database schema (schema version {_confVersion})."));
                }

                RootTreeNode.Name = Convert.ToString(_sqlDataReader["Name"]);

                var rootInfo = new RootNodeInfo(RootNodeType.Connection)
                {
                    Name     = RootTreeNode.Name,
                    TreeNode = RootTreeNode
                };

                RootTreeNode.Tag                = rootInfo;
                RootTreeNode.ImageIndex         = (int)TreeImageType.Root;
                RootTreeNode.SelectedImageIndex = (int)TreeImageType.Root;

                var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
                if (cryptographyProvider.Decrypt(Convert.ToString(_sqlDataReader["Protected"]), _pW) != "ThisIsNotProtected")
                {
                    if (Authenticate(Convert.ToString(_sqlDataReader["Protected"]), false, rootInfo) == false)
                    {
                        mRemoteNG.Settings.Default.LoadConsFromCustomLocation = false;
                        mRemoteNG.Settings.Default.CustomConsPath             = "";
                        RootTreeNode.Remove();
                        return;
                    }
                }

                _sqlDataReader.Close();
                Windows.treeForm.tvConnections.BeginUpdate();

                // SECTION 3. Populate the TreeView with the DOM nodes.
                AddNodesFromSql(RootTreeNode);
                RootTreeNode.Expand();

                //expand containers
                foreach (ContainerInfo contI in ContainerList)
                {
                    if (contI.IsExpanded)
                    {
                        contI.TreeNode.Expand();
                    }
                }

                Windows.treeForm.tvConnections.EndUpdate();

                //open connections from last mremote session
                if (mRemoteNG.Settings.Default.OpenConsFromLastSession && !mRemoteNG.Settings.Default.NoReconnect)
                {
                    foreach (ConnectionInfo conI in ConnectionList)
                    {
                        if (conI.PleaseConnect)
                        {
                            Runtime.OpenConnection(conI);
                        }
                    }
                }

                Runtime.IsConnectionsFileLoaded = true;
                Windows.treeForm.InitialRefresh();
                SetSelectedNode(_selectedTreeNode);
            }
            finally
            {
                _sqlConnection?.Close();
            }
        }
コード例 #7
0
ファイル: DialogFactory.cs プロジェクト: 756616071/mRemoteNG
        /// <summary>
        /// Creates and shows a dialog to either create a new connections file, load a different one,
        /// exit, or optionally cancel the operation.
        /// </summary>
        /// <param name="connectionFileName"></param>
        /// <param name="messageText"></param>
        /// <param name="showCancelButton"></param>
        public static void ShowLoadConnectionsFailedDialog(string connectionFileName,
                                                           string messageText,
                                                           bool showCancelButton)
        {
            var commandButtons = new List <string>
            {
                Language.ConfigurationCreateNew,
                Language.strOpenADifferentFile,
                Language.strMenuExit
            };

            if (showCancelButton)
            {
                commandButtons.Add(Language.strButtonCancel);
            }

            var answered = false;

            while (!answered)
            {
                try
                {
                    CTaskDialog.ShowTaskDialogBox(
                        GeneralAppInfo.ProductName,
                        messageText,
                        "", "", "", "", "",
                        string.Join(" | ", commandButtons),
                        ETaskDialogButtons.None,
                        ESysIcons.Question,
                        ESysIcons.Question);

                    switch (CTaskDialog.CommandButtonResult)
                    {
                    case 0:     // New
                        var saveAsDialog = ConnectionsSaveAsDialog();
                        saveAsDialog.ShowDialog();
                        Runtime.ConnectionsService.NewConnectionsFile(saveAsDialog.FileName);
                        answered = true;
                        break;

                    case 1:     // Load
                        Runtime.LoadConnections(true);
                        answered = true;
                        break;

                    case 2:     // Exit
                        Application.Exit();
                        answered = true;
                        break;

                    case 3:     // Cancel
                        answered = true;
                        break;
                    }
                }
                catch (Exception exception)
                {
                    Runtime.MessageCollector.AddExceptionMessage(
                        string
                        .Format(Language.strConnectionsFileCouldNotBeLoadedNew,
                                connectionFileName),
                        exception,
                        MessageClass.WarningMsg);
                }
            }
        }