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,25 +80,23 @@ 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 UncFilePath = $UncFilePath
UncFilePath = $UncFilePath FileName = $FileName
FileName = $FileName Section = $parsedCred["Section"]
Section = $parsedCred["Section"] ObjectName = "NA"
ObjectName = "NA" TargetURL = $TargetURL
TargetURL = $TargetURL TargetServer = $parsedCred["TargetServer"]
TargetServer = $parsedCred["TargetServer"] TargetPort = $parsedCred["TargetPort"]
TargetPort = $parsedCred["TargetPort"] Database = "NA"
Database = "NA" Domain = "NA"
Domain = "NA" Username = $parsedCred["Username"]
Username = $parsedCred["Username"][$i] Password = $parsedCred["Password"]
Password = $parsedCred["Password"][$i] PasswordEnc = "NA"
PasswordEnc = "NA" KeyFilePath = "NA"
KeyFilePath = "NA"
}
} }
} }
} }