Changes to SSH including new password

This commit is contained in:
2025-10-21 14:01:27 +01:00
parent e39a36183a
commit 01268ddda5
11 changed files with 79 additions and 243 deletions

View File

@@ -35,6 +35,8 @@ namespace AiQ_GUI
try
{
string JSONdata = BuildJsonUpdate(jsonArrayData, ID);
JSONdata = JSONdata.Replace("\"14\"", "14").Replace("\"30\"", "30"); // Fixes & encoding issue
MainForm.Instance.AddToActionsList(JSONdata);
string url = $"http://{IPAddress}/api/update-config";
return await Network.SendHttpRequest(url, HttpMethod.Post, 2, JSONdata);
}

View File

@@ -10,11 +10,11 @@ namespace AiQ_GUI
internal class ImageProcessing
{
// API to get snapshot then downsize and downscale image to save size.
public static async Task<Image?> GetProcessedImage(string suffix, string IPAddress, string DevPass, string? savePath = null, PictureBox? PcBx = null, bool SaveDisplay = false)
public static async Task<Image?> GetProcessedImage(string Module, string IPAddress, string DevPass, string? savePath = null, PictureBox? PcBx = null, bool SaveDisplay = false)
{
try
{
string requestUrl = $"http://{IPAddress}/{suffix}";
string requestUrl = $"http://{IPAddress}/{Module}-snapshot";
HttpClientHandler handler = new()
{
@@ -85,7 +85,7 @@ namespace AiQ_GUI
public static async Task ImageCheck(PictureBox PicBxOV, PictureBox PicBxF2, PictureBox PicBxF16, Label LblF2, Label LblF16, Camera CamOnTest)
{
// Take OV snapshot
Task<Image?> Colour_Response = GetProcessedImage("Colour-snapshot", CamOnTest.IP, CamOnTest.DevPass, LDS.MAVPath + LDS.OVsavePath, PicBxOV, true);
Task<Image?> Colour_Response = GetProcessedImage("Colour", CamOnTest.IP, CamOnTest.DevPass, LDS.MAVPath + LDS.OVsavePath, PicBxOV, true);
// Change to wide iris F2.0
await FlexiAPI.APIHTTPVISCA(CamOnTest.IP, "8101044B00000100FF", true);
@@ -93,7 +93,7 @@ namespace AiQ_GUI
await Task.Delay(200); // Wait for iris to settle before taking IR image
// Take IR bright light image
Image? F2_Response = await GetProcessedImage("Infrared-snapshot", CamOnTest.IP, CamOnTest.DevPass, LDS.MAVPath + LDS.IROpensavePath, PicBxF2, true);
Image? F2_Response = await GetProcessedImage("Infrared", CamOnTest.IP, CamOnTest.DevPass, LDS.MAVPath + LDS.IROpensavePath, PicBxF2, true);
if (F2_Response == null)
{
MainForm.Instance.AddToActionsList("IR F2.0 image response is blank.");
@@ -106,7 +106,7 @@ namespace AiQ_GUI
await Task.Delay(200); // Wait for iris to settle before taking IR image
// Take IR low light image
Image? F16_Response = await GetProcessedImage("Infrared-snapshot", CamOnTest.IP, CamOnTest.DevPass, LDS.MAVPath + LDS.IRTightsavePath, PicBxF16, true);
Image? F16_Response = await GetProcessedImage("Infrared", CamOnTest.IP, CamOnTest.DevPass, LDS.MAVPath + LDS.IRTightsavePath, PicBxF16, true);
if (F16_Response == null)
{
MainForm.Instance.AddToActionsList("IR F16.0 image response is blank.");

View File

@@ -1,4 +1,5 @@
using Renci.SshNet;
using Renci.SshNet.Common;
namespace AiQ_GUI
{
@@ -6,6 +7,29 @@ namespace AiQ_GUI
{
public const string SSHUsername = "mav";
public const string SSHPassword = "mavPA$$";
public const string SSHPasswordNEW = "#!mavsoftMESA19"; // New password for SSH after last one got leaked
private static SshClient SshConnect(string IPAddress)
{
SshClient client = new(IPAddress, SSHUsername, SSHPasswordNEW);
try
{
client.Connect();
return client;
}
catch (SshAuthenticationException)
{
client = new(IPAddress, SSHUsername, SSHPassword);
client.Connect();
return client;
}
catch (Exception Ex)
{
MainForm.Instance.AddToActionsList($"SSH connection failed: {Ex.Message}. Check password or network.");
}
return null;
}
// Connects to camera over SSH and collects the Vaxtor packages, filesystem name, filesystem size, and tailscale status.
public static SSHData CollectSSHData(string IPAddress)
@@ -14,8 +38,7 @@ namespace AiQ_GUI
try
{
using SshClient client = new(IPAddress, SSHUsername, SSHPassword);
client.Connect();
SshClient client = SshConnect(IPAddress);
try
{
@@ -34,8 +57,7 @@ namespace AiQ_GUI
catch (Exception ex)
{
MainForm.Instance.AddToActionsList($"Failed to get filesystem info: {ex.Message}");
Data.FilesystemName = "Unknown";
Data.FilesystemSize = "Unknown";
Data.FilesystemName = Data.FilesystemSize = "Unknown";
}
try
@@ -49,6 +71,7 @@ namespace AiQ_GUI
}
client.Disconnect();
client.Dispose();
}
catch (Exception ex)
{
@@ -131,8 +154,7 @@ namespace AiQ_GUI
{
try
{
using SshClient client = new SshClient(IPAddress, SSHUsername, SSHPassword);
client.Connect();
SshClient client = SshConnect(IPAddress);
try
{
@@ -144,6 +166,7 @@ namespace AiQ_GUI
}
client.Disconnect();
client.Dispose();
}
catch (Exception ex)
{
@@ -191,10 +214,10 @@ namespace AiQ_GUI
{
try
{
using SshClient client = new(IPAddress, SSHUsername, SSHPassword);
client.Connect();
SshClient client = SshConnect(IPAddress);
(string FilesystemName, string FilesystemSize) = GetRootFilesystemInfo(client);
client.Disconnect();
client.Dispose();
return (FilesystemName, FilesystemSize);
}
catch (Exception ex)
@@ -207,19 +230,19 @@ namespace AiQ_GUI
// Checks the filesystem size and expands it if necessary, displays on the label how big the SD card is.
public static async Task<SSHData> CheckFSSize(string IPAddress, Label LblFSSize, SSHData sshData)
{
const double MinGoodSize = 100.0; // 100GB
const double MaxGoodSize = 150.0; // 150GB
const double GoodSize = 128.0; // 128GB
const double Deviation = 20.0; // ±20GB
double currentSize = NormaliseFSSize(sshData.FilesystemSize);
LblFSSize.Text = $"Filesystem Size = {currentSize}GB";
if (currentSize >= MinGoodSize && currentSize <= MaxGoodSize)
if (Math.Abs(GoodSize - currentSize) < Deviation)
{
LblFSSize.ForeColor = Color.LightGreen;
return sshData;
}
if (currentSize < MinGoodSize)
if (currentSize < GoodSize - Deviation)
{
try
{
@@ -230,7 +253,7 @@ namespace AiQ_GUI
double newSize = NormaliseFSSize(sshData.FilesystemSize);
LblFSSize.Text = $"Filesystem Size = {newSize}GB";
if (newSize >= MinGoodSize && newSize <= MaxGoodSize)
if (Math.Abs(GoodSize - newSize) < Deviation)
{
LblFSSize.ForeColor = Color.LightGreen;
return sshData;
@@ -261,10 +284,9 @@ namespace AiQ_GUI
// Extract value & unit
System.Text.RegularExpressions.Match match = RegexCache.FileSizeRegex().Match(rootSize.Trim());
if (!match.Success)
return 0;
if (!double.TryParse(match.Groups["value"].Value, out double value))
// Return 0 if no match or invalid number
if (!match.Success || !double.TryParse(match.Groups["value"].Value, out double value))
return 0;
string unit = match.Groups["unit"].Value.ToUpperInvariant();
@@ -288,15 +310,14 @@ namespace AiQ_GUI
return 0;
}
// Expands the filesystem to max
// Expands the filesystem to max
public async static Task<bool> ExpandFS(string device, string IPAddress)
{
try
{
using SshClient ssh = new SshClient(IPAddress, SSHUsername, SSHPassword);
ssh.Connect();
SshClient client = SshConnect(IPAddress);
SshCommand checkDevice = ssh.RunCommand($"[ -b {device} ] && echo OK || echo NOT_FOUND");
SshCommand checkDevice = client.RunCommand($"[ -b {device} ] && echo OK || echo NOT_FOUND");
if (!string.IsNullOrWhiteSpace(checkDevice.Error))
throw new Exception(checkDevice.Error);
@@ -306,7 +327,7 @@ namespace AiQ_GUI
return false;
}
SshCommand umountCmd = ssh.RunCommand($"sudo umount {device}");
SshCommand umountCmd = client.RunCommand($"sudo umount {device}");
if (!string.IsNullOrWhiteSpace(umountCmd.Error) && !umountCmd.Error.Contains("not mounted"))
{
MainForm.Instance.AddToActionsList($"Unmount error: {umountCmd.Error}");
@@ -315,15 +336,16 @@ namespace AiQ_GUI
await Task.Delay(1000); // Wait for mount to settle
SshCommand fsckCmd = ssh.RunCommand($"sudo e2fsck -f -y -v -C 0 {device}");
SshCommand fsckCmd = client.RunCommand($"sudo e2fsck -f -y -v -C 0 {device}");
if (!string.IsNullOrWhiteSpace(fsckCmd.Error))
{
MainForm.Instance.AddToActionsList($"e2fsck error: {fsckCmd.Error}");
return false;
}
SshCommand resizeFs = ssh.RunCommand($"sudo resize2fs {device}");
ssh.Disconnect();
SshCommand resizeFs = client.RunCommand($"sudo resize2fs {device}");
client.Disconnect();
client.Dispose();
if (!string.IsNullOrWhiteSpace(resizeFs.Error))
{
@@ -348,10 +370,9 @@ namespace AiQ_GUI
{
try
{
using SshClient ssh = new SshClient(IPAddress, SSHUsername, SSHPassword);
ssh.Connect();
SshClient client = SshConnect(IPAddress);
SshCommand checkDevice = ssh.RunCommand("sync");
SshCommand checkDevice = client.RunCommand("sync");
if (!string.IsNullOrWhiteSpace(checkDevice.Error))
throw new Exception(checkDevice.Error);
@@ -360,6 +381,9 @@ namespace AiQ_GUI
MainForm.Instance.AddToActionsList($"Cannot sync files to disk. Replied: {checkDevice.Result}. DO NOT TURN OFF, GET SUPERVISOR");
return;
}
client.Disconnect();
client.Dispose();
}
catch (Exception ex)
{