Harden defaults load and layout handlers
This commit is contained in:
101
certy.ps1
101
certy.ps1
@@ -129,6 +129,17 @@ function Save-Defaults {
|
|||||||
Set-Content -Path $path -Value $json -Encoding ascii
|
Set-Content -Path $path -Value $json -Encoding ascii
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Get-DefaultValue {
|
||||||
|
param(
|
||||||
|
[object]$Defaults,
|
||||||
|
[string]$Name
|
||||||
|
)
|
||||||
|
if ($null -eq $Defaults) { return $null }
|
||||||
|
$prop = $Defaults.PSObject.Properties[$Name]
|
||||||
|
if ($null -eq $prop) { return $null }
|
||||||
|
return $prop.Value
|
||||||
|
}
|
||||||
|
|
||||||
function Resolve-HostEntry {
|
function Resolve-HostEntry {
|
||||||
param(
|
param(
|
||||||
[string]$Name,
|
[string]$Name,
|
||||||
@@ -715,27 +726,61 @@ function Update-CertGenerationUI {
|
|||||||
|
|
||||||
$loadedDefaults = Load-Defaults
|
$loadedDefaults = Load-Defaults
|
||||||
if ($loadedDefaults) {
|
if ($loadedDefaults) {
|
||||||
if ($loadedDefaults.DefaultZone) { $zoneBox.Text = $loadedDefaults.DefaultZone }
|
$value = Get-DefaultValue -Defaults $loadedDefaults -Name "DefaultZone"
|
||||||
if ($loadedDefaults.TargetIp) { $ipBox.Text = $loadedDefaults.TargetIp }
|
if (-not [string]::IsNullOrWhiteSpace($value)) { $zoneBox.Text = $value }
|
||||||
if ($loadedDefaults.DnsServer) { $dnsServerBox.Text = $loadedDefaults.DnsServer }
|
|
||||||
if ($loadedDefaults.ReplicationTargets) { $replicationTargetsBox.Text = $loadedDefaults.ReplicationTargets }
|
$value = Get-DefaultValue -Defaults $loadedDefaults -Name "TargetIp"
|
||||||
if ($loadedDefaults.ReplicationCommand) { $replicationCmdBox.Text = $loadedDefaults.ReplicationCommand }
|
if (-not [string]::IsNullOrWhiteSpace($value)) { $ipBox.Text = $value }
|
||||||
if ($loadedDefaults.PSObject.Properties["ReplicationEnabled"]) {
|
|
||||||
$replicationEnabledBox.Checked = [bool]$loadedDefaults.ReplicationEnabled
|
$value = Get-DefaultValue -Defaults $loadedDefaults -Name "DnsServer"
|
||||||
}
|
if (-not [string]::IsNullOrWhiteSpace($value)) { $dnsServerBox.Text = $value }
|
||||||
if ($loadedDefaults.WacsPath) { $wacsPathBox.Text = $loadedDefaults.WacsPath }
|
|
||||||
if ($loadedDefaults.OutputPath) { $outputPathBox.Text = $loadedDefaults.OutputPath }
|
$value = Get-DefaultValue -Defaults $loadedDefaults -Name "ReplicationTargets"
|
||||||
if ($loadedDefaults.PfxPassword) { $pfxPasswordBox.Text = $loadedDefaults.PfxPassword }
|
if (-not [string]::IsNullOrWhiteSpace($value)) { $replicationTargetsBox.Text = $value }
|
||||||
if ($loadedDefaults.BaseUri) { $baseUriBox.Text = $loadedDefaults.BaseUri }
|
|
||||||
if ($loadedDefaults.Validation) { $validationBox.Text = $loadedDefaults.Validation }
|
$value = Get-DefaultValue -Defaults $loadedDefaults -Name "ReplicationCommand"
|
||||||
if ($loadedDefaults.ValidationPort) { $validationPortBox.Text = $loadedDefaults.ValidationPort }
|
if (-not [string]::IsNullOrWhiteSpace($value)) { $replicationCmdBox.Text = $value }
|
||||||
if ($null -ne $loadedDefaults.UseProvidedFqdn) { $useFqdnBox.Checked = [bool]$loadedDefaults.UseProvidedFqdn }
|
|
||||||
if ($null -ne $loadedDefaults.RunWacs) { $runWacsBox.Checked = [bool]$loadedDefaults.RunWacs }
|
$value = Get-DefaultValue -Defaults $loadedDefaults -Name "ReplicationEnabled"
|
||||||
if ($null -ne $loadedDefaults.Verbose) { $verboseBox.Checked = [bool]$loadedDefaults.Verbose }
|
if ($null -ne $value) { $replicationEnabledBox.Checked = [bool]$value }
|
||||||
if ($null -ne $loadedDefaults.PerHostCerts) { $perHostBox.Checked = [bool]$loadedDefaults.PerHostCerts }
|
|
||||||
if ($null -ne $loadedDefaults.DisableCertGeneration) { $disableCertsBox.Checked = [bool]$loadedDefaults.DisableCertGeneration }
|
$value = Get-DefaultValue -Defaults $loadedDefaults -Name "WacsPath"
|
||||||
if ($loadedDefaults.OutputType) { $outputTypeBox.SelectedItem = $loadedDefaults.OutputType }
|
if (-not [string]::IsNullOrWhiteSpace($value)) { $wacsPathBox.Text = $value }
|
||||||
|
|
||||||
|
$value = Get-DefaultValue -Defaults $loadedDefaults -Name "OutputPath"
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($value)) { $outputPathBox.Text = $value }
|
||||||
|
|
||||||
|
$value = Get-DefaultValue -Defaults $loadedDefaults -Name "PfxPassword"
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($value)) { $pfxPasswordBox.Text = $value }
|
||||||
|
|
||||||
|
$value = Get-DefaultValue -Defaults $loadedDefaults -Name "BaseUri"
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($value)) { $baseUriBox.Text = $value }
|
||||||
|
|
||||||
|
$value = Get-DefaultValue -Defaults $loadedDefaults -Name "Validation"
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($value)) { $validationBox.Text = $value }
|
||||||
|
|
||||||
|
$value = Get-DefaultValue -Defaults $loadedDefaults -Name "ValidationPort"
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($value)) { $validationPortBox.Text = $value }
|
||||||
|
|
||||||
|
$value = Get-DefaultValue -Defaults $loadedDefaults -Name "UseProvidedFqdn"
|
||||||
|
if ($null -ne $value) { $useFqdnBox.Checked = [bool]$value }
|
||||||
|
|
||||||
|
$value = Get-DefaultValue -Defaults $loadedDefaults -Name "RunWacs"
|
||||||
|
if ($null -ne $value) { $runWacsBox.Checked = [bool]$value }
|
||||||
|
|
||||||
|
$value = Get-DefaultValue -Defaults $loadedDefaults -Name "Verbose"
|
||||||
|
if ($null -ne $value) { $verboseBox.Checked = [bool]$value }
|
||||||
|
|
||||||
|
$value = Get-DefaultValue -Defaults $loadedDefaults -Name "PerHostCerts"
|
||||||
|
if ($null -ne $value) { $perHostBox.Checked = [bool]$value }
|
||||||
|
|
||||||
|
$value = Get-DefaultValue -Defaults $loadedDefaults -Name "DisableCertGeneration"
|
||||||
|
if ($null -ne $value) { $disableCertsBox.Checked = [bool]$value }
|
||||||
|
|
||||||
|
$value = Get-DefaultValue -Defaults $loadedDefaults -Name "OutputType"
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($value)) { $outputTypeBox.SelectedItem = $value }
|
||||||
if (-not $outputTypeBox.SelectedItem) { $outputTypeBox.SelectedIndex = 0 }
|
if (-not $outputTypeBox.SelectedItem) { $outputTypeBox.SelectedIndex = 0 }
|
||||||
|
|
||||||
Update-OutputTypeUI
|
Update-OutputTypeUI
|
||||||
if (Test-Path function:Update-ReplicationUI) { Update-ReplicationUI }
|
if (Test-Path function:Update-ReplicationUI) { Update-ReplicationUI }
|
||||||
Update-CertGenerationUI
|
Update-CertGenerationUI
|
||||||
@@ -1037,9 +1082,17 @@ $runBtn.Add_Click({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
[void]$form.Add_Load({ Apply-Layout })
|
[void]$form.Add_Load({
|
||||||
[void]$form.Add_Shown({ $form.BeginInvoke([Action]{ Apply-Layout }) })
|
try { Apply-Layout } catch {}
|
||||||
[void]$panel.Add_SizeChanged({ Apply-Layout })
|
})
|
||||||
[void]$form.Add_Resize({ Apply-Layout })
|
[void]$form.Add_Shown({
|
||||||
|
try { $form.BeginInvoke([Action]{ try { Apply-Layout } catch {} }) } catch {}
|
||||||
|
})
|
||||||
|
[void]$panel.Add_SizeChanged({
|
||||||
|
try { Apply-Layout } catch {}
|
||||||
|
})
|
||||||
|
[void]$form.Add_Resize({
|
||||||
|
try { Apply-Layout } catch {}
|
||||||
|
})
|
||||||
|
|
||||||
[void]$form.ShowDialog()
|
[void]$form.ShowDialog()
|
||||||
|
|||||||
Reference in New Issue
Block a user