Improve certificate path probing with demo UNC target and remove Sonic container scan.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using ZA.CoreService.ESBCertificateManager.Models;
|
||||
using ZA.CoreService.ESBCertificateManager.Services;
|
||||
|
||||
namespace ZA.CoreService.ESBCertificateManager.Setup;
|
||||
|
||||
@@ -381,9 +382,7 @@ public sealed class SetupWizardForm : Form
|
||||
|
||||
Panel toolbar = CreateToolbar(
|
||||
"+ Container hinzufügen",
|
||||
async () => await AddContainerAsync(),
|
||||
secondaryText: "Von Sonic scannen",
|
||||
onSecondary: async () => await ScanContainersForSelectedSystemAsync());
|
||||
async () => await AddContainerAsync());
|
||||
|
||||
_lvContainers = SettingsUi.CreateListView();
|
||||
_lvContainers.Dock = DockStyle.Fill;
|
||||
@@ -400,20 +399,22 @@ public sealed class SetupWizardForm : Form
|
||||
{
|
||||
_panelPaths = CreateContentPanel(
|
||||
"Zertifikat-Pfade",
|
||||
"Zielverzeichnisse und Dateinamen für Deployments.");
|
||||
"Dateipfade (UNC/lokal) zum Austausch. Container = nur Neustart-Ziel.");
|
||||
|
||||
Panel toolbar = CreateToolbar(
|
||||
"+ Pfad hinzufügen",
|
||||
async () => await AddPathAsync());
|
||||
async () => await AddPathAsync(),
|
||||
"Pfad prüfen",
|
||||
async () => await ProbeSelectedPathAsync());
|
||||
|
||||
_lvPaths = SettingsUi.CreateListView();
|
||||
_lvPaths.Dock = DockStyle.Fill;
|
||||
_lvPaths.Columns.Add("Company", 70);
|
||||
_lvPaths.Columns.Add("Container", 140);
|
||||
_lvPaths.Columns.Add("Verzeichnis", 280);
|
||||
_lvPaths.Columns.Add("Datei", 120);
|
||||
_lvPaths.Columns.Add("Neustart-Container", 140);
|
||||
_lvPaths.Columns.Add("Zertifikat-Pfad", 360);
|
||||
_lvPaths.Columns.Add("Ablauf", 140);
|
||||
_lvPaths.Columns.Add("Backup", 80);
|
||||
_lvPaths.Columns.Add("System", 140);
|
||||
_lvPaths.Columns.Add("System", 120);
|
||||
|
||||
FinishPanelLayout(_panelPaths, _lvPaths, toolbar);
|
||||
}
|
||||
@@ -644,13 +645,14 @@ public sealed class SetupWizardForm : Form
|
||||
await _coordinator.LoadCertificateTargetsAsync();
|
||||
|
||||
_lvPaths.Items.Clear();
|
||||
CertificateProbeService probe = new();
|
||||
|
||||
foreach (CertificateTargetOption target in targets)
|
||||
{
|
||||
ListViewItem item = new(target.CompanyCode);
|
||||
item.SubItems.Add(target.ContainerName);
|
||||
item.SubItems.Add(target.TargetDirectory);
|
||||
item.SubItems.Add(target.TargetFileName);
|
||||
item.SubItems.Add(target.FullTargetPath);
|
||||
item.SubItems.Add("…");
|
||||
item.SubItems.Add(
|
||||
target.BackupEnabled
|
||||
? target.BackupDirectoryName
|
||||
@@ -658,6 +660,11 @@ public sealed class SetupWizardForm : Form
|
||||
item.SubItems.Add(target.ConnectionName);
|
||||
item.Tag = target;
|
||||
_lvPaths.Items.Add(item);
|
||||
|
||||
CertificateProbeResult result = await Task.Run(
|
||||
() => probe.Probe(target.FullTargetPath));
|
||||
|
||||
item.SubItems[3].Text = FormatProbeExpiry(result);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -666,6 +673,110 @@ public sealed class SetupWizardForm : Form
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ProbeSelectedPathAsync()
|
||||
{
|
||||
if (_lvPaths.SelectedItems.Count == 0
|
||||
|| _lvPaths.SelectedItems[0].Tag is not CertificateTargetOption target)
|
||||
{
|
||||
MessageBox.Show(
|
||||
this,
|
||||
"Bitte zuerst einen Zertifikat-Pfad in der Liste wählen.",
|
||||
"Pfad prüfen",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
CertificateProbeService probe = new();
|
||||
CertificateProbeResult result = probe.Probe(
|
||||
target.FullTargetPath,
|
||||
() => PromptCertificatePassword(this));
|
||||
|
||||
_lvPaths.SelectedItems[0].SubItems[3].Text =
|
||||
FormatProbeExpiry(result);
|
||||
|
||||
MessageBoxIcon icon = result.Success && result.Certificate is not null
|
||||
? (result.Certificate.IsCurrentlyValid
|
||||
? MessageBoxIcon.Information
|
||||
: MessageBoxIcon.Warning)
|
||||
: MessageBoxIcon.Warning;
|
||||
|
||||
MessageBox.Show(
|
||||
this,
|
||||
result.Message + "\n\n" + target.FullTargetPath,
|
||||
"Pfad prüfen",
|
||||
MessageBoxButtons.OK,
|
||||
icon);
|
||||
}
|
||||
|
||||
private static string FormatProbeExpiry(CertificateProbeResult result)
|
||||
{
|
||||
if (result.Success && result.Certificate is not null)
|
||||
{
|
||||
return result.Certificate.ValidUntil
|
||||
.ToLocalTime()
|
||||
.ToString("dd.MM.yyyy HH:mm");
|
||||
}
|
||||
|
||||
if (result.FileExists)
|
||||
{
|
||||
return "Kennwort nötig";
|
||||
}
|
||||
|
||||
return result.Success ? "fehlt" : "n/a";
|
||||
}
|
||||
|
||||
private static string? PromptCertificatePassword(IWin32Window owner)
|
||||
{
|
||||
using Form dialog = new()
|
||||
{
|
||||
Text = "PFX/P12-Kennwort",
|
||||
FormBorderStyle = FormBorderStyle.FixedDialog,
|
||||
StartPosition = FormStartPosition.CenterParent,
|
||||
ClientSize = new Size(360, 140),
|
||||
MaximizeBox = false,
|
||||
MinimizeBox = false,
|
||||
ShowInTaskbar = false,
|
||||
BackColor = SettingsUi.Background,
|
||||
ForeColor = SettingsUi.Text
|
||||
};
|
||||
|
||||
Label label = new()
|
||||
{
|
||||
Text = "Kennwort für die Zertifikatsdatei:",
|
||||
Location = new Point(16, 16),
|
||||
AutoSize = true
|
||||
};
|
||||
|
||||
TextBox txtPwd = new()
|
||||
{
|
||||
Location = new Point(16, 44),
|
||||
Width = 320,
|
||||
UseSystemPasswordChar = true
|
||||
};
|
||||
|
||||
Button btnOk = SettingsUi.CreatePrimaryButton("OK");
|
||||
btnOk.Location = new Point(196, 90);
|
||||
btnOk.Size = new Size(140, 32);
|
||||
btnOk.DialogResult = DialogResult.OK;
|
||||
|
||||
Button btnCancel = SettingsUi.CreateGhostButton("Abbrechen");
|
||||
btnCancel.Location = new Point(100, 90);
|
||||
btnCancel.Size = new Size(90, 32);
|
||||
btnCancel.DialogResult = DialogResult.Cancel;
|
||||
|
||||
dialog.Controls.Add(label);
|
||||
dialog.Controls.Add(txtPwd);
|
||||
dialog.Controls.Add(btnOk);
|
||||
dialog.Controls.Add(btnCancel);
|
||||
dialog.AcceptButton = btnOk;
|
||||
dialog.CancelButton = btnCancel;
|
||||
|
||||
return dialog.ShowDialog(owner) == DialogResult.OK
|
||||
? txtPwd.Text
|
||||
: null;
|
||||
}
|
||||
|
||||
private async Task AddSystemAsync()
|
||||
{
|
||||
using AddSonicSystemForm dialog = new(_coordinator);
|
||||
@@ -706,78 +817,6 @@ public sealed class SetupWizardForm : Form
|
||||
"Prüfung OK",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information);
|
||||
|
||||
SonicSystemOption? createdSystem = _systems
|
||||
.FirstOrDefault(system =>
|
||||
system.SonicConnectionId == createdId);
|
||||
|
||||
if (createdSystem is null
|
||||
&& _lvSystems.SelectedItems.Count > 0)
|
||||
{
|
||||
createdSystem =
|
||||
_lvSystems.SelectedItems[0].Tag as SonicSystemOption;
|
||||
}
|
||||
|
||||
if (createdSystem is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DialogResult next = MessageBox.Show(
|
||||
this,
|
||||
"Container jetzt per Sonic-Scan oder manuell zuordnen?",
|
||||
"Container",
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question);
|
||||
|
||||
if (next != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using SelectContainersForm selectForm =
|
||||
new(_coordinator, createdSystem);
|
||||
|
||||
if (selectForm.ShowDialog(this) == DialogResult.OK)
|
||||
{
|
||||
await LoadContainersListAsync();
|
||||
await RefreshAllAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ScanContainersForSelectedSystemAsync()
|
||||
{
|
||||
SonicSystemOption? system = null;
|
||||
|
||||
if (_lvSystems.SelectedItems.Count > 0)
|
||||
{
|
||||
system = _lvSystems.SelectedItems[0].Tag as SonicSystemOption;
|
||||
}
|
||||
|
||||
system ??= _systems.FirstOrDefault();
|
||||
|
||||
if (system is null)
|
||||
{
|
||||
// Systeme-Liste ggf. nachladen
|
||||
await LoadSystemsListAsync();
|
||||
system = _systems.FirstOrDefault();
|
||||
}
|
||||
|
||||
if (system is null)
|
||||
{
|
||||
ShowWarning(
|
||||
"Bitte zuerst ein Sonic-System anlegen oder auswählen.");
|
||||
return;
|
||||
}
|
||||
|
||||
using SelectContainersForm selectForm =
|
||||
new(_coordinator, system);
|
||||
|
||||
if (selectForm.ShowDialog(this) == DialogResult.OK)
|
||||
{
|
||||
await LoadContainersListAsync();
|
||||
await RefreshAllAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task AddContainerAsync()
|
||||
|
||||
Reference in New Issue
Block a user