private void buttonSave_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(CommandLineOptions.getcommand(textBoxExtraArgs.Text, "-pw"))) { if (MessageBox.Show("SuperPutty save the password in Sessions.xml file in plain text.\nUse a password in 'Extra PuTTY Arguments' is very insecure.\nFor a secure connection use SSH authentication with Pageant. \nSelect yes, if you want save the password", "Are you sure that you want to save the password?", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) == DialogResult.Cancel) { return; } } Session.SessionName = textBoxSessionName.Text.Trim(); Session.PuttySession = comboBoxPuttyProfile.Text.Trim(); Session.Host = textBoxHostname.Text.Trim(); Session.ExtraArgs = textBoxExtraArgs.Text.Trim(); Session.Port = int.Parse(textBoxPort.Text.Trim()); Session.Username = textBoxUsername.Text.Trim(); Session.SessionId = SessionData.CombineSessionIds(SessionData.GetSessionParentId(Session.SessionId), Session.SessionName); Session.ImageKey = buttonImageSelect.ImageKey; Session.SPSLFileName = textBoxSPSLScriptFile.Text.Trim(); Session.RemotePath = textBoxRemotePathSesion.Text.Trim(); Session.LocalPath = textBoxLocalPathSesion.Text.Trim(); for (int i = 0; i < groupBox1.Controls.Count; i++) { RadioButton rb = (RadioButton)groupBox1.Controls[i]; if (rb.Checked) { Session.Proto = (ConnectionProtocol)rb.Tag; } } DialogResult = DialogResult.OK; }
/// <summary>Import sessions from a from a <seealso cref="List"/> object into the specified folder</summary> /// <param name="sessions">A <seealso cref="List"/> of <seealso cref="SessionData"/> objects</param> /// <param name="folder">The destination folder name</param> public static void ImportSessions(List <SessionData> sessions, string folder) { foreach (SessionData session in sessions) { // pre-pend session id with the provided folder to put them session.SessionId = MakeUniqueSessionId(SessionData.CombineSessionIds(folder, session.SessionId)); session.SessionName = SessionData.GetSessionNameFromId(session.SessionId); AddSession(session); } Log.InfoFormat("Imported {0} sessions into {1}", sessions.Count, folder); SaveSessions(); }
private void sessionDetailPropertyGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e) { SessionData Session = sessionDetailPropertyGrid.SelectedObject as SessionData; if (Session != null) { String HostPropertyName = "Host"; String PuttySessionPropertyName = "PuttySession"; if (e.ChangedItem.PropertyDescriptor.Name == HostPropertyName || e.ChangedItem.PropertyDescriptor.Name == PuttySessionPropertyName) { if (String.IsNullOrEmpty(Session.PuttySession) && String.IsNullOrEmpty(Session.Host)) { if (e.ChangedItem.PropertyDescriptor.Name == HostPropertyName) { MessageBox.Show("A host name must be specified if a Putty Session Profile is not selected"); Session.Host = (String)e.OldValue; } else { MessageBox.Show("A Putty Session Profile must be selected if a Host Name is not provided"); Session.PuttySession = (String)e.OldValue; } sessionDetailPropertyGrid.Refresh(); } } String ExtraArgsPropertyName = "ExtraArgs"; if (e.ChangedItem.PropertyDescriptor.Name == ExtraArgsPropertyName) { if (!String.IsNullOrEmpty(CommandLineOptions.getcommand(Session.ExtraArgs, "-pw"))) { if (MessageBox.Show("SuperPutty save the password in Sessions.xml file in plain text.\nUse a password in 'Extra PuTTY Arguments' is very insecure.\nFor a secure connection use SSH authentication with Pageant. \nSelect yes, if you want save the password", "Are you sure that you want to save the password?", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) == DialogResult.Cancel) { Session.ExtraArgs = (String)e.OldValue; return; } } sessionDetailPropertyGrid.Refresh(); } Session.SessionId = SessionData.CombineSessionIds(SessionData.GetSessionParentId(Session.SessionId), Session.SessionName); } SuperPuTTY.SaveSessions(); }
private void buttonSave_Click(object sender, EventArgs e) { int val = 0; if (!String.IsNullOrEmpty(CommandLineOptions.getcommand(textBoxExtraArgs.Text, "-pw"))) { if (MessageBox.Show("SuperPutty saves the extra arguments Sessions.xml file in plain text.\nUse of -pw password in 'Extra Arguments' is very insecure.\nFor a secure connection use SSH authentication with Pageant. \nSelect yes, if you want save the password", "Are you sure that you want to save the password?", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) == DialogResult.Cancel) { return; } } Session.SessionName = textBoxSessionName.Text.Trim(); Session.PuttySession = comboBoxPuttyProfile.Text.Trim(); Session.Host = textBoxHostname.Text.Trim(); Session.ExtraArgs = textBoxExtraArgs.Text.Trim(); if (!Int32.TryParse(this.textBoxPort.Text, out val)) { Session.Port = 0; } else { Session.Port = int.Parse(textBoxPort.Text.Trim()); } Session.Username = textBoxUsername.Text.Trim(); Session.SessionId = SessionData.CombineSessionIds(SessionData.GetSessionParentId(Session.SessionId), Session.SessionName); Session.ImageKey = buttonImageSelect.ImageKey; Session.SPSLFileName = textBoxSPSLScriptFile.Text.Trim(); Session.RemotePath = textBoxRemotePathSesion.Text.Trim(); Session.LocalPath = textBoxLocalPathSesion.Text.Trim(); if (this.protoTypesMap.ContainsKey(comboBoxProto.SelectedItem)) { Session.Proto = (ConnectionProtocol)this.protoTypesMap[comboBoxProto.SelectedItem]; } DialogResult = DialogResult.OK; }
private void buttonSave_Click(object sender, EventArgs e) { Session.SessionName = textBoxSessionName.Text.Trim(); Session.PuttySession = comboBoxPuttyProfile.Text.Trim(); Session.Host = textBoxHostname.Text.Trim(); Session.ExtraArgs = textBoxExtraArgs.Text.Trim(); Session.Port = int.Parse(textBoxPort.Text.Trim()); Session.Username = textBoxUsername.Text.Trim(); Session.SessionId = SessionData.CombineSessionIds(SessionData.GetSessionParentId(Session.SessionId), Session.SessionName); Session.ImageKey = buttonImageSelect.ImageKey; for (int i = 0; i < groupBox1.Controls.Count; i++) { RadioButton rb = (RadioButton)groupBox1.Controls[i]; if (rb.Checked) { Session.Proto = (ConnectionProtocol)rb.Tag; } } DialogResult = DialogResult.OK; }
/// <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(); } }
/// <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(); } }