示例#1
0
        public ctlPuttyPanel(frmSuperPutty superPutty, SessionData session, PuttyClosedCallback callback, bool isPutty)
        {
            m_SuperPutty = superPutty;
            m_Session = session;
            m_ApplicationExit = callback;

            if (isPutty)
            {
                string args = "-" + session.Proto.ToString().ToLower() + " ";
                args += (!String.IsNullOrEmpty(m_Session.Password) && m_Session.Password.Length > 0) ? "-pw " + m_Session.Password + " " : "";
                args += "-P " + m_Session.Port + " ";
                args += (!String.IsNullOrEmpty(m_Session.PuttySession)) ? "-load \"" + m_Session.PuttySession + "\" " : "";
                args += (!String.IsNullOrEmpty(m_Session.Username) && m_Session.Username.Length > 0) ? m_Session.Username + "@" : "";
                args += m_Session.Host;
                Logger.Log("Args: '{0}'", args);
                this.ApplicationParameters = args;
            }
            else
            {
                this.ApplicationParameters = "-l - /bin/bash -l";
            }

            InitializeComponent();
            this.Text = session.SessionName;
            CreatePanel(isPutty);
        }
示例#2
0
        public dlgLogin(SessionData session)
        {
            m_Session = session;
            InitializeComponent();

            if (!String.IsNullOrEmpty(m_Session.Username))
                this.Username = m_Session.Username;

            textBoxUsername.Text = this.Username;
        }
示例#3
0
 public SessionData(SessionData data)
 {
     SessionName = data.SessionName;
     Host = data.Host;
     Port = data.Port;
     Proto = data.Proto;
     PuttySession = data.PuttySession;
     Username = data.Username;
     LastDockstate = data.LastDockstate;
     AutoStartSession = data.AutoStartSession;
 }
        public RemoteFileListPanel(PscpTransfer transfer, DockPanel dockPanel, SessionData session)
        {
            Logger.Log("Started new File Transfer Session for {0}", session.SessionName);
            m_Session = session;
            m_DockPanel = dockPanel;
            m_Transfer = transfer;
            m_MouseFollower = new dlgMouseFeedback();
            InitializeComponent();
            
            this.TabText = session.SessionName;

            LoadDirectory(m_Path);
        }
示例#5
0
        public dlgEditSession(SessionData session)
        {
            Session = session;
            InitializeComponent();

            // get putty saved settings from the registry to populate
            // the dropdown
            PopulatePuttySettings();

            if (!String.IsNullOrEmpty(Session.SessionName))
            {
                this.Text = "Edit session: " + session.SessionName;
                this.textBoxSessionName.Text = Session.SessionName;
                this.textBoxHostname.Text = Session.Host;
                this.textBoxPort.Text = Session.Port.ToString();
                this.textBoxUsername.Text = Session.Username;

                if (this.comboBoxPuttyProfile.Items.Contains(session.SessionName))
                    this.comboBoxPuttyProfile.SelectedItem = session.SessionName;

                switch (Session.Proto)
                {
                    case ConnectionProtocol.Raw:
                        radioButtonRaw.Checked = true;
                        break;
                    case ConnectionProtocol.Rlogin:
                        radioButtonRlogin.Checked = true;
                        break;
                    case ConnectionProtocol.Serial:
                        radioButtonSerial.Checked = true;
                        break;
                    case ConnectionProtocol.SSH:
                        radioButtonSSH.Checked = true;
                        break;
                    case ConnectionProtocol.Telnet:
                        radioButtonTelnet.Checked = true;
                        break;
                    default:
                        radioButtonSSH.Checked = true;
                        break;
                }
            }
            else
            {
                this.Text = "Create new session";
                radioButtonSSH.Checked = true;
            }
        }
示例#6
0
        /// <summary>
        /// Open a directory listing on the selected nodes host to allow dropping files
        /// for drag + drop copy.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fileBrowserToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SessionData session = (SessionData)treeView1.SelectedNode.Tag;

            SuperPuTTY.OpenScpSession(session);
        }
