Skip to content

Commit e143126

Browse files
authored
Merge pull request KelvinTegelaar#1442 from Ren-Roros-Digital/PhishSimSpoofIntelligence
feat: PhishSimSpoofIntelligence replace switch
2 parents d2aac3e + 895d8d8 commit e143126

File tree

2 files changed

+42
-22
lines changed

2 files changed

+42
-22
lines changed

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ function Invoke-CIPPStandardPhishSimSpoofIntelligence {
3535

3636
[String[]]$AddDomain = $Settings.AllowedDomains.value | Where-Object { $_ -notin $DomainState.SendingInfrastructure }
3737

38-
$RemoveDomain = $DomainState | Where-Object { $_.SendingInfrastructure -notin $Settings.AllowedDomains.value } |
39-
Select-Object -Property Identity,SendingInfrastructure
38+
if ($Settings.RemoveExtraDomains -eq $true) {
39+
$RemoveDomain = $DomainState | Where-Object { $_.SendingInfrastructure -notin $Settings.AllowedDomains.value } |
40+
Select-Object -Property Identity,SendingInfrastructure
41+
} else {
42+
$RemoveDomain = @()
43+
}
4044

4145
$StateIsCorrect = ($AddDomain.Count -eq 0 -and $RemoveDomain.Count -eq 0)
4246

@@ -51,15 +55,17 @@ function Invoke-CIPPStandardPhishSimSpoofIntelligence {
5155
} Else {
5256
$BulkRequests = New-Object System.Collections.Generic.List[Hashtable]
5357

54-
# Prepare removal requests
55-
If ($RemoveDomain.Count -gt 0) {
56-
Write-Host "Removing $($RemoveDomain.Count) domains from Spoof Intelligence"
57-
$BulkRequests.Add(@{
58-
CmdletInput = @{
59-
CmdletName = 'Remove-TenantAllowBlockListSpoofItems'
60-
Parameters = @{ Identity = 'default'; Ids = $RemoveDomain.Identity }
61-
}
62-
})
58+
if ($Settings.RemoveExtraDomains -eq $true) {
59+
# Prepare removal requests
60+
If ($RemoveDomain.Count -gt 0) {
61+
Write-Host "Removing $($RemoveDomain.Count) domains from Spoof Intelligence"
62+
$BulkRequests.Add(@{
63+
CmdletInput = @{
64+
CmdletName = 'Remove-TenantAllowBlockListSpoofItems'
65+
Parameters = @{ Identity = 'default'; Ids = $RemoveDomain.Identity }
66+
}
67+
})
68+
}
6369
}
6470

6571
# Prepare addition requests

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

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,18 @@ function Invoke-CIPPStandardPhishingSimulations {
4545
Select-Object -Property Identity,Name,SenderIpRanges,Domains,SenderDomainIs
4646

4747
[String[]]$AddSenderIpRanges = $Settings.SenderIpRanges.value | Where-Object { $_ -notin $RuleState.SenderIpRanges }
48-
[String[]]$RemoveSenderIpRanges = $RuleState.SenderIpRanges | Where-Object { $_ -notin $Settings.SenderIpRanges.value }
48+
if ($Settings.RemoveExtraUrls -eq $true) {
49+
[String[]]$RemoveSenderIpRanges = $RuleState.SenderIpRanges | Where-Object { $_ -notin $Settings.SenderIpRanges.value }
50+
} else {
51+
$RemoveSenderIpRanges = @()
52+
}
4953

5054
[String[]]$AddDomains = $Settings.Domains.value | Where-Object { $_ -notin $RuleState.Domains }
51-
[String[]]$RemoveDomains = $RuleState.Domains | Where-Object { $_ -notin $Settings.Domains.value }
55+
if ($Settings.RemoveExtraUrls -eq $true) {
56+
[String[]]$RemoveDomains = $RuleState.Domains | Where-Object { $_ -notin $Settings.Domains.value }
57+
} else {
58+
$RemoveDomains = @()
59+
}
5260

5361
$RuleIsCorrect = ($RuleState.Name -like "*PhishSimOverr*") -and
5462
($AddSenderIpRanges.Count -eq 0 -and $RemoveSenderIpRanges.Count -eq 0) -and
@@ -59,7 +67,11 @@ function Invoke-CIPPStandardPhishingSimulations {
5967
Select-Object -Property Value
6068

6169
[String[]]$AddEntries = $Settings.PhishingSimUrls.value | Where-Object { $_ -notin $SimUrlState.value }
62-
[String[]]$RemoveEntries = $SimUrlState.value | Where-Object { $_ -notin $Settings.PhishingSimUrls.value }
70+
if ($Settings.RemoveExtraUrls -eq $true) {
71+
[String[]]$RemoveEntries = $SimUrlState.value | Where-Object { $_ -notin $Settings.PhishingSimUrls.value }
72+
} else {
73+
$RemoveEntries = @()
74+
}
6375

6476
$PhishingSimUrlsIsCorrect = ($AddEntries.Count -eq 0 -and $RemoveEntries.Count -eq 0)
6577

@@ -133,14 +145,16 @@ function Invoke-CIPPStandardPhishingSimulations {
133145
ListType = 'Url'
134146
ListSubType = 'AdvancedDelivery'
135147
}
136-
# Remove entries that are not in the settings
137-
If ($RemoveEntries.Count -gt 0) {
138-
$cmdParams.Entries = $RemoveEntries
139-
Try {
140-
$null = New-ExoRequest -TenantId $Tenant -cmdlet 'Remove-TenantAllowBlockListItems' -cmdParams $cmdParams
141-
Write-LogMessage -API 'Standards' -Tenant $Tenant -message "Removed Phishing Simulation URLs from Allowlist." -sev Info
142-
} Catch {
143-
Write-LogMessage -API 'Standards' -Tenant $Tenant -message "Failed to remove Phishing Simulation URLs from Allowlist." -sev Error -LogData $_
148+
if ($Settings.RemoveExtraUrls -eq $true) {
149+
# Remove entries that are not in the settings
150+
If ($RemoveEntries.Count -gt 0) {
151+
$cmdParams.Entries = $RemoveEntries
152+
Try {
153+
$null = New-ExoRequest -TenantId $Tenant -cmdlet 'Remove-TenantAllowBlockListItems' -cmdParams $cmdParams
154+
Write-LogMessage -API 'Standards' -Tenant $Tenant -message "Removed Phishing Simulation URLs from Allowlist." -sev Info
155+
} Catch {
156+
Write-LogMessage -API 'Standards' -Tenant $Tenant -message "Failed to remove Phishing Simulation URLs from Allowlist." -sev Error -LogData $_
157+
}
144158
}
145159
}
146160
# Add entries that are in the settings

0 commit comments

Comments
 (0)