internal void ShowHideMenuItemsForPuttyNode(PuttySessionInfo connectionInfo)
        {
            _cMenTreeAddConnection.Enabled = false;
            _cMenTreeAddFolder.Enabled     = false;

            if (connectionInfo.OpenConnections.Count == 0)
            {
                _cMenTreeDisconnect.Enabled = false;
            }

            if (!(connectionInfo.Protocol == ProtocolType.SSH1 | connectionInfo.Protocol == ProtocolType.SSH2))
            {
                _cMenTreeToolsTransferFile.Enabled = false;
            }

            _cMenTreeConnectWithOptionsConnectInFullscreen.Enabled     = false;
            _cMenTreeConnectWithOptionsConnectToConsoleSession.Enabled = false;
            _cMenTreeToolsSort.Enabled  = false;
            _cMenTreeDuplicate.Enabled  = false;
            _cMenTreeRename.Enabled     = false;
            _cMenTreeDelete.Enabled     = false;
            _cMenTreeMoveUp.Enabled     = false;
            _cMenTreeMoveDown.Enabled   = false;
            _cMenTreeImport.Enabled     = false;
            _cMenTreeExportFile.Enabled = false;
            _cMenTreeConnectWithOptionsViewOnly.Enabled = false;
        }
Example #2
0
        public void CantDragNodeBelowPuttySessionNodes()
        {
            var source          = _connection1;
            var target          = new PuttySessionInfo();
            var dragDropEffects = _dragAndDropHandler.CanModelDrop(source, target, DropTargetLocation.BelowItem);

            Assert.That(dragDropEffects, Is.EqualTo(DragDropEffects.None));
        }
Example #3
0
        public void CantDragPuttySessionInfo()
        {
            var source          = new PuttySessionInfo();
            var target          = _container2;
            var dragDropEffects = _dragAndDropHandler.CanModelDrop(source, target, DropTargetLocation.Item);

            Assert.That(dragDropEffects, Is.EqualTo(DragDropEffects.None));
        }
        public override PuttySessionInfo GetSession(string sessionName)
        {
            var sessionsKey = Registry.CurrentUser.OpenSubKey(PuttySessionsKey);
            var sessionKey  = sessionsKey?.OpenSubKey(sessionName);

            if (sessionKey == null)
            {
                return(null);
            }

            sessionName = HttpUtility.UrlDecode(sessionName.Replace("+", "%2B"));

            var sessionInfo = new PuttySessionInfo
            {
                PuttySession = sessionName,
                Name         = sessionName,
                Hostname     = Convert.ToString(sessionKey.GetValue("HostName")),
                Username     = Convert.ToString(sessionKey.GetValue("UserName"))
            };
            var protocol = Convert.ToString(sessionKey.GetValue("Protocol")) ?? "ssh";

            switch (protocol.ToLowerInvariant())
            {
            case "raw":
                sessionInfo.Protocol = ProtocolType.RAW;
                break;

            case "rlogin":
                sessionInfo.Protocol = ProtocolType.Rlogin;
                break;

            case "serial":
                return(null);

            case "ssh":
                var sshVersionObject = sessionKey.GetValue("SshProt");
                if (sshVersionObject != null)
                {
                    var sshVersion = Convert.ToInt32(sshVersionObject);
                    sessionInfo.Protocol = sshVersion >= 2 ? ProtocolType.SSH2 : ProtocolType.SSH1;
                }
                else
                {
                    sessionInfo.Protocol = ProtocolType.SSH2;
                }
                break;

            case "telnet":
                sessionInfo.Protocol = ProtocolType.Telnet;
                break;

            default:
                return(null);
            }
            sessionInfo.Port = Convert.ToInt32(sessionKey.GetValue("PortNumber"));

            return(sessionInfo);
        }
Example #5
0
 protected virtual void RemoveSession(PuttySessionInfo sessionInfo)
 {
     if (!Sessions.Contains(sessionInfo))
     {
         return;
     }
     RootInfo.RemoveChild(sessionInfo);
     RaisePuttySessionCollectionChangedEvent(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, sessionInfo));
 }
Example #6
0
 protected virtual void AddSession(PuttySessionInfo sessionInfo)
 {
     if (string.IsNullOrEmpty(sessionInfo?.Name) || Sessions.Any(child => child.Name == sessionInfo.Name))
     {
         return;
     }
     RootInfo.AddChild(sessionInfo);
     RaisePuttySessionCollectionChangedEvent(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, sessionInfo));
 }