示例#7
0
        public void ParseClArguments(string[] args)
        {
            SessionData sessionData = null;
            bool        use_scp     = false;
            bool        is_uri      = false;

            if (args.Length > 0)
            {
                sessionData = new SessionData();
                string proto = "", port = "", username = "", puttySession = "", password = "";

                if (args[0].StartsWith("ssh:"))
                {
                    args[0]                 = args[0].Remove(0, 6);
                    sessionData.Host        = args[0];
                    sessionData.SessionName = args[0];
                    is_uri = true;
                    args[args.Length - 1] = args[args.Length - 1].Remove(args[args.Length - 1].Length - 1, 1);
                }

                for (int i = 0; i < args.Length - 1; i++)
                {
                    switch (args[i].ToString().ToLower())
                    {
                    case "-ssh":
                        proto = "SSH";
                        break;

                    case "-serial":
                        proto = "Serial";
                        break;

                    case "-telnet":
                        proto = "Telnet";
                        break;

                    case "-scp":
                        proto   = "SSH";
                        use_scp = true;
                        break;

                    case "-raw":
                        proto = "Raw";
                        break;

                    case "-rlogin":
                        proto = "Rlogin";
                        break;

                    case "-p":
                        port = args[i + 1];
                        i++;
                        break;

                    case "-l":
                        username = args[i + 1];
                        i++;
                        break;

                    case "-pw":
                        password = args[i + 1];
                        i++;
                        break;

                    case "-load":
                        puttySession             = args[i + 1];
                        sessionData.PuttySession = args[i + 1];
                        i++;
                        break;
                    }
                }
                if (!is_uri)
                {
                    sessionData.Host        = args[args.Length - 1];
                    sessionData.SessionName = args[args.Length - 1];
                }

                sessionData.Proto        = (proto != "") ? (ConnectionProtocol)Enum.Parse(typeof(ConnectionProtocol), proto) : (ConnectionProtocol)Enum.Parse(typeof(ConnectionProtocol), "SSH");
                sessionData.Port         = (port != "") ? Convert.ToInt32(port) : 22;
                sessionData.Username     = (username != "") ? username : "";
                sessionData.Password     = (password != "") ? password : "";
                sessionData.PuttySession = (puttySession != "") ? puttySession : "Default Settings";

                if (use_scp && IsScpEnabled)
                {
                    CreateRemoteFileListPanel(sessionData);
                }
                else
                {
                    CreatePuttyPanel(sessionData);
                }
            }
        }
示例#8
0
 public PscpTransfer(SessionData session)
 {
     m_Session = session;
     m_Login = new dlgLogin(m_Session);
 }
示例#9
0
        /// <summary>
        /// Create/Update a session entry
        /// </summary>
        /// <param name="sender">The toolstripmenuitem control that was clicked</param>
        /// <param name="e">An Empty EventArgs object</param>
        private void CreateOrEditSessionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SessionData session = null;
            TreeNode    node    = null;
            TreeNode    nodeRef = this.nodeRoot;
            string      title   = null;

            if (sender is ToolStripMenuItem)
            {
                ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
                bool isFolderNode          = IsFolderNode(treeView1.SelectedNode);
                if (menuItem.Text.ToLower().Equals("new") || isFolderNode)
                {
                    session = new SessionData();
                    nodeRef = isFolderNode ? treeView1.SelectedNode : treeView1.SelectedNode.Parent;
                    title   = "Create New Session";
                }
                else if (menuItem == this.createLikeToolStripMenuItem)
                {
                    // copy as
                    session             = (SessionData)((SessionData)treeView1.SelectedNode.Tag).Clone();
                    session.SessionId   = SuperPuTTY.MakeUniqueSessionId(session.SessionId);
                    session.SessionName = SessionData.GetSessionNameFromId(session.SessionId);
                    nodeRef             = treeView1.SelectedNode.Parent;
                    title = "Create New Session Like " + session.OldName;
                }
                else
                {
                    // edit, session node selected
                    // We make a clone of the session since we do not want to directly edit the real object.
                    session = (SessionData)((SessionData)treeView1.SelectedNode.Tag).Clone();
                    node    = treeView1.SelectedNode;
                    nodeRef = node.Parent;
                    title   = "Edit Session: " + session.SessionName;
                }
            }

            dlgEditSession form = new dlgEditSession(session, this.treeView1.ImageList)
            {
                Text = title
            };

            form.SessionNameValidator += delegate(string txt, out string error)
            {
                bool IsValid = ValidateSessionNameChange(nodeRef, node, txt, out error);
                return(IsValid);
            };

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                /* "node" will only be assigned if we're editing an existing session entry */
                if (node == null)
                {
                    // get the path up to the ref (parent) node
                    if (nodeRoot != nodeRef)
                    {
                        UpdateSessionId(nodeRef, session);
                        session.SessionId = SessionData.CombineSessionIds(session.SessionId, session.SessionName);
                    }
                    SuperPuTTY.AddSession(session);

                    // find new node and select it
                    TreeNode nodeNew = nodeRef.Nodes[session.SessionName];
                    if (nodeNew != null)
                    {
                        this.treeView1.SelectedNode = nodeNew;
                    }
                }
                else
                {
                    SessionData RealSession = (SessionData)treeView1.SelectedNode.Tag;
                    RealSession.CopyFrom(session);
                    RealSession.SessionName     = session.SessionName;
                    this.treeView1.SelectedNode = node;
                }

                //treeView1.ExpandAll();
                SuperPuTTY.SaveSessions();
            }
        }
