Changes to SSH including new password
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user