Example #7
0
        private static PuttySessionInfo ModifyRegistrySessionInfo(PuttySessionInfo sessionInfo)
        {
            if (sessionInfo == null)
            {
                return(null);
            }

            sessionInfo.Name         = string.Format(RegistrySessionNameFormat, sessionInfo.Name);
            sessionInfo.PuttySession = string.Format(RegistrySessionNameFormat, sessionInfo.PuttySession);
            return(sessionInfo);
        }
Example #8
0
        public void CannotDuplicatePuttyConnectionNode()
        {
            var connectionTreeModel = new ConnectionTreeModel();
            var puttyRoot           = new RootNodeInfo(RootNodeType.PuttySessions);
            var puttyConnection     = new PuttySessionInfo();

            puttyRoot.AddChild(puttyConnection);
            connectionTreeModel.AddRootNode(puttyRoot);
            _connectionTree.ConnectionTreeModel = connectionTreeModel;
            _connectionTree.ExpandAll();

            _connectionTree.SelectedObject = puttyConnection;
            _connectionTree.DuplicateSelectedNode();

            Assert.That(puttyRoot.Children, Has.One.Items);
        }
        public virtual PuttySessionInfo[] GetSessions()
        {
            List <PuttySessionInfo> sessionList = new List <PuttySessionInfo>();
            PuttySessionInfo        sessionInfo = (PuttySessionInfo)default(ConnectionInfo);

            foreach (string sessionName in GetSessionNames(true))
            {
                sessionInfo = GetSession(sessionName);
                if (sessionInfo == null || string.IsNullOrEmpty(sessionInfo.Hostname))
                {
                    continue;
                }
                sessionList.Add(sessionInfo);
            }
            return(sessionList.ToArray());
        }
