Skip to content

Commit

Permalink
changed how we handle operations
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Aug 8, 2023
1 parent 028243b commit e3f781d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 8 additions & 2 deletions Modules/CIPPCore/Public/Invoke-CIPPWebhookProcessing.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ function Invoke-CippWebhookProcessing {
$TenantFilter,
$Data,
$Resource,
$Operations,
$AllowedLocations,
$CIPPPURL,
$APIName = "Process webhook",
Expand All @@ -28,8 +29,13 @@ function Invoke-CippWebhookProcessing {
#Custom cipp operations.
if ($data.operation -eq "UserloggedIn" -and $data.UserType -eq 2) { $data.operation = "AdminLoggedIn" }
if ($data.operation -eq "UserLoggedIn" -and $Country -notin $AllowedLocations) { $data.operation = "UserLoggedInFromUnknownLocation" }
if ($data.operation -eq "UserLoggedIn" -and $Country -notin $PreviousLocations) { $data.operation = "UserLoggedInFromUnknownLocation" }
Write-Host "Selecting the Operation: $($data.operation)"

#Check if the operation is allowed for this webhook.
if ($data.operation -notin $Operations) {
Write-Host "No need to process this operation."
return ""
}

switch ($data.Operation) {
"New-InboxRule" {
$Title = "$($TenantFilter) - New Rule Detected for $($data.UserId)"
Expand Down
7 changes: 1 addition & 6 deletions PublicWebhooks/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ if ($Request.CIPPID -in $Webhooks.CIPPID) {
Write-Host "Found matching CIPPID"

$Webhookinfo = $Webhooks | Where-Object -Property RowKey -EQ $Request.query.CIPPID
Write-Host "Webhookinfo: $($Webhookinfo | ConvertTo-Json -Depth 10)"
if ($Request.query.ValidationToken -or $Request.body.validationCode) {
Write-Host "Validation token received"
$body = $request.query.ValidationToken
Expand All @@ -26,12 +25,8 @@ if ($Request.CIPPID -in $Webhooks.CIPPID) {
$operations = $Webhookinfo.Operations -split ','
Write-Host "Operations to process for this client: $($Webhookinfo.Operations)"
foreach ($Item in $Data) {
Write-Host "Item: $($item | ConvertTo-Json -Depth 10)"
Write-Host "Processing $($item.operation)"
if ($item.Operation -in $operations) {
Write-Host "Working on $($item.operation)."
Invoke-CippWebhookProcessing -TenantFilter $TenantFilter -Data $Item -CIPPPURL $url -allowedlocations $Webhookinfo.AllowedLocations
}
Invoke-CippWebhookProcessing -TenantFilter $TenantFilter -Data $Item -CIPPPURL $url -allowedlocations $Webhookinfo.AllowedLocations -Operations $operations
$body = "OK"
}
}
Expand Down

0 comments on commit e3f781d

Please sign in to comment.