Skip to content

Commit 3ac3aae

Browse files
authored
Merge pull request KelvinTegelaar#1064 from KelvinTegelaar/dev
Dev to hotfix
2 parents dc4b4ff + 04c71ac commit 3ac3aae

8 files changed

Lines changed: 88 additions & 21 deletions

File tree

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Webhooks/Push-AuditLogTenant.ps1

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
function Push-AuditLogTenant {
22
Param($Item)
33

4+
# Get Table contexts
45
$AuditBundleTable = Get-CippTable -tablename 'AuditLogBundles'
56
$SchedulerConfig = Get-CIPPTable -TableName 'SchedulerConfig'
6-
$CIPPURL = Get-CIPPAzDataTableEntity @SchedulerConfig -Filter "PartitionKey eq 'webhookcreation'" | Select-Object -First 1 -ExpandProperty CIPPURL
77
$WebhookTable = Get-CippTable -tablename 'webhookTable'
8-
$Webhooks = Get-CIPPAzDataTableEntity @WebhookTable -Filter "PartitionKey eq '$($Item.TenantFilter)' and Version eq '3'" | Where-Object { $_.Resource -match '^Audit' }
9-
$ExistingBundles = Get-CIPPAzDataTableEntity @AuditBundleTable -Filter "PartitionKey eq '$($Item.TenantFilter)' and ContentType eq '$ContentType'"
108
$ConfigTable = Get-CIPPTable -TableName 'WebhookRules'
9+
10+
# Query CIPPURL for linking
11+
$CIPPURL = Get-CIPPAzDataTableEntity @SchedulerConfig -Filter "PartitionKey eq 'webhookcreation'" | Select-Object -First 1 -ExpandProperty CIPPURL
12+
13+
# Get all webhooks for the tenant
14+
$Webhooks = Get-CIPPAzDataTableEntity @WebhookTable -Filter "PartitionKey eq '$($Item.TenantFilter)' and Version eq '3'" | Where-Object { $_.Resource -match '^Audit' }
15+
16+
# Get webhook rules
1117
$ConfigEntries = Get-CIPPAzDataTableEntity @ConfigTable
1218

19+
# Date filter for existing bundles
20+
$LastHour = (Get-Date).AddHours(-1).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss')
21+
1322
$NewBundles = [System.Collections.Generic.List[object]]::new()
1423
foreach ($Webhook in $Webhooks) {
1524
# only process webhooks that are configured in the webhookrules table
@@ -28,6 +37,7 @@ function Push-AuditLogTenant {
2837
EndTime = $Item.EndTime
2938
}
3039
$LogBundles = Get-CIPPAuditLogContentBundles @ContentBundleQuery
40+
$ExistingBundles = Get-CIPPAzDataTableEntity @AuditBundleTable -Filter "PartitionKey eq '$($Item.TenantFilter)' and ContentType eq '$LogType' and Timestamp ge datetime'$($LastHour)'"
3141

3242
foreach ($Bundle in $LogBundles) {
3343
if ($ExistingBundles.RowKey -notcontains $Bundle.contentId) {
@@ -61,5 +71,4 @@ function Push-AuditLogTenant {
6171
$InstanceId = Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Depth 5 -Compress)
6272
Write-Host "Started orchestration with ID = '$InstanceId'"
6373
}
64-
6574
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
Function Invoke-ExecOffloadFunctions {
3+
<#
4+
.FUNCTIONALITY
5+
Entrypoint
6+
.ROLE
7+
CIPP.SuperAdmin.ReadWrite
8+
#>
9+
[CmdletBinding()]
10+
param($Request, $TriggerMetadata)
11+
12+
$roles = ([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($request.headers.'x-ms-client-principal')) | ConvertFrom-Json).userRoles
13+
if ('superadmin' -notin $roles) {
14+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
15+
StatusCode = [HttpStatusCode]::Forbidden
16+
Body = @{ error = 'You do not have permission to perform this action.' }
17+
})
18+
return
19+
} else {
20+
$Table = Get-CippTable -tablename 'Config'
21+
22+
if ($Request.Query.Action -eq 'ListCurrent') {
23+
$CurrentState = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'OffloadFunctions' and RowKey eq 'OffloadFunctions'"
24+
$CurrentState = if (!$CurrentState) {
25+
[PSCustomObject]@{
26+
OffloadFunctions = $false
27+
}
28+
} else {
29+
[PSCustomObject]@{
30+
OffloadFunctions = $CurrentState.state
31+
}
32+
}
33+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
34+
StatusCode = [HttpStatusCode]::OK
35+
Body = $CurrentState
36+
})
37+
} else {
38+
Add-CIPPAzDataTableEntity @Table -Entity @{
39+
PartitionKey = 'OffloadFunctions'
40+
RowKey = 'OffloadFunctions'
41+
state = $request.Body.OffloadFunctions
42+
} -Force
43+
44+
if ($Request.Body.OffloadFunctions) {
45+
$Results = 'Enabled Offload Functions'
46+
} else {
47+
$Results = 'Disabled Offload Functions'
48+
}
49+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
50+
StatusCode = [HttpStatusCode]::OK
51+
Body = @{ results = $Results }
52+
})
53+
}
54+
55+
}
56+
}