Example #10
0
        private void ShowHideTreeContextMenuItems(TreeNode selectedNode)
        {
            if (selectedNode == null)
            {
                return;
            }

            try
            {
                cMenTree.Enabled = true;
                EnableMenuItemsRecursive(cMenTree.Items);

                if (ConnectionTreeNode.GetNodeType(selectedNode) == TreeNodeType.Connection)
                {
                    ConnectionInfo connectionInfo = (ConnectionInfo)selectedNode.Tag;

                    if (connectionInfo.OpenConnections.Count == 0)
                    {
                        cMenTreeDisconnect.Enabled = false;
                    }

                    if (!(connectionInfo.Protocol == ProtocolType.SSH1 |
                          connectionInfo.Protocol == ProtocolType.SSH2))
                    {
                        cMenTreeToolsTransferFile.Enabled = false;
                    }

                    if (!(connectionInfo.Protocol == ProtocolType.RDP | connectionInfo.Protocol == ProtocolType.ICA))
                    {
                        cMenTreeConnectWithOptionsConnectInFullscreen.Enabled     = false;
                        cMenTreeConnectWithOptionsConnectToConsoleSession.Enabled = false;
                    }

                    if (connectionInfo.Protocol == ProtocolType.IntApp)
                    {
                        cMenTreeConnectWithOptionsNoCredentials.Enabled = false;
                    }
                }
                else if (ConnectionTreeNode.GetNodeType(selectedNode) == TreeNodeType.PuttySession)
                {
                    PuttySessionInfo puttySessionInfo = (PuttySessionInfo)selectedNode.Tag;

                    cMenTreeAddConnection.Enabled = false;
                    cMenTreeAddFolder.Enabled     = false;

                    if (puttySessionInfo.OpenConnections.Count == 0)
                    {
                        cMenTreeDisconnect.Enabled = false;
                    }

                    if (!(puttySessionInfo.Protocol == ProtocolType.SSH1 | puttySessionInfo.Protocol == ProtocolType.SSH2))
                    {
                        cMenTreeToolsTransferFile.Enabled = false;
                    }

                    cMenTreeConnectWithOptionsConnectInFullscreen.Enabled     = false;
                    cMenTreeConnectWithOptionsConnectToConsoleSession.Enabled = false;
                    cMenTreeToolsSort.Enabled = false;
                    cMenTreeDuplicate.Enabled = false;
                    cMenTreeRename.Enabled    = false;
                    cMenTreeDelete.Enabled    = false;
                    cMenTreeMoveUp.Enabled    = false;
                    cMenTreeMoveDown.Enabled  = false;
                }
                else if (ConnectionTreeNode.GetNodeType(selectedNode) == TreeNodeType.Container)
                {
                    cMenTreeConnectWithOptionsConnectInFullscreen.Enabled     = false;
                    cMenTreeConnectWithOptionsConnectToConsoleSession.Enabled = false;
                    cMenTreeDisconnect.Enabled = false;

                    int openConnections = 0;
                    foreach (TreeNode node in selectedNode.Nodes)
                    {
                        if (node.Tag is ConnectionInfo)
                        {
                            var connectionInfo = (ConnectionInfo)node.Tag;
                            openConnections = openConnections + connectionInfo.OpenConnections.Count;
                        }
                    }
                    if (openConnections == 0)
                    {
                        cMenTreeDisconnect.Enabled = false;
                    }

                    cMenTreeToolsTransferFile.Enabled = false;
                    cMenTreeToolsExternalApps.Enabled = false;
                }
                else if (ConnectionTreeNode.GetNodeType(selectedNode) == TreeNodeType.Root)
                {
                    cMenTreeConnect.Enabled            = false;
                    cMenTreeConnectWithOptions.Enabled = false;
                    cMenTreeConnectWithOptionsConnectInFullscreen.Enabled         = false;
                    cMenTreeConnectWithOptionsConnectToConsoleSession.Enabled     = false;
                    cMenTreeConnectWithOptionsChoosePanelBeforeConnecting.Enabled = false;
                    cMenTreeDisconnect.Enabled        = false;
                    cMenTreeToolsTransferFile.Enabled = false;
                    cMenTreeToolsExternalApps.Enabled = false;
                    cMenTreeDuplicate.Enabled         = false;
                    cMenTreeDelete.Enabled            = false;
                    cMenTreeMoveUp.Enabled            = false;
                    cMenTreeMoveDown.Enabled          = false;
                }
                else if (ConnectionTreeNode.GetNodeType(selectedNode) == TreeNodeType.PuttyRoot)
                {
                    cMenTreeAddConnection.Enabled      = false;
                    cMenTreeAddFolder.Enabled          = false;
                    cMenTreeConnect.Enabled            = false;
                    cMenTreeConnectWithOptions.Enabled = false;
                    cMenTreeDisconnect.Enabled         = false;
                    cMenTreeToolsTransferFile.Enabled  = false;
                    cMenTreeConnectWithOptions.Enabled = false;
                    cMenTreeToolsSort.Enabled          = false;
                    cMenTreeToolsExternalApps.Enabled  = false;
                    cMenTreeDuplicate.Enabled          = false;
                    cMenTreeRename.Enabled             = true;
                    cMenTreeDelete.Enabled             = false;
                    cMenTreeMoveUp.Enabled             = false;
                    cMenTreeMoveDown.Enabled           = false;
                }
                else
                {
                    cMenTree.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddExceptionStackTrace("ShowHideTreeContextMenuItems (UI.Window.ConnectionTreeWindow) failed", ex);
            }
        }
Example #11
0
        public override PuttySessionInfo GetSession(string sessionName)
        {
            var registrySessionName = GetRegistrySessionName(sessionName);

            if (!string.IsNullOrEmpty(registrySessionName))
            {
                return(ModifyRegistrySessionInfo(PuttySessionsRegistryProvider.GetSession(registrySessionName)));
            }

            var sessionsFolderPath = GetSessionsFolderPath();

            if (!Directory.Exists(sessionsFolderPath))
            {
                return(null);
            }

            var sessionFile = Path.Combine(sessionsFolderPath, sessionName);

            if (!File.Exists(sessionFile))
            {
                return(null);
            }

            sessionName = System.Web.HttpUtility.UrlDecode(sessionName.Replace("+", "%2B"));

            var sessionFileReader = new SessionFileReader(sessionFile);
            var sessionInfo       = new PuttySessionInfo
            {
                PuttySession = sessionName,
                Name         = sessionName,
                Hostname     = sessionFileReader.GetValue("HostName"),
                Username     = sessionFileReader.GetValue("UserName")
            };
            var protocol = sessionFileReader.GetValue("Protocol") ?? "ssh";

            switch (protocol.ToLowerInvariant())
            {
            case "raw":
                sessionInfo.Protocol = ProtocolType.RAW;
                break;

            case "rlogin":
                sessionInfo.Protocol = ProtocolType.Rlogin;
                break;

            case "serial":
                return(null);

            case "ssh":
                object sshVersionObject = sessionFileReader.GetValue("SshProt");
                if (sshVersionObject != null)
                {
                    var sshVersion = Convert.ToInt32(sshVersionObject);
                    sessionInfo.Protocol = sshVersion >= 2 ? ProtocolType.SSH2 : ProtocolType.SSH1;
                }
                else
                {
                    sessionInfo.Protocol = ProtocolType.SSH2;
                }
                break;

            case "telnet":
                sessionInfo.Protocol = ProtocolType.Telnet;
                break;

            default:
                return(null);
            }
            sessionInfo.Port = Convert.ToInt32(sessionFileReader.GetValue("PortNumber"));

            return(sessionInfo);
        }
Example #12
0
        public override PuttySessionInfo GetSession(string sessionName)
        {
            RegistryKey sessionsKey = Registry.CurrentUser.OpenSubKey(PuttySessionsKey);

            if (sessionsKey == null)
            {
                return(null);
            }

            RegistryKey sessionKey = sessionsKey.OpenSubKey(sessionName);

            if (sessionKey == null)
            {
                return(null);
            }

            sessionName = System.Web.HttpUtility.UrlDecode(sessionName.Replace("+", "%2B"));

            PuttySessionInfo sessionInfo = new PuttySessionInfo();

            sessionInfo.PuttySession = sessionName;
            sessionInfo.Name         = sessionName;
            sessionInfo.Hostname     = Convert.ToString(sessionKey.GetValue("HostName"));
            sessionInfo.Username     = Convert.ToString(sessionKey.GetValue("UserName"));
            string protocol = Convert.ToString(sessionKey.GetValue("Protocol"));

            if (protocol == null)
            {
                protocol = "ssh";
            }
            switch (protocol.ToLowerInvariant())
            {
            case "raw":
                sessionInfo.Protocol = ProtocolType.RAW;
                break;

            case "rlogin":
                sessionInfo.Protocol = ProtocolType.Rlogin;
                break;

            case "serial":
                return(null);

            case "ssh":
                object sshVersionObject = sessionKey.GetValue("SshProt");
                if (sshVersionObject != null)
                {
                    int sshVersion = Convert.ToInt32(sshVersionObject);
                    if (sshVersion >= 2)
                    {
                        sessionInfo.Protocol = ProtocolType.SSH2;
                    }
                    else
                    {
                        sessionInfo.Protocol = ProtocolType.SSH1;
                    }
                }
                else
                {
                    sessionInfo.Protocol = ProtocolType.SSH2;
                }
                break;

            case "telnet":
                sessionInfo.Protocol = ProtocolType.Telnet;
                break;

            default:
                return(null);
            }
            sessionInfo.Port = Convert.ToInt32(sessionKey.GetValue("PortNumber"));

            return(sessionInfo);
        }
 public PuttySessionChangedEventArgs(PuttySessionInfo sessionChanged = null)
 {
     Session = sessionChanged;
 }
        public override PuttySessionInfo GetSession(string sessionName)
        {
            if (string.IsNullOrEmpty(sessionName))
            {
                return(null);
            }

            var sessionsKey = Registry.CurrentUser.OpenSubKey(PuttySessionsKey);
            var sessionKey  = sessionsKey?.OpenSubKey(sessionName);

            if (sessionKey == null)
            {
                return(null);
            }

            sessionName = HttpUtility.UrlDecode(sessionName.Replace("+", "%2B"), Encoding.GetEncoding("iso-8859-1"));

            var sessionInfo = new PuttySessionInfo
            {
                PuttySession = sessionName,
                Name         = sessionName,
                Hostname     = sessionKey.GetValue("HostName")?.ToString() ?? "",
                Username     = sessionKey.GetValue("UserName")?.ToString() ?? ""
            };


            var protocol = string.IsNullOrEmpty(sessionKey.GetValue("Protocol")?.ToString())
                ? "ssh"
                : sessionKey.GetValue("Protocol").ToString();

            switch (protocol.ToLowerInvariant())
            {
            case "raw":
                sessionInfo.Protocol = ProtocolType.RAW;
                break;

            case "rlogin":
                sessionInfo.Protocol = ProtocolType.Rlogin;
                break;

            case "serial":
                return(null);

            case "ssh":
                int.TryParse(sessionKey.GetValue("SshProt")?.ToString(), out var sshVersion);

                /* Per PUTTY.H in PuTTYNG & PuTTYNG Upstream (PuTTY proper currently)
                 * expect 0 for SSH1, 3 for SSH2 ONLY
                 * 1 for SSH1 with a 2 fallback
                 * 2 for SSH2 with a 1 fallback
                 *
                 * default to SSH2 if any other value is received
                 */
                sessionInfo.Protocol = sshVersion == 1 || sshVersion == 0 ? ProtocolType.SSH1 : ProtocolType.SSH2;
                break;

            case "telnet":
                sessionInfo.Protocol = ProtocolType.Telnet;
                break;

            default:
                return(null);
            }

            int.TryParse(sessionKey.GetValue("PortNumber")?.ToString(), out var portNumber);
            if (portNumber == default(int))
            {
                sessionInfo.SetDefaultPort();
            }
            else
            {
                sessionInfo.Port = portNumber;
            }

            return(sessionInfo);
        }