load different profile.json

fix bugs relating to profile loading
This commit is contained in:
AnD
2026-04-15 18:05:45 -06:00
parent f07fe51193
commit fdfca14fb3
9 changed files with 114 additions and 29 deletions

View File

@@ -1,4 +1,4 @@
namespace SSH_Test namespace FHT
{ {
partial class FormConfiguration partial class FormConfiguration
{ {
@@ -41,14 +41,17 @@
this.label5 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label();
this.textBoxTftpIP = new System.Windows.Forms.TextBox(); this.textBoxTftpIP = new System.Windows.Forms.TextBox();
this.groupBox3 = new System.Windows.Forms.GroupBox(); this.groupBox3 = new System.Windows.Forms.GroupBox();
this.groupBox5 = new System.Windows.Forms.GroupBox();
this.buttonProfilePath = new System.Windows.Forms.Button();
this.groupBox4 = new System.Windows.Forms.GroupBox(); this.groupBox4 = new System.Windows.Forms.GroupBox();
this.buttonTasklistDec = new System.Windows.Forms.Button(); this.buttonTasklistDec = new System.Windows.Forms.Button();
this.buttonTasklistEnc = new System.Windows.Forms.Button(); this.buttonTasklistEnc = new System.Windows.Forms.Button();
this.buttonEncryptTaskList = new System.Windows.Forms.Button(); this.buttonEncryptTaskList = new System.Windows.Forms.Button();
this.openFileDialogTasklist = new System.Windows.Forms.OpenFileDialog(); this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout(); this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout(); this.groupBox3.SuspendLayout();
this.groupBox5.SuspendLayout();
this.groupBox4.SuspendLayout(); this.groupBox4.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
@@ -154,6 +157,7 @@
// //
// groupBox3 // groupBox3
// //
this.groupBox3.Controls.Add(this.groupBox5);
this.groupBox3.Controls.Add(this.groupBox4); this.groupBox3.Controls.Add(this.groupBox4);
this.groupBox3.Controls.Add(this.buttonEncryptTaskList); this.groupBox3.Controls.Add(this.buttonEncryptTaskList);
this.groupBox3.Location = new System.Drawing.Point(307, 12); this.groupBox3.Location = new System.Drawing.Point(307, 12);
@@ -161,7 +165,27 @@
this.groupBox3.Size = new System.Drawing.Size(240, 177); this.groupBox3.Size = new System.Drawing.Size(240, 177);
this.groupBox3.TabIndex = 6; this.groupBox3.TabIndex = 6;
this.groupBox3.TabStop = false; this.groupBox3.TabStop = false;
this.groupBox3.Text = "Encryption"; this.groupBox3.Text = "Profile && Encryption";
//
// groupBox5
//
this.groupBox5.Controls.Add(this.buttonProfilePath);
this.groupBox5.Location = new System.Drawing.Point(8, 87);
this.groupBox5.Name = "groupBox5";
this.groupBox5.Size = new System.Drawing.Size(200, 54);
this.groupBox5.TabIndex = 10;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "Profile Path";
//
// buttonProfilePath
//
this.buttonProfilePath.Location = new System.Drawing.Point(15, 18);
this.buttonProfilePath.Name = "buttonProfilePath";
this.buttonProfilePath.Size = new System.Drawing.Size(163, 29);
this.buttonProfilePath.TabIndex = 9;
this.buttonProfilePath.Text = "profile.json";
this.buttonProfilePath.UseVisualStyleBackColor = true;
this.buttonProfilePath.Click += new System.EventHandler(this.buttonProfilePath_Click);
// //
// groupBox4 // groupBox4
// //
@@ -203,12 +227,12 @@
this.buttonEncryptTaskList.Text = "Encrypt"; this.buttonEncryptTaskList.Text = "Encrypt";
this.buttonEncryptTaskList.UseVisualStyleBackColor = true; this.buttonEncryptTaskList.UseVisualStyleBackColor = true;
// //
// openFileDialogTasklist // openFileDialog
// //
this.openFileDialogTasklist.DefaultExt = "json"; this.openFileDialog.DefaultExt = "json";
this.openFileDialogTasklist.FileName = "tasklisk.json"; this.openFileDialog.FileName = "*.json";
this.openFileDialogTasklist.Filter = "json file|*.json|Powershell scrips|*.ps1"; this.openFileDialog.Filter = "json file|*.json|Powershell scrips|*.ps1";
this.openFileDialogTasklist.Title = "Task list file"; this.openFileDialog.Title = "File Path";
// //
// FormConfiguration // FormConfiguration
// //
@@ -228,6 +252,7 @@
this.groupBox2.ResumeLayout(false); this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout(); this.groupBox2.PerformLayout();
this.groupBox3.ResumeLayout(false); this.groupBox3.ResumeLayout(false);
this.groupBox5.ResumeLayout(false);
this.groupBox4.ResumeLayout(false); this.groupBox4.ResumeLayout(false);
this.ResumeLayout(false); this.ResumeLayout(false);
@@ -251,6 +276,8 @@
private System.Windows.Forms.GroupBox groupBox4; private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.Button buttonTasklistDec; private System.Windows.Forms.Button buttonTasklistDec;
private System.Windows.Forms.Button buttonTasklistEnc; private System.Windows.Forms.Button buttonTasklistEnc;
private System.Windows.Forms.OpenFileDialog openFileDialogTasklist; private System.Windows.Forms.OpenFileDialog openFileDialog;
private System.Windows.Forms.Button buttonProfilePath;
private System.Windows.Forms.GroupBox groupBox5;
} }
} }

