Skip to content

Commit 6609317

Browse files
Merge pull request KelvinTegelaar#911 from KelvinTegelaar/dev
Dev to release
2 parents 784d666 + 66caa1c commit 6609317

115 files changed

Lines changed: 1754 additions & 993 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action
2+
# More GitHub Actions for Azure: https://github.com/Azure/actions
3+
4+
name: Build and deploy Powershell project to Azure Function App - cippacnqv
5+
6+
on:
7+
push:
8+
branches:
9+
- dev
10+
workflow_dispatch:
11+
12+
env:
13+
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
14+
15+
jobs:
16+
deploy:
17+
runs-on: windows-latest
18+
permissions:
19+
id-token: write #This is required for requesting the JWT
20+
21+
steps:
22+
- name: 'Checkout GitHub Action'
23+
uses: actions/checkout@v4
24+
25+
- name: Login to Azure
26+
uses: azure/login@v1
27+
with:
28+
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_6085081ED1124B799258E9FF743FF4B9 }}
29+
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_9BDB2DDBFAFA4BC19C20A58B204BFAF3 }}
30+
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_02B5224812794971B05EDD557AF2B867 }}
31+
32+
- name: 'Run Azure Functions Action'
33+
uses: Azure/functions-action@v1
34+
id: fa
35+
with:
36+
app-name: 'cippacnqv'
37+
slot-name: 'Production'
38+
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
39+

