Skip to content

Commit 38c4374

Browse files
Merge pull request #1354 from kris6673/spoof-warn
Feat: AllowList functionality to SpoofWarn standard
2 parents 9976aff + 32c0719 commit 38c4374

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardSpoofWarn.ps1

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ function Invoke-CIPPStandardSpoofWarn {
4242

4343
# Get state value using null-coalescing operator
4444
$state = $Settings.state.value ?? $Settings.state
45+
$AllowListAdd = $Settings.AllowListAdd.value ?? $Settings.AllowListAdd
46+
47+
# Test if all entries in the AllowListAdd variable are in the AllowList
48+
$AllowListCorrect = $true
49+
$AllowListAddEntries = foreach ($entry in $AllowListAdd) {
50+
if ($CurrentInfo.AllowList -notcontains $entry) {
51+
$AllowListCorrect = $false
52+
Write-Host "AllowList entry $entry not found in current AllowList"
53+
$entry
54+
} else {
55+
Write-Host "AllowList entry $entry found in current AllowList."
56+
}
57+
}
58+
$AllowListAdd = @{'@odata.type' = '#Exchange.GenericHashTable'; Add = $AllowListAddEntries }
59+
60+
# Debug output
61+
# Write-Host ($CurrentInfo | ConvertTo-Json -Depth 10)
62+
# Write-Host ($AllowListAdd | ConvertTo-Json -Depth 10)
4563

4664
# Input validation
4765
if (([string]::IsNullOrWhiteSpace($state) -or $state -eq 'Select a value') -and ($Settings.remediate -eq $true -or $Settings.alert -eq $true)) {
@@ -50,22 +68,37 @@ function Invoke-CIPPStandardSpoofWarn {
5068
}
5169

5270
If ($Settings.remediate -eq $true) {
71+
Write-Host 'Time to remediate!'
5372
$status = if ($Settings.enable -and $Settings.disable) {
5473
# Handle pre standards v2.0 legacy settings when this was 2 separate standards
5574
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'You cannot both enable and disable the Spoof Warnings setting' -sev Error
5675
Return
5776
} elseif ($state -eq 'enabled' -or $Settings.enable) { $true } else { $false }
5877

59-
if ($CurrentInfo.Enabled -eq $status) {
60-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Outlook external spoof warnings are already set to $status." -sev Info
61-
} else {
62-
try {
78+
try {
79+
if ($CurrentInfo.Enabled -eq $status -and $AllowListCorrect -eq $true) {
80+
# Status correct, AllowList correct
81+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Outlook external spoof warnings are already set to $status and the AllowList is correct." -sev Info
82+
83+
} elseif ($CurrentInfo.Enabled -eq $status -and $AllowListCorrect -eq $false) {
84+
# Status correct, AllowList incorrect
85+
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-ExternalInOutlook' -cmdParams @{ AllowList = $AllowListAdd; }
86+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Outlook external spoof warnings already set to $status. Added $($AllowListAdd.Add -join ', ') to the AllowList." -sev Info
87+
88+
} elseif ($CurrentInfo.Enabled -ne $status -and $AllowListCorrect -eq $false) {
89+
# Status incorrect, AllowList incorrect
90+
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-ExternalInOutlook' -cmdParams @{ Enabled = $status; AllowList = $AllowListAdd; }
91+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Outlook external spoof warnings set to $status. Added $($AllowListAdd.Add -join ', ') to the AllowList." -sev Info
92+
93+
} else {
94+
# Status incorrect, AllowList correct
6395
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-ExternalInOutlook' -cmdParams @{ Enabled = $status; }
6496
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Outlook external spoof warnings set to $status." -sev Info
65-
} catch {
66-
$ErrorMessage = Get-CippException -Exception $_
67-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Could not set Outlook external spoof warnings to $status. Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
97+
6898
}
99+
} catch {
100+
$ErrorMessage = Get-CippException -Exception $_
101+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Could not set Outlook external spoof warnings to $status. Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
69102
}
70103
}
71104

0 commit comments

Comments
 (0)