View File

@@ -12,7 +12,7 @@ using System.Windows.Forms;
using System.IO; using System.IO;
using System.Security.Cryptography; using System.Security.Cryptography;
namespace SSH_Test namespace FHT
{ {
public partial class FormConfiguration : Form public partial class FormConfiguration : Form
{ {
@@ -29,15 +29,17 @@ namespace SSH_Test
public static ILog log; public static ILog log;
public FormConfiguration(string tftp_IP, string sftpIP, string sftp_Username, string sftp_Password, bool bencryption public FormConfiguration(string tftp_IP, string sftpIP, string sftp_Username, string sftp_Password, bool bencryption
, Aes aaes, ILog Log) , Aes aaes, string sprofilepath, ILog Log)
{ {
InitializeComponent(); InitializeComponent();
this.textBoxTftpIP.Text = Tftp_IP = tftp_IP; this.textBoxTftpIP.Text = Tftp_IP = tftp_IP;
this.textBoxSftpIP.Text = Sftp_IP = sftpIP; this.textBoxSftpIP.Text = Sftp_IP = sftpIP;
this.textBoxSftpUsername.Text = Sftp_Username = sftp_Username; this.textBoxSftpUsername.Text = Sftp_Username = sftp_Username;
this.textBoxSftpPassword.Text = Sftp_Password = sftp_Password; this.textBoxSftpPassword.Text = Sftp_Password = sftp_Password;
buttonProfilePath.Text = sProfilePath = sprofilepath;
aes = aaes; aes = aaes;
log = Log; log = Log;
this.Update(); this.Update();
} }
@@ -66,10 +68,10 @@ namespace SSH_Test
private void buttonTasklistEnc_Click(object sender, EventArgs e) private void buttonTasklistEnc_Click(object sender, EventArgs e)
{ {
Utilities utilities = new Utilities(log); Utilities utilities = new Utilities(log);
if (openFileDialogTasklist.ShowDialog() == DialogResult.OK) if (openFileDialog.ShowDialog() == DialogResult.OK)
{ {
string Jsonfilename = openFileDialogTasklist.FileName; string Jsonfilename = openFileDialog.FileName;
string buttonTasklistPath = openFileDialogTasklist.SafeFileName; string buttonTasklistPath = openFileDialog.SafeFileName;
if (File.Exists(Jsonfilename)) if (File.Exists(Jsonfilename))
{ {
try try
@@ -99,10 +101,10 @@ namespace SSH_Test
private void buttonTasklistDec_Click(object sender, EventArgs e) private void buttonTasklistDec_Click(object sender, EventArgs e)
{ {
Utilities utilities = new Utilities(log); Utilities utilities = new Utilities(log);
if (openFileDialogTasklist.ShowDialog() == DialogResult.OK) if (openFileDialog.ShowDialog() == DialogResult.OK)
{ {
string JsonFileName = openFileDialogTasklist.FileName; string JsonFileName = openFileDialog.FileName;
string buttonTasklistPath = openFileDialogTasklist.SafeFileName; string buttonTasklistPath = openFileDialog.SafeFileName;
if (File.Exists(JsonFileName)) if (File.Exists(JsonFileName))
{ {
try try
@@ -126,5 +128,14 @@ namespace SSH_Test
} }
} }
} }
private void buttonProfilePath_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
sProfilePath = openFileDialog.FileName;
buttonProfilePath.Text = openFileDialog.SafeFileName;
}
}
} }
} }

View File

@@ -117,7 +117,7 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="openFileDialogTasklist.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>17, 17</value>
</metadata> </metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

View File

@@ -27,14 +27,14 @@ using System.Windows.Forms;
using System.Xml; using System.Xml;
using static System.Windows.Forms.VisualStyles.VisualStyleElement; using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace SSH_Test namespace FHT
{ {
public partial class TastList : Form public partial class TastList : Form
{ {
// set to false to enable Encrypt , Decrypt Buttons // set to false to enable Encrypt , Decrypt Buttons
public const bool IsAdminDisabled = true; public const bool IsAdminDisabled = false;
public List<cTask> Tasks = new List<cTask>(); public List<cTask> Tasks = new List<cTask>();
@@ -133,8 +133,12 @@ namespace SSH_Test
dataGridViewTask.AllowDrop = true; dataGridViewTask.AllowDrop = true;
dataGridViewTask.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText; dataGridViewTask.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
dataGridViewTask.RowTemplate.ContextMenuStrip = contextMenuStripRow; dataGridViewTask.RowTemplate.ContextMenuStrip = contextMenuStripRow;
//Load Profile list from "profile.json"
Profiles = utilities.LoadProfile("profile.json", aes); //ask for AES key
buttonAESString_Click(null, null);
//Load Profile list from "Profilefilename"
Profiles = utilities.LoadProfile(Profilefilename, aes);
// Configure Profile list to dropdown menu // Configure Profile list to dropdown menu
// AES button will update the dropdown menu when AES key is inputed. // AES button will update the dropdown menu when AES key is inputed.
@@ -316,10 +320,12 @@ namespace SSH_Test
row.Cells[1].Value = task.sTaskDescription; row.Cells[1].Value = task.sTaskDescription;
row.Cells[2].Value = task.sTaskDevice; row.Cells[2].Value = task.sTaskDevice;
row.Cells[4].Value = task.bTaskSelect; row.Cells[4].Value = task.bTaskSelect;
var comboBoxColumn = (DataGridViewComboBoxColumn)dataGridViewTask.Columns[7]; // var comboBoxColumn = (DataGridViewComboBoxColumn)dataGridViewTask.Columns[7];
// test if task.sprofile name mach any in Profiles, if true, assign that name // test if task.sprofile name mach any in Profiles, if true, assign that name
if (Profiles.Any(pr => pr.ProfileName == task.sProfile)) if (Profiles.Any(pr => pr.ProfileName == task.sProfile))
row.Cells[7].Value = task.sProfile; row.Cells[7].Value = task.sProfile;
else
row.Cells[7].Value = null;
dataGridViewTask.Rows.Add(row); dataGridViewTask.Rows.Add(row);
} }
catch (Exception ex) catch (Exception ex)
@@ -335,18 +341,49 @@ namespace SSH_Test
{ {
FormConfiguration formConfiguration = new FormConfiguration(conInfo.sTftpIP, conInfo.sSftpIP, FormConfiguration formConfiguration = new FormConfiguration(conInfo.sTftpIP, conInfo.sSftpIP,
conInfo.sSftpUsername, conInfo.sSftpPassword, conInfo.sSftpUsername, conInfo.sSftpPassword,
bEncryption, aes, log); bEncryption, aes, Profilefilename,log);
// Disable Encrypt, Decrypt buttons // Disable Encrypt, Decrypt buttons
if(IsAdminDisabled) if(IsAdminDisabled)
{ {
formConfiguration.AdminDisable(); formConfiguration.AdminDisable();
} }
formConfiguration.ShowDialog(); formConfiguration.ShowDialog();
//reload profile and task list
Profilefilename = formConfiguration.sProfilePath;
//try reloading Profilefilename
Profiles.Clear();
Profiles = utilities.LoadProfile(Profilefilename, 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);
}
//reload tasklist
buttonLoad_Click(null, null);
conInfo.sTftpIP = formConfiguration.Tftp_IP; conInfo.sTftpIP = formConfiguration.Tftp_IP;
conInfo.sSftpIP = formConfiguration.Sftp_IP; conInfo.sSftpIP = formConfiguration.Sftp_IP;
conInfo.sSftpUsername = formConfiguration.Sftp_Username; conInfo.sSftpUsername = formConfiguration.Sftp_Username;
conInfo.sSftpPassword = formConfiguration.Sftp_Password; conInfo.sSftpPassword = formConfiguration.Sftp_Password;
dataGridViewTask.Refresh();
} }
private void dataGridViewTask_CellClick(object sender, DataGridViewCellEventArgs e) private void dataGridViewTask_CellClick(object sender, DataGridViewCellEventArgs e)
@@ -753,9 +790,9 @@ namespace SSH_Test
{ {
aes.Key = Convert.FromBase64String(formParameter.dParameters["AES string"]); aes.Key = Convert.FromBase64String(formParameter.dParameters["AES string"]);
//try reloading profile.json //try reloading Profilefilename
Profiles.Clear(); Profiles.Clear();
Profiles = utilities.LoadProfile("profile.json", aes); Profiles = utilities.LoadProfile(Profilefilename, aes);
// Configure Profile list to dropdown menu // Configure Profile list to dropdown menu
try try
{ {
@@ -782,6 +819,9 @@ namespace SSH_Test
} }
} }
//reload tasklist
buttonLoad_Click(null, null);
} }
} }

BIN
bin/Debug/FHT.exe Normal file

Binary file not shown.

BIN
bin/Debug/FHT.pdb Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -417,7 +417,10 @@
"ProfileCommands": [ "ProfileCommands": [
"racadm set iDRAC.Users.{Index}.Username {Username}", "racadm set iDRAC.Users.{Index}.Username {Username}",
"racadm set iDRAC.Users.{Index}.Password {Password}", "racadm set iDRAC.Users.{Index}.Password {Password}",
"racadm get iDRAC.Users.{Index}.Username" "racadm get iDRAC.Users.{Index}.Username",
"racadm set iDRAC.Users.{Index}.Enable 1",
"racadm set iDRAC.Users.{Index}.IpmiLanPriv 4"
], ],
"ProfileParameters": [ "{Index}", "{Username}", "{Password}" ] "ProfileParameters": [ "{Index}", "{Username}", "{Password}" ]
}, },
@@ -433,7 +436,11 @@
"racadm set iDRAC.Users.4.Password {Password 4}", "racadm set iDRAC.Users.4.Password {Password 4}",
"racadm get iDRAC.Users.2.Username", "racadm get iDRAC.Users.2.Username",
"racadm get iDRAC.Users.3.Username", "racadm get iDRAC.Users.3.Username",
"racadm get iDRAC.Users.4.Username" "racadm get iDRAC.Users.4.Username",
"racadm set iDRAC.Users.3.Enable 1",
"racadm set iDRAC.Users.3.IpmiLanPriv 4",
"racadm set iDRAC.Users.4.Enable 1",
"racadm set iDRAC.Users.4.IpmiLanPriv 4"
], ],
"ProfileParameters": [ "ProfileParameters": [
"{Password 2 root}", "{Password 2 root}",