Cache_SAMSetup/SAMManifest.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@
159159
{ "id": "cb8f45a0-5c2e-4ea1-b803-84b870a7d7ec", "type": "Scope" },
160160
{ "id": "4c06a06a-098a-4063-868e-5dfee3827264", "type": "Scope" },
161161
{ "id": "1bfefb4e-e0b5-418b-a88f-73c46d2cc8e9", "type": "Role" },
162-
{ "id": "e67e6727-c080-415e-b521-e3f35d5248e9", "type": "Scope" }
162+
{ "id": "e67e6727-c080-415e-b521-e3f35d5248e9", "type": "Scope" },
163+
{ "id": "b6890674-9dd5-4e42-bb15-5af07f541ae1", "type": "Role" }
164+
163165
]
164166
},
165167
{

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertQuotaUsed.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@ function Get-CIPPAlertQuotaUsed {
1717
return
1818
}
1919
$AlertData | ForEach-Object {
20-
if ($_.StorageUsedInBytes -eq 0) { return }
20+
if ($_.StorageUsedInBytes -eq 0 -or $_.prohibitSendReceiveQuotaInBytes -eq 0) { return }
2121
$PercentLeft = [math]::round(($_.storageUsedInBytes / $_.prohibitSendReceiveQuotaInBytes) * 100)
22-
if ($InputValue) { $Value = [int]$InputValue } else { $Value = 90 }
22+
try {
23+
if ([int]$InputValue -gt 0) {
24+
$Value = [int]$InputValue
25+
} else {
26+
$Value = 90
27+
}
28+
} catch {
29+
$Value = 90
30+
}
2331
if ($PercentLeft -gt $Value) {
2432
"$($_.userPrincipalName): Mailbox is more than $($value)% full. Mailbox is $PercentLeft% full"
2533
}

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertSharepointQuota.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ function Get-CIPPAlertSharepointQuota {
1212
$TenantFilter
1313
)
1414
Try {
15-
$tenantName = (New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/domains' -tenantid $TenantFilter | Where-Object { $_.isInitial -eq $true }).id.Split('.')[0]
15+
$tenantName = (New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/sites/root' -tenantid $TenantFilter).id.Split('.')[0]
1616
$sharepointToken = (Get-GraphToken -scope "https://$($tenantName)-admin.sharepoint.com/.default" -tenantid $TenantFilter)
1717
$sharepointToken.Add('accept', 'application/json')
1818
$sharepointQuota = (Invoke-RestMethod -Method 'GET' -Headers $sharepointToken -Uri "https://$($tenantName)-admin.sharepoint.com/_api/StorageQuotas()?api-version=1.3.2" -ErrorAction Stop).value
1919
} catch {
2020
return
2121
}
2222
if ($sharepointQuota) {
23-
if ($InputValue -Is [Boolean]) { $Value = 90 } else { $Value = $InputValue }
23+
try {
24+
if ([int]$InputValue -gt 0) { $Value = [int]$InputValue } else { $Value = 90 }
25+
} catch {
26+
$Value = 90
27+
}
2428
$UsedStoragePercentage = [int](($sharepointQuota.GeoUsedStorageMB / $sharepointQuota.TenantStorageMB) * 100)
2529
if ($UsedStoragePercentage -gt $Value) {
2630
$AlertData = "SharePoint Storage is at $($UsedStoragePercentage)%. Your alert threshold is $($Value)%"

Modules/CIPPCore/Public/CippQueue/Invoke-ListCippQueue.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function Invoke-ListCippQueue {
4141
$TotalCompleted = $TaskStatus.Completed ?? 0
4242
$TotalFailed = $TaskStatus.Failed ?? 0
4343
$TotalRunning = $TaskStatus.Running ?? 0
44+
if ($Queue.TotalTasks -eq 0) { $Queue.TotalTasks = 1 }
4445

4546
[PSCustomObject]@{
4647
PartitionKey = $Queue.PartitionKey

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserDomain.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function Push-DomainAnalyserDomain {
3030
}
3131
Set-DnsResolver -Resolver $Resolver
3232

33-
$Domain = $DomainObject.rowKey
33+
$Domain = $DomainObject.RowKey
3434

3535
try {
3636
$Tenant = $DomainObject.TenantDetails | ConvertFrom-Json -ErrorAction Stop
@@ -250,7 +250,7 @@ function Push-DomainAnalyserDomain {
250250
# Final Write to Output
251251
Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message "DNS Analyser Finished For $Domain" -sev Info
252252
} catch {
253-
Write-LogMessage -API -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message "Error saving domain $Domain to table " -sev Error -LogData (Get-CippException -Exception $_)
253+
Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message "Error saving domain $Domain to table " -sev Error -LogData (Get-CippException -Exception $_)
254254
}
255255
return $null
256256
}

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserTenant.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function Push-DomainAnalyserTenant {
2020
return
2121
} else {
2222
try {
23-
$Domains = New-GraphGetRequest -uri 'https://graph.microsoft.com/v1.0/domains' -tenantid $Tenant.customerId | Where-Object { ($_.id -notlike '*.microsoftonline.com' -and $_.id -NotLike '*.exclaimer.cloud' -and $_.id -Notlike '*.excl.cloud' -and $_.id -NotLike '*.codetwo.online' -and $_.id -NotLike '*.call2teams.com' -and $_.isVerified) }
23+
$Domains = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/domains' -tenantid $Tenant.customerId | Where-Object { ($_.id -notlike '*.microsoftonline.com' -and $_.id -NotLike '*.exclaimer.cloud' -and $_.id -Notlike '*.excl.cloud' -and $_.id -NotLike '*.codetwo.online' -and $_.id -NotLike '*.call2teams.com' -and $_.isVerified) }
2424

2525
$TenantDomains = foreach ($d in $Domains) {
2626
[PSCustomObject]@{
@@ -38,9 +38,11 @@ function Push-DomainAnalyserTenant {
3838
}
3939
}
4040

41+
Write-Information ($TenantDomains | ConvertTo-Json -Depth 10)
42+
4143
$DomainCount = ($TenantDomains | Measure-Object).Count
4244
if ($DomainCount -gt 0) {
43-
Write-Host "$DomainCount tenant Domains"
45+
Write-Host "############# $DomainCount tenant Domains"
4446
$TenantDomainObjects = [System.Collections.Generic.List[object]]::new()
4547
try {
4648
foreach ($TenantDomain in $TenantDomains) {

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ function Push-ExecScheduledCommand {
6262
$TableDesign = '<style>table.blueTable{border:1px solid #1C6EA4;background-color:#EEE;width:100%;text-align:left;border-collapse:collapse}table.blueTable td,table.blueTable th{border:1px solid #AAA;padding:3px 2px}table.blueTable tbody td{font-size:13px}table.blueTable tr:nth-child(even){background:#D0E4F5}table.blueTable thead{background:#1C6EA4;background:-moz-linear-gradient(top,#5592bb 0,#327cad 66%,#1C6EA4 100%);background:-webkit-linear-gradient(top,#5592bb 0,#327cad 66%,#1C6EA4 100%);background:linear-gradient(to bottom,#5592bb 0,#327cad 66%,#1C6EA4 100%);border-bottom:2px solid #444}table.blueTable thead th{font-size:15px;font-weight:700;color:#FFF;border-left:2px solid #D0E4F5}table.blueTable thead th:first-child{border-left:none}table.blueTable tfoot{font-size:14px;font-weight:700;color:#FFF;background:#D0E4F5;background:-moz-linear-gradient(top,#dcebf7 0,#d4e6f6 66%,#D0E4F5 100%);background:-webkit-linear-gradient(top,#dcebf7 0,#d4e6f6 66%,#D0E4F5 100%);background:linear-gradient(to bottom,#dcebf7 0,#d4e6f6 66%,#D0E4F5 100%);border-top:2px solid #444}table.blueTable tfoot td{font-size:14px}table.blueTable tfoot .links{text-align:right}table.blueTable tfoot .links a{display:inline-block;background:#1C6EA4;color:#FFF;padding:2px 8px;border-radius:5px}</style>'
6363
$FinalResults = if ($results -is [array] -and $results[0] -is [string]) { $Results | ConvertTo-Html -Fragment -Property @{ l = 'Text'; e = { $_ } } } else { $Results | ConvertTo-Html -Fragment }
6464
$HTML = $FinalResults -replace '<table>', "This alert is for tenant $tenant. <br /><br /> $TableDesign<table class=blueTable>" | Out-String
65-
$title = "$TaskType - $($task.Name) - $tenant"
65+
$title = "$TaskType - $tenant - $($task.Name)"
6666
Write-Host 'Scheduler: Sending the results to the target.'
6767
Write-Host "The content of results is: $Results"
6868
switch -wildcard ($task.PostExecution) {
69-
'*psa*' { Send-CIPPAlert -Type 'psa' -Title $title -HTMLContent $HTML }
70-
'*email*' { Send-CIPPAlert -Type 'email' -Title $title -HTMLContent $HTML }
69+
'*psa*' { Send-CIPPAlert -Type 'psa' -Title $title -HTMLContent $HTML -TenantFilter $tenant }
70+
'*email*' { Send-CIPPAlert -Type 'email' -Title $title -HTMLContent $HTML -TenantFilter $tenant }
7171
'*webhook*' {
7272
$Webhook = [PSCustomObject]@{
7373
'Tenant' = $tenant
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function Push-AuditLogBundleProcessing {
2+
Param($Item)
3+
4+
try {
5+
$AuditBundleTable = Get-CippTable -tablename 'AuditLogBundles'
6+
$AuditLogBundle = Get-CIPPAzDataTableEntity @AuditBundleTable -Filter "PartitionKey eq '$($Item.TenantFilter)' and RowKey eq '$($Item.ContentId)'"
7+
if ($AuditLogBundle.ProcessingStatus -ne 'Pending') {
8+
Write-Information 'Audit log bundle already processed'
9+
return
10+
}
11+
try {
12+
$AuditLogTest = Test-CIPPAuditLogRules -TenantFilter $Item.TenantFilter -LogType $AuditLogBundle.ContentType -ContentUri $AuditLogBundle.ContentUri
13+
$AuditLogBundle.ProcessingStatus = 'Completed'
14+
$AuditLogBundle.MatchedRules = [string](ConvertTo-Json -Compress -Depth 10 -InputObject $AuditLogTest.MatchedRules)
15+
$AuditLogBundle.MatchedLogs = $AuditLogTest.MatchedLogs
16+
} catch {
17+
$AuditLogBundle.ProcessingStatus = 'Failed'
18+
$AuditLogBundle | Add-Member -NotePropertyName Error -NotePropertyValue $_.InvocationInfo.PositionMessage -TypeName string
19+
}
20+
try {
21+
Add-CIPPAzDataTableEntity @AuditBundleTable -Entity $AuditLogBundle -Force
22+
} catch {
23+
Write-Host ( 'Error logging audit bundle: {0} line {1} - {2}' -f $_.InvocationInfo.ScriptName, $_.InvocationInfo.ScriptLineNumber, $_.Exception.Message)
24+
}
25+
26+
$DataToProcess = ($AuditLogTest).DataToProcess
27+
Write-Information "Webhook: Data to process found: $($DataToProcess.count) items"
28+
foreach ($AuditLog in $DataToProcess) {
29+
Write-Information "Processing $($AuditLog.operation)"
30+
$Webhook = @{
31+
Data = $AuditLog
32+
CIPPURL = [string]$AuditLogBundle.CIPPURL
33+
TenantFilter = $Item.TenantFilter
34+
}
35+
Invoke-CippWebhookProcessing @Webhook
36+
}
37+
} catch {
38+
Write-Host ( 'Audit log error {0} line {1} - {2}' -f $_.InvocationInfo.ScriptName, $_.InvocationInfo.ScriptLineNumber, $_.Exception.Message)
39+
}
40+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
function Push-AuditLogTenant {
2+
Param($Item)
3+
4+
$AuditBundleTable = Get-CippTable -tablename 'AuditLogBundles'
5+
$SchedulerConfig = Get-CIPPTable -TableName 'SchedulerConfig'
6+
$CIPPURL = Get-CIPPAzDataTableEntity @SchedulerConfig -Filter "PartitionKey eq 'webhookcreation'" | Select-Object -First 1 -ExpandProperty CIPPURL
7+
$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'"
10+
11+
$NewBundles = [System.Collections.Generic.List[object]]::new()
12+
foreach ($Webhook in $Webhooks) {
13+
$TenantFilter = $Webhook.PartitionKey
14+
$LogType = $Webhook.Resource
15+
Write-Information "Querying for $LogType on $TenantFilter"
16+
$ContentBundleQuery = @{
17+
TenantFilter = $TenantFilter
18+
ContentType = $LogType
19+
StartTime = $Item.StartTime
20+
EndTime = $Item.EndTime
21+
}
22+
$LogBundles = Get-CIPPAuditLogContentBundles @ContentBundleQuery
23+
24+
foreach ($Bundle in $LogBundles) {
25+
if ($ExistingBundles.RowKey -notcontains $Bundle.contentId) {
26+
$NewBundles.Add([PSCustomObject]@{
27+
PartitionKey = $TenantFilter
28+
RowKey = $Bundle.contentId
29+
DefaultDomainName = $TenantFilter
30+
ContentType = $Bundle.contentType
31+
ContentUri = $Bundle.contentUri
32+
ContentCreated = $Bundle.contentCreated
33+
ContentExpiration = $Bundle.contentExpiration
34+
CIPPURL = [string]$CIPPURL
35+
ProcessingStatus = 'Pending'
36+
MatchedRules = ''
37+
MatchedLogs = 0
38+
})
39+
}
40+
}
41+
}
42+
43+
if (($NewBundles | Measure-Object).Count -gt 0) {
44+
Add-CIPPAzDataTableEntity @AuditBundleTable -Entity $NewBundles
45+
Write-Information ($NewBundles | ConvertTo-Json -Depth 5 -Compress)
46+
47+
$Batch = $NewBundles | Select-Object @{Name = 'ContentId'; Expression = { $_.RowKey } }, @{Name = 'TenantFilter'; Expression = { $_.PartitionKey } }, @{Name = 'FunctionName'; Expression = { 'AuditLogBundleProcessing' } }
48+
$InputObject = [PSCustomObject]@{
49+
OrchestratorName = 'AuditLogs'
50+
Batch = @($Batch)
51+
SkipLog = $true
52+
}
53+
$InstanceId = Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Depth 5 -Compress)
54+
Write-Host "Started orchestration with ID = '$InstanceId'"
55+
}
56+
57+
}

0 commit comments

Comments
 (0)