示例#10
0
        public void CreatePuttyPanel(SessionData sessionData)
        {
            ctlPuttyPanel sessionPanel = null;

            // This is the callback fired when the panel containing the terminal is closed
            // We use this to save the last docking location
            PuttyClosedCallback callback = delegate(bool closed)
            {
                if (sessionPanel != null)
                {
                    // save the last dockstate (if it has been changed)
                    if (sessionData.LastDockstate != sessionPanel.DockState
                        && sessionPanel.DockState != DockState.Unknown
                        && sessionPanel.DockState != DockState.Hidden)
                    {
                        sessionData.LastDockstate = sessionPanel.DockState;
                        sessionData.SaveToRegistry();
                    }

                    if (sessionPanel.InvokeRequired)
                    {
                        this.BeginInvoke((MethodInvoker)delegate()
                        {
                            sessionPanel.Close();
                         });
                    }
                    else
                    {
                        sessionPanel.Close();
                    }
                }
            };

            sessionPanel = new ctlPuttyPanel(sessionData, callback);
            sessionPanel.Show(dockPanel1, sessionData.LastDockstate);
        }
示例#11
0
        public void ParseClArguments(string[] args)
        {
            SessionData sessionData = null;
            bool use_scp = false;
            bool is_uri = false;
            if (args.Length > 0)
            {
                sessionData = new SessionData();
                string proto = "", port = "", username = "", puttySession = "", password = "";

                if (args[0].StartsWith("ssh:"))
                {
                    args[0] = args[0].Remove(0, 6);
                    sessionData.Host = args[0];
                    sessionData.SessionName = args[0];
                    is_uri = true;
                    args[args.Length - 1] = args[args.Length - 1].Remove(args[args.Length - 1].Length - 1, 1);
                }

                for (int i = 0; i < args.Length - 1; i++)
                {
                    switch (args[i].ToString().ToLower())
                    {
                        case "-ssh":
                            proto = "SSH";
                            break;

                        case "-serial":
                            proto = "Serial";
                            break;

                        case "-telnet":
                            proto = "Telnet";
                            break;

                        case "-scp":
                            proto = "SSH";
                            use_scp = true;
                            break;

                        case "-raw":
                            proto = "Raw";
                            break;

                        case "-rlogin":
                            proto = "Rlogin";
                            break;

                        case "-P":
                            port = args[i + 1];
                            i++;
                            break;

                        case "-l":
                            username = args[i + 1];
                            i++;
                            break;

                        case "-pw":
                            password = args[i + 1];
                            i++;
                            break;

                        case "-load":
                            puttySession = args[i + 1];
                            sessionData.PuttySession = args[i + 1];
                            i++;
                            break;
                    }
                }
                if (!is_uri)
                {
                    sessionData.Host = args[args.Length - 1];
                    sessionData.SessionName = args[args.Length - 1];
                }

                sessionData.Proto = (proto != "") ? (ConnectionProtocol)Enum.Parse(typeof(ConnectionProtocol), proto) : (ConnectionProtocol)Enum.Parse(typeof(ConnectionProtocol), "SSH");
                sessionData.Port = (port != "") ? Convert.ToInt32(port) : 22;
                sessionData.Username = (username != "") ? username : "";
                sessionData.Password = (password != "") ? password : "";
                sessionData.PuttySession = (puttySession != "") ? puttySession : "Default Settings";

                if (use_scp && IsScpEnabled)
                {
                    CreateRemoteFileListPanel(sessionData);
                }
                else
                {
                    CreatePuttyPanel(sessionData);
                }
            }
        }
示例#12
0
 /// <summary>
 /// Copy sessions from PuTTY into SuperPutty Sessions
 /// </summary>
 public static void copySessionsFromPuTTY()
 {
     RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\SimonTatham\PuTTY\Sessions");
     if (key != null)
     {
         string[] savedSessionNames = key.GetSubKeyNames();
         foreach (string keyName in savedSessionNames)
         {
             RegistryKey sessionKey = key.OpenSubKey(keyName);
             if (sessionKey != null)
             {
                 SessionData session = new SessionData();
                 session.Host = (string)sessionKey.GetValue("HostName", "");
                 session.Port = (int)sessionKey.GetValue("PortNUmber", 22);
                 session.Proto = (ConnectionProtocol)Enum.Parse(typeof(ConnectionProtocol),
                     (string)sessionKey.GetValue("Protocol", "SSH"), true);
                 session.PuttySession = (string)sessionKey.GetValue("PuttySession", HttpUtility.UrlDecode(keyName));
                 session.SessionName = HttpUtility.UrlDecode(keyName);
                 session.Username = (string)sessionKey.GetValue("UserName", "");
                 session.LastDockstate = DockState.Document;
                 session.AutoStartSession = false;
                 session.SaveToRegistry();
             }
         }
     }
 }
