Esempio n. 1
0
        /// <summary>
        /// Opens a new Config Target Editor dialog.
        /// </summary>
        /// <param name="ConfigTargetID">The ID of the Target to Edit. If empty or set to -1 dialog goes into insert mode</param>
        ///
        public ConfigTarget(PGTDataSet ds, int ConfigTargetID = -1)
        {
            InitializeComponent();
            this.pgtDataSet = ds;
            if (ConfigTargetID != -1)
            {
                this.configTargetsTableAdapter.FillByConfigTargetID(this.configDS.ConfigTargets, ConfigTargetID);
            }
            else
            {
                this.Text = "Add new Configuration Target";
                ConfigDS.ConfigTargetsRow newRow = this.configDS.ConfigTargets.NewConfigTargetsRow();
                newRow.TargetGroup  = "default";
                newRow.TargetName   = "";
                newRow.TargetIP     = "0.0.0.0";
                newRow.DeviceVendor = "Cisco";
                newRow.Protocol     = "Telnet";
                newRow.JumpServerIP = "";
                this.configDS.ConfigTargets.AddConfigTargetsRow(newRow);
            }
            distinctTargetGroupsTableAdapter.Fill(configDS.DistinctTargetGroups);
            var distinctGroupNames = from groupname in configDS.DistinctTargetGroups select groupname.DistinctTargetGroup;

            cbxTargetGroup.DataSource = distinctGroupNames.ToList();
        }
 /// <summary>
 /// Open terminal connection to target currently selected
 /// </summary>
 /// <param name="TargetID"></param>
 private void ConnectToTarget()
 {
     if (lvTargets.SelectedItems.Count == 1)
     {
         int            TargetID = (int)lvTargets.SelectedItems[0].Tag;
         TerminalWindow term;
         string         host = string.Empty;
         try
         {
             ConfigDS.ConfigTargetsRow[] targets = configDS.ConfigTargets.Select(string.Format("ConfigTargetID = {0}", TargetID)) as ConfigDS.ConfigTargetsRow[];
             if (targets.Length > 0)
             {
                 ConfigDS.ConfigTargetsRow selectedTarget = targets[0];
                 host = selectedTarget.TargetIP;
                 SNGDataSet.ScriptSettingRow _localScriptSettings = Scriptngo.Common.SettingsManager.GetCurrentScriptSettings(this.SNGDataSet);
                 ConnectionParameters        CP = new ConnectionParameters
                 {
                     DeviceIP       = selectedTarget.TargetIP,
                     Protocol       = (ConnectionProtocol)Enum.Parse(typeof(ConnectionProtocol), selectedTarget.Protocol, true),
                     Port           = selectedTarget.IsPortNull() ? 0 : selectedTarget.Port,
                     DeviceVendor   = selectedTarget.DeviceVendor,
                     JumpServer     = selectedTarget.JumpServerIP.Trim(),
                     LogonUserName  = _localScriptSettings.ScriptingUserName,
                     EnablePassword = _localScriptSettings.DeviceEnablePassword,
                     LogonPassword  = _localScriptSettings.ScriptingPassword,
                     AuthType       = (SNGTermAuthType)Enum.Parse(typeof(SNGTermAuthType), _localScriptSettings.TerminalAuthType),
                     LineFeedRule   = (LineFeedRule)Enum.Parse(typeof(LineFeedRule), _localScriptSettings.TerminalLineFeedRule),
                     EncodingType   = (EncodingType)Enum.Parse(typeof(EncodingType), _localScriptSettings.TerminalEncoding),
                     TerminalType   = (TerminalType)Enum.Parse(typeof(TerminalType), _localScriptSettings.TerminalType),
                     NewLine        = (NewLine)Enum.Parse(typeof(NewLine), _localScriptSettings.TerminalTransmitNL)
                 };
                 var t = from Form form in Application.OpenForms where form is TerminalWindow select form;
                 if (t.Count() > 0)
                 {
                     term = (TerminalWindow)t.ElementAt(0);
                 }
                 else
                 {
                     term = new TerminalWindow();
                 }
                 term.MdiParent = this.MdiParent;
                 term.Show();
                 term.BringToFront();
                 term.ConnectDisconnectTask(ConnectionTaskAction.Connect, true, CP);
             }
             else
             {
                 MessageBox.Show("Unable to open a terminal because the script target was not found.", "Cannot open terminal", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             }
         }
         catch (Exception Ex)
         {
             MessageBox.Show(string.Format("An error occurred while opening connection to {0}. The error was : {1}", host, Ex.Message), "Connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Esempio n. 3
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     try
     {
         if (targetNameTextBox.Text != "")
         {
             if (targetIPTextBox.Text.IsValidIP())
             {
                 int?port = null;
                 int p    = -1;
                 if (int.TryParse(portTextBox.Text, out p))
                 {
                     port = p;
                 }
                 int?count = (int?)qTA.GetTargetCount(cbxTargetGroup.Text, targetIPTextBox.Text, port);
                 if (count == 0)
                 {
                     ConfigDS.ConfigTargetsRow curRow = (ConfigDS.ConfigTargetsRow)((DataRowView)configTargetsBS.Current).Row;
                     if (cbxJumpServers.SelectedValue != null)
                     {
                         curRow.JumpServerIP = (cbxJumpServers.SelectedItem as PGTDataSet.JumpServersRow).IPAddress;
                     }
                     configTargetsBS.EndEdit();
                     configTargetsTableAdapter.Update(configDS);
                 }
                 else
                 {
                     MessageBox.Show("It is not allowed to add more targets to the same Target Group with the same ip address.", "Invalid data", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                     DialogResult = DialogResult.None;
                 }
             }
             else
             {
                 MessageBox.Show("A Target must have a valid IPv4 address", "Invalid data", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                 DialogResult = DialogResult.None;
             }
         }
         else
         {
             MessageBox.Show("A Target must have a name.", "nIvalid data", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             DialogResult = DialogResult.None;
         }
     }
     catch (Exception Ex)
     {
         MessageBox.Show("An error occurred while saving target to database : " + Ex.Message, "Database error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 4
0
        private void InitLookupLists()
        {
            // populate vendors
            cbxVendors.DataSource = Common.VendorsManager.SupportedVendors();
            if (!string.IsNullOrEmpty(Properties.Settings.Default.MRUVendor))
            {
                cbxVendors.Text = Properties.Settings.Default.MRUVendor;
            }
            if (!string.IsNullOrEmpty(Properties.Settings.Default.MRUProtocol))
            {
                cbxProtocols.Text = Properties.Settings.Default.MRUProtocol;
            }
            // populate jump servers
            cbxJumpServers.Items.Clear();
            var js = JumpServersManager.GetJumpServers(this.pgtDataSet);

            PGTDataSet.JumpServersRow emptyRow = JumpServersManager.DefaultJumpServerSettings();
            emptyRow.IPAddress = "";
            emptyRow.HostName  = "";
            List <PGTDataSet.JumpServersRow> jumpServerList = js.ToList();

            jumpServerList.Insert(0, emptyRow);
            cbxJumpServers.DataSource = jumpServerList;
            // set values for dropdown lists
            if (!string.IsNullOrEmpty(Properties.Settings.Default.MRUJumpServer))
            {
                cbxJumpServers.Text = Properties.Settings.Default.MRUJumpServer;
            }
            ConfigDS.ConfigTargetsRow curRow = (ConfigDS.ConfigTargetsRow)((DataRowView)configTargetsBS.Current).Row;
            if (curRow != null)
            {
                PGTDataSet.JumpServersRow thisJumpServer = jumpServerList.FirstOrDefault(j => j.IPAddress == curRow.JumpServerIP);
                cbxJumpServers.SelectedItem = thisJumpServer;
                cbxVendors.Text             = curRow.DeviceVendor;
                cbxProtocols.Text           = curRow.Protocol;
            }
        }