Modules/CIPPCore/Public/GraphHelper/Write-LogMessage.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ function Write-LogMessage {
2525
if (!$tenant) { $tenant = 'None' }
2626
if (!$username) { $username = 'CIPP' }
2727
if ($sev -eq 'Debug' -and $env:DebugMode -ne $true) {
28-
Write-Information 'Not writing to log file - Debug mode is not enabled.'
2928
return
3029
}
3130
$PartitionKey = (Get-Date -UFormat '%Y%m%d').ToString()
@@ -48,4 +47,4 @@ function Write-LogMessage {
4847

4948
$Table.Entity = $TableRow
5049
Add-CIPPAzDataTableEntity @Table | Out-Null
51-
}
50+
}

Modules/CIPPCore/Public/Set-CIPPAssignedPolicy.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,6 @@ function Set-CIPPAssignedPolicy {
8080
} catch {
8181
#$ErrorMessage = Get-CippException -Exception $_
8282
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
83-
Write-LogMessage -user $ExecutingUser -API $APIName -message "Failed to assign $GroupName to Policy $PolicyId. Error:$ErrorMessage" -Sev 'Error' -tenant $TenantFilter -LogData $ErrorMessage
83+
Write-LogMessage -user $ExecutingUser -API $APIName -message "Failed to assign $GroupName to Policy $PolicyId, using Platform $PlatformType and $Type. The error is:$ErrorMessage" -Sev 'Error' -tenant $TenantFilter -LogData $ErrorMessage
8484
}
8585
}

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ function Invoke-CIPPStandardIntuneTemplate {
2020
$displayname = $request.body.Displayname
2121
$description = $request.body.Description
2222
$RawJSON = $Request.body.RawJSON
23+
$TemplateTypeURL = $Request.body.Type
2324

24-
Set-CIPPIntunePolicy -TemplateType $Request.body.Type -Description $description -DisplayName $displayname -RawJSON $RawJSON -AssignTo $null -tenantFilter $Tenant
25+
Set-CIPPIntunePolicy -TemplateType $Request.body.Type -Description $description -DisplayName $displayname -RawJSON $RawJSON -AssignTo $Template.AssignedTo -tenantFilter $Tenant
2526

26-
#Legacy assign.
27+
#Legacy assign, only required for older templates.
2728
if ($Settings.AssignTo) {
2829
Write-Host "Assigning Policy to $($Settings.AssignTo) the create ID is $($CreateRequest)"
2930
if ($Settings.AssignTo -eq 'customGroup') { $Settings.AssignTo = $Settings.customGroup }
@@ -36,16 +37,6 @@ function Invoke-CIPPStandardIntuneTemplate {
3637
}
3738
}
3839

39-
if ($Template.AssignedTo) {
40-
Write-Host "New: Assigning Policy to $($Template.AssignedTo) the create ID is $($CreateRequest)"
41-
if ($ExistingID) {
42-
Set-CIPPAssignedPolicy -PolicyId $ExistingID.id -TenantFilter $tenant -GroupName $Template.AssignedTo -Type $TemplateTypeURL
43-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Successfully updated Intune Template $PolicyName policy for $($Tenant)" -sev 'Info'
44-
} else {
45-
Set-CIPPAssignedPolicy -PolicyId $CreateRequest.id -TenantFilter $tenant -GroupName $Template.AssignedTo -Type $TemplateTypeURL
46-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Successfully created Intune Template $PolicyName policy for $($Tenant)" -sev 'Info'
47-
}
48-
}
4940
} catch {
5041
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
5142
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to create or update Intune Template $PolicyName, Error: $ErrorMessage" -sev 'Error'

Scheduler_GetQueue/run.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ $Tasks = foreach ($Tenant in $Tenants) {
2727
}
2828
}
2929

30+
if (($Tasks | Measure-Object).Count -eq 0) {
31+
return
32+
}
33+
3034
$Queue = New-CippQueueEntry -Name 'Scheduler' -TotalTasks ($Tasks | Measure-Object).Count
3135

3236
$Batch = foreach ($Task in $Tasks) {
@@ -49,4 +53,4 @@ $InputObject = [PSCustomObject]@{
4953
#Write-Information ($InputObject | ConvertTo-Json)
5054
$InstanceId = Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Depth 5 -Compress)
5155
Write-Information "Started orchestration with ID = '$InstanceId'"
52-
#$Orchestrator = New-OrchestrationCheckStatusResponse -Request $Request -InstanceId $InstanceId
56+
#$Orchestrator = New-OrchestrationCheckStatusResponse -Request $Request -InstanceId $InstanceId

Scheduler_PollAuditLogs/run.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
param($Timer)
22

33
try {
4+
$ConfigTable = Get-CIPPTable -tablename Config
5+
$Config = Get-CIPPAzDataTableEntity @ConfigTable -Filter "PartitionKey eq 'OffloadFunctions' and RowKey eq 'OffloadFunctions'"
6+
7+
if ($Config -and $Config.state -eq $true) {
8+
Write-Host 'Offload functions are enabled. Exiting.'
9+
return 0
10+
}
11+
412
$webhookTable = Get-CIPPTable -tablename webhookTable
513
$Webhooks = Get-CIPPAzDataTableEntity @webhookTable -Filter "Version eq '3'" | Where-Object { $_.Resource -match '^Audit' -and $_.Status -ne 'Disabled' }
614
if (($Webhooks | Measure-Object).Count -eq 0) {

version_latest.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.2.2
1+
6.2.3

0 commit comments

Comments
 (0)