/// <summary> /// 连接SSH /// </summary> /// <param name="server"></param> private void ConnectSSH(RDSServer server) { var parent = currentRDPanel; SSHControl ssh = null; if (parent.HasChildren) { ssh = (SSHControl)currentRDPanel.Controls[0]; ssh.Tag = server.ServerID.ToString(); if (!ssh.IsConnected) { ssh.Connect(); ssh.Focus(); } } else { ssh = new SSHControl(server); ssh.Tag = server.ServerID.ToString(); ssh.Dock = System.Windows.Forms.DockStyle.Fill; ssh.OnConnected += Ssh_OnConnected; ssh.OnDisconnected += Ssh_OnDisconnected; parent.Controls.Add(ssh); ssh.Connect(); ssh.Focus(); } }
public ServerEditForm() { InitializeComponent(); if (model == null) { model = new RDSServer(); } }
/// <summary> /// 连接Windows远程桌面 /// </summary> /// <param name="server"></param> private void ConnectWindowsDesktop(RDSServer server) { AxMSTSCLib.AxMsRdpClient9NotSafeForScripting rdp = null; // 如果Panel中包含子控件,则让远程桌面控件启动连接 if (currentRDPanel.HasChildren) { rdp = (AxMSTSCLib.AxMsRdpClient9NotSafeForScripting)currentRDPanel.Controls[0]; // About Connected https://msdn.microsoft.com/en-us/library/aa382835(v=vs.85).aspx if (rdp.Connected == 0) { // 防止服务器相关参数变更 rdp.Tag = server.ServerID.ToString(); rdp.Name = "rdp_" + server.ServerID.ToString(); rdp.Server = server.ServerAddress; rdp.AdvancedSettings9.RDPPort = server.ServerPort; rdp.UserName = server.UserName; rdp.AdvancedSettings9.ClearTextPassword = EncryptUtils.DecryptServerPassword(server); rdp.Connect(); } } // 如果远程桌面控件不存在,则创建 if (rdp == null) { rdp = new AxMSTSCLib.AxMsRdpClient9NotSafeForScripting(); rdp.Width = this.splitContainer1.Panel2.Width; rdp.Height = this.splitContainer1.Panel2.Height; rdp.Dock = System.Windows.Forms.DockStyle.None; currentRDPanel.Controls.Add(rdp); rdp.Tag = server.ServerID.ToString(); rdp.Name = "rdp_" + server.ServerID.ToString(); rdp.Server = server.ServerAddress; rdp.UserName = server.UserName; rdp.CausesValidation = false; rdp.AdvancedSettings9.EnableCredSspSupport = true; rdp.AdvancedSettings9.RDPPort = server.ServerPort; rdp.AdvancedSettings9.ClearTextPassword = EncryptUtils.DecryptServerPassword(server); rdp.AdvancedSettings9.BandwidthDetection = true; rdp.AdvancedSettings.allowBackgroundInput = 1; rdp.ColorDepth = 32; rdp.ConnectingText = "正在连接"; rdp.DisconnectedText = "连接已断开"; rdp.OnConnected += Rdp_OnConnected; rdp.OnDisconnected += Rdp_OnDisconnected; rdp.OnFatalError += Rdp_OnFatalError; rdp.Connect(); } }
/// <summary> /// 添加服务器 /// </summary> /// <param name="model"></param> public void AddServer(RDSServer model) { XDocument doc = GetData(); var root = doc.Element("rds"); var element = new XElement("server"); element.SetAttributeValue("id", model.ServerID); element.SetAttributeValue("name", model.ServerName); element.SetAttributeValue("address", model.ServerAddress); element.SetAttributeValue("port", model.ServerPort); element.SetAttributeValue("username", model.UserName); element.SetAttributeValue("password", model.Password); element.SetAttributeValue("optype", model.OpType); element.SetAttributeValue("linktype", model.LinkType); var docElelment = root.Descendants("server").Where(d => d.Attribute("id").Value == model.ServerID.ToString()).FirstOrDefault(); if (docElelment == null) { if (model.GroupID == Guid.Empty) { root.Add(element); } else { var parentGroup = root.DescendantsAndSelf("group").Where(d => d.Attribute("id").Value == model.GroupID.ToString()).FirstOrDefault(); if (parentGroup == null) { throw new ArgumentException("分组不存在!"); } parentGroup.Add(element); } } else { docElelment.SetAttributeValue("id", model.ServerID); docElelment.SetAttributeValue("name", model.ServerName); docElelment.SetAttributeValue("address", model.ServerAddress); docElelment.SetAttributeValue("port", model.ServerPort); docElelment.SetAttributeValue("username", model.UserName); docElelment.SetAttributeValue("password", model.Password); docElelment.SetAttributeValue("optype", model.OpType); docElelment.SetAttributeValue("linktype", model.LinkType); } doc.Save(dataPath); }
public static string DecryptServerPassword(RDSServer server) { return(DecryptPassword(server.Password).Replace(MD5Encrypt16(server.ServerAddress, Encoding.ASCII), "")); }
public static string EncryptServerPassword(RDSServer server) { return(EncryptPassword(MD5Encrypt16(server.ServerAddress, Encoding.ASCII) + server.Password)); }