Update parser-fetchmailrc.ps1

This commit is contained in:
Scott Sutherland 2024-10-07 08:06:14 -05:00 committed by GitHub
parent d66f9c112f
commit aaa7356409
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -45,8 +45,16 @@ function Get-PwFetchmailrc {
} }
# Extract users, passwords, server, protocol, and port # Extract users, passwords, server, protocol, and port
$cred["Username"] = [regex]::Matches($line, '\s+user(?:name)?\s+(\S+)') | ForEach-Object { $_.Groups[1].Value } $userMatch = [regex]::Match($line, '\s+user(?:name)?\s+"([^"]+)"')
$cred["Password"] = [regex]::Matches($line, '\s+pass(?:word)?\s+(\S+)') | ForEach-Object { $_.Groups[1].Value } if ($userMatch.Success) {
$cred["Username"] = $userMatch.Groups[1].Value
}
$passMatch = [regex]::Match($line, '\s+pass(?:word)?\s+"([^"]+)"')
if ($passMatch.Success) {
$cred["Password"] = $passMatch.Groups[1].Value
}
$cred["TargetServer"] = if ($line -match '^(?:poll|skip)\s+(\S+)') { $matches[1] } else { $cred["TargetServer"] } $cred["TargetServer"] = if ($line -match '^(?:poll|skip)\s+(\S+)') { $matches[1] } else { $cred["TargetServer"] }
$cred["Section"] = if ($line -match '\s+proto(?:col)?\s+(\S+)') { $matches[1] } else { $cred["Section"] } $cred["Section"] = if ($line -match '\s+proto(?:col)?\s+(\S+)') { $matches[1] } else { $cred["Section"] }
$cred["TargetPort"] = if ($line -match '\s+(?:port|service)\s+(\S+)') { $matches[1] } else { $cred["TargetPort"] } $cred["TargetPort"] = if ($line -match '\s+(?:port|service)\s+(\S+)') { $matches[1] } else { $cred["TargetPort"] }
@ -72,8 +80,7 @@ function Get-PwFetchmailrc {
} }
# Add parsed credentials if valid # Add parsed credentials if valid
if ($parsedCred["TargetServer"] -and $parsedCred["Section"] -and $parsedCred["Username"].Count -eq $parsedCred["Password"].Count) { if ($parsedCred["TargetServer"] -and $parsedCred["Section"] -and $parsedCred["Username"] -and $parsedCred["Password"]) {
for ($i = 0; $i -lt $parsedCred["Username"].Count; $i++) {
$credentials += [pscustomobject]@{ $credentials += [pscustomobject]@{
ComputerName = $ComputerName ComputerName = $ComputerName
ShareName = $ShareName ShareName = $ShareName
@ -86,14 +93,13 @@ function Get-PwFetchmailrc {
TargetPort = $parsedCred["TargetPort"] TargetPort = $parsedCred["TargetPort"]
Database = "NA" Database = "NA"
Domain = "NA" Domain = "NA"
Username = $parsedCred["Username"][$i] Username = $parsedCred["Username"]
Password = $parsedCred["Password"][$i] Password = $parsedCred["Password"]
PasswordEnc = "NA" PasswordEnc = "NA"
KeyFilePath = "NA" KeyFilePath = "NA"
} }
} }
} }
}
# Output credentials # Output credentials
if ($credentials.Count -eq 0) { if ($credentials.Count -eq 0) {