diff --git a/SSH_Test/Profile.cs b/SSH_Test/Profile.cs index e81b19d..252ccd8 100644 --- a/SSH_Test/Profile.cs +++ b/SSH_Test/Profile.cs @@ -1,24 +1,24 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; - -namespace SSH_Test -{ - internal class Profile - { - public string ProfileName { get; set; } - public string ProfileType { get; set; } - public string[] ProfileCommands { get; set; } - public Profile(string profileName, string profileType, string[] profileCommands) - { - ProfileName = profileName; - ProfileType = profileType; - ProfileCommands = profileCommands; - } - - } - -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace SSH_Test +{ + internal class Profile + { + public string ProfileName { get; set; } + public string ProfileType { get; set; } + public string[] ProfileCommands { get; set; } + public Profile(string profileName, string profileType, string[] profileCommands) + { + ProfileName = profileName; + ProfileType = profileType; + ProfileCommands = profileCommands; + } + + } + +} diff --git a/SSH_Test/SSH_Test.csproj b/SSH_Test/SSH_Test.csproj index 6b61ae0..f9271f0 100644 --- a/SSH_Test/SSH_Test.csproj +++ b/SSH_Test/SSH_Test.csproj @@ -1,203 +1,229 @@ - - - - - Debug - AnyCPU - {73DED4CD-B2B1-491E-87B7-BC1F11759C53} - Exe - SSH_Test - SSH_Test - v4.8 - 512 - true - true - false - - - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - true - - - AnyCPU - true - full - true - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - packages\BouncyCastle.Cryptography.2.6.2\lib\net461\BouncyCastle.Cryptography.dll - - - packages\Microsoft.Bcl.AsyncInterfaces.10.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll - - - packages\Microsoft.Extensions.DependencyInjection.Abstractions.8.0.2\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll - - - packages\Microsoft.Extensions.Logging.Abstractions.8.0.3\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll - - - packages\SSH.NET.2025.1.0\lib\net462\Renci.SshNet.dll - - - - packages\System.Buffers.4.6.1\lib\net462\System.Buffers.dll - - - - packages\System.Formats.Asn1.8.0.2\lib\net462\System.Formats.Asn1.dll - - - packages\System.IO.Pipelines.10.0.0\lib\net462\System.IO.Pipelines.dll - - - packages\System.Memory.4.6.3\lib\net462\System.Memory.dll - - - - packages\System.Numerics.Vectors.4.6.1\lib\net462\System.Numerics.Vectors.dll - - - packages\System.Runtime.CompilerServices.Unsafe.6.1.2\lib\net462\System.Runtime.CompilerServices.Unsafe.dll - - - packages\System.Text.Encodings.Web.10.0.0\lib\net462\System.Text.Encodings.Web.dll - - - packages\System.Text.Json.10.0.0\lib\net462\System.Text.Json.dll - - - packages\System.Threading.Tasks.Extensions.4.6.3\lib\net462\System.Threading.Tasks.Extensions.dll - - - - - - - - - - - - - - Form - - - FormConfiguration.cs - - - Form - - - FormCredential.cs - - - Form - - - FormProfile.cs - - - - Form - - - TastList.cs - - - - - FormConfiguration.cs - - - FormCredential.cs - - - FormProfile.cs - - - TastList.cs - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - True - Resources.resx - True - - - - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - True - Settings.settings - True - - - - - - - - False - Microsoft .NET Framework 4.8 %28x86 and x64%29 - true - - - False - .NET Framework 3.5 SP1 - false - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - + + + + + Debug + AnyCPU + {73DED4CD-B2B1-491E-87B7-BC1F11759C53} + WinExe + SSH_Test + SSH_Test + v4.8 + 512 + true + true + false + + + D:\Shared\VS\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + true + true + + + AnyCPU + true + full + true + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + LocalIntranet + + + false + + + Properties\app.manifest + + + 4A871742B5537E7E2FE907BD60809E3A6E6EEDBF + + + SSH_Test_TemporaryKey.pfx + + + true + + + + packages\BouncyCastle.Cryptography.2.6.2\lib\net461\BouncyCastle.Cryptography.dll + + + packages\log4net.3.2.0\lib\net462\log4net.dll + + + packages\Microsoft.Bcl.AsyncInterfaces.10.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll + + + packages\Microsoft.Extensions.DependencyInjection.Abstractions.8.0.2\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll + + + packages\Microsoft.Extensions.Logging.Abstractions.8.0.3\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll + + + packages\SSH.NET.2025.1.0\lib\net462\Renci.SshNet.dll + + + + packages\System.Buffers.4.6.1\lib\net462\System.Buffers.dll + + + + + packages\System.Formats.Asn1.8.0.2\lib\net462\System.Formats.Asn1.dll + + + packages\System.IO.Pipelines.10.0.0\lib\net462\System.IO.Pipelines.dll + + + packages\System.Memory.4.6.3\lib\net462\System.Memory.dll + + + + packages\System.Numerics.Vectors.4.6.1\lib\net462\System.Numerics.Vectors.dll + + + packages\System.Runtime.CompilerServices.Unsafe.6.1.2\lib\net462\System.Runtime.CompilerServices.Unsafe.dll + + + packages\System.Text.Encodings.Web.10.0.0\lib\net462\System.Text.Encodings.Web.dll + + + packages\System.Text.Json.10.0.0\lib\net462\System.Text.Json.dll + + + packages\System.Threading.Tasks.Extensions.4.6.3\lib\net462\System.Threading.Tasks.Extensions.dll + + + + + + + + + + + + + + + Form + + + FormConfiguration.cs + + + Form + + + FormCredential.cs + + + Form + + + FormProfile.cs + + + + Form + + + TastList.cs + + + + + FormConfiguration.cs + + + FormCredential.cs + + + FormProfile.cs + + + TastList.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + Always + + + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + False + Microsoft .NET Framework 4.8 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file diff --git a/SSH_Test/SSH_Test.csproj.user b/SSH_Test/SSH_Test.csproj.user index d213892..ec617e1 100644 --- a/SSH_Test/SSH_Test.csproj.user +++ b/SSH_Test/SSH_Test.csproj.user @@ -1,13 +1,16 @@ - - - - publish\ - - - - - - en-US - false - + + + + D:\Shared\VS\|publish\ + + + + + + en-US + false + + + false + \ No newline at end of file diff --git a/SSH_Test/SSH_Test_TemporaryKey.pfx b/SSH_Test/SSH_Test_TemporaryKey.pfx new file mode 100644 index 0000000..937ec9f Binary files /dev/null and b/SSH_Test/SSH_Test_TemporaryKey.pfx differ diff --git a/SSH_Test/TastList.cs b/SSH_Test/TastList.cs index c86442b..dcdae63 100644 --- a/SSH_Test/TastList.cs +++ b/SSH_Test/TastList.cs @@ -1,655 +1,798 @@ -using Org.BouncyCastle.Cms; -using Renci.SshNet; -using Renci.SshNet.Common; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Diagnostics; -using System.Drawing; -using System.IO; -using System.Linq; -using System.Linq.Expressions; -using System.Text; -using System.Text.Json; -using System.Text.RegularExpressions; -using System.Threading; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.Xml; -using static System.Windows.Forms.VisualStyles.VisualStyleElement; - - -namespace SSH_Test -{ - - - public partial class TastList : Form - { - - public List Tasks = new List(); - public cConInfo conInfo = new cConInfo("","","","","","","","",""); - private List Profiles = new List(); - - public TastList() - { - - - InitializeComponent(); - - // For creating the default profile.json - //Profile profile = new Profile("SSH_Cisco_Tftp_Running", "SSH", new string[] { "copy run tftp://" }); - //Profiles.Add(profile); - //profile = new Profile("SSH_Cisco_Tftp_Startup", "SSH", new string[] { "copy startup-config tftp://" }); - //Profiles.Add(profile); - //profile = new Profile("SSH_Cisco_Tftp_Enable_Running", "SSH", new string[] { "enable","copy running-config tftp://" }); - //Profiles.Add(profile); - //SaveProfile(Profiles, "profile.json"); - - //Load Profile list from "profile.json" - Profiles = LoadProfile("profile.json"); - - foreach (Profile p in Profiles) - { - Console.WriteLine("Profile: {0}", p.ProfileName); - - } - - var comboBoxColumn = (DataGridViewComboBoxColumn)dataGridViewTask.Columns[7]; - comboBoxColumn.DataSource = Profiles; // Set the data source of the ComboBox column - comboBoxColumn.DisplayMember = "profileName"; // Displayed property name - comboBoxColumn.ValueMember = "profileName"; //The property name of the value - dataGridViewTask.Refresh(); - - } - - private void fSSHTest_Load(object sender, EventArgs e) - { - } - - private void bRunAll_Click(object sender, EventArgs e) - { - - - } - - private void dataGridViewTask_CellContentClick(object sender, DataGridViewCellEventArgs e) - { - string host = ""; - string username = ""; - string password = ""; - Profile profile; - - try - { - var currentTask = Tasks[e.RowIndex]; - host = currentTask.sTaskIP.ToString(); - username = currentTask.sUsername.ToString(); - password = currentTask.sPassword.ToString(); - switch (e.ColumnIndex) - { - case 5: - - profile = Profiles.Find(x => x.ProfileName == currentTask.sProfile.ToString()); - cHostInfo hostInfo = new cHostInfo(); - hostInfo.host = host; - hostInfo.username = username; - hostInfo.password = password; - hostInfo.device = currentTask.sTaskDevice.ToString(); - - // print out task - Console.WriteLine("Current task profile {0}:", hostInfo.device); - - foreach (string c in profile.ProfileCommands) - Console.WriteLine(c); - - hostInfo.Commands = profile.ProfileCommands; - switch (profile.ProfileType) - { - case "SSH": - Thread thread1 = new Thread(new ParameterizedThreadStart(fSSH)); - hostInfo.TftpIP = conInfo.sTftpIP; - hostInfo.SftpIP = conInfo.sTftpIP; - hostInfo.SftpPassword = conInfo.sTftpPassword; - hostInfo.SftpUsername = conInfo.sTftpUsername; - thread1.Start(hostInfo); - break; - case "SSH_Catalyst": - Thread thread2 = new Thread(new ParameterizedThreadStart(fSSH_Catalyst)); - hostInfo.TftpIP = conInfo.sTftpIP; - hostInfo.SftpIP = conInfo.sTftpIP; - hostInfo.SftpPassword = conInfo.sTftpPassword; - hostInfo.SftpUsername = conInfo.sTftpUsername; - thread2.Start(hostInfo); - - break; - case "RAC9": - - string command = ""; - command = " --nocertwarn -r " + conInfo.sIDracIP + " -u " + conInfo.sIDracUsername + " -p " + conInfo.sIDracPassword + " "; - - - foreach (string c in profile.ProfileCommands) - { - Process process = new Process(); - process.StartInfo.FileName = "racadm.exe"; - process.StartInfo.UseShellExecute = false; // Required for 'runas' verb - process.StartInfo.Verb = "runas"; // Request administrator privileges - process.StartInfo.WorkingDirectory = Environment.CurrentDirectory; // current working dir - process.StartInfo.RedirectStandardOutput = true; - - try - { - - string tempfile = DateTime.Now.ToString().Replace(":", "").Replace(" ","") + ".txt"; - - process.StartInfo.Arguments = command + " " + c; - process.Start(); - string result = process.StandardOutput.ReadToEnd(); - Console.WriteLine("From RAC9 {0}: {1}", currentTask.sTaskDevice.ToString(), result); - process.WaitForExit(); - - - } - catch (Win32Exception ex) - { - Console.WriteLine($"Error: {ex.Message}. The user likely declined the UAC prompt."); - } - } - - break; - default: - break; - - } - //switch (profile) - //{ - // case "Cisco_Switch": - // Thread thread1 = new Thread(new ParameterizedThreadStart(fSSHCisco)); - // thread1.Start(hostInfo); - // break; - // case "Cisco_Switch_Tftp": - // hostInfo.SftpIP = ftpInfo.sTftpIP; - - // Thread thread2 = new Thread(new ParameterizedThreadStart(fSSHCisco_Tftp)); - // thread2.Start(hostInfo); - // break; - // case "Cisco_Switch_Tftp_Startup": - // hostInfo.SftpIP = ftpInfo.sTftpIP; - // hostInfo.SftpPassword = ftpInfo.sTftpPassword; - // hostInfo.SftpUsername = ftpInfo.sTftpUsername; - - - // Thread thread3 = new Thread(new ParameterizedThreadStart(fSSHCisco_Tftp_Startup)); - // thread3.Start(hostInfo); - // break; - - // default: - // break; - - - //} - - - - - break; - case 6: //call Credential - - FormCredential formCredential = new FormCredential(username, password); - formCredential.ShowDialog(); - if ((formCredential.Username != "") && (formCredential.Username != username)) - username = currentTask.sUsername = formCredential.Username; - if ((formCredential.Password != "") && formCredential.Password != password) - password = currentTask.sPassword = formCredential.Password; - - break; - case 7: //select profile - - //FormProfile formProfile = new FormProfile(profile); - //formProfile.ShowDialog(); - //profile = currentTask.sProfile = formProfile.sProfile; - - // dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = profile; - break; - - default: - break; - - } - } - catch ( Exception ex) - { - } - - - - - - - - - } - - private void dataGridViewTask_CellEndEdit(object sender, DataGridViewCellEventArgs e) - { - if (e.ColumnIndex != 5) - { - if (Tasks.Count < (e.RowIndex + 1)) - { - Tasks.Add(new cTask(e.RowIndex + 1, "", "", "", "", "", "","")); - } - switch (e.ColumnIndex) - { - case 0: - Tasks[e.RowIndex].iTaskNum = e.RowIndex + 1; - break; - case 1: - Tasks[e.RowIndex].sTaskDescription = (string)dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; - break; - case 2: - Tasks[e.RowIndex].sTaskDevice = (string)dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; - break; - case 3: - Tasks[e.RowIndex].sTaskIP = (string)dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; - break; - case 4: - Tasks[e.RowIndex].uTaskPort = (string)dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; - break; - case 5: - - break; - case 7: // Profile - Tasks[e.RowIndex].sProfile = (string)dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; - Console.WriteLine("Task {0}, profile {1}", e.RowIndex, Tasks[e.RowIndex].sProfile); - break; - default: - break; - } - } - } - - private void buttonSave_Click(object sender, EventArgs e) - { - if (Tasks.Count >= 1) - { - using (Stream stream = File.Open("tasklist.dat", FileMode.Create)) - { - Console.WriteLine("Saving Tasklist.dat"); - var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); - binaryFormatter.Serialize(stream, Tasks); - } - using (Stream stream = File.Open("ftpInfo.dat", FileMode.Create)) - { - var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); - binaryFormatter.Serialize(stream, conInfo); - } - } - } - - private void buttonLoad_Click(object sender, EventArgs e) - { - using (Stream stream = File.Open("tasklist.dat", FileMode.Open)) - { - - var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); - Tasks = (List)binaryFormatter.Deserialize(stream); - } - using (Stream stream = File.Open("ftpInfo.dat", FileMode.Open)) - { - - var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); - conInfo = (cConInfo)binaryFormatter.Deserialize(stream); - } - - //clear TaskList - dataGridViewTask.Rows.Clear(); - - foreach (var task in Tasks) - { - DataGridViewRow row = (DataGridViewRow)dataGridViewTask.Rows[0].Clone(); - row.Cells[0].Value = task.iTaskNum; - row.Cells[1].Value = task.sTaskDescription; - row.Cells[2].Value = task.sTaskDevice; - row.Cells[3].Value = task.sTaskIP; - row.Cells[4].Value = task.uTaskPort; - row.Cells[7].Value = task.sProfile; - dataGridViewTask.Rows.Add(row); - - } - } - public class cHostInfo - { - public string device { get; set; } - public string host { get; set; } - public string username { get; set; } - public string password { get; set; } - public string TftpIP { get; set; } - - public string SftpIP { get; set; } - public string SftpUsername { get; set; } - public string SftpPassword { get; set; } - public string[] Commands { get; set; } - public cHostInfo() - { - device = ""; - host = "localhost"; - username = ""; - password = ""; - TftpIP = "127.0.0.1"; - SftpIP = "127.0.0.1"; - SftpUsername = ""; - SftpPassword = ""; - } - - } - - public void fSSH(object data) - { - cHostInfo hostinfo = (cHostInfo)data; - - string host = hostinfo.host; - string device = hostinfo.device; - string username = hostinfo.username; - string password = hostinfo.password; - string tftpIp = hostinfo.TftpIP; - string sftpIp = hostinfo.SftpIP; - string sftpUsername = hostinfo.SftpUsername; - string sftpPassword = hostinfo.SftpPassword; - string[] Commands = hostinfo.Commands; - - var client = new SshClient(hostinfo.host, hostinfo.username, hostinfo.password); - Console.WriteLine("From fSSH {0}: Establishing a connection", device); - - client.Connect(); - Console.WriteLine(client.ConnectionInfo.ServerVersion); - - - - - if (client.IsConnected) - { - var shellStream = client.CreateShellStream("xterm", 80, 24, 800, 600, 1024); - var output = ""; - var result = ""; - - //wait for "User Name:" - - output = shellStream.Expect(new Regex(@"Name:|name:")); - Console.WriteLine("From fSSH {0}: {1}", device, output); - - //send username - shellStream.WriteLine(username); - - //wait for "Password:" - output = shellStream.Expect(new Regex(@"word:")); - Console.WriteLine("From fSSH {0}: {1}", device, output); - - //send password - shellStream.WriteLine(password); - - //wait for "Prompt:" - output = shellStream.Expect(new Regex(@"#")); - Console.WriteLine("From fSSH {0}: {1}", device, output); - - output = ""; - - //create filename - string datetime = DateTime.Now.ToString().Replace(":", ""); - datetime = datetime.Replace(" ", "_"); - // string filePath = string.Format("{0}_{1}.txt", currentTask.sTaskDevice, datetime.Replace("-", "")); - string filePath = string.Format("{0}_{1}.txt", device, datetime.Replace("-", "")); - - foreach (string c in Commands) - { - switch (c) - { - //enable - case "enable": - output = ""; - shellStream.WriteLine(c); - //wait for "Password:" - output = shellStream.Expect(new Regex(@"word:")); - Console.WriteLine("From fSSH {0}: {1}", device, c); - - //send password - shellStream.WriteLine(password); - break; - - // tftp - case string s when Regex.IsMatch(c, @"tftp"): - output = ""; - string command = string.Format("{0}{1}/{2}", c, tftpIp, filePath); - Console.WriteLine("From fSSH {0}: {1}", device, command); - - //send tftp command - shellStream.WriteLine(command); - - - //wait "" to send "space" and loop until get prompt - while (!Regex.IsMatch(output, "#")) - { - output = shellStream.Expect(new Regex(@"More||#")); - - shellStream.WriteLine(" "); - string[] lines = output.Split('\n'); - var output1 = ""; - for (int ii = 0; ii < (lines.Length - 1); ii++) - output1 += lines[ii]; - Console.WriteLine(output1); - result += output1; - } - break; - default: - shellStream.WriteLine(c); - //wait for "Prompt:" - output = shellStream.Expect(new Regex(@"#")); - Console.WriteLine("From fSSH_Test {0}: {1}", device, output); - break; - - } - } - - - - } - - client.Disconnect(); - Console.WriteLine("From SSH_Test: Disconnected"); - } - - public void fSSH_Catalyst(object data) - { - cHostInfo hostinfo = (cHostInfo)data; - - string host = hostinfo.host; - string device = hostinfo.device; - string username = hostinfo.username; - string password = hostinfo.password; - string tftpIp = hostinfo.TftpIP; - string sftpIp = hostinfo.SftpIP; - string sftpUsername = hostinfo.SftpUsername; - string sftpPassword = hostinfo.SftpPassword; - string[] Commands = hostinfo.Commands; - - var client = new SshClient(hostinfo.host, hostinfo.username, hostinfo.password); - Console.WriteLine("From fSSH_Catalyst {0}: Establishing a connection", device); - - client.Connect(); - Console.WriteLine("From fSSH_Catalyst {0}: {1}", device, client.ConnectionInfo.ServerVersion); - - - if (client.IsConnected) - { - var shellStream = client.CreateShellStream("xterm", 80, 24, 800, 600, 1024); - var output = ""; - var result = ""; - var prompt = ""; - //output = ""; - output = shellStream.Expect(new Regex(@"#")); - Console.WriteLine("From fSSH_Catalyst {0}: {1}", device, output); - prompt = output; - - shellStream.WriteLine(""); - shellStream.Flush(); - - output = shellStream.Expect(new Regex(prompt)); - Console.WriteLine("From fSSH_Catalyst {0}: {1}", device, output); - - //create filename - string datetime = DateTime.Now.ToString().Replace(":", ""); - datetime = datetime.Replace(" ", "_"); - // string filePath = string.Format("{0}_{1}.txt", currentTask.sTaskDevice, datetime.Replace("-", "")); - string filePath = string.Format("{0}_{1}.txt", device, datetime.Replace("-", "")); - - foreach (string c in Commands) - { - switch (c) - { - //enable - case "enable": - output = ""; - shellStream.WriteLine(c); - //wait for "Password:" - output = shellStream.Expect(new Regex(@"word:")); - Console.WriteLine("From fSSH_Catalyst {0}: {1}", device, c); - - //send password - shellStream.WriteLine(password); - break; - - // tftp - case string s when Regex.IsMatch(c, @"tftp"): - output = ""; - - string command = string.Format("{0}{1}/{2}", c, tftpIp, filePath); - Console.WriteLine("From fSSH_Catalyst {0}: {1}", device, command); - - //send tftp command - output = ""; - shellStream.WriteLine(command); - shellStream.Flush(); - - //handle shell interaction, wait for "?" then send "enter" - - output = shellStream.Expect(new Regex(@"\?")); - Console.WriteLine("From fSSH{0}: {1}", device, output); - - while (output.Contains("?")) - { - output = ""; - shellStream.WriteLine(""); - shellStream.Flush(); - output = shellStream.Expect(new Regex(@"\?|#")); - Console.WriteLine("From fSSH_Catalyst {0}: {1}", device, output); - } - - break; - default: - shellStream.WriteLine(c); - //wait for "Prompt:" - output = shellStream.Expect(prompt); - Console.WriteLine("From fSSH_Test {0}: {1}", device, output); - break; - - } - } - - } - - client.Disconnect(); - Console.WriteLine("From SSH_Test: Disconnected"); - } - - - - private void buttonConf_Click(object sender, EventArgs e) - { - FormConfiguration formConfiguration = new FormConfiguration(conInfo.sTftpIP, conInfo.sSftpIP, conInfo.sSftpUsername, conInfo.sSftpPassword,conInfo.sIDracIP, conInfo.sIDracUsername, conInfo.sIDracPassword); - formConfiguration.ShowDialog(); - conInfo.sTftpIP = formConfiguration.Tftp_IP; - conInfo.sSftpIP = formConfiguration.Sftp_IP; - conInfo.sSftpUsername = formConfiguration.Sftp_Username; - conInfo.sSftpPassword = formConfiguration.Sftp_Password; - conInfo.sIDracIP = formConfiguration.IDRAC_IP; - conInfo.sIDracUsername = formConfiguration.IDRAC_Username; - conInfo.sIDracPassword = formConfiguration.IDRAC_Password; - - } - //Seriallize Profile to a Json file - private static void SaveProfile(List data, string filePath) - { - JsonSerializerOptions options = new JsonSerializerOptions - { - WriteIndented = true - }; - string jsonString = JsonSerializer.Serialize(data, options); - File.WriteAllText(filePath, jsonString); - } - //Deseriallize Profile from a Json file - private static List LoadProfile(string filePath) - { - if (File.Exists(filePath)) - { - string jsonString = File.ReadAllText(filePath); - return JsonSerializer.Deserialize>(jsonString); - } - return new List(); // Return an empty list if file doesn't exist - } - - [Serializable] - public class cTask - { - public int iTaskNum { get; set; } - public String sTaskDescription { get; set; } - public String sTaskDevice { get; set; } - public String sTaskIP { get; set; } - public String uTaskPort { get; set; } - public String sUsername { get; set; } - public String sPassword { get; set; } - public String sProfile { get; set; } - public cTask(int iTaskNum, string uTaskDescription, string uTaskDevice, string uTaskIP, string uTaskPort, string sUsername, string sPassword, string sProfile) - { - this.iTaskNum = iTaskNum; - this.sTaskDescription = uTaskDescription; - this.sTaskDevice = uTaskDevice; - this.sTaskIP = uTaskIP; - this.uTaskPort = uTaskPort; - this.sUsername = sUsername; - this.sPassword = sPassword; - } - } - - - [Serializable] - public class cConInfo - { - - public String sTftpIP { get; set; } - public String sTftpUsername { get; set; } - public String sTftpPassword { get; set; } - public String sSftpIP { get; set; } - public String sSftpUsername { get; set; } - public String sSftpPassword { get; set; } - public string sIDracIP { get; set; } - public string sIDracUsername { get; set; } - public string sIDracPassword { get; set; } - - public cConInfo( string TftpIP, string TftpUsername, string TftpPassword, string SftpIP, String SftpUsername, String SftPassword, String IdracIP, String IdracUsername, String IdracPassword) - { - this.sTftpIP = TftpIP; - this.sTftpUsername = TftpUsername; - this.sTftpPassword = TftpPassword; - this.sSftpIP = SftpIP; - this.sSftpUsername = SftpUsername; - this.sSftpPassword = SftPassword; - this.sIDracIP = IdracIP; - this.sIDracUsername = IdracUsername; - this.sIDracPassword = IdracPassword; - - } - } - - } - +using log4net; +using log4net.Config; +using Org.BouncyCastle.Cms; +using Renci.SshNet; +using Renci.SshNet.Common; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using System.Text; +using System.Text.Json; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Xml; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; + +namespace SSH_Test +{ + + + public partial class TastList : Form + { + + public List Tasks = new List(); + public cConInfo conInfo = new cConInfo("","","","","","","","","",false); + private List Profiles = new List(); + private static readonly ILog log = LogManager.GetLogger(typeof(Program)); + public TastList() + { + + var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); + XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config")); + + InitializeComponent(); + + + //Load Profile list from "profile.json" + Profiles = LoadProfile("profile.json"); + + // Configure Profile list to dropdown menu + try + { + foreach (Profile p in Profiles) + { + log.Info(string.Format("Profile: {0}", p.ProfileName)); + } + + var comboBoxColumn = (DataGridViewComboBoxColumn)dataGridViewTask.Columns[7]; + comboBoxColumn.DataSource = Profiles; // Set the data source of the ComboBox column + comboBoxColumn.DisplayMember = "profileName"; // Displayed property name + comboBoxColumn.ValueMember = "profileName"; //The property name of the value + } + catch(Exception ex) + { + log.Error(ex.Message); + } + + dataGridViewTask.Refresh(); + + } + + private void fSSHTest_Load(object sender, EventArgs e) + { + } + + private void bRunAll_Click(object sender, EventArgs e) + { + + + } + + private void dataGridViewTask_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + string host = ""; + string username = ""; + string password = ""; + Profile profile; + + try + { + var currentTask = Tasks[e.RowIndex]; + host = currentTask.sTaskIP.ToString(); + username = currentTask.sUsername.ToString(); + password = currentTask.sPassword.ToString(); + switch (e.ColumnIndex) + { + case 5: + + profile = Profiles.Find(x => x.ProfileName == currentTask.sProfile.ToString()); + cHostInfo hostInfo = new cHostInfo(); + hostInfo.host = host; + hostInfo.username = username; + hostInfo.password = password; + hostInfo.device = currentTask.sTaskDevice.ToString(); + + // print out task + log.Info(string.Format("Current task profile {0}:", hostInfo.device)); + + foreach (string c in profile.ProfileCommands) + log.Info(c); + + hostInfo.Commands = profile.ProfileCommands; + + + switch (profile.ProfileType) + { + case "SSH": + try + { + Thread thread1 = new Thread(new ParameterizedThreadStart(fSSH)); + hostInfo.TftpIP = conInfo.sTftpIP; + hostInfo.SftpIP = conInfo.sTftpIP; + hostInfo.SftpPassword = conInfo.sTftpPassword; + hostInfo.SftpUsername = conInfo.sTftpUsername; + thread1.Start(hostInfo); + } + catch(Exception ex1) + { + log.Error(ex1); + } + + break; + case "SSH_Catalyst": + try + { + Thread thread2 = new Thread(new ParameterizedThreadStart(fSSH_Catalyst)); + hostInfo.TftpIP = conInfo.sTftpIP; + hostInfo.SftpIP = conInfo.sTftpIP; + hostInfo.SftpPassword = conInfo.sTftpPassword; + hostInfo.SftpUsername = conInfo.sTftpUsername; + thread2.Start(hostInfo); + } + catch (Exception ex1) + { + log.Error(ex1); + + } + + + break; + case "RAC9": + string command = ""; + + if (!conInfo.bisLocal) + { + command = " --nocertwarn -r " + conInfo.sIDracIP + " -u " + conInfo.sIDracUsername + " -p " + conInfo.sIDracPassword + " "; + } + + foreach (string c in profile.ProfileCommands) + { + Process process = new Process(); + process.StartInfo.FileName = "racadm.exe"; + process.StartInfo.UseShellExecute = false; // Required for 'runas' verb + process.StartInfo.Verb = "runas"; // Request administrator privileges + process.StartInfo.WorkingDirectory = Environment.CurrentDirectory; // current working dir + process.StartInfo.RedirectStandardOutput = true; + + try + { + + string tempfile = DateTime.Now.ToString().Replace(":", "").Replace(" ","") + ".txt"; + + process.StartInfo.Arguments = command + " " + c; + process.Start(); + string result = process.StandardOutput.ReadToEnd(); + log.Info(string.Format("From RAC9 {0}: {1}", currentTask.sTaskDevice.ToString(), result)); + + process.WaitForExit(); + + + } + catch (Win32Exception ex) + { + log.Info(string.Format($"Error: {ex.Message}. The user likely declined the UAC prompt.")); + + } + } + break; + + case "CMD": + command = "/c"; + + foreach (string c in profile.ProfileCommands) + { + Process process = new Process(); + process.StartInfo.FileName = "cmd.exe"; + process.StartInfo.UseShellExecute = false; // Required for 'runas' verb + process.StartInfo.Verb = "runas"; // Request administrator privileges + process.StartInfo.WorkingDirectory = Environment.CurrentDirectory; // current working dir + process.StartInfo.RedirectStandardOutput = true; + + try + { + + string tempfile = DateTime.Now.ToString().Replace(":", "").Replace(" ", "") + ".txt"; + + process.StartInfo.Arguments = command + " " + c; + process.Start(); + string result = process.StandardOutput.ReadToEnd(); + + log.Info(string.Format("From CMD {0}: {1}", currentTask.sTaskDevice.ToString(), result)); + process.WaitForExit(); + + + } + catch (Win32Exception ex) + { + log.Error(ex); + } + } + break; + case "Powershell": + command = " "; + + foreach (string c in profile.ProfileCommands) + { + Process process = new Process(); + process.StartInfo.FileName = "powershell"; + process.StartInfo.UseShellExecute = false; // Required for 'runas' verb + process.StartInfo.Verb = "runas"; // Request administrator privileges + string folderPathPS = Environment.CurrentDirectory + "\\PS"; + process.StartInfo.WorkingDirectory = folderPathPS; // current working dir + + // check if Powershell Script folder "PS" exists, if not , create one. + if (!Directory.Exists(folderPathPS)) + { + Directory.CreateDirectory(folderPathPS); + log.Info(string.Format("Cound not find folder PS, create new {0}", folderPathPS)); + + } + + + process.StartInfo.RedirectStandardOutput = true; + + try + { + + string tempfile = DateTime.Now.ToString().Replace(":", "").Replace(" ", "") + ".txt"; + + process.StartInfo.Arguments = command + " " + c; + process.Start(); + string result = process.StandardOutput.ReadToEnd(); + log.Info(string.Format("From Powershell {0}: {1}", currentTask.sTaskDevice.ToString(), result)); + + process.WaitForExit(); + + + } + catch (Win32Exception ex) + { + log.Error(ex); + + } + } + break; + + default: + break; + + } + //switch (profile) + //{ + // case "Cisco_Switch": + // Thread thread1 = new Thread(new ParameterizedThreadStart(fSSHCisco)); + // thread1.Start(hostInfo); + // break; + // case "Cisco_Switch_Tftp": + // hostInfo.SftpIP = ftpInfo.sTftpIP; + + // Thread thread2 = new Thread(new ParameterizedThreadStart(fSSHCisco_Tftp)); + // thread2.Start(hostInfo); + // break; + // case "Cisco_Switch_Tftp_Startup": + // hostInfo.SftpIP = ftpInfo.sTftpIP; + // hostInfo.SftpPassword = ftpInfo.sTftpPassword; + // hostInfo.SftpUsername = ftpInfo.sTftpUsername; + + + // Thread thread3 = new Thread(new ParameterizedThreadStart(fSSHCisco_Tftp_Startup)); + // thread3.Start(hostInfo); + // break; + + // default: + // break; + + + //} + + + + + break; + case 6: //call Credential + + FormCredential formCredential = new FormCredential(username, password); + formCredential.ShowDialog(); + if ((formCredential.Username != "") && (formCredential.Username != username)) + username = currentTask.sUsername = formCredential.Username; + if ((formCredential.Password != "") && formCredential.Password != password) + password = currentTask.sPassword = formCredential.Password; + + break; + case 7: //select profile + + //FormProfile formProfile = new FormProfile(profile); + //formProfile.ShowDialog(); + //profile = currentTask.sProfile = formProfile.sProfile; + + // dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = profile; + break; + + default: + break; + + } + } + catch ( Exception ex) + { + log.Error(ex); + } + } + + private void dataGridViewTask_CellEndEdit(object sender, DataGridViewCellEventArgs e) + { + if (e.ColumnIndex != 5) + { + if (Tasks.Count < (e.RowIndex + 1)) + { + Tasks.Add(new cTask(e.RowIndex + 1, "", "", "", "", "", "","")); + } + switch (e.ColumnIndex) + { + case 0: + Tasks[e.RowIndex].iTaskNum = e.RowIndex + 1; + break; + case 1: + Tasks[e.RowIndex].sTaskDescription = (string)dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; + break; + case 2: + Tasks[e.RowIndex].sTaskDevice = (string)dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; + break; + case 3: + Tasks[e.RowIndex].sTaskIP = (string)dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; + break; + case 4: + Tasks[e.RowIndex].uTaskPort = (string)dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; + break; + case 5: + + break; + case 7: // Profile + Tasks[e.RowIndex].sProfile = (string)dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; + log.Info(string.Format("Task {0}, profile {1}", e.RowIndex, Tasks[e.RowIndex].sProfile)); + + break; + default: + break; + } + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (Tasks.Count >= 1) + { + using (Stream stream = File.Open("tasklist.dat", FileMode.Create)) + { + log.Info("Saving Tasklist.dat"); + var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); + binaryFormatter.Serialize(stream, Tasks); + } + using (Stream stream = File.Open("ftpInfo.dat", FileMode.Create)) + { + var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); + binaryFormatter.Serialize(stream, conInfo); + } + } + } + + private void buttonLoad_Click(object sender, EventArgs e) + { + using (Stream stream = File.Open("tasklist.dat", FileMode.Open)) + { + + var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); + Tasks = (List)binaryFormatter.Deserialize(stream); + } + using (Stream stream = File.Open("ftpInfo.dat", FileMode.Open)) + { + + var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); + conInfo = (cConInfo)binaryFormatter.Deserialize(stream); + } + + //clear TaskList + dataGridViewTask.Rows.Clear(); + + foreach (var task in Tasks) + { + DataGridViewRow row = (DataGridViewRow)dataGridViewTask.Rows[0].Clone(); + row.Cells[0].Value = task.iTaskNum; + row.Cells[1].Value = task.sTaskDescription; + row.Cells[2].Value = task.sTaskDevice; + row.Cells[3].Value = task.sTaskIP; + row.Cells[4].Value = task.uTaskPort; + row.Cells[7].Value = task.sProfile; + dataGridViewTask.Rows.Add(row); + + } + } + public class cHostInfo + { + public string device { get; set; } + public string host { get; set; } + public string username { get; set; } + public string password { get; set; } + public string TftpIP { get; set; } + + public string SftpIP { get; set; } + public string SftpUsername { get; set; } + public string SftpPassword { get; set; } + public string[] Commands { get; set; } + public cHostInfo() + { + device = ""; + host = "localhost"; + username = ""; + password = ""; + TftpIP = "127.0.0.1"; + SftpIP = "127.0.0.1"; + SftpUsername = ""; + SftpPassword = ""; + } + + } + + public void fSSH(object data) + { + try + { + cHostInfo hostinfo = (cHostInfo)data; + string host = hostinfo.host; + string device = hostinfo.device; + string username = hostinfo.username; + string password = hostinfo.password; + string tftpIp = hostinfo.TftpIP; + string sftpIp = hostinfo.SftpIP; + string sftpUsername = hostinfo.SftpUsername; + string sftpPassword = hostinfo.SftpPassword; + string[] Commands = hostinfo.Commands; + var client = new SshClient(hostinfo.host, hostinfo.username, hostinfo.password); + log.Info(string.Format("From fSSH {0}: Establishing a connection", device)); + + + client.Connect(); + log.Info(client.ConnectionInfo.ServerVersion); + + if (client.IsConnected) + { + var shellStream = client.CreateShellStream("xterm", 80, 24, 800, 600, 1024); + var output = ""; + var result = ""; + + //wait for "User Name:" + + output = shellStream.Expect(new Regex(@"Name:|name:")); + log.Info(string.Format("From fSSH {0}: {1}", device, output)); + + + //send username + shellStream.WriteLine(username); + + //wait for "Password:" + output = shellStream.Expect(new Regex(@"word:")); + log.Info(string.Format("From fSSH {0}: {1}", device, output)); + + //send password + shellStream.WriteLine(password); + + //wait for "Prompt:" + output = shellStream.Expect(new Regex(@"#")); + log.Info(string.Format("From fSSH {0}: {1}", device, output)); + + output = ""; + + //create filename + string datetime = DateTime.Now.ToString().Replace(":", ""); + datetime = datetime.Replace(" ", "_"); + // string filePath = string.Format("{0}_{1}.txt", currentTask.sTaskDevice, datetime.Replace("-", "")); + string filePath = string.Format("{0}_{1}.txt", device, datetime.Replace("-", "")); + + foreach (string c in Commands) + { + switch (c) + { + //enable + case "enable": + output = ""; + shellStream.WriteLine(c); + //wait for "Password:" + output = shellStream.Expect(new Regex(@"word:")); + log.Info(string.Format("From fSSH {0}: {1}", device, c)); + + + //send password + shellStream.WriteLine(password); + break; + + // tftp + case string s when Regex.IsMatch(c, @"tftp"): + output = ""; + string command = string.Format("{0}{1}/{2}", c, tftpIp, filePath); + log.Info(string.Format("From fSSH {0}: {1}", device, command)); + + + //send tftp command + shellStream.WriteLine(command); + + + //wait "" to send "space" and loop until get prompt + while (!Regex.IsMatch(output, "#")) + { + output = shellStream.Expect(new Regex(@"More||#")); + + shellStream.WriteLine(" "); + string[] lines = output.Split('\n'); + var output1 = ""; + for (int ii = 0; ii < (lines.Length - 1); ii++) + output1 += lines[ii]; + log.Info(output1); + + result += output1; + } + break; + default: + shellStream.WriteLine(c); + //wait for "Prompt:" + output = shellStream.Expect(new Regex(@"#")); + log.Info(string.Format("From fSSH_Test {0}: {1}", device, output)); + + break; + + } + } + } + + client.Disconnect(); + log.Info(string.Format("From SSH_Test: Disconnected")); + + } + catch (Exception e) + { + log.Error("SSH function: cannot run SSH"); + log.Error(e); + + } + + } + + public void fSSH_Catalyst(object data) + { + try + { + cHostInfo hostinfo = (cHostInfo)data; + + string host = hostinfo.host; + string device = hostinfo.device; + string username = hostinfo.username; + string password = hostinfo.password; + string tftpIp = hostinfo.TftpIP; + string sftpIp = hostinfo.SftpIP; + string sftpUsername = hostinfo.SftpUsername; + string sftpPassword = hostinfo.SftpPassword; + string[] Commands = hostinfo.Commands; + + var client = new SshClient(hostinfo.host, hostinfo.username, hostinfo.password); + log.Info(string.Format("From fSSH_Catalyst {0}: Establishing a connection {1}", device, host)); + + + client.Connect(); + log.Info(string.Format("From fSSH_Catalyst {0}: {1}", device, client.ConnectionInfo.ServerVersion)); + + + + if (client.IsConnected) + { + var shellStream = client.CreateShellStream("xterm", 80, 24, 800, 600, 1024); + var output = ""; + var result = ""; + var prompt = ""; + //output = ""; + output = shellStream.Expect(new Regex(@"#")); + log.Info(string.Format("From fSSH_Catalyst {0}: {1}", device, output)); + + prompt = output; + + shellStream.WriteLine(""); + shellStream.Flush(); + + output = shellStream.Expect(new Regex(prompt)); + log.Info(string.Format("From fSSH_Catalyst {0}: {1}", device, output)); + + + //create filename + string datetime = DateTime.Now.ToString().Replace(":", ""); + datetime = datetime.Replace(" ", "_"); + // string filePath = string.Format("{0}_{1}.txt", currentTask.sTaskDevice, datetime.Replace("-", "")); + string filePath = string.Format("{0}_{1}.txt", device, datetime.Replace("-", "")); + + foreach (string c in Commands) + { + switch (c) + { + //enable + case "enable": + output = ""; + shellStream.WriteLine(c); + //wait for "Password:" + output = shellStream.Expect(new Regex(@"word:")); + log.Info(string.Format("From fSSH_Catalyst {0}: {1}", device, c)); + + + //send password + shellStream.WriteLine(password); + break; + + // tftp + case string s when Regex.IsMatch(c, @"tftp"): + output = ""; + + string command = string.Format("{0}{1}/{2}", c, tftpIp, filePath); + + log.Info(string.Format("From fSSH_Catalyst {0}: {1}", device, command)); + //send tftp command + output = ""; + shellStream.WriteLine(command); + shellStream.Flush(); + + //handle shell interaction, wait for "?" then send "enter" + + output = shellStream.Expect(new Regex(@"\?")); + + log.Info(string.Format("From fSSH_Catalyst{0}: {1}", device, output)); + while (output.Contains("?")) + { + output = ""; + shellStream.WriteLine(""); + shellStream.Flush(); + output = shellStream.Expect(new Regex(@"\?|#")); + log.Info(string.Format("From fSSH_Catalyst {0}: {1}", device, output)); + + } + + break; + default: + shellStream.WriteLine(c); + //wait for "Prompt:" + output = shellStream.Expect(prompt); + + log.Info(string.Format("From fSSH_Catalyst {0}: {1}", device, output)); + break; + + } + } + + } + + client.Disconnect(); + log.Info(string.Format("From SSH_Catalyst: Disconnected")); + + + } + catch (Exception e) + { + log.Error("SSH_Catalyst function: cannot run SSH_Catalyst"); + log.Error(e); + + } + } + + + + private void buttonConf_Click(object sender, EventArgs e) + { + FormConfiguration formConfiguration = new FormConfiguration(conInfo.sTftpIP, conInfo.sSftpIP, conInfo.sSftpUsername, conInfo.sSftpPassword,conInfo.sIDracIP, conInfo.sIDracUsername, conInfo.sIDracPassword, conInfo.bisLocal); + formConfiguration.ShowDialog(); + conInfo.sTftpIP = formConfiguration.Tftp_IP; + conInfo.sSftpIP = formConfiguration.Sftp_IP; + conInfo.sSftpUsername = formConfiguration.Sftp_Username; + conInfo.sSftpPassword = formConfiguration.Sftp_Password; + conInfo.sIDracIP = formConfiguration.IDRAC_IP; + conInfo.sIDracUsername = formConfiguration.IDRAC_Username; + conInfo.sIDracPassword = formConfiguration.IDRAC_Password; + conInfo.bisLocal = formConfiguration.IDRAC_Local; + + } + //Seriallize Profile to a Json file + private static void SaveProfile(List data, string filePath) + { + JsonSerializerOptions options = new JsonSerializerOptions + { + WriteIndented = true + }; + string jsonString = JsonSerializer.Serialize(data, options); + File.WriteAllText(filePath, jsonString); + } + //Deseriallize Profile from a Json file + private static List LoadProfile(string filePath) + { + + if (File.Exists(filePath)) + { + try + { + string jsonString = File.ReadAllText(filePath); + return JsonSerializer.Deserialize>(jsonString); + } + catch (Exception ex) + { + //could not read profile.json properly + log.Error("Could not load profile.json"); + log.Error(ex); + + //return an empty list if file could not be read + + return new List(); + + } + + } + return new List(); // Return an empty list if file doesn't exist + } + + [Serializable] + public class cTask + { + public int iTaskNum { get; set; } + public String sTaskDescription { get; set; } + public String sTaskDevice { get; set; } + public String sTaskIP { get; set; } + public String uTaskPort { get; set; } + public String sUsername { get; set; } + public String sPassword { get; set; } + public String sProfile { get; set; } + public cTask(int iTaskNum, string uTaskDescription, string uTaskDevice, string uTaskIP, string uTaskPort, string sUsername, string sPassword, string sProfile) + { + this.iTaskNum = iTaskNum; + this.sTaskDescription = uTaskDescription; + this.sTaskDevice = uTaskDevice; + this.sTaskIP = uTaskIP; + this.uTaskPort = uTaskPort; + this.sUsername = sUsername; + this.sPassword = sPassword; + } + } + + + [Serializable] + public class cConInfo + { + + public String sTftpIP { get; set; } + public String sTftpUsername { get; set; } + public String sTftpPassword { get; set; } + public String sSftpIP { get; set; } + public String sSftpUsername { get; set; } + public String sSftpPassword { get; set; } + public string sIDracIP { get; set; } + public string sIDracUsername { get; set; } + public string sIDracPassword { get; set; } + public bool bisLocal { get; set; } + public cConInfo( string TftpIP, string TftpUsername, string TftpPassword, string SftpIP, String SftpUsername, String SftPassword, String IdracIP, String IdracUsername, String IdracPassword, bool IsLocal) + { + this.sTftpIP = TftpIP; + this.sTftpUsername = TftpUsername; + this.sTftpPassword = TftpPassword; + this.sSftpIP = SftpIP; + this.sSftpUsername = SftpUsername; + this.sSftpPassword = SftPassword; + this.sIDracIP = IdracIP; + this.sIDracUsername = IdracUsername; + this.sIDracPassword = IdracPassword; + this.bisLocal = IsLocal; + + } + } + + } + } \ No newline at end of file