示例#13
0
        private void duplicateSessionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SessionData sessionData = new SessionData(m_Session);

            m_SuperPutty.CreatePuttyPanel(sessionData);
        }
示例#14
0
        /// <summary>
        /// Create/Update a session entry
        /// </summary>
        /// <param name="sender">The toolstripmenuitem control that was clicked</param>
        /// <param name="e">An Empty EventArgs object</param>
        private void CreateOrEditSessionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SessionData session = null;
            TreeNode    node    = null;
            TreeNode    nodeRef = this.nodeRoot;
            bool        isEdit  = false;
            string      title   = null;

            if (sender is ToolStripMenuItem)
            {
                ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
                bool isFolderNode          = IsFolderNode(treeView1.SelectedNode);
                if (menuItem.Text.ToLower().Equals("new") || isFolderNode)
                {
                    session = new SessionData();
                    nodeRef = isFolderNode ? treeView1.SelectedNode : treeView1.SelectedNode.Parent;
                    title   = "Create New Session";
                }
                else if (menuItem == this.createLikeToolStripMenuItem)
                {
                    // copy as
                    session             = (SessionData)((SessionData)treeView1.SelectedNode.Tag).Clone();
                    session.SessionId   = SuperPuTTY.MakeUniqueSessionId(session.SessionId);
                    session.SessionName = SessionData.GetSessionNameFromId(session.SessionId);
                    nodeRef             = treeView1.SelectedNode.Parent;
                    title = "Create New Session Like " + session.OldName;
                }
                else
                {
                    // edit, session node selected
                    session = (SessionData)treeView1.SelectedNode.Tag;
                    node    = treeView1.SelectedNode;
                    nodeRef = node.Parent;
                    isEdit  = true;
                    title   = "Edit Session: " + session.SessionName;
                }
            }

            dlgEditSession form = new dlgEditSession(session, this.treeView1.ImageList);

            form.Text = title;
            form.SessionNameValidator += delegate(string txt, out string error)
            {
                error = String.Empty;
                bool isDupeNode = isEdit ? txt != node.Text && nodeRef.Nodes.ContainsKey(txt) : nodeRef.Nodes.ContainsKey(txt);
                if (isDupeNode)
                {
                    error = "Session with same name exists";
                }
                else if (txt.Contains(SessionIdDelim))
                {
                    error = "Invalid character ( " + SessionIdDelim + " ) in name";
                }
                else if (string.IsNullOrEmpty(txt) || txt.Trim() == String.Empty)
                {
                    error = "Empty name";
                }
                return(string.IsNullOrEmpty(error));
            };

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                /* "node" will only be assigned if we're editing an existing session entry */
                if (node == null)
                {
                    // get the path up to the ref (parent) node
                    if (nodeRoot != nodeRef)
                    {
                        UpdateSessionId(nodeRef, session);
                        session.SessionId = SessionData.CombineSessionIds(session.SessionId, session.SessionName);
                    }
                    SuperPuTTY.AddSession(session);

                    // find new node and select it
                    TreeNode nodeNew = nodeRef.Nodes[session.SessionName];
                    if (nodeNew != null)
                    {
                        this.treeView1.SelectedNode = nodeNew;
                    }
                }
                else
                {
                    // handle renames
                    node.Text             = session.SessionName;
                    node.Name             = session.SessionName;
                    node.ImageKey         = session.ImageKey;
                    node.SelectedImageKey = session.ImageKey;
                    if (session.SessionId != session.OldSessionId)
                    {
                        try
                        {
                            this.isRenamingNode = true;
                            SuperPuTTY.RemoveSession(session.OldSessionId);
                            SuperPuTTY.AddSession(session);
                        }
                        finally
                        {
                            this.isRenamingNode = false;
                        }
                    }
                    ResortNodes();
                    this.treeView1.SelectedNode = node;
                }

                //treeView1.ExpandAll();
                SuperPuTTY.SaveSessions();
            }
        }
