diff --git a/App.config b/App.config index bbb4072..1b52a61 100644 --- a/App.config +++ b/App.config @@ -1,13 +1,10 @@  - - - - + @@ -25,6 +22,10 @@ + + + + \ No newline at end of file diff --git a/FormConfiguration.Designer.cs b/FormConfiguration.Designer.cs index 5347d47..e76c440 100644 --- a/FormConfiguration.Designer.cs +++ b/FormConfiguration.Designer.cs @@ -41,16 +41,16 @@ this.label5 = new System.Windows.Forms.Label(); this.textBoxTftpIP = new System.Windows.Forms.TextBox(); this.groupBox3 = new System.Windows.Forms.GroupBox(); - this.checkBox_Local = new System.Windows.Forms.CheckBox(); - this.label3 = new System.Windows.Forms.Label(); - this.textBoxIDRACPassword = new System.Windows.Forms.TextBox(); - this.label4 = new System.Windows.Forms.Label(); - this.textBoxIDRACUsername = new System.Windows.Forms.TextBox(); - this.label6 = new System.Windows.Forms.Label(); - this.textBoxIDRACIP = new System.Windows.Forms.TextBox(); + this.groupBox4 = new System.Windows.Forms.GroupBox(); + this.buttonTasklistDec = new System.Windows.Forms.Button(); + this.buttonTasklistEnc = new System.Windows.Forms.Button(); + this.buttonEncryptTaskList = new System.Windows.Forms.Button(); + this.checkBox_Encryption = new System.Windows.Forms.CheckBox(); + this.openFileDialogTasklist = new System.Windows.Forms.OpenFileDialog(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); + this.groupBox4.SuspendLayout(); this.SuspendLayout(); // // labelIP @@ -61,7 +61,6 @@ this.labelIP.Size = new System.Drawing.Size(17, 13); this.labelIP.TabIndex = 0; this.labelIP.Text = "IP"; - this.labelIP.Click += new System.EventHandler(this.label1_Click); // // textBoxSftpIP // @@ -69,7 +68,6 @@ this.textBoxSftpIP.Name = "textBoxSftpIP"; this.textBoxSftpIP.Size = new System.Drawing.Size(214, 20); this.textBoxSftpIP.TabIndex = 1; - this.textBoxSftpIP.TextChanged += new System.EventHandler(this.textBox1_TextChanged); // // groupBox1 // @@ -85,7 +83,6 @@ this.groupBox1.TabIndex = 3; this.groupBox1.TabStop = false; this.groupBox1.Text = "Sftp"; - this.groupBox1.Enter += new System.EventHandler(this.groupBox1_Enter); // // label2 // @@ -95,7 +92,6 @@ this.label2.Size = new System.Drawing.Size(53, 13); this.label2.TabIndex = 4; this.label2.Text = "Password"; - this.label2.Click += new System.EventHandler(this.label2_Click); // // textBoxSftpPassword // @@ -159,85 +155,79 @@ // // groupBox3 // - this.groupBox3.Controls.Add(this.checkBox_Local); - this.groupBox3.Controls.Add(this.label3); - this.groupBox3.Controls.Add(this.textBoxIDRACPassword); - this.groupBox3.Controls.Add(this.label4); - this.groupBox3.Controls.Add(this.textBoxIDRACUsername); - this.groupBox3.Controls.Add(this.label6); - this.groupBox3.Controls.Add(this.textBoxIDRACIP); + this.groupBox3.Controls.Add(this.groupBox4); + this.groupBox3.Controls.Add(this.buttonEncryptTaskList); + this.groupBox3.Controls.Add(this.checkBox_Encryption); this.groupBox3.Location = new System.Drawing.Point(307, 12); this.groupBox3.Name = "groupBox3"; - this.groupBox3.Size = new System.Drawing.Size(278, 152); + this.groupBox3.Size = new System.Drawing.Size(240, 177); this.groupBox3.TabIndex = 6; this.groupBox3.TabStop = false; - this.groupBox3.Text = "IDRAC"; + this.groupBox3.Text = "Encryption"; // - // checkBox_Local + // groupBox4 // - this.checkBox_Local.AutoSize = true; - this.checkBox_Local.Location = new System.Drawing.Point(23, 19); - this.checkBox_Local.Name = "checkBox_Local"; - this.checkBox_Local.Size = new System.Drawing.Size(52, 17); - this.checkBox_Local.TabIndex = 6; - this.checkBox_Local.Text = "Local"; - this.checkBox_Local.UseVisualStyleBackColor = true; - this.checkBox_Local.CheckedChanged += new System.EventHandler(this.checkBox_Local_CheckedChanged); + this.groupBox4.Controls.Add(this.buttonTasklistDec); + this.groupBox4.Controls.Add(this.buttonTasklistEnc); + this.groupBox4.Location = new System.Drawing.Point(8, 42); + this.groupBox4.Name = "groupBox4"; + this.groupBox4.Size = new System.Drawing.Size(220, 62); + this.groupBox4.TabIndex = 8; + this.groupBox4.TabStop = false; + this.groupBox4.Text = "Tasklist, Profile, Powershell Script File"; // - // label3 + // buttonTasklistDec // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(20, 105); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(53, 13); - this.label3.TabIndex = 4; - this.label3.Text = "Password"; + this.buttonTasklistDec.Location = new System.Drawing.Point(123, 19); + this.buttonTasklistDec.Name = "buttonTasklistDec"; + this.buttonTasklistDec.Size = new System.Drawing.Size(86, 37); + this.buttonTasklistDec.TabIndex = 8; + this.buttonTasklistDec.Text = "Decrypt"; + this.buttonTasklistDec.UseVisualStyleBackColor = true; + this.buttonTasklistDec.Click += new System.EventHandler(this.buttonTasklistDec_Click); // - // textBoxIDRACPassword + // buttonTasklistEnc // - this.textBoxIDRACPassword.Location = new System.Drawing.Point(83, 102); - this.textBoxIDRACPassword.Name = "textBoxIDRACPassword"; - this.textBoxIDRACPassword.Size = new System.Drawing.Size(186, 20); - this.textBoxIDRACPassword.TabIndex = 5; - this.textBoxIDRACPassword.UseSystemPasswordChar = true; + this.buttonTasklistEnc.Location = new System.Drawing.Point(11, 19); + this.buttonTasklistEnc.Name = "buttonTasklistEnc"; + this.buttonTasklistEnc.Size = new System.Drawing.Size(86, 37); + this.buttonTasklistEnc.TabIndex = 7; + this.buttonTasklistEnc.Text = "Encrypt"; + this.buttonTasklistEnc.UseVisualStyleBackColor = true; + this.buttonTasklistEnc.Click += new System.EventHandler(this.buttonTasklistEnc_Click); // - // label4 + // buttonEncryptTaskList // - this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(20, 79); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(57, 13); - this.label4.TabIndex = 2; - this.label4.Text = "UserName"; + this.buttonEncryptTaskList.Location = new System.Drawing.Point(23, 43); + this.buttonEncryptTaskList.Name = "buttonEncryptTaskList"; + this.buttonEncryptTaskList.Size = new System.Drawing.Size(75, 23); + this.buttonEncryptTaskList.TabIndex = 7; + this.buttonEncryptTaskList.Text = "Encrypt"; + this.buttonEncryptTaskList.UseVisualStyleBackColor = true; // - // textBoxIDRACUsername + // checkBox_Encryption // - this.textBoxIDRACUsername.Location = new System.Drawing.Point(83, 76); - this.textBoxIDRACUsername.Name = "textBoxIDRACUsername"; - this.textBoxIDRACUsername.Size = new System.Drawing.Size(186, 20); - this.textBoxIDRACUsername.TabIndex = 3; + this.checkBox_Encryption.AutoSize = true; + this.checkBox_Encryption.Location = new System.Drawing.Point(23, 19); + this.checkBox_Encryption.Name = "checkBox_Encryption"; + this.checkBox_Encryption.Size = new System.Drawing.Size(59, 17); + this.checkBox_Encryption.TabIndex = 6; + this.checkBox_Encryption.Text = "Enable"; + this.checkBox_Encryption.UseVisualStyleBackColor = true; + this.checkBox_Encryption.CheckedChanged += new System.EventHandler(this.checkBox_Local_CheckedChanged); // - // label6 + // openFileDialogTasklist // - this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(56, 53); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(17, 13); - this.label6.TabIndex = 0; - this.label6.Text = "IP"; - // - // textBoxIDRACIP - // - this.textBoxIDRACIP.Location = new System.Drawing.Point(83, 50); - this.textBoxIDRACIP.Name = "textBoxIDRACIP"; - this.textBoxIDRACIP.Size = new System.Drawing.Size(186, 20); - this.textBoxIDRACIP.TabIndex = 1; + this.openFileDialogTasklist.DefaultExt = "json"; + this.openFileDialogTasklist.FileName = "tasklisk.json"; + this.openFileDialogTasklist.Filter = "json file|*.json|Powershell scrips|*.ps1"; + this.openFileDialogTasklist.Title = "Task list file"; // // FormConfiguration // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(586, 228); + this.ClientSize = new System.Drawing.Size(552, 228); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox2); this.Controls.Add(this.buttonOK); @@ -252,6 +242,7 @@ this.groupBox2.PerformLayout(); this.groupBox3.ResumeLayout(false); this.groupBox3.PerformLayout(); + this.groupBox4.ResumeLayout(false); this.ResumeLayout(false); } @@ -270,12 +261,11 @@ private System.Windows.Forms.Label label5; private System.Windows.Forms.TextBox textBoxTftpIP; private System.Windows.Forms.GroupBox groupBox3; - private System.Windows.Forms.Label label3; - private System.Windows.Forms.TextBox textBoxIDRACPassword; - private System.Windows.Forms.Label label4; - private System.Windows.Forms.TextBox textBoxIDRACUsername; - private System.Windows.Forms.Label label6; - private System.Windows.Forms.TextBox textBoxIDRACIP; - private System.Windows.Forms.CheckBox checkBox_Local; + private System.Windows.Forms.CheckBox checkBox_Encryption; + private System.Windows.Forms.Button buttonEncryptTaskList; + private System.Windows.Forms.GroupBox groupBox4; + private System.Windows.Forms.Button buttonTasklistDec; + private System.Windows.Forms.Button buttonTasklistEnc; + private System.Windows.Forms.OpenFileDialog openFileDialogTasklist; } } \ No newline at end of file diff --git a/FormConfiguration.cs b/FormConfiguration.cs index eb027bc..886417f 100644 --- a/FormConfiguration.cs +++ b/FormConfiguration.cs @@ -1,12 +1,16 @@ -using System; +using log4net; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; +using System.Text.Json; using System.Threading.Tasks; using System.Windows.Forms; +using System.IO; +using System.Security.Cryptography; namespace SSH_Test { @@ -16,53 +20,36 @@ namespace SSH_Test public string Sftp_IP { get; set; } public string Sftp_Username { get; set; } public string Sftp_Password { get; set; } - public string IDRAC_IP { get; set; } - public string IDRAC_Username { get; set; } - public string IDRAC_Password { get; set; } - public bool IDRAC_Local { get; set; } + public bool bEncryption { get; set; } + public string sTasklistPath { get; set; } + public string sProfilePath { get; set; } + public Aes aes { get; set; } - public FormConfiguration(string tftp_IP, string sftpIP, string sftp_Username, string sftp_Password) + public static ILog log; + + public FormConfiguration(string tftp_IP, string sftpIP, string sftp_Username, string sftp_Password, bool bencryption + , Aes aaes, ILog Log) { InitializeComponent(); this.textBoxTftpIP.Text = Tftp_IP = tftp_IP; this.textBoxSftpIP.Text = Sftp_IP = sftpIP; this.textBoxSftpUsername.Text = Sftp_Username = sftp_Username; this.textBoxSftpPassword.Text = Sftp_Password = sftp_Password; + checkBox_Encryption.Checked = bEncryption = bencryption; + aes = aaes; + log = Log; this.Update(); } - private void groupBox1_Enter(object sender, EventArgs e) - { - - } - - private void textBox1_TextChanged(object sender, EventArgs e) - { - - } - - private void label1_Click(object sender, EventArgs e) - { - - } - - private void label2_Click(object sender, EventArgs e) - { - - } - private void buttonOK_Click(object sender, EventArgs e) { Tftp_IP = textBoxTftpIP.Text; Sftp_IP = textBoxSftpIP.Text; Sftp_Username = textBoxSftpUsername.Text; Sftp_Password = textBoxSftpPassword.Text; - IDRAC_IP = textBoxIDRACIP.Text; - IDRAC_Username= textBoxIDRACUsername.Text; - IDRAC_Password= textBoxIDRACPassword.Text; - IDRAC_Local=checkBox_Local.Checked; + bEncryption = checkBox_Encryption.Checked; this.Close(); } @@ -73,17 +60,81 @@ namespace SSH_Test private void checkBox_Local_CheckedChanged(object sender, EventArgs e) { - if (checkBox_Local.Checked) + if (checkBox_Encryption.Checked) { - checkBox_Local.Checked = true; - IDRAC_Local = checkBox_Local.Checked; + checkBox_Encryption.Checked = true; + bEncryption = checkBox_Encryption.Checked; } else { - checkBox_Local.Checked = false; - IDRAC_Local = checkBox_Local.Checked; + checkBox_Encryption.Checked = false; + bEncryption = checkBox_Encryption.Checked; } } + + private void buttonTasklistEnc_Click(object sender, EventArgs e) + { + Utilities utilities = new Utilities(log); + if (openFileDialogTasklist.ShowDialog() == DialogResult.OK) + { + string Jsonfilename = openFileDialogTasklist.FileName; + string buttonTasklistPath = openFileDialogTasklist.SafeFileName; + if (File.Exists(Jsonfilename)) + { + try + { + //read tasklist data from file + string sData = File.ReadAllText(Jsonfilename); + log.Info(string.Format("Read {0} to String", Jsonfilename)); + //encrypt data + byte[] bData = Utilities.EncryptStringAES(sData, aes.Key); + + //write encrypted data to file + File.WriteAllBytes(Jsonfilename, bData); + + } + catch (Exception ex) + { + //could not read tasklist.json properly + log.Error(string.Format("Could not load {0} for encrypting", Jsonfilename)); + log.Error(ex); + } + + + } + } + } + + private void buttonTasklistDec_Click(object sender, EventArgs e) + { + Utilities utilities = new Utilities(log); + if (openFileDialogTasklist.ShowDialog() == DialogResult.OK) + { + string JsonFileName = openFileDialogTasklist.FileName; + string buttonTasklistPath = openFileDialogTasklist.SafeFileName; + if (File.Exists(JsonFileName)) + { + try + { + //read json data from file + byte[] bData = File.ReadAllBytes(JsonFileName); + + //decrypt data and save to file + + File.WriteAllText(JsonFileName, Utilities.DecryptStringFromBytes(bData, aes.Key)); + + } + catch (Exception ex) + { + //could not read tasklist.json properly + log.Error(string.Format("Could not load {0} for encrypting", JsonFileName)); + log.Error(ex); + } + + + } + } + } } } diff --git a/FormConfiguration.resx b/FormConfiguration.resx index 152021a..e895283 100644 --- a/FormConfiguration.resx +++ b/FormConfiguration.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + diff --git a/FormParameters.cs b/FormParameters.cs index 40ccb57..ed4c4e2 100644 --- a/FormParameters.cs +++ b/FormParameters.cs @@ -7,7 +7,7 @@ using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; -using System.Web.UI.WebControls; + using System.Windows.Forms; using static System.Windows.Forms.VisualStyles.VisualStyleElement; using TextBox = System.Windows.Forms.TextBox; diff --git a/Profile.cs b/Profile.cs index 1ba3530..82b7bd8 100644 --- a/Profile.cs +++ b/Profile.cs @@ -4,8 +4,7 @@ using System.Linq; using System.Text; using System.Text.Json.Serialization; using System.Threading.Tasks; -using System.Web.Profile; -using System.Web.UI.WebControls; + using System.Xml.Linq; namespace SSH_Test diff --git a/SSH_Test.csproj b/SSH_Test.csproj index 88a3172..ee4d744 100644 --- a/SSH_Test.csproj +++ b/SSH_Test.csproj @@ -15,6 +15,7 @@ false + D:\Shared\VS\Publish\ true Disk @@ -88,8 +89,8 @@ packages\log4net.3.2.0\lib\net462\log4net.dll - - packages\Microsoft.Bcl.AsyncInterfaces.10.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll + + packages\Microsoft.Bcl.AsyncInterfaces.10.0.2\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll packages\Microsoft.Extensions.DependencyInjection.Abstractions.8.0.2\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll @@ -109,8 +110,11 @@ 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.IO.Pipelines.10.0.2\lib\net462\System.IO.Pipelines.dll + + + packages\Microsoft.PowerShell.5.1.ReferenceAssemblies.1.0.0\lib\net461\System.Management.Automation.dll packages\System.Memory.4.6.3\lib\net462\System.Memory.dll @@ -131,14 +135,12 @@ packages\System.Threading.Tasks.Extensions.4.6.3\lib\net462\System.Threading.Tasks.Extensions.dll - - @@ -193,12 +195,13 @@ Resources.resx True + Always - Always + PreserveNewest @@ -216,9 +219,6 @@ PreserveNewest - - - False @@ -238,11 +238,11 @@ - 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/TastList.Designer.cs b/TastList.Designer.cs index b910637..d7cc2e5 100644 --- a/TastList.Designer.cs +++ b/TastList.Designer.cs @@ -54,6 +54,11 @@ this.buttonSave = new System.Windows.Forms.Button(); this.bRun = new System.Windows.Forms.Button(); this.checkBoxArrangeTask = new System.Windows.Forms.CheckBox(); + this.openFileDialogTasklist = new System.Windows.Forms.OpenFileDialog(); + this.buttonTasklistPath = new System.Windows.Forms.Button(); + this.toolTipbuttonTasklist = new System.Windows.Forms.ToolTip(this.components); + this.toolTipGeneralConf = new System.Windows.Forms.ToolTip(this.components); + this.buttonAESString = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewTask)).BeginInit(); this.contextMenuStripRow.SuspendLayout(); this.groupBox1.SuspendLayout(); @@ -62,7 +67,7 @@ // // buttonConf // - this.buttonConf.Location = new System.Drawing.Point(419, 12); + this.buttonConf.Location = new System.Drawing.Point(725, 12); this.buttonConf.Name = "buttonConf"; this.buttonConf.Size = new System.Drawing.Size(96, 50); this.buttonConf.TabIndex = 6; @@ -96,6 +101,7 @@ this.Run, this.Configuration, this.Profile}); + this.dataGridViewTask.ContextMenuStrip = this.contextMenuStripRow; this.dataGridViewTask.Dock = System.Windows.Forms.DockStyle.Fill; this.dataGridViewTask.Location = new System.Drawing.Point(3, 16); this.dataGridViewTask.Name = "dataGridViewTask"; @@ -118,6 +124,7 @@ this.TaskNum.Name = "TaskNum"; this.TaskNum.ReadOnly = true; this.TaskNum.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; + this.TaskNum.ToolTipText = "sfasfsfsfsaf"; this.TaskNum.Width = 50; // // contextMenuStripRow @@ -130,6 +137,8 @@ // // MoveToolStripMenuItem // + this.MoveToolStripMenuItem.AutoToolTip = true; + this.MoveToolStripMenuItem.CheckOnClick = true; this.MoveToolStripMenuItem.Image = global::SSH_Test.Properties.Resources.Arrange16; this.MoveToolStripMenuItem.Name = "MoveToolStripMenuItem"; this.MoveToolStripMenuItem.Size = new System.Drawing.Size(147, 22); @@ -280,11 +289,11 @@ // this.buttonLoad.Image = global::SSH_Test.Properties.Resources.Load24b; this.buttonLoad.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.buttonLoad.Location = new System.Drawing.Point(12, 9); + this.buttonLoad.Location = new System.Drawing.Point(6, 35); this.buttonLoad.Name = "buttonLoad"; - this.buttonLoad.Size = new System.Drawing.Size(80, 50); + this.buttonLoad.Size = new System.Drawing.Size(80, 30); this.buttonLoad.TabIndex = 1; - this.buttonLoad.Text = "Load Tasklist"; + this.buttonLoad.Text = "ReLoad"; this.buttonLoad.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; this.buttonLoad.UseMnemonic = false; this.buttonLoad.UseVisualStyleBackColor = true; @@ -294,11 +303,11 @@ // this.buttonSave.Image = global::SSH_Test.Properties.Resources.Save24b; this.buttonSave.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.buttonSave.Location = new System.Drawing.Point(97, 9); + this.buttonSave.Location = new System.Drawing.Point(91, 35); this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(80, 50); + this.buttonSave.Size = new System.Drawing.Size(80, 30); this.buttonSave.TabIndex = 2; - this.buttonSave.Text = "Save TaskList"; + this.buttonSave.Text = "Save"; this.buttonSave.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; this.buttonSave.UseVisualStyleBackColor = true; this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); @@ -320,7 +329,7 @@ // this.checkBoxArrangeTask.AutoSize = true; this.checkBoxArrangeTask.Image = global::SSH_Test.Properties.Resources.Arrange24; - this.checkBoxArrangeTask.Location = new System.Drawing.Point(183, 12); + this.checkBoxArrangeTask.Location = new System.Drawing.Point(182, 38); this.checkBoxArrangeTask.Name = "checkBoxArrangeTask"; this.checkBoxArrangeTask.Size = new System.Drawing.Size(119, 24); this.checkBoxArrangeTask.TabIndex = 9; @@ -329,11 +338,45 @@ this.checkBoxArrangeTask.UseVisualStyleBackColor = true; this.checkBoxArrangeTask.CheckedChanged += new System.EventHandler(this.checkBoxArrangeTask_CheckedChanged); // + // openFileDialogTasklist + // + this.openFileDialogTasklist.DefaultExt = "json"; + this.openFileDialogTasklist.FileName = "tasklisk.json"; + this.openFileDialogTasklist.Filter = "json file (*.json)|*.json"; + this.openFileDialogTasklist.Title = "Task list file"; + // + // buttonTasklistPath + // + this.buttonTasklistPath.AccessibleDescription = "Choose Task list file"; + this.buttonTasklistPath.Location = new System.Drawing.Point(6, 2); + this.buttonTasklistPath.Margin = new System.Windows.Forms.Padding(1); + this.buttonTasklistPath.Name = "buttonTasklistPath"; + this.buttonTasklistPath.Size = new System.Drawing.Size(165, 30); + this.buttonTasklistPath.TabIndex = 10; + this.buttonTasklistPath.Text = "tasklist.json"; + this.buttonTasklistPath.UseVisualStyleBackColor = true; + this.buttonTasklistPath.Click += new System.EventHandler(this.buttonTasklistPath_Click); + // + // buttonAESString + // + this.buttonAESString.Image = global::SSH_Test.Properties.Resources.Encryption24; + this.buttonAESString.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.buttonAESString.Location = new System.Drawing.Point(182, 2); + this.buttonAESString.Name = "buttonAESString"; + this.buttonAESString.Size = new System.Drawing.Size(80, 30); + this.buttonAESString.TabIndex = 11; + this.buttonAESString.Text = "AES"; + this.buttonAESString.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; + this.buttonAESString.UseVisualStyleBackColor = true; + this.buttonAESString.Click += new System.EventHandler(this.buttonAESString_Click); + // // TastList // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1094, 794); + this.Controls.Add(this.buttonAESString); + this.Controls.Add(this.buttonTasklistPath); this.Controls.Add(this.checkBoxArrangeTask); this.Controls.Add(this.buttonUncheckAll); this.Controls.Add(this.buttonCheckAll); @@ -346,6 +389,7 @@ this.Controls.Add(this.bRun); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "TastList"; + this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; this.Text = "Task List"; this.Load += new System.EventHandler(this.fSSHTest_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewTask)).EndInit(); @@ -374,6 +418,9 @@ private System.Windows.Forms.ContextMenuStrip contextMenuStripRow; private System.Windows.Forms.ToolStripMenuItem MoveToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem DeleteToolStripMenuItem; + private System.Windows.Forms.OpenFileDialog openFileDialogTasklist; + private System.Windows.Forms.Button buttonTasklistPath; + private System.Windows.Forms.ToolTip toolTipbuttonTasklist; private System.Windows.Forms.DataGridViewTextBoxColumn TaskNum; private System.Windows.Forms.DataGridViewTextBoxColumn TaskDescription; private System.Windows.Forms.DataGridViewTextBoxColumn TaskDevice; @@ -382,6 +429,8 @@ private System.Windows.Forms.DataGridViewImageColumn Run; private System.Windows.Forms.DataGridViewButtonColumn Configuration; private System.Windows.Forms.DataGridViewComboBoxColumn Profile; + private System.Windows.Forms.ToolTip toolTipGeneralConf; + private System.Windows.Forms.Button buttonAESString; } } diff --git a/TastList.cs b/TastList.cs index e9b0a30..9196280 100644 --- a/TastList.cs +++ b/TastList.cs @@ -14,13 +14,15 @@ using System.IO; using System.Linq; using System.Linq.Expressions; using System.Reflection; +using System.Runtime.InteropServices; // for moving console window using System.Runtime.Remoting.Contexts; +using System.Security.Cryptography; using System.Text; +using System.Text.Encodings.Web; using System.Text.Json; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; -using System.Web.UI.WebControls; using System.Windows.Forms; using System.Xml; using static System.Windows.Forms.VisualStyles.VisualStyleElement; @@ -35,42 +37,120 @@ namespace SSH_Test public List Tasks = new List(); public cConInfo conInfo = new cConInfo("", "", "", "", "", ""); private List Profiles = new List(); - private static ILog log = LogManager.GetLogger(typeof(Program)); - private static Utilities utilities = new Utilities(log); + public static ILog log = LogManager.GetLogger(typeof(Program)); private int RowToDrag = -1; //for arrange tasks private int RowToDrop = -1; // for arrange tasks + private string Tasklistfilename = "tasklist.json"; + private string Profilefilename = "profile.json"; + private bool bEncryption = true; + private static Aes aes ; + private static Utilities utilities = new Utilities(log); + + //for moving console window + // Import the necessary Windows API functions + [DllImport("kernel32.dll", SetLastError = true)] + static extern IntPtr GetConsoleWindow(); + + [DllImport("user32.dll", SetLastError = true)] + internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); + + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool SetForegroundWindow(IntPtr hWnd); + public TastList() { + this.StartPosition = FormStartPosition.Manual; + this.Location = new Point(100,100); var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); log4net.Util.LogLog.InternalDebugging = true; XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config")); InitializeComponent(); + + //encryption + aes = Aes.Create(); + + + + //set default tasklist file + openFileDialogTasklist.InitialDirectory = System.IO.Directory.GetCurrentDirectory(); + openFileDialogTasklist.FileName = Tasklistfilename; + buttonTasklistPath.Text = Tasklistfilename; + + + // set Tooltip + toolTipbuttonTasklist.ToolTipTitle = "Task List and Profile"; + toolTipbuttonTasklist.SetToolTip(buttonTasklistPath, " Pick another, the default is tasklist.json"); + toolTipbuttonTasklist.SetToolTip(buttonLoad, " Load or reload task list file"); + toolTipbuttonTasklist.SetToolTip(buttonSave, "Save the current task list file"); + toolTipbuttonTasklist.SetToolTip(buttonAESString, " Input or change EAS string"); + + toolTipGeneralConf.ToolTipTitle = "Configuration"; + toolTipGeneralConf.SetToolTip(buttonConf, " Configure TFTP, Encrypion and more"); + + + + + + //move console window + int newX = this.Right; // to right size of the main form + int newY = this.Top; // align top + int NewWidth = 400; + int NewHeight = this.Height; + + IntPtr consoleHandle = GetConsoleWindow(); + + if (consoleHandle != IntPtr.Zero) + { + + + + bool success = MoveWindow(consoleHandle, newX, newY, NewWidth, NewHeight, true); + + if (success) + { + Console.WriteLine($"Console to ({newX}, {newY})."); + } + else + { + Console.WriteLine("Failed to move console."); + } + + SetForegroundWindow(consoleHandle); + } + else + { + Console.WriteLine("Failed get console window handle."); + } + + //Initialize Gridview behaviours dataGridViewTask.AllowDrop = true; dataGridViewTask.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText; dataGridViewTask.RowTemplate.ContextMenuStrip = contextMenuStripRow; //Load Profile list from "profile.json" - Profiles = utilities.LoadProfile("profile.json"); + Profiles = utilities.LoadProfile("profile.json", aes); // Configure Profile list to dropdown menu - try - { - foreach (Profile p in Profiles) - { - log.Info(string.Format("Profile: {0}", p.ProfileName)); - } + // AES button will update the dropdown menu when AES key is inputed. + //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); - } + // 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(); @@ -85,6 +165,7 @@ namespace SSH_Test //Disable Arrange Tasks first checkBoxArrangeTask.Checked = false; log.Info("Run selected Tasks was called"); + string listofruntasks = "Task(s) ran: \n"; foreach (DataGridViewRow row in dataGridViewTask.Rows) { Profile profile; @@ -133,9 +214,11 @@ namespace SSH_Test //clear richtextboxoutput //richTextBoxOutput.Clear(); - // Run a Task and display result on the textbox - richTextBoxOutput.AppendText(Utilities.RunaTask(currentTask, profile, conInfo)); + // insert task name to listofruntasks + listofruntasks += string.Format(" Task {0}: {1}, profile: {2} \n", currentTask.iTaskNum, currentTask.sTaskDescription, currentTask.sProfile); + // Run a Task and display result on the textbox + richTextBoxOutput.AppendText(Utilities.RunaTask(currentTask, profile, conInfo,aes)); richTextBoxOutput.SelectionStart = richTextBoxOutput.Text.Length; richTextBoxOutput.ScrollToCaret(); } @@ -147,6 +230,7 @@ namespace SSH_Test } } } + //dump output to file.txt string filepath = string.Format("{0}\\{1}\\{2}_{3}.txt", Environment.CurrentDirectory, Environment.MachineName, Environment.MachineName, DateTime.Now.ToString("yyyyMMdd_HHmmss")); @@ -161,8 +245,8 @@ namespace SSH_Test Directory.CreateDirectory(dir); } - File.WriteAllText(filepath, richTextBoxOutput.Text.ToString()); - + File.WriteAllText(filepath, listofruntasks); + File.AppendAllText(filepath, richTextBoxOutput.Text.ToString()); log.Info(string.Format("Wrote to file: {0}", filepath)); } catch (Exception ex) @@ -173,6 +257,158 @@ namespace SSH_Test log.Info("Run selected Tasks End"); } + + private void buttonTasklistPath_Click(object sender, EventArgs e) + { + if (openFileDialogTasklist.ShowDialog() == DialogResult.OK) + { + Tasklistfilename = openFileDialogTasklist.FileName; + buttonTasklistPath.Text = openFileDialogTasklist.SafeFileName; + + //load tasklist + buttonLoad_Click(null,null); + } + } + private void buttonSave_Click(object sender, EventArgs e) + { + //Disable Arrange Tasks first + checkBoxArrangeTask.Checked = false; + + if (Tasks.Count >= 1) + { + utilities.SaveTasklist(Tasks, Tasklistfilename, aes); + } + } + + private void buttonLoad_Click(object sender, EventArgs e) + { + + + //Disable Arrange Tasks first + checkBoxArrangeTask.Checked = false; + + Tasks = utilities.LoadTaskList(Tasklistfilename, aes); + + //clear TaskList + dataGridViewTask.Rows.Clear(); + + foreach (var task in Tasks) + { + try + { + 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[4].Value = task.bTaskSelect; + var comboBoxColumn = (DataGridViewComboBoxColumn)dataGridViewTask.Columns[7]; + // test if task.sprofile name mach any in Profiles, if true, assign that name + if (Profiles.Any(pr => pr.ProfileName == task.sProfile)) + row.Cells[7].Value = task.sProfile; + dataGridViewTask.Rows.Add(row); + } + catch (Exception ex) + { + log.Error(string.Format("Error while loading saved tasklist: \n {0}", ex.Message)); + } + + + } + } + + private void buttonConf_Click(object sender, EventArgs e) + { + FormConfiguration formConfiguration = new FormConfiguration(conInfo.sTftpIP, conInfo.sSftpIP, + conInfo.sSftpUsername, conInfo.sSftpPassword, + bEncryption, aes, log); + + formConfiguration.ShowDialog(); + conInfo.sTftpIP = formConfiguration.Tftp_IP; + conInfo.sSftpIP = formConfiguration.Sftp_IP; + conInfo.sSftpUsername = formConfiguration.Sftp_Username; + conInfo.sSftpPassword = formConfiguration.Sftp_Password; + + } + + private void dataGridViewTask_CellClick(object sender, DataGridViewCellEventArgs e) + { + // Ensure the click is on a valid celland not in arrange mode and not the header and start edit mode immediately + if ((!checkBoxArrangeTask.Checked) && (e.RowIndex >= 0) && (e.ColumnIndex > 0)) + { + // Set the cell as the current cell (if not already) + dataGridViewTask.CurrentCell = dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex]; + + + dataGridViewTask.BeginEdit(true); + } + } + + private void dataGridViewTask_CellToolTipTextNeeded(object sender, DataGridViewCellToolTipTextNeededEventArgs e) + { + //show tool tips for cells in Run column 5 + log.Info("Handle showing tooltip at a cell"); + if (e.ColumnIndex == 5) + { + e.ToolTipText = string.Format("Run Task {0}: {1}", dataGridViewTask.Rows[e.RowIndex].Cells[1], dataGridViewTask.Rows[e.RowIndex].Cells[2]); + } + } + + private void buttonCheckAll_Click(object sender, EventArgs e) + { + //Disable Arrange Tasks first + checkBoxArrangeTask.Checked = false; + + foreach (DataGridViewRow row in dataGridViewTask.Rows) + { + DataGridViewCheckBoxCell cell = row.Cells[4] as DataGridViewCheckBoxCell; + + if (cell.Value != null) + { + cell.Value = true; + Tasks[row.Index].bTaskSelect = true; + } + } + dataGridViewTask.Refresh(); + } + + private void buttonUncheckAll_Click(object sender, EventArgs e) + { + //Disable Arrange Tasks first + checkBoxArrangeTask.Checked = false; + + foreach (DataGridViewRow row in dataGridViewTask.Rows) + { + DataGridViewCheckBoxCell cell = row.Cells[4] as DataGridViewCheckBoxCell; + + if (cell.Value != null) + { + cell.Value = false; + Tasks[row.Index].bTaskSelect = false; + } + } + dataGridViewTask.Refresh(); + } + + private void checkBoxArrangeTask_CheckedChanged(object sender, EventArgs e) + { + if (checkBoxArrangeTask.Checked) + { + dataGridViewTask.AllowUserToAddRows = false; + // change mouse cursor to Hand + dataGridViewTask.Cursor = System.Windows.Forms.Cursors.Hand; + + + } + else + { + dataGridViewTask.AllowUserToAddRows = true; + // change mouse cursor back to Default + dataGridViewTask.Cursor = System.Windows.Forms.Cursors.Default; + + } + + } + private void dataGridViewTask_CellContentClick(object sender, DataGridViewCellEventArgs e) { @@ -234,7 +470,7 @@ namespace SSH_Test // Run a Task and display result on the textbox - richTextBoxOutput.AppendText(Utilities.RunaTask(currentTask, profile, conInfo)); + richTextBoxOutput.AppendText(Utilities.RunaTask(currentTask, profile, conInfo,aes)); richTextBoxOutput.SelectionStart = richTextBoxOutput.Text.Length; richTextBoxOutput.ScrollToCaret(); } @@ -270,7 +506,7 @@ namespace SSH_Test private void dataGridViewTask_CellEndEdit(object sender, DataGridViewCellEventArgs e) { - Profile profile = new Profile() ; + Profile profile = new Profile(); if (e.ColumnIndex != 5) { if (Tasks.Count < (e.RowIndex + 1)) @@ -286,7 +522,7 @@ namespace SSH_Test switch (e.ColumnIndex) { case 0: - + break; case 1: Tasks[e.RowIndex].sTaskDescription = (string)dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; @@ -310,8 +546,8 @@ namespace SSH_Test else Tasks[e.RowIndex].sProfile = "Do nothing"; - profile = Profiles.Find(x => x.ProfileName == Tasks[e.RowIndex].sProfile.ToString()); - if (profile.ProfileParameters.Length > 0) + profile = Profiles.Find(x => x.ProfileName == Tasks[e.RowIndex].sProfile.ToString()); + if ( (profile != null) && (profile.ProfileParameters.Length > 0)) { //clear task profile parameters first Tasks[e.RowIndex].dParameters.Clear(); @@ -326,171 +562,19 @@ namespace SSH_Test break; default: - + break; } - } } - private void buttonSave_Click(object sender, EventArgs e) - { - //Disable Arrange Tasks first - checkBoxArrangeTask.Checked = false; - - 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); - //} - utilities.SaveTasklist(Tasks, "tasklist.json"); - } - } - - 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); - //} - - //Disable Arrange Tasks first - checkBoxArrangeTask.Checked = false; - - Tasks = utilities.LoadTaskList("tasklist.json"); - - //clear TaskList - dataGridViewTask.Rows.Clear(); - - foreach (var task in Tasks) - { - try - { - 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[4].Value = task.bTaskSelect; - var comboBoxColumn = (DataGridViewComboBoxColumn)dataGridViewTask.Columns[7]; - // test if task.sprofile name mach any in Profiles, if true, assign that name - if (Profiles.Any(pr => pr.ProfileName == task.sProfile)) - row.Cells[7].Value = task.sProfile; - dataGridViewTask.Rows.Add(row); - } - catch (Exception ex) - { - log.Error(string.Format("Error while loading saved tasklist: \n {0}", ex.Message)); - } - - - } - } - - - - private void buttonConf_Click(object sender, EventArgs e) - { - FormConfiguration formConfiguration = new FormConfiguration(conInfo.sTftpIP, conInfo.sSftpIP, conInfo.sSftpUsername, conInfo.sSftpPassword); - formConfiguration.ShowDialog(); - conInfo.sTftpIP = formConfiguration.Tftp_IP; - conInfo.sSftpIP = formConfiguration.Sftp_IP; - conInfo.sSftpUsername = formConfiguration.Sftp_Username; - conInfo.sSftpPassword = formConfiguration.Sftp_Password; - - } - - private void dataGridViewTask_CellClick(object sender, DataGridViewCellEventArgs e) - { - // Ensure the click is on a valid cell and not the header - if (e.RowIndex >= 0 && e.ColumnIndex >= 0) - { - // Set the cell as the current cell (if not already) - dataGridViewTask.CurrentCell = dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex]; - - // Start the edit mode immediately - dataGridViewTask.BeginEdit(true); - } - } - - private void dataGridViewTask_CellToolTipTextNeeded(object sender, DataGridViewCellToolTipTextNeededEventArgs e) - { - //show tool tips for cells in Run column 5 - log.Info("Handle showing tooltip at a cell"); - if (e.ColumnIndex == 5) - { - e.ToolTipText = string.Format("Run Task {0}: {1}", dataGridViewTask.Rows[e.RowIndex].Cells[1], dataGridViewTask.Rows[e.RowIndex].Cells[2]); - } - } - - private void buttonCheckAll_Click(object sender, EventArgs e) - { - //Disable Arrange Tasks first - checkBoxArrangeTask.Checked = false; - - foreach (DataGridViewRow row in dataGridViewTask.Rows) - { - DataGridViewCheckBoxCell cell = row.Cells[4] as DataGridViewCheckBoxCell; - - if (cell.Value != null) - { - cell.Value = true; - Tasks[row.Index].bTaskSelect = true; - } - } - dataGridViewTask.Refresh(); - } - - private void buttonUncheckAll_Click(object sender, EventArgs e) - { - //Disable Arrange Tasks first - checkBoxArrangeTask.Checked = false; - - foreach (DataGridViewRow row in dataGridViewTask.Rows) - { - DataGridViewCheckBoxCell cell = row.Cells[4] as DataGridViewCheckBoxCell; - - if (cell.Value != null) - { - cell.Value = false; - Tasks[row.Index].bTaskSelect = false; - } - } - dataGridViewTask.Refresh(); - } - - private void checkBoxArrangeTask_CheckedChanged(object sender, EventArgs e) - { - if (checkBoxArrangeTask.Checked) - { - dataGridViewTask.AllowUserToAddRows = false; - - } - else - { - dataGridViewTask.AllowUserToAddRows = true; - } - } - private void dataGridViewTask_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { + + + if (checkBoxArrangeTask.Checked) { // start "drag" handle with mouse left click @@ -500,8 +584,12 @@ namespace SSH_Test RowToDrag = e.RowIndex; // start to catch "drag" dataGridViewTask.DoDragDrop(dataGridViewTask.Rows[e.RowIndex], DragDropEffects.Move); - + // move focus to Dropped Cell + dataGridViewTask.CurrentCell = dataGridViewTask.Rows[RowToDrop].Cells[e.ColumnIndex]; + dataGridViewTask.Rows[RowToDrop].Cells[e.ColumnIndex].Selected = true; + return; + } } @@ -511,7 +599,7 @@ namespace SSH_Test if (e.Button == MouseButtons.Right) { - //select the firt cell of the row if click is at the first cell of the row + //select the first cell of the row if (e.RowIndex >= 0) { @@ -540,7 +628,7 @@ namespace SSH_Test } } } - + private void dataGridViewTask_DragEnter(object sender, DragEventArgs e) { if (checkBoxArrangeTask.Checked) @@ -556,6 +644,7 @@ namespace SSH_Test } } + private void dataGridViewTask_DragDrop(object sender, DragEventArgs e) { if (checkBoxArrangeTask.Checked) @@ -564,8 +653,9 @@ namespace SSH_Test { Point clientPoint = dataGridViewTask.PointToClient(new Point(e.X, e.Y)); DataGridView.HitTestInfo hitpoint = dataGridViewTask.HitTest(clientPoint.X, clientPoint.Y); + - if (hitpoint.Type == DataGridViewHitTestType.Cell || hitpoint.Type == DataGridViewHitTestType.RowHeader) + if (hitpoint.Type == DataGridViewHitTestType.Cell) { RowToDrop = hitpoint.RowIndex; @@ -579,14 +669,9 @@ namespace SSH_Test // move Task in Tasks cTask data = Tasks[RowToDrag]; Tasks.RemoveAt(RowToDrag); - Tasks.Insert(RowToDrop, data); + Tasks.Insert(RowToDrop, data); - // move focus to Dropped Cell - dataGridViewTask.ClearSelection(); - dataGridViewTask.CurrentCell = dataGridViewTask.Rows[RowToDrop].Cells[hitpoint.ColumnIndex]; - dataGridViewTask.Rows[RowToDrop].Cells[hitpoint.ColumnIndex].Selected = true; // regenerate Task Num - RegenerateTaskNum(); } } @@ -597,7 +682,7 @@ namespace SSH_Test private void MoveToolStripMenuItem_Click(object sender, EventArgs e) { - checkBoxArrangeTask.Checked = true; + checkBoxArrangeTask.Checked = !checkBoxArrangeTask.Checked; } private void DeleteToolStripMenuItem_Click(object sender, EventArgs e) @@ -608,8 +693,8 @@ namespace SSH_Test if ( MessageBox.Show(string.Format("Remove Task: {0} ?", dataGridViewTask.CurrentRow.Cells[0].Value), "Confirm to Delete Task", MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes) { - dataGridViewTask.Rows.RemoveAt(dataGridViewTask.CurrentRow.Index); Tasks.RemoveAt(dataGridViewTask.CurrentRow.Index); + dataGridViewTask.Rows.RemoveAt(dataGridViewTask.CurrentRow.Index); dataGridViewTask.Refresh(); RegenerateTaskNum(); } @@ -627,8 +712,53 @@ namespace SSH_Test } } - private void buttonDeleteSelected_Click(object sender, EventArgs e) + private void buttonAESString_Click(object sender, EventArgs e) { + //Get or show current AES String + var dictionary = new Dictionary(); + dictionary.Add("AES string", Convert.ToBase64String(aes.Key)); + FormParameters formParameter = new FormParameters(dictionary, richTextBoxOutput.Text, + string.Format("{0}: {1}", "EAS String", "Edit to update with a different EAS String")); + + + if (formParameter.ShowDialog() == DialogResult.Cancel) + { + log.Info("AES formParameter returns with Cancel"); + } + else + { + try + { + aes.Key = Convert.FromBase64String(formParameter.dParameters["AES string"]); + + //try reloading profile.json + Profiles.Clear(); + Profiles = utilities.LoadProfile("profile.json", aes); + // 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(); + } + catch + { + log.Error("Cannot load AES key"); + } + } } } diff --git a/TastList.resx b/TastList.resx index 0d3158a..ac56254 100644 --- a/TastList.resx +++ b/TastList.resx @@ -144,6 +144,15 @@ True + + 188, 17 + + + 359, 17 + + + 457, 17 + diff --git a/Utilities.cs b/Utilities.cs index bcd9938..9ef063d 100644 --- a/Utilities.cs +++ b/Utilities.cs @@ -1,13 +1,19 @@ using log4net; using log4net.Core; using Renci.SshNet; +using Renci.SshNet.Security; using SSH_Test; using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; +using System.Globalization; using System.IO; using System.Linq; +using System.Management.Automation; //for powershell +using System.Collections.ObjectModel; + +using System.Security.Cryptography; using System.Text; using System.Text.Json; using System.Text.Json.Serialization; @@ -15,6 +21,9 @@ using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using System.Xml.Linq; +using Microsoft.Win32.SafeHandles; +using System.Diagnostics.Eventing.Reader; namespace SSH_Test { @@ -25,16 +34,17 @@ namespace SSH_Test public Utilities(ILog Log) { log = Log; + } - public static string RunaTask(cTask currentTask, Profile profile, cConInfo conInfo) + public static string RunaTask(cTask currentTask, Profile profile, cConInfo conInfo, Aes aes) { string result = "-------------------------------------------------------------------------\n"; - result += string.Format("{0:s} Task: {1}, profile: {2} \n", DateTime.Now, currentTask.sTaskDescription, currentTask.sProfile); + result += string.Format("{0:s} Task {1}: {2}, profile: {3} \n", DateTime.Now, currentTask.iTaskNum, currentTask.sTaskDescription, currentTask.sProfile); result += "-------------------------------------------------------------------------\n"; cHostInfo hostInfo = new cHostInfo(); log.Info(string.Format("Run task: {0}, profile: {1}", currentTask.sTaskDescription, currentTask.sProfile)); - + //foreach (var c in currentTask.dParameters) // log.Info(string.Format("Parameter {0}: {1}", c.Key, c.Value)); @@ -44,11 +54,11 @@ namespace SSH_Test hostInfo.host = currentTask.dParameters["{IP Address}"]; hostInfo.username = currentTask.dParameters["{User Name}"]; hostInfo.password = currentTask.dParameters["{Password}"]; - hostInfo.device = currentTask.sTaskDevice.ToString(); + hostInfo.device = currentTask.sTaskDevice.ToString(); hostInfo.dParameters = new Dictionary(); hostInfo.Commands = profile.ProfileCommands; - + try { @@ -67,7 +77,7 @@ namespace SSH_Test break; case "SSH_Catalyst": - + hostInfo.host = currentTask.dParameters["{IP Address}"]; hostInfo.username = currentTask.dParameters["{User Name}"]; hostInfo.password = currentTask.dParameters["{Password}"]; @@ -120,7 +130,7 @@ namespace SSH_Test string tempfile = DateTime.Now.ToString().Replace(":", "").Replace(" ", "") + ".txt"; process.StartInfo.Arguments = command + " " + c; - + process.Start(); string temp = process.StandardOutput.ReadToEnd(); log.Info(string.Format("From RAC9 {0}: {1}", currentTask.sTaskDevice.ToString(), result)); @@ -194,7 +204,7 @@ namespace SSH_Test StreamWriter si = process.StandardInput; si.Write("\n"); string temp = sr.ReadToEnd(); - + log.Info(string.Format("From CMD {0}: {1}", currentTask.sTaskDevice.ToString(), temp)); result += temp; @@ -242,78 +252,158 @@ namespace SSH_Test log.Info(command); - - Process process = new Process(); - process.StartInfo.FileName = "powershell"; - process.StartInfo.UseShellExecute = false; // Required for 'runas' verb - process.StartInfo.Verb = "runas"; // Request administrator privileges - process.StartInfo.RedirectStandardOutput = true; - string folderPathPS = Environment.CurrentDirectory + "\\PS\\"; - process.StartInfo.WorkingDirectory = folderPathPS; // current working dir - - log.Info(process.StartInfo.WorkingDirectory); - // check if Powershell Script folder "PS" exists, if not , create one. - if (!Directory.Exists(folderPathPS)) + + using (PowerShell ps = PowerShell.Create()) { - Directory.CreateDirectory(folderPathPS); - log.Info(string.Format("Cound not find folder PS, create new {0}", folderPathPS)); - - } - - - - try - { - // will create temporary ps script file from command for better compatibility - - string tempfile = Path.GetRandomFileName() + ".ps1"; - if (command.Contains("-File") || command.Contains("-file")) { - // command contains "-File" for running a script, do nothing - command = "-NoProfile -ExecutionPolicy Bypass " + command; + // command contains "-File" for running a script, check if file was encrypted with USI prefix. + string PSPath = Environment.CurrentDirectory + "\\PS\\"; + //contruct the path, remove -File|-file from command: + string pattern = "-file"; + command = command.Replace("\"",""); + PSPath += Regex.Replace(command, pattern, "", RegexOptions.IgnoreCase).Trim(); + + try + { + string data = File.ReadAllText(PSPath); + //check if PS file is encrypted + if (data.Contains("Unified Systems Inc.")) + { + byte[] bData = File.ReadAllBytes(PSPath); + string ddata = DecryptStringFromBytes(bData,aes.Key); + ps.AddScript(ddata); + } + else + { + result += " Cannot open Powershell script file."; + } + } + catch { + log.Error(string.Format("Failed to open PS file at: {0}", PSPath)); + } + + } else { - //create ps script file from command - try - { - File.WriteAllText(".\\PS\\" + tempfile, command); - } - catch - { - log.Error(string.Format("Cannot create or write temporary Powershell script file {0}", tempfile)); - } - command = string.Format("-NoProfile -ExecutionPolicy Bypass -File {0}", tempfile); + // FOR more detailed output, uncommend the below + //ps.AddScript(string.Format("{0}|OUt-String",command)); + //Comment the below if the above is used. + ps.AddScript(command); } - //log.Info(string.Format(command)); - process.StartInfo.Arguments = command; - process.Start(); - string temp = process.StandardOutput.ReadToEnd(); - log.Info(string.Format("From Powershell {0}: {1}", currentTask.sTaskDevice.ToString(), temp)); - result += temp; + Collection results = ps.Invoke(); - process.WaitForExit(); - try + + foreach (PSObject Item in results) { - File.Delete(".\\PS\\" + tempfile); - log.Info(string.Format("Deleted temporary PS file: ", tempfile)); + if (Item != null) + { + // Access the underlying object for its actual value + result += string.Format("{0} \n", Item.ToString()); + } + } - catch (Exception ex) + + // Check for errors + if (ps.Streams.Error.Count > 0) { - log.Error(string.Format("Cannot delete temporary PS file: ", tempfile)); - log.Error(ex); + log.Error("\nErrors encountered:"); + foreach (ErrorRecord error in ps.Streams.Error) + { + + log.Error(error.ToString()); + result += string.Format("Failed to execute \n {0}", error.ToString()); + } } } - catch (Win32Exception ex) - { - log.Error(ex); - } + + ////////////////// OLD - NEED TO REWRITE TO WORK WITH ENCRYPTED PS SCRIPTS 20260223 //////////////// + + //Process process = new Process(); + //process.StartInfo.FileName = "powershell"; + //process.StartInfo.UseShellExecute = false; // Required for 'runas' verb + //process.StartInfo.Verb = "runas"; // Request administrator privileges + //process.StartInfo.RedirectStandardOutput = true; + //string folderPathPS = Environment.CurrentDirectory + "\\PS\\"; + //process.StartInfo.WorkingDirectory = folderPathPS; // current working dir + + //log.Info(process.StartInfo.WorkingDirectory); + + + //// 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)); + + //} + + + //try + //{ + //// // will create temporary ps script file from command for better compatibility + + //// string tempfile = Path.GetRandomFileName() + ".ps1"; + + //// if (command.Contains("-File") || command.Contains("-file")) + //// { + //// // command contains "-File" for running a script, do nothing + //// command = "-NoProfile -ExecutionPolicy Bypass " + command; + //// } + //// else + //// { + //// //create ps script file from command + //// try + //// { + //// File.WriteAllText(".\\PS\\" + tempfile, command); + //// } + //// catch + //// { + //// log.Error(string.Format("Cannot create or write temporary Powershell script file {0}", tempfile)); + //// } + //// command = string.Format("-NoProfile -ExecutionPolicy Bypass -File {0}", tempfile); + + //// } + //// //log.Info(string.Format(command)); + //// process.StartInfo.Arguments = command; + + //// process.Start(); + //// string temp = process.StandardOutput.ReadToEnd(); + + + // //log.Info(string.Format("From Powershell {0}: {1}", currentTask.sTaskDevice.ToString(), temp)); + // //result += temp; + + // //process.WaitForExit(); + // //try + // //{ + // // File.Delete(".\\PS\\" + tempfile); + // // log.Info(string.Format("Deleted temporary PS file: ", tempfile)); + // //} + + + // //catch (Exception ex) + // //{ + // // log.Error(string.Format("Cannot delete temporary PS file: ", tempfile)); + // // log.Error(ex); + // //} + + + //} + //catch (Win32Exception ex) + //{ + // log.Error(ex); + + //} + + + i++; } break; @@ -572,7 +662,7 @@ namespace SSH_Test } //Seriallize Tasklist to a Json file - public void SaveTasklist(List data, string filePath) + public void SaveTasklist(List data, string filePath, Aes aes) { JsonSerializerOptions options = new JsonSerializerOptions { @@ -585,10 +675,11 @@ namespace SSH_Test }; string jsonString = JsonSerializer.Serialize(data, options); - File.WriteAllText(filePath, jsonString); + + File.WriteAllBytes(filePath, EncryptStringAES(jsonString,aes.Key)); } //Deseriallize Tasklist from a Json file - public List LoadTaskList(string filePath) + public List LoadTaskList(string filePath, Aes aes) { JsonSerializerOptions options = new JsonSerializerOptions { @@ -605,17 +696,39 @@ namespace SSH_Test { try { - string jsonString = File.ReadAllText(filePath); - log.Info("Process tasklist.json"); - + + log.Info(string.Format("Try loading {0}", filePath)); + string jsonString = ""; + + if (File.Exists(filePath)) + { + try + { + //read json data from file + byte[] bData = File.ReadAllBytes(filePath); - return JsonSerializer.Deserialize>(jsonString,options); - log.Info("Process tasklist.json"); + //decrypt data and save to file + + jsonString = DecryptStringFromBytes(bData, aes.Key); + + } + catch (Exception ex) + { + //could not read tasklist.json properly + log.Error(string.Format("Could not load {0} for decrypting", filePath)); + log.Error(ex); + } + + + } + + + return JsonSerializer.Deserialize>(jsonString, options); } catch (Exception ex) { //could not read tasklist.json properly - log.Error("Could not load tasklist.json"); + log.Error(string.Format("Could not load {0}", filePath)); log.Error(ex); //return an empty list if file could not be read @@ -640,15 +753,31 @@ namespace SSH_Test //Deseriallize Profile from a Json file - public List LoadProfile(string filePath) + public List LoadProfile(string filePath, Aes aes) { if (File.Exists(filePath)) { try { - string jsonString = File.ReadAllText(filePath); - log.Info("Process tasklist.json"); + string jsonString = ""; + try + { + //read json data from file + byte[] bData = File.ReadAllBytes(filePath); + + //decrypt data and save to file + + jsonString = DecryptStringFromBytes(bData, aes.Key); + + } + catch (Exception ex) + { + //could not read tasklist.json properly + log.Error(string.Format("Could not load {0} for decrypting", filePath)); + log.Error(ex); + } + log.Info("Process profile.json"); return JsonSerializer.Deserialize>(jsonString); } catch (Exception ex) @@ -666,10 +795,110 @@ namespace SSH_Test } return new List(); // Return an empty list if file doesn't exist } + + //Encrypt a file with AES, append "Unified Systems Inc." + IV at the beginning of the file + public static byte[] EncryptStringAES(string sData, byte[] key) + { + // Check arguments + if (sData == null || sData.Length <= 0) + throw new ArgumentNullException(nameof(sData)); + if (key == null || key.Length <= 0) + throw new ArgumentNullException(nameof(Key)); + + byte[] encrypted ; + byte[] USI = Encoding.UTF8.GetBytes("Unified Systems Inc."); + Aes aes = Aes.Create(); + + aes.Key = key; + // Create an encryptor. + ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV); + + // Use streams for encryption. + using (MemoryStream msEncrypt = new MemoryStream()) + { + using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) + { + using (StreamWriter swEncrypt = new StreamWriter(csEncrypt)) + { + // Write all data to the stream. + swEncrypt.Write(sData); + } + + encrypted = msEncrypt.ToArray(); + } + } + + + //return encrypted data with USI + IV at the beginning + byte[] USIIV = USI.Concat(aes.IV).ToArray(); + return USIIV.Concat(encrypted).ToArray(); + } + + + //Decrypt a file with AES, with "Unified Systems Inc." + IV at the beginning of the file + public static string DecryptStringFromBytes(byte[] eDdata, byte[] Key) + { + // Check arguments. + if (eDdata == null || eDdata.Length <= 0) + throw new ArgumentNullException(nameof(eDdata)); + if (Key == null || Key.Length <= 0) + throw new ArgumentNullException(nameof(Key)); + + //extract IV and remove USI + IV + byte[] IV = new byte[16]; + byte[] USI = Encoding.UTF8.GetBytes("Unified Systems Inc."); + byte[] USIIV = USI.Concat(IV).ToArray(); + + + Array.Copy(eDdata, 0, USIIV, 0, USIIV.Length); + Array.Copy(USIIV,USI.Length,IV, 0, IV.Length); + + //remove USIIV from bData: + + int dataLength = eDdata.Length - USIIV.Length; + byte[] bdatanoIV = new byte[dataLength]; + + Array.Copy(eDdata, USIIV.Length, bdatanoIV, 0, dataLength); + + + // Declare the string used to hold the decrypted text. + string sData = null; + + using (Aes aes = Aes.Create()) + { + aes.Key = Key; + aes.IV = IV; + + // Create a decryptor to perform the stream transform. + ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV); + + // Create the streams used for decryption. + using (MemoryStream msDecrypt = new MemoryStream(bdatanoIV)) + { + using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) + { + using (StreamReader srDecrypt = new StreamReader(csDecrypt)) + { + + // Read the decrypted bytes from the decrypting stream + // and place them in a string. + sData = srDecrypt.ReadToEnd(); + } + } + } + } + + return sData; + } + + + + + + } - - public class cHostInfo + public class cHostInfo { public string device { get; set; } public string host { get; set; } diff --git a/bin/Debug/SSH_Test.exe b/bin/Debug/SSH_Test.exe index d68f755..4b7907f 100644 Binary files a/bin/Debug/SSH_Test.exe and b/bin/Debug/SSH_Test.exe differ diff --git a/bin/Debug/SSH_Test.exe.config b/bin/Debug/SSH_Test.exe.config index bbb4072..1b52a61 100644 --- a/bin/Debug/SSH_Test.exe.config +++ b/bin/Debug/SSH_Test.exe.config @@ -1,13 +1,10 @@  - - - - + @@ -25,6 +22,10 @@ + + + + \ No newline at end of file diff --git a/bin/Debug/SSH_Test.pdb b/bin/Debug/SSH_Test.pdb index 9d3e70b..e7eb86c 100644 Binary files a/bin/Debug/SSH_Test.pdb and b/bin/Debug/SSH_Test.pdb differ diff --git a/bin/Debug/profile.json b/bin/Debug/profile.json index ac5b1b2..0d634c0 100644 Binary files a/bin/Debug/profile.json and b/bin/Debug/profile.json differ diff --git a/bin/Debug/tasklist - Copy.json b/bin/Debug/tasklist - Copy.json index c70ba3c..28600d8 100644 --- a/bin/Debug/tasklist - Copy.json +++ b/bin/Debug/tasklist - Copy.json @@ -1,187 +1,6 @@ [ { "iTaskNum": 1, - "sTaskDescription": "Bios enable Power on AC Recovery", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "RAC9_ACPwrRcvry_On", - "dParameters": {} - }, - { - "iTaskNum": 2, - "sTaskDescription": "Change HostName", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "Change Hostname", - "dParameters": { - "{New Host Name}": "" - } - }, - { - "iTaskNum": 3, - "sTaskDescription": "Reboot by IDRAC", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "RAC9_Commit_Changes_reboot_NOW", - "dParameters": {} - }, - { - "iTaskNum": 4, - "sTaskDescription": "Server have 2nd power supply?", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "RAC9_PS_status_dual", - "dParameters": {} - }, - { - "iTaskNum": 5, - "sTaskDescription": "10GB ports", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "RAC9_networkinterfaces", - "dParameters": {} - }, - { - "iTaskNum": 6, - "sTaskDescription": "OS", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "CMD_OS_name", - "dParameters": {} - }, - { - "iTaskNum": 7, - "sTaskDescription": "GPU", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "Powershell_VideoController", - "dParameters": {} - }, - { - "iTaskNum": 8, - "sTaskDescription": "Power redundancy", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "RAC9_Power_redundancy", - "dParameters": {} - }, - { - "iTaskNum": 9, - "sTaskDescription": "Raid volume check", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "RAC9_storage_vdisks", - "dParameters": {} - }, - { - "iTaskNum": 10, - "sTaskDescription": "Windows Activation Status", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "CMD_Windows_Activation_status", - "dParameters": {} - }, - { - "iTaskNum": 11, - "sTaskDescription": "Avigilon Version", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "CMD_Avigilon_Version", - "dParameters": {} - }, - { - "iTaskNum": 12, - "sTaskDescription": "Get Network Interface Name", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "Powershell_Get_NetworkInterface", - "dParameters": {} - }, - { - "iTaskNum": 13, - "sTaskDescription": "Create NIC team for Cameras", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "Powershell_NetworkInterface_Team_LACP_Dynamic", - "dParameters": { - "{Team Name}": "", - "{NIC1}": "", - "{NIC2}": "" - } - }, - { - "iTaskNum": 14, - "sTaskDescription": "Create 2 Windows Admins", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "CMD_Add_Local_2_Admin_Users", - "dParameters": { - "{Local Admin User 1}": "", - "{Password 1}": "", - "{Local Admin User 2}": "", - "{Password 2}": "" - } - }, - { - "iTaskNum": 15, - "sTaskDescription": "IDRAC Assigned IP address", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "RAC9_IDRAC_Assign_IP_Network_Interface", - "dParameters": { - "{IP Address}": "", - "{Network Mask}": "", - "{Gateway}": "" - } - }, - { - "iTaskNum": 16, - "sTaskDescription": "IDRAC Set User Password root, 3,4", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "RAC9_IDRAC_Configure_Users_at_234", - "dParameters": { - "{Password 2 root}": "", - "{Username 3}": "", - "{Password 3}": "", - "{Username 4}": "", - "{Password 4}": "" - } - }, - { - "iTaskNum": 17, - "sTaskDescription": "Firewall", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "Powershell_Firewall Rule", - "dParameters": {} - }, - { - "iTaskNum": 18, - "sTaskDescription": "ACC Antivirus Exclusions", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "Powershell_ACC8 Antivirus Exclusions", - "dParameters": {} - }, - { - "iTaskNum": 19, - "sTaskDescription": "Folder Options", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "Powershell_Folder Options", - "dParameters": {} - }, - { - "iTaskNum": 20, - "sTaskDescription": "Power Options", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "Powershell_Power Options", - "dParameters": {} - }, - { - "iTaskNum": 21, "sTaskDescription": "Remote Desktop Enable", "sTaskDevice": "", "bTaskSelect": false, @@ -189,24 +8,223 @@ "dParameters": {} }, { - "iTaskNum": 22, - "sTaskDescription": "Windows Update Restart", + "iTaskNum": 2, + "sTaskDescription": "Bios enable Power on AC Recovery", "sTaskDevice": "", "bTaskSelect": false, - "sProfile": "Powershell_Windows Update Restart", + "sProfile": "RAC9_ACPwrRcvry_On", + "dParameters": {} + }, + { + "iTaskNum": 3, + "sTaskDescription": "Change HostName", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "Change Hostname", + "dParameters": { + "{New Host Name}": "dfghdfhdfgh" + } + }, + { + "iTaskNum": 4, + "sTaskDescription": "Create 2 Windows Admins", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "CMD_Add_Local_2_Admin_Users", + "dParameters": { + "{Local Admin User 1}": "USI-Admin", + "{Password 1}": "", + "{Local Admin User 2}": "SIGA-Admin", + "{Password 2}": "" + } + }, + { + "iTaskNum": 5, + "sTaskDescription": "Reboot by IDRAC", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "RAC9_Commit_Changes_reboot_NOW", + "dParameters": {} + }, + { + "iTaskNum": 6, + "sTaskDescription": "Get Service Tag", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "RAC9_IDRAC_Get_ServiceTag", + "dParameters": {} + }, + { + "iTaskNum": 7, + "sTaskDescription": "Server have 2nd power supply?", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "RAC9_PS_status_dual", + "dParameters": {} + }, + { + "iTaskNum": 8, + "sTaskDescription": "10GB ports", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "RAC9_networkinterfaces", + "dParameters": {} + }, + { + "iTaskNum": 9, + "sTaskDescription": "OS", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "CMD_OS_name", + "dParameters": {} + }, + { + "iTaskNum": 10, + "sTaskDescription": "GPU", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "Powershell_VideoController", + "dParameters": {} + }, + { + "iTaskNum": 11, + "sTaskDescription": "Power redundancy", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "RAC9_Power_redundancy", + "dParameters": {} + }, + { + "iTaskNum": 12, + "sTaskDescription": "Raid volume check", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "RAC9_storage_vdisks", + "dParameters": {} + }, + { + "iTaskNum": 13, + "sTaskDescription": "Windows Activation Status", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "CMD_Windows_Activation_status", + "dParameters": {} + }, + { + "iTaskNum": 14, + "sTaskDescription": "Avigilon Version", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "CMD_Avigilon_Version", + "dParameters": {} + }, + { + "iTaskNum": 15, + "sTaskDescription": "Get Network Interface Name", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "Powershell_Get_NetworkInterface", + "dParameters": {} + }, + { + "iTaskNum": 16, + "sTaskDescription": "Create NIC team for Cameras", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "Powershell_NetworkInterface_Team_LACP_Dynamic", + "dParameters": { + "{Team Name}": "Camera Lan", + "{NIC1}": "Integrated NIC 1 Port 1-1", + "{NIC2}": "Integrated NIC 1 Port 2-1" + } + }, + { + "iTaskNum": 17, + "sTaskDescription": "IDRAC Assigned IP address", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "RAC9_IDRAC_Assign_IP_Network_Interface", + "dParameters": { + "{IP Address}": "192.168.39.2", + "{Network Mask}": "255.255.255.0", + "{Gateway}": "192.168.39.1" + } + }, + { + "iTaskNum": 18, + "sTaskDescription": "IDRAC Set User Password root, 3,4", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "RAC9_IDRAC_Configure_Users_at_234", + "dParameters": { + "{Password 2 root}": "", + "{Username 3}": "USI-Admin", + "{Password 3}": "", + "{Username 4}": "SIGA-Admin", + "{Password 4}": "" + } + }, + { + "iTaskNum": 19, + "sTaskDescription": "Firewall", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "Powershell_Firewall Rule", + "dParameters": {} + }, + { + "iTaskNum": 20, + "sTaskDescription": "ACC Antivirus Exclusions", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "Powershell_ACC8 Antivirus Exclusions", + "dParameters": {} + }, + { + "iTaskNum": 21, + "sTaskDescription": "Folder Options", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "Powershell_Folder Options", + "dParameters": {} + }, + { + "iTaskNum": 22, + "sTaskDescription": "Power Options", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "Powershell_Power Options", "dParameters": {} }, { "iTaskNum": 23, - "sTaskDescription": "Show network Interface names, using CMD", + "sTaskDescription": "Show network Interface names, using CMD ", "sTaskDevice": "", "bTaskSelect": false, "sProfile": "CMD_Show_NetworkInterfaces", - "dParameters": {} + "dParameters": { + "{P00}": "", + "{P01}": "", + "{P02}": "", + "{P03}": "" + } }, { "iTaskNum": 24, - "sTaskDescription": "Assign an IPv4 address to an interface", + "sTaskDescription": "Assign an IPv4 address to an interface Camera Lan", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "CMD_Assign_IPv4Address", + "dParameters": { + "{Name of Interface}": "LAN 1 (Workstation)", + "{IP Address}": "192.168.38.41", + "{Net mask}": "255.255.255.0", + "{Gateway}": "192.168.38.1" + } + }, + { + "iTaskNum": 25, + "sTaskDescription": "Assign an IPv4 address to an interface Workstation", "sTaskDevice": "", "bTaskSelect": false, "sProfile": "CMD_Assign_IPv4Address", @@ -218,11 +236,59 @@ } }, { - "iTaskNum": 25, - "sTaskDescription": "Get Service Tag", + "iTaskNum": 26, + "sTaskDescription": "Enable ScreenSaver for current user", "sTaskDevice": "", "bTaskSelect": false, - "sProfile": "RAC9_IDRAC_Get_ServiceTag", + "sProfile": "CMD_ScreenSaver", + "dParameters": {} + }, + { + "iTaskNum": 27, + "sTaskDescription": "Install Foxit Reader", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "CMD_Install_FoxitReader", + "dParameters": {} + }, + { + "iTaskNum": 28, + "sTaskDescription": "Set timezone to SK Canada Central Standard -6", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "CMD_Timezone_CanCentralStandardTime_6", + "dParameters": {} + }, + { + "iTaskNum": 29, + "sTaskDescription": "IPv6 Disable All", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "CMD_Ipv6_Disable_ALL", + "dParameters": { + "{P00}": "", + "{P01}": "", + "{P02}": "", + "{P03}": "" + } + }, + { + "iTaskNum": 30, + "sTaskDescription": "Install Meinberg ntp-4.2.8p", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "CMD_Meinberg ntp-4.2.8", + "dParameters": { + "{IP Address 1}": "", + "{IP Address 2}": "" + } + }, + { + "iTaskNum": 31, + "sTaskDescription": "Windows Update Restart", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "Powershell_Windows Update Restart", "dParameters": {} } ] \ No newline at end of file diff --git a/bin/Debug/tasklist.json b/bin/Debug/tasklist.json index 298b0e3..aa820dd 100644 Binary files a/bin/Debug/tasklist.json and b/bin/Debug/tasklist.json differ diff --git a/packages.config b/packages.config index dfce748..9efe4b4 100644 --- a/packages.config +++ b/packages.config @@ -2,13 +2,16 @@ - + + + - + + diff --git a/profile.json b/profile.json index ac5b1b2..3be3e8a 100644 --- a/profile.json +++ b/profile.json @@ -1,8 +1,8 @@ [ { "ProfileName": "Do nothing", - "ProfileType": "CMD", - "ProfileCommands": ["Do nothing" + "ProfileType": "", + "ProfileCommands": [ ], "ProfileParameters": [ "{P00}", @@ -332,6 +332,26 @@ "ProfileParameters": [] }, + { + "ProfileName": "CMD_Install_TeamViewer.msi", + "ProfileType": "CMD", + "ProfileCommands": [ + "C:\\USI\\Apps\\TeamViewer.msi /qn", + "winget list --disable-interactivity --accept-source-agreements| FINDSTR /i \"TeamViewer\"" + ], + "ProfileParameters": [] + }, + + { + "ProfileName": "CMD_ShowAllSoftwareVersion", + "ProfileType": "CMD", + "ProfileCommands": [ + + "winget list --disable-interactivity --accept-source-agreements " + ], + "ProfileParameters": [] + }, + { "ProfileName": "CMD_Timezone_CanCentralStandardTime_6", "ProfileType": "CMD", diff --git a/tasklist.json b/tasklist.json index 298b0e3..b1a9a26 100644 --- a/tasklist.json +++ b/tasklist.json @@ -1,6 +1,14 @@ [ { "iTaskNum": 1, + "sTaskDescription": "Remote Desktop Enable", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "Powershell_Remote Desktop Enable", + "dParameters": {} + }, + { + "iTaskNum": 2, "sTaskDescription": "Bios enable Power on AC Recovery", "sTaskDevice": "", "bTaskSelect": false, @@ -8,7 +16,7 @@ "dParameters": {} }, { - "iTaskNum": 2, + "iTaskNum": 3, "sTaskDescription": "Change HostName", "sTaskDevice": "", "bTaskSelect": false, @@ -18,63 +26,68 @@ } }, { - "iTaskNum": 3, + "iTaskNum": 4, + "sTaskDescription": "Create 2 Windows Admins", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "CMD_Add_Local_2_Admin_Users", + "dParameters": { + "{Local Admin User 1}": "USI-Admin", + "{Password 1}": "", + "{Local Admin User 2}": "SIGA-Admin", + "{Password 2}": "" + } + }, + { + "iTaskNum": 5, "sTaskDescription": "Reboot by IDRAC", "sTaskDevice": "", "bTaskSelect": false, "sProfile": "RAC9_Commit_Changes_reboot_NOW", "dParameters": {} }, - { - "iTaskNum": 4, - "sTaskDescription": "Server have 2nd power supply?", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "RAC9_PS_status_dual", - "dParameters": {} - }, - { - "iTaskNum": 5, - "sTaskDescription": "OS", - "sTaskDevice": "", - "bTaskSelect": true, - "sProfile": "CMD_OS_name", - "dParameters": {} - }, { "iTaskNum": 6, - "sTaskDescription": "10GB ports", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "RAC9_networkinterfaces", - "dParameters": {} - }, - { - "iTaskNum": 7, - "sTaskDescription": "GPU", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "Powershell_VideoController", - "dParameters": {} - }, - { - "iTaskNum": 8, - "sTaskDescription": "Windows Activation Status", - "sTaskDevice": "", - "bTaskSelect": true, - "sProfile": "CMD_Windows_Activation_status", - "dParameters": {} - }, - { - "iTaskNum": 9, "sTaskDescription": "Get Service Tag", "sTaskDevice": "", "bTaskSelect": false, "sProfile": "RAC9_IDRAC_Get_ServiceTag", "dParameters": {} }, + { + "iTaskNum": 7, + "sTaskDescription": "Server have 2nd power supply?", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "RAC9_PS_status_dual", + "dParameters": {} + }, + { + "iTaskNum": 8, + "sTaskDescription": "10GB ports", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "RAC9_networkinterfaces", + "dParameters": {} + }, + { + "iTaskNum": 9, + "sTaskDescription": "OS", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "CMD_OS_name", + "dParameters": {} + }, { "iTaskNum": 10, + "sTaskDescription": "GPU", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "Powershell_VideoController", + "dParameters": {} + }, + { + "iTaskNum": 11, "sTaskDescription": "Power redundancy", "sTaskDevice": "", "bTaskSelect": false, @@ -82,7 +95,7 @@ "dParameters": {} }, { - "iTaskNum": 11, + "iTaskNum": 12, "sTaskDescription": "Raid volume check", "sTaskDevice": "", "bTaskSelect": false, @@ -90,7 +103,15 @@ "dParameters": {} }, { - "iTaskNum": 12, + "iTaskNum": 13, + "sTaskDescription": "Windows Activation Status", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "CMD_Windows_Activation_status", + "dParameters": {} + }, + { + "iTaskNum": 14, "sTaskDescription": "Avigilon Version", "sTaskDevice": "", "bTaskSelect": false, @@ -98,7 +119,7 @@ "dParameters": {} }, { - "iTaskNum": 13, + "iTaskNum": 15, "sTaskDescription": "Get Network Interface Name", "sTaskDevice": "", "bTaskSelect": false, @@ -106,58 +127,45 @@ "dParameters": {} }, { - "iTaskNum": 14, + "iTaskNum": 16, "sTaskDescription": "Create NIC team for Cameras", "sTaskDevice": "", "bTaskSelect": false, "sProfile": "Powershell_NetworkInterface_Team_LACP_Dynamic", "dParameters": { - "{Team Name}": "fgdhdf", - "{NIC1}": "dfghdfgh", - "{NIC2}": "fdghfdgh" + "{Team Name}": "Camera Lan", + "{NIC1}": "Integrated NIC 1 Port 1-1", + "{NIC2}": "Integrated NIC 1 Port 2-1" } }, { - "iTaskNum": 15, - "sTaskDescription": "Create 2 Windows Admins", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "CMD_Add_Local_2_Admin_Users", - "dParameters": { - "{Local Admin User 1}": "", - "{Password 1}": "", - "{Local Admin User 2}": "", - "{Password 2}": "" - } - }, - { - "iTaskNum": 16, + "iTaskNum": 17, "sTaskDescription": "IDRAC Assigned IP address", "sTaskDevice": "", "bTaskSelect": false, "sProfile": "RAC9_IDRAC_Assign_IP_Network_Interface", "dParameters": { - "{IP Address}": "", - "{Network Mask}": "", - "{Gateway}": "" + "{IP Address}": "192.168.39.2", + "{Network Mask}": "255.255.255.0", + "{Gateway}": "192.168.39.1" } }, { - "iTaskNum": 17, + "iTaskNum": 18, "sTaskDescription": "IDRAC Set User Password root, 3,4", "sTaskDevice": "", "bTaskSelect": false, "sProfile": "RAC9_IDRAC_Configure_Users_at_234", "dParameters": { "{Password 2 root}": "", - "{Username 3}": "", + "{Username 3}": "USI-Admin", "{Password 3}": "", - "{Username 4}": "", + "{Username 4}": "SIGA-Admin", "{Password 4}": "" } }, { - "iTaskNum": 18, + "iTaskNum": 19, "sTaskDescription": "Firewall", "sTaskDevice": "", "bTaskSelect": false, @@ -165,7 +173,7 @@ "dParameters": {} }, { - "iTaskNum": 19, + "iTaskNum": 20, "sTaskDescription": "ACC Antivirus Exclusions", "sTaskDevice": "", "bTaskSelect": false, @@ -173,7 +181,7 @@ "dParameters": {} }, { - "iTaskNum": 20, + "iTaskNum": 21, "sTaskDescription": "Folder Options", "sTaskDevice": "", "bTaskSelect": false, @@ -181,7 +189,7 @@ "dParameters": {} }, { - "iTaskNum": 21, + "iTaskNum": 22, "sTaskDescription": "Power Options", "sTaskDevice": "", "bTaskSelect": false, @@ -189,40 +197,47 @@ "dParameters": {} }, { - "iTaskNum": 22, - "sTaskDescription": "Show network Interface names, using CMD", + "iTaskNum": 23, + "sTaskDescription": "Show network Interface names, using CMD ", "sTaskDevice": "", "bTaskSelect": false, "sProfile": "CMD_Show_NetworkInterfaces", - "dParameters": {} - }, - { - "iTaskNum": 23, - "sTaskDescription": "Remote Desktop Enable", - "sTaskDevice": "", - "bTaskSelect": false, - "sProfile": "Powershell_Remote Desktop Enable", - "dParameters": {} + "dParameters": { + "{P00}": "", + "{P01}": "", + "{P02}": "", + "{P03}": "" + } }, { "iTaskNum": 24, - "sTaskDescription": "Windows Update Restart", + "sTaskDescription": "Assign an IPv4 address to an interface Camera Lan", "sTaskDevice": "", "bTaskSelect": false, - "sProfile": "Powershell_Windows Update Restart", - "dParameters": {} + "sProfile": "CMD_Assign_IPv4Address", + "dParameters": { + "{Name of Interface}": "LAN 1 (Workstation)", + "{IP Address}": "192.168.38.41", + "{Net mask}": "255.255.255.0", + "{Gateway}": "192.168.38.1" + } }, { "iTaskNum": 25, - "sTaskDescription": "IPv06 disable All", + "sTaskDescription": "Assign an IPv4 address to an interface Workstation", "sTaskDevice": "", "bTaskSelect": false, - "sProfile": "CMD_Ipv6_Disable_ALL", - "dParameters": {} + "sProfile": "CMD_Assign_IPv4Address", + "dParameters": { + "{Name of Interface}": "", + "{IP Address}": "", + "{Net mask}": "", + "{Gateway}": "" + } }, { "iTaskNum": 26, - "sTaskDescription": "Screen Saver for USI-Admin", + "sTaskDescription": "Enable ScreenSaver for current user", "sTaskDevice": "", "bTaskSelect": false, "sProfile": "CMD_ScreenSaver", @@ -230,15 +245,66 @@ }, { "iTaskNum": 27, - "sTaskDescription": "hgkghk", + "sTaskDescription": "Install Foxit Reader", "sTaskDevice": "", "bTaskSelect": false, - "sProfile": "Powershell_Assign_IPv4Address", + "sProfile": "CMD_Install_FoxitReader", + "dParameters": {} + }, + { + "iTaskNum": 28, + "sTaskDescription": "Set timezone to SK Canada Central Standard -6", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "CMD_Timezone_CanCentralStandardTime_6", + "dParameters": {} + }, + { + "iTaskNum": 29, + "sTaskDescription": "IPv6 Disable All", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "CMD_Ipv6_Disable_ALL", "dParameters": { - "{Name of Interface}": "", - "{IP Address}": "", - "{PrefixLength}": "", - "{Gateway}": "" + "{P00}": "", + "{P01}": "", + "{P02}": "", + "{P03}": "" } + }, + { + "iTaskNum": 30, + "sTaskDescription": "Install Meinberg ntp-4.2.8p", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "CMD_Meinberg ntp-4.2.8", + "dParameters": { + "{IP Address 1}": "", + "{IP Address 2}": "" + } + }, + { + "iTaskNum": 31, + "sTaskDescription": "Windows Update Restart", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "Powershell_Windows Update Restart", + "dParameters": {} + }, + { + "iTaskNum": 32, + "sTaskDescription": "Install Teamviewer 15", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "CMD_Install_TeamViewer.msi", + "dParameters": {} + }, + { + "iTaskNum": 33, + "sTaskDescription": "Show all software version", + "sTaskDevice": "", + "bTaskSelect": false, + "sProfile": "CMD_ShowAllSoftwareVersion", + "dParameters": {} } ] \ No newline at end of file