示例#1
0
        public static SSHConnectionDetails FromXmlElement(System.Xml.XmlElement node)
        {
            SSHConnectionDetails conn = new SSHConnectionDetails();

            conn.SSHSecurityOption = SSHSecurityOptionTypeConverter.FromString(node.ReadXmlElementAttr("sshSecOpt", "password"));
            conn.ComputerName      = node.ReadXmlElementAttr("machine", ".");
            conn.SSHPort           = node.ReadXmlElementAttr("sshPort", 22);
            conn.UserName          = node.ReadXmlElementAttr("userName", "");
            conn.Password          = node.ReadXmlElementAttr("password", "");
            conn.PrivateKeyFile    = node.ReadXmlElementAttr("privateKeyFile", "");
            conn.PassPhrase        = node.ReadXmlElementAttr("passPhrase", "");
            conn.Persistent        = node.ReadXmlElementAttr("persistent", false);
            return(conn);
        }
示例#2
0
        private void SaveSelectedTemplate()
        {
            ListViewItem     lvi;
            QuickMonTemplate t;

            if (txtName.Text.Trim().Length == 0)
            {
                MessageBox.Show("You must specify the a name for the template!", "Name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtName.Focus();
                return;
            }
            if (cboType.SelectedIndex == -1)
            {
                MessageBox.Show("You must specify the template type!", "Type", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                cboType.Focus();
                return;
            }
            if (txtConfig.Text.Trim().Length == 0)
            {
                MessageBox.Show("You must specify the config for the template!", "Config", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtConfig.Focus();
                return;
            }
            if (((TemplateType)cboType.SelectedIndex) == TemplateType.CollectorHost)
            {
                try
                {
                    System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument();
                    xdoc.LoadXml(txtConfig.Text);
                    System.Xml.XmlElement root = xdoc.DocumentElement;
                    if (root.ReadXmlElementAttr("uniqueId", "") == "" || root.ReadXmlElementAttr("dependOnParentId", "") == "")
                    {
                        root.SetAttributeValue("uniqueId", "");
                        root.SetAttributeValue("dependOnParentId", "");
                        txtConfig.Text = XmlFormattingUtils.NormalizeXML(xdoc.OuterXml);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Invalid config!\r\n" + ex.Message, "Config", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
            }

            if (lvwTemplates.SelectedItems.Count == 1 && lvwTemplates.SelectedItems[0].Tag is QuickMonTemplate)
            {
                lvi = lvwTemplates.SelectedItems[0];
                t   = (QuickMonTemplate)lvwTemplates.SelectedItems[0].Tag;
            }
            else
            {
                lvi = new ListViewItem(txtName.Text);
                lvi.SubItems.Add(cboClass.Text);
                lvi.SubItems.Add(txtDescription.Text);
                t = new QuickMonTemplate();
                lvwTemplates.Items.Add(lvi);
            }
            t.Name         = txtName.Text;
            t.TemplateType = (TemplateType)cboType.SelectedIndex;
            t.ForClass     = cboClass.Text;
            t.Description  = txtDescription.Text;
            t.Config       = txtConfig.Text;

            ListViewGroup lg = (from ListViewGroup g in lvwTemplates.Groups
                                where
                                (g.Header == "Monitor Pack" && t.TemplateType == TemplateType.MonitorPack) ||
                                (g.Header == "Collector Host" && t.TemplateType == TemplateType.CollectorHost) ||
                                (g.Header == "Collector Agent" && t.TemplateType == TemplateType.CollectorAgent) ||
                                (g.Header == "Notifier Host" && t.TemplateType == TemplateType.NotifierHost) ||
                                (g.Header == "Notifier Agent" && t.TemplateType == TemplateType.NotifierAgent)
                                select g).FirstOrDefault();

            lvi.Selected         = true;
            lvi.Text             = t.Name;
            lvi.SubItems[1].Text = t.ForClass;
            lvi.SubItems[2].Text = t.Description;
            lvi.Group            = lg;
            lvi.Tag = t;
            SaveAllTemplates();
            SetSaveButton(false);
        }
示例#3
0
        public static SSHConnectionDetails FromXmlElement(System.Xml.XmlElement node)
        {
            SSHConnectionDetails conn = new SSHConnectionDetails();

            conn.UseConnectionString = node.ReadXmlElementAttr("useConnStr", false);
            conn.ConnectionString    = node.ReadXmlElementAttr("connStr", "");

            if (conn.ConnectionString.Length > 0) // conn.UseConnectionString)
            {
                //Parse ConnectionString
                FromConnectionString(conn);

                //string sshConnectionString = conn.ConnectionString;
                //if (sshConnectionString.Length > 0)
                //{
                //    if (System.IO.File.Exists(sshConnectionString))
                //    {
                //        sshConnectionString = System.IO.File.ReadAllText(sshConnectionString);
                //    }

                //    string[] pa = sshConnectionString.Split(';');
                //    foreach (string s in pa)
                //    {
                //        if (s.ToLower().StartsWith("name="))
                //        {
                //            conn.ConnectionName = s.Substring("name=".Length);
                //        }
                //        if (s.ToLower().StartsWith("computer="))
                //        {
                //            string computerName = s.Substring("computer=".Length);
                //            int port = 22;
                //            if (computerName.Contains(':') && computerName.Split(':')[1].IsInteger())
                //            {
                //                port = int.Parse(computerName.Split(':')[1]);
                //                computerName = computerName.Split(':')[0];
                //            }
                //            conn.ComputerName = computerName;
                //            conn.SSHPort = port;
                //        }
                //        if (s.ToLower().StartsWith("secopt="))
                //        {
                //            conn.SSHSecurityOption = SSHSecurityOptionTypeConverter.FromString(s.Substring("secopt=".Length));
                //        }
                //        if (s.ToLower().StartsWith("user="******"user="******"pass="******"pass="******"privatekeyfile="))
                //        {
                //            conn.PrivateKeyFile = s.Substring("privatekeyfile=".Length);
                //        }
                //        if (s.ToLower().StartsWith("passphrase="))
                //        {
                //            conn.PassPhrase = s.Substring("passphrase=".Length);
                //        }
                //        if (s.ToLower().StartsWith("persistent="))
                //        {
                //            conn.Persistent = FormatUtils.NBool(s.Substring("persistent=".Length));
                //        }
                //    }
                //}
            }
            else
            {
                conn.SSHSecurityOption = SSHSecurityOptionTypeConverter.FromString(node.ReadXmlElementAttr("sshSecOpt", "password"));
                conn.ComputerName      = node.ReadXmlElementAttr("machine", ".");
                conn.SSHPort           = node.ReadXmlElementAttr("sshPort", 22);
                conn.UserName          = node.ReadXmlElementAttr("userName", "");
                conn.Password          = node.ReadXmlElementAttr("password", "");
                conn.PrivateKeyFile    = node.ReadXmlElementAttr("privateKeyFile", "");
                conn.PassPhrase        = node.ReadXmlElementAttr("passPhrase", "");
                conn.Persistent        = node.ReadXmlElementAttr("persistent", false);
                conn.ConnectionName    = node.ReadXmlElementAttr("name", "");
                conn.ConnectionString  = FormatSSHConnection(conn);
            }
            //if (!conn.UseConnectionString || conn.ConnectionString.Length == 0)
            //{
            //    conn.SSHSecurityOption = SSHSecurityOptionTypeConverter.FromString(node.ReadXmlElementAttr("sshSecOpt", "password"));
            //    conn.ComputerName = node.ReadXmlElementAttr("machine", ".");
            //    conn.SSHPort = node.ReadXmlElementAttr("sshPort", 22);
            //    conn.UserName = node.ReadXmlElementAttr("userName", "");
            //    conn.Password = node.ReadXmlElementAttr("password", "");
            //    conn.PrivateKeyFile = node.ReadXmlElementAttr("privateKeyFile", "");
            //    conn.PassPhrase = node.ReadXmlElementAttr("passPhrase", "");
            //    conn.Persistent = node.ReadXmlElementAttr("persistent", false);
            //    conn.ConnectionName = node.ReadXmlElementAttr("name", "");
            //}

            return(conn);
        }