Skip to content

Commit 49b6099

Browse files
committed
add location data check when CIPPGeoLocation is a condition
1 parent 438edcc commit 49b6099

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

Modules/CIPPCore/Public/Webhooks/Test-CIPPAuditLogRules.ps1

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function Test-CIPPAuditLogRules {
22
[CmdletBinding()]
3-
Param(
3+
param(
44
[Parameter(Mandatory = $true)]
55
$TenantFilter,
66
[Parameter(Mandatory = $true)]
@@ -94,7 +94,9 @@ function Test-CIPPAuditLogRules {
9494
}
9595
}
9696

97-
if ($Data.clientip -and $Data.clientip -notmatch '[X]+') {
97+
98+
$HasLocationData = $false
99+
if (![string]::IsNullOrEmpty($Data.clientip) -and $Data.clientip -notmatch '[X]+') {
98100
# Ignore IP addresses that have been redacted
99101
if ($Data.clientip -match '^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+$') {
100102
$Data.clientip = $Data.clientip -replace ':\d+$', '' # Remove the port number if present
@@ -144,6 +146,7 @@ function Test-CIPPAuditLogRules {
144146
Hosting = "$hosting"
145147
ASName = "$ASName"
146148
}
149+
$HasLocationData = $true
147150
try {
148151
$null = Add-CIPPAzDataTableEntity @LocationTable -Entity $LocationInfo -Force
149152
} catch {
@@ -159,7 +162,7 @@ function Test-CIPPAuditLogRules {
159162
$Data.AuditRecord = ($RootProperties | ConvertTo-Json)
160163
}
161164
}
162-
$Data | Select-Object * -ExcludeProperty ExtendedProperties, DeviceProperties, parameters
165+
$Data | Select-Object *, @{n = 'HasLocationData'; exp = { $HasLocationData } } -ExcludeProperty ExtendedProperties, DeviceProperties, parameters
163166
} catch {
164167
#write-warning "Audit log: Error processing data: $($_.Exception.Message)`r`n$($_.InvocationInfo.PositionMessage)"
165168
Write-LogMessage -API 'Webhooks' -message 'Error Processing Audit Log Data' -LogData (Get-CippException -Exception $_) -sev Error -tenant $TenantFilter
@@ -181,14 +184,20 @@ function Test-CIPPAuditLogRules {
181184
#write-warning "Creating filters - $(($ProcessedData.operation | Sort-Object -Unique) -join ',') - $($TenantFilter)"
182185

183186
$Where = $Configuration | ForEach-Object {
184-
if ($TenantFilter -In $_.Excluded.value) {
187+
if ($TenantFilter -in $_.Excluded.value) {
185188
return
186189
}
187190
$conditions = $_.Conditions | ConvertFrom-Json | Where-Object { $_.Input.value -ne '' }
188191
$actions = $_.Actions
189192
$conditionStrings = [System.Collections.Generic.List[string]]::new()
190193
$CIPPClause = [System.Collections.Generic.List[string]]::new()
194+
$AddedLocationCondition = $false
191195
foreach ($condition in $conditions) {
196+
if ($condition.Input.value -eq 'CIPPGeoLocation' -and !$AddedLocationCondition) {
197+
$conditionsString.Add("`$_.HasLocationData -eq `$true")
198+
$CIPPClause.Add('HasLocationData is true')
199+
$AddedLocationCondition = $true
200+
}
192201
$value = if ($condition.Input.value -is [array]) {
193202
$arrayAsString = $condition.Input.value | ForEach-Object {
194203
"'$_'"

0 commit comments

Comments
 (0)