示例#15
0
 /// <summary>
 /// Read any existing saved sessions from the registry, decode and populat a list containing the data
 /// </summary>
 /// <returns>A list containing the entries retrieved from the registry</returns>
 private static List<SessionData> LoadSessionsFromRegistry()
 {
     List<SessionData> sessionList = new List<SessionData>();
     RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Jim Radford\SuperPuTTY\Sessions");
     if (key != null)
     {
         string[] sessionKeys = key.GetSubKeyNames();
         foreach (string session in sessionKeys)
         {
             SessionData sessionData = new SessionData();
             RegistryKey itemKey = key.OpenSubKey(session);
             if (itemKey != null)
             {
                 sessionData.Host = (string)itemKey.GetValue("Host", "");
                 sessionData.Port = (int)itemKey.GetValue("Port", 22);
                 sessionData.Proto = (ConnectionProtocol)Enum.Parse(typeof(ConnectionProtocol), (string)itemKey.GetValue("Proto", "SSH"));
                 sessionData.PuttySession = (string)itemKey.GetValue("PuttySession", "Default Session");
                 sessionData.SessionName = session;
                 sessionData.Username = (string)itemKey.GetValue("Login", "");
                 sessionData.LastDockstate = (DockState)itemKey.GetValue("Last Dock", DockState.Document);
                 sessionData.AutoStartSession = bool.Parse((string)itemKey.GetValue("Auto Start", "False"));
                 sessionList.Add(sessionData);
             }
         }
     }
     return sessionList;
 }
示例#16
0
        private void InitNewSessionToolStripMenuItems()
        {
            List <ToolStripMenuItem> tsmi = new List <ToolStripMenuItem>();

            foreach (SessionData session in SuperPuTTY.GetAllSessions())
            {
                ToolStripMenuItem tsmiParent = null;
                foreach (string part in SessionData.GetSessionNameParts(session.SessionId))
                {
                    if (part == session.SessionName)
                    {
                        ToolStripMenuItem newSessionTSMI = new ToolStripMenuItem
                        {
                            Tag  = session,
                            Text = session.SessionName
                        };
                        newSessionTSMI.Click      += new System.EventHandler(newSessionTSMI_Click);
                        newSessionTSMI.ToolTipText = session.ToString();
                        if (tsmiParent == null)
                        {
                            tsmi.Add(newSessionTSMI);
                        }
                        else
                        {
                            tsmiParent.DropDownItems.Add(newSessionTSMI);
                        }
                    }
                    else
                    {
                        if (tsmiParent == null)
                        {
                            tsmiParent = tsmi.FirstOrDefault((item) => string.Equals(item.Name, part));
                            if (tsmiParent == null)
                            {
                                tsmiParent = new ToolStripMenuItem(part)
                                {
                                    Name = part
                                };
                                tsmi.Add(tsmiParent);
                            }
                        }
                        else
                        {
                            if (tsmiParent.DropDownItems.ContainsKey(part))
                            {
                                tsmiParent = (ToolStripMenuItem)tsmiParent.DropDownItems[part];
                            }
                            else
                            {
                                ToolStripMenuItem newSessionFolder = new ToolStripMenuItem(part)
                                {
                                    Name = part
                                };
                                tsmiParent.DropDownItems.Add(newSessionFolder);
                                tsmiParent = newSessionFolder;
                            }
                        }
                    }
                }
            }

            if (InvokeRequired)
            {
                Invoke(new Action(() => {
                    if (newSessionToolStripMenuItem.DropDownItems.Count == 0)
                    {
                        newSessionToolStripMenuItem.DropDownItems.AddRange(tsmi.ToArray());
                    }
                }));
            }
            else
            if (newSessionToolStripMenuItem.DropDownItems.Count == 0)
            {
                newSessionToolStripMenuItem.DropDownItems.AddRange(tsmi.ToArray());
            }
        }
示例#17
0
        /// <summary>Open a new putty window with its settings being passed in a <seealso cref="SessionData"/> object</summary>
        /// <param name="session">The <seealso cref="SessionData"/> object containing the settings</param>
        public static ctlPuttyPanel OpenProtoSession(SessionData session)
        {
            Log.InfoFormat("Opening putty session, id={0}", session == null ? "" : session.SessionId);
            ctlPuttyPanel panel = null;

            if (session != null)
            {
                String Executable = PuttyStartInfo.GetExecutable(session);
                if (String.IsNullOrEmpty(Executable))
                {
                    MessageBox.Show("Error trying to create session: " + session.ToString() +
                                    "\nExecutable not set for " + session.Proto.ToString() + " protocol." +
                                    "\nGo to tools->options->General tab to set the path to the executable."
                                    , "Failed to create a session", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }
                if (!File.Exists(Executable))
                {
                    MessageBox.Show("Error trying to create session: " + session.ToString() +
                                    "\nExecutable not found for " + session.Proto.ToString() + " protocol." +
                                    "\nThe path for the executable was set as \"" + Executable + "\"." +
                                    "\nGo to tools->options->General tab to set the path to the executable."
                                    , "Failed to create a session", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }

                // This is the callback fired when the panel containing the terminal is closed
                // We use this to save the last docking location and to close the panel
                PuttyClosedCallback callback = delegate
                {
                    if (panel != null)
                    {
                        // save the last dockstate (if it has been changed)
                        if (session.LastDockstate != panel.DockState &&
                            panel.DockState != DockState.Unknown &&
                            panel.DockState != DockState.Hidden)
                        {
                            session.LastDockstate = panel.DockState;
                            SuperPuTTY.SaveSessions();
                        }

                        if (panel.InvokeRequired)
                        {
                            panel.BeginInvoke((MethodInvoker) delegate {
                                panel.Close();
                            });
                        }
                        else
                        {
                            panel.Close();
                        }
                    }
                };

                try {
                    panel = new ctlPuttyPanel(session, callback);

                    ApplyDockRestrictions(panel);
                    ApplyIconForWindow(panel, session);
                    panel.Show(MainForm.DockPanel, session.LastDockstate);
                    ReportStatus("Opened session: {0} [{1}]", session.SessionId, session.Proto);

                    if (!String.IsNullOrWhiteSpace(session.SPSLFileName))
                    {
                        String fileName = session.SPSLFileName;
                        String script   = String.Empty;

                        if (Regex.IsMatch(fileName, @"^https?:\/\/", RegexOptions.IgnoreCase))
                        {
                            try
                            {
                                HttpWebRequest req      = WebRequest.CreateHttp(fileName);
                                var            response = req.GetResponse();
                                using (var stream = new StreamReader(response.GetResponseStream()))
                                {
                                    script = stream.ReadToEnd();
                                }
                            }
                            catch (Exception)
                            {
                                script = String.Empty;
                            }
                        }
                        else
                        {
                            if (fileName.StartsWith("file://", StringComparison.OrdinalIgnoreCase))
                            {
                                fileName = fileName.Substring("file://".Length);
                            }

                            if (File.Exists(fileName))
                            {
                                script = File.ReadAllText(fileName);
                            }
                        }

                        if (!String.IsNullOrEmpty(script))
                        {
                            ExecuteScriptEventArgs scriptArgs = new ExecuteScriptEventArgs()
                            {
                                Script = script, Handle = panel.AppPanel.AppWindowHandle
                            };
                            SPSL.BeginExecuteScript(scriptArgs);
                        }
                    }
                } catch (InvalidOperationException ex)
                {
                    MessageBox.Show("Error trying to create session " + ex.Message, "Failed to create session panel", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            return(panel);
        }
示例#18
0
 public PscpTransfer(SessionData session)
 {
     m_Session = session;
     m_Login   = new dlgLogin(m_Session);
 }
示例#19
0
 void RestartSessionToolStripMenuItemClick(object sender, EventArgs e)
 {
 	SessionData sessionData = new SessionData(m_Session);
     m_SuperPutty.CreatePuttyPanel(sessionData);
     this.Close();
 }
示例#20
0
 private void launchMintty()
 {
     SessionData sessionData = new SessionData();
     sessionData.SessionName = "mintty";
     CreatePuttyPanel(sessionData, false);
 }
示例#21
0
        /// <summary>Open a new putty window with its settings being passed in a <seealso cref="SessionData"/> object</summary>
        /// <param name="session">The <seealso cref="SessionData"/> object containing the settings</param>
        public static ctlPuttyPanel OpenProtoSession(SessionData session)
        {
            Log.InfoFormat("Opening putty session, id={0}", session == null ? "" : session.SessionId);
            ctlPuttyPanel panel = null;

            if (session != null)
            {
                String Executable = PuttyStartInfo.GetExecutable(session);
                if (String.IsNullOrEmpty(Executable))
                {
                    MessageBox.Show("Error trying to create session: " + session.ToString() +
                                    "\nExecutable not set for " + session.Proto.ToString() + " protocol." +
                                    "\nGo to tools->options->General tab to set the path to the executable."
                                    , "Failed to create a session", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }
                if (!File.Exists(Executable))
                {
                    MessageBox.Show("Error trying to create session: " + session.ToString() +
                                    "\nExecutable not found for " + session.Proto.ToString() + " protocol." +
                                    "\nThe path for the executable was set as \"" + Executable + "\"." +
                                    "\nGo to tools->options->General tab to set the path to the executable."
                                    , "Failed to create a session", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }

                // This is the callback fired when the panel containing the terminal is closed
                // We use this to save the last docking location and to close the panel
                PuttyClosedCallback callback = delegate
                {
                    if (panel != null)
                    {
                        // save the last dockstate (if it has been changed)
                        if (session.LastDockstate != panel.DockState &&
                            panel.DockState != DockState.Unknown &&
                            panel.DockState != DockState.Hidden)
                        {
                            session.LastDockstate = panel.DockState;
                            SuperPuTTY.SaveSessions();
                        }

                        if (panel.InvokeRequired)
                        {
                            panel.BeginInvoke((MethodInvoker) delegate {
                                panel.Close();
                            });
                        }
                        else
                        {
                            panel.Close();
                        }
                    }
                };

                try {
                    panel = new ctlPuttyPanel(session, callback);

                    ApplyDockRestrictions(panel);
                    ApplyIconForWindow(panel, session);
                    panel.Show(MainForm.DockPanel, session.LastDockstate);
                    ReportStatus("Opened session: {0} [{1}]", session.SessionId, session.Proto);

                    if (!String.IsNullOrEmpty(session.SPSLFileName) &&
                        File.Exists(session.SPSLFileName))
                    {
                        ExecuteScriptEventArgs scriptArgs = new ExecuteScriptEventArgs()
                        {
                            Script = File.ReadAllText(session.SPSLFileName), Handle = panel.AppPanel.AppWindowHandle
                        };
                        if (!String.IsNullOrEmpty(scriptArgs.Script))
                        {
                            SPSL.BeginExecuteScript(scriptArgs);
                        }
                    }
                } catch (InvalidOperationException ex)
                {
                    MessageBox.Show("Error trying to create session " + ex.Message, "Failed to create session panel", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            return(panel);
        }
示例#22
0
 public dlgLogin(SessionData session) : this(session.Username)
 {
     m_Session = session;
 }
示例#23
0
        /// <summary>
        /// Create/Update a session entry
        /// </summary>
        /// <param name="sender">The toolstripmenuitem control that was clicked</param>
        /// <param name="e">An Empty EventArgs object</param>
        private void CreateOrEditSessionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SessionData session = null;
            TreeNode node = null;

            if (sender is ToolStripMenuItem)
            {
                ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
                if (menuItem.Text.ToLower().Equals("new") || treeView1.SelectedNode.Tag == null)
                {
                    session = new SessionData();
                }
                else
                {
                    session = (SessionData)treeView1.SelectedNode.Tag;
                    node = treeView1.SelectedNode;
                }
            }

            dlgEditSession form = new dlgEditSession(session);
            if (form.ShowDialog() == DialogResult.OK)
            {
                /* "node" will only be assigned if we're editing an existing session entry */
                if (node == null)
                {
                    node = treeView1.Nodes["root"].Nodes.Add(session.SessionName, session.SessionName, 1, 1);
                }
                else
                {
                    // handle renames
                    node.Text = session.SessionName;
                }

                node.Tag = session;
                treeView1.ExpandAll();
            }
        }
示例#24
0
 /// <summary>Save in-application Session Database to XML File</summary>
 public static void SaveSessions()
 {
     Log.InfoFormat("Saving all sessions");
     SessionData.SaveSessionsToFile(GetAllSessions(), SessionsFileName);
 }
示例#25
0
 public void CreatePuttyPanel(SessionData sessionData)
 {
     CreatePuttyPanel(sessionData, true);
 }
示例#26
0
 private static void ApplyIconForWindow(ToolWindow win, SessionData session)
 {
     win.Icon = GetIconForSession(session);
 }
示例#27
0
 private void duplicateSessionToolStripMenuItem_Click(object sender, EventArgs e)
 {
     SessionData sessionData = new SessionData(m_Session);
     m_SuperPutty.CreatePuttyPanel(sessionData);
 }
示例#28
0
        public dlgEditSession(SessionData session, ImageList iconList)
        {
            Session = session;
            InitializeComponent();

            // get putty saved settings from the registry to populate
            // the dropdown
            PopulatePuttySettings();

            if (!String.IsNullOrEmpty(Session.SessionName))
            {
                this.Text = "Edit session: " + session.SessionName;
                this.textBoxSessionName.Text      = Session.SessionName;
                this.textBoxHostname.Text         = Session.Host;
                this.textBoxPort.Text             = Session.Port.ToString();
                this.textBoxExtraArgs.Text        = Session.ExtraArgs;
                this.textBoxUsername.Text         = Session.Username;
                this.textBoxSPSLScriptFile.Text   = Session.SPSLFileName;
                this.textBoxRemotePathSesion.Text = Session.RemotePath;
                this.textBoxLocalPathSesion.Text  = Session.LocalPath;

                switch (Session.Proto)
                {
                case ConnectionProtocol.Raw:
                    radioButtonRaw.Checked = true;
                    break;

                case ConnectionProtocol.Rlogin:
                    radioButtonRlogin.Checked = true;
                    break;

                case ConnectionProtocol.Serial:
                    radioButtonSerial.Checked = true;
                    break;

                case ConnectionProtocol.SSH:
                    radioButtonSSH.Checked = true;
                    break;

                case ConnectionProtocol.Telnet:
                    radioButtonTelnet.Checked = true;
                    break;

                case ConnectionProtocol.Cygterm:
                    radioButtonCygterm.Checked = true;
                    break;

                case ConnectionProtocol.Mintty:
                    radioButtonMintty.Checked = true;
                    break;

                case ConnectionProtocol.VNC:
                    radioButtonVNC.Checked = true;
                    if (Session.Port == 0)
                    {
                        this.textBoxPort.Text = "";
                    }
                    break;

                default:
                    radioButtonSSH.Checked = true;
                    break;
                }

                comboBoxPuttyProfile.DropDownStyle = ComboBoxStyle.DropDownList;
                foreach (String settings in this.comboBoxPuttyProfile.Items)
                {
                    if (settings == session.PuttySession)
                    {
                        this.comboBoxPuttyProfile.SelectedItem = settings;
                        break;
                    }
                }

                this.buttonSave.Enabled = true;
            }
            else
            {
                this.Text = "Create new session";
                radioButtonSSH.Checked  = true;
                this.buttonSave.Enabled = false;
            }


            // Setup icon chooser
            this.buttonImageSelect.ImageList = iconList;
            this.buttonImageSelect.ImageKey  = string.IsNullOrEmpty(Session.ImageKey)
                ? SessionTreeview.ImageKeySession
                : Session.ImageKey;
            this.toolTip.SetToolTip(this.buttonImageSelect, buttonImageSelect.ImageKey);

            this.isInitialized = true;
        }
示例#29
0
        public void CreateRemoteFileListPanel(SessionData sessionData)
        {
            RemoteFileListPanel dir = null;
            bool cancelShow = false;
            if (sessionData != null)
            {
                PuttyClosedCallback callback = delegate(bool error)
                {
                    cancelShow = error;
                };
                PscpTransfer xfer = new PscpTransfer(sessionData);
                xfer.PuttyClosed = callback;

                dir = new RemoteFileListPanel(xfer, dockPanel1, sessionData);
                if (!cancelShow)
                {
                    dir.Show(dockPanel1);
                }
            }
        }
示例#30
0
        private void fileZillaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SessionData session = (SessionData)treeView1.SelectedNode.Tag;

            ExternalApplications.openFileZilla(session);
        }
示例#31
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            SessionData sessionData = new SessionData();

            sessionData.Host = HostTextBox.Text;
            sessionData.Port = Convert.ToInt32(PortTextBox.Text);
            sessionData.Proto = (ProtocolBox.Text == "SCP") ? (ConnectionProtocol)Enum.Parse(typeof(ConnectionProtocol), "SSH") : (ConnectionProtocol)Enum.Parse(typeof(ConnectionProtocol), ProtocolBox.Text);
            sessionData.PuttySession = "Default Settings";
            sessionData.SessionName = HostTextBox.Text;
            sessionData.Username = LoginTextBox.Text;
            sessionData.Password = PasswordTextBox.Text;

            if (ProtocolBox.Text == "SCP" && IsScpEnabled)
            {
                CreateRemoteFileListPanel(sessionData);
            }
            else
            {
                CreatePuttyPanel(sessionData);
            }
        }
示例#32
0
        public void SessionPropertyChanged(SessionData Session, String PropertyName)
        {
            if (Session == null)
            {
                return;
            }

            if (PropertyName == "SessionName" || PropertyName == "ImageKey")
            {
                TreeNode Node = FindSessionNode(Session.SessionId);
                if (Node == null)
                {
                    // It is possible that the session id was changed before the
                    // session name. In this case, we check to see if we
                    // can find a node with the old session id that is also associated
                    // to the session data.
                    Node = FindSessionNode(Session.OldSessionId);
                    if (Node == null || Node.Tag != Session)
                    {
                        return;
                    }
                }

                Node.Text             = Session.SessionName;
                Node.Name             = Session.SessionName;
                Node.ImageKey         = Session.ImageKey;
                Node.SelectedImageKey = Session.ImageKey;

                bool IsSelectedSession = treeView1.SelectedNode == Node;
                ResortNodes();
                if (IsSelectedSession)
                {
                    // Re-selecting the node since it will be unselected when sorting.
                    treeView1.SelectedNode = Node;
                }
            }
            else if (PropertyName == "SessionId")
            {
                TreeNode Node = FindSessionNode(Session.OldSessionId);
                if (Node == null)
                {
                    // It is possible that the session name was changed before the
                    // session id. In this case, we check to see if we
                    // can find a node with the current session id that is also associated
                    // to the session data.
                    Node = FindSessionNode(Session.SessionId);
                    if (Node == null || Node.Tag != Session)
                    {
                        return;
                    }
                }

                try
                {
                    this.isRenamingNode = true;
                    SuperPuTTY.RemoveSession(Session.OldSessionId);
                    SuperPuTTY.AddSession(Session);
                }
                finally
                {
                    this.isRenamingNode = false;
                }
            }
        }