Persist replication credentials
This commit is contained in:
58
certy.ps1
58
certy.ps1
@@ -130,6 +130,33 @@ function Save-Defaults {
|
|||||||
Set-Content -Path $path -Value $json -Encoding ascii
|
Set-Content -Path $path -Value $json -Encoding ascii
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Get-ReplicationCredentialPath {
|
||||||
|
$dir = Join-Path $env:ProgramData "Certy"
|
||||||
|
return Join-Path $dir "replication-cred.xml"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Load-ReplicationCredential {
|
||||||
|
$path = Get-ReplicationCredentialPath
|
||||||
|
if (-not (Test-Path -Path $path -PathType Leaf)) { return $null }
|
||||||
|
try {
|
||||||
|
$cred = Import-Clixml -Path $path
|
||||||
|
if ($cred -is [pscredential]) { return $cred }
|
||||||
|
} catch {
|
||||||
|
# Ignore load errors and treat as missing.
|
||||||
|
}
|
||||||
|
return $null
|
||||||
|
}
|
||||||
|
|
||||||
|
function Save-ReplicationCredential {
|
||||||
|
param([pscredential]$Credential)
|
||||||
|
$path = Get-ReplicationCredentialPath
|
||||||
|
$dir = Split-Path -Path $path -Parent
|
||||||
|
if (-not (Test-Path -Path $dir -PathType Container)) {
|
||||||
|
New-Item -Path $dir -ItemType Directory -Force | Out-Null
|
||||||
|
}
|
||||||
|
$Credential | Export-Clixml -Path $path
|
||||||
|
}
|
||||||
|
|
||||||
function Get-DefaultValue {
|
function Get-DefaultValue {
|
||||||
param(
|
param(
|
||||||
[object]$Defaults,
|
[object]$Defaults,
|
||||||
@@ -658,6 +685,14 @@ $replicationRemoteBox = Add-CheckBox "Run repadmin remotely (PowerShell)" $xInpu
|
|||||||
$replicationRemoteBox.Checked = $true
|
$replicationRemoteBox.Checked = $true
|
||||||
$y += $rowHeight + $gap
|
$y += $rowHeight + $gap
|
||||||
|
|
||||||
|
$replicationCredBtn = New-Object System.Windows.Forms.Button
|
||||||
|
$replicationCredBtn.Text = "Set Replication Credentials"
|
||||||
|
$replicationCredBtn.Location = [System.Drawing.Point]::new($xInput, $y)
|
||||||
|
$replicationCredBtn.Size = [System.Drawing.Size]::new(220, 26)
|
||||||
|
$panel.Controls.Add($replicationCredBtn)
|
||||||
|
Style-ButtonSecondary $replicationCredBtn
|
||||||
|
$y += $rowHeight + $gap
|
||||||
|
|
||||||
$y += $gap
|
$y += $gap
|
||||||
|
|
||||||
Add-SectionHeader "ACME / Output"
|
Add-SectionHeader "ACME / Output"
|
||||||
@@ -768,6 +803,7 @@ function Update-ReplicationUI {
|
|||||||
$replicationCmdBox.Enabled = $enabled
|
$replicationCmdBox.Enabled = $enabled
|
||||||
$replicationDelayBox.Enabled = $enabled
|
$replicationDelayBox.Enabled = $enabled
|
||||||
$replicationRemoteBox.Enabled = $enabled
|
$replicationRemoteBox.Enabled = $enabled
|
||||||
|
$replicationCredBtn.Enabled = $enabled
|
||||||
$dnsListBox.Enabled = $enabled
|
$dnsListBox.Enabled = $enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -898,6 +934,7 @@ function Apply-Layout {
|
|||||||
$replicationCmdBox.Width = $inputWidthCalc
|
$replicationCmdBox.Width = $inputWidthCalc
|
||||||
$replicationDelayBox.Width = $inputWidthCalc
|
$replicationDelayBox.Width = $inputWidthCalc
|
||||||
$replicationRemoteBox.Width = $inputWidthCalc
|
$replicationRemoteBox.Width = $inputWidthCalc
|
||||||
|
$replicationCredBtn.Width = [Math]::Min($inputWidthCalc, 260)
|
||||||
$wacsPathBox.Width = $inputWidthCalc
|
$wacsPathBox.Width = $inputWidthCalc
|
||||||
$outputTypeBox.Width = $inputWidthCalc
|
$outputTypeBox.Width = $inputWidthCalc
|
||||||
$outputPathBox.Width = $inputWidthCalc
|
$outputPathBox.Width = $inputWidthCalc
|
||||||
@@ -1035,6 +1072,16 @@ $outputTypeBox.Add_SelectedIndexChanged({
|
|||||||
Update-OutputTypeUI
|
Update-OutputTypeUI
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$replicationCredBtn.Add_Click({
|
||||||
|
$cred = Get-Credential -Message "Enter credentials for replication sessions."
|
||||||
|
if (-not $cred) {
|
||||||
|
& $logAction "Replication credentials not set."
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Save-ReplicationCredential -Credential $cred
|
||||||
|
& $logAction "Replication credentials saved for this user."
|
||||||
|
})
|
||||||
|
|
||||||
$hostsBox.Add_TextChanged({
|
$hostsBox.Add_TextChanged({
|
||||||
Update-ZoneFromHostInput
|
Update-ZoneFromHostInput
|
||||||
})
|
})
|
||||||
@@ -1139,10 +1186,15 @@ $runBtn.Add_Click({
|
|||||||
}
|
}
|
||||||
$replicationCredential = $null
|
$replicationCredential = $null
|
||||||
if ($replicationRemoteBox.Checked) {
|
if ($replicationRemoteBox.Checked) {
|
||||||
$replicationCredential = Get-Credential -Message "Enter credentials for replication targets."
|
$replicationCredential = Load-ReplicationCredential
|
||||||
if (-not $replicationCredential) {
|
if (-not $replicationCredential) {
|
||||||
& $logAction "Replication canceled: credentials not provided."
|
$replicationCredential = Get-Credential -Message "Enter credentials for replication targets."
|
||||||
return
|
if (-not $replicationCredential) {
|
||||||
|
& $logAction "Replication canceled: credentials not provided."
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Save-ReplicationCredential -Credential $replicationCredential
|
||||||
|
& $logAction "Replication credentials saved for this user."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Invoke-Replication -Servers $replicationTargets -Command $replicationCmdBox.Text -UseRemote $replicationRemoteBox.Checked -Credential $replicationCredential -Log $logAction
|
Invoke-Replication -Servers $replicationTargets -Command $replicationCmdBox.Text -UseRemote $replicationRemoteBox.Checked -Credential $replicationCredential -Log $logAction
|
||||||
|
|||||||
Reference in New Issue
Block a user