Skip to content

Commit af6913e

Browse files
authored
Merge pull request #868 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 7c91ae8 + ab098b3 commit af6913e

28 files changed

Lines changed: 17979 additions & 16539 deletions

ConversionTable.csv

Lines changed: 4146 additions & 4115 deletions
Large diffs are not rendered by default.

Modules/CIPPCore/Public/Add-CippTestResult.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ function Add-CippTestResult {
5656
[Parameter(Mandatory = $false)]
5757
[string]$ResultMarkdown,
5858

59+
[Parameter(Mandatory = $false)]
60+
[string]$ResultDataJson,
61+
5962
[Parameter(Mandatory = $false)]
6063
[string]$Risk,
6164

@@ -83,6 +86,7 @@ function Add-CippTestResult {
8386
RowKey = $TestId
8487
Status = $Status
8588
ResultMarkdown = $ResultMarkdown ?? ''
89+
ResultDataJson = $ResultDataJson ?? ''
8690
Risk = $Risk ?? ''
8791
Name = $Name ?? ''
8892
Pillar = $Pillar ?? ''

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

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,55 @@ function Get-CIPPAlertAppCertificateExpiry {
1111
$TenantFilter
1212
)
1313

14+
$Now = Get-Date
15+
$AlertData = @()
16+
1417
try {
15-
Write-Host "Checking app expire for $($TenantFilter)"
16-
$appList = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/applications?`$select=appId,displayName,keyCredentials" -tenantid $TenantFilter
18+
$appList = New-CIPPDbRequest -TenantFilter $TenantFilter -Type 'Apps'
1719
} catch {
18-
return
20+
$appList = @()
1921
}
2022

21-
$AlertData = foreach ($App in $applist) {
22-
Write-Host "checking $($App.displayName)"
23+
$AppAlertData = foreach ($App in $appList) {
2324
if ($App.keyCredentials) {
2425
foreach ($Credential in $App.keyCredentials) {
25-
if ($Credential.endDateTime -lt (Get-Date).AddDays(30) -and $Credential.endDateTime -gt (Get-Date).AddDays(-7)) {
26-
Write-Host ("Application '{0}' has certificates expiring on {1}" -f $App.displayName, $Credential.endDateTime)
27-
@{ DisplayName = $App.displayName; Expires = $Credential.endDateTime }
26+
if ($Credential.endDateTime -lt $Now.AddDays(30) -and $Credential.endDateTime -gt $Now.AddDays(-7)) {
27+
@{
28+
DisplayName = $App.displayName
29+
Expires = $Credential.endDateTime
30+
AppId = $App.appId
31+
Type = 'Application'
32+
}
2833
}
2934
}
3035
}
3136
}
37+
38+
try {
39+
$servicePrincipals = New-CIPPDbRequest -TenantFilter $TenantFilter -Type 'ServicePrincipals'
40+
} catch {
41+
$servicePrincipals = @()
42+
}
43+
44+
$SamlAlertData = foreach ($ServicePrincipal in $servicePrincipals) {
45+
$ExpiryDate = $null
46+
if ($ServicePrincipal.preferredTokenSigningKeyEndDateTime) {
47+
$ExpiryDate = [datetime]$ServicePrincipal.preferredTokenSigningKeyEndDateTime
48+
}
49+
if ($ExpiryDate -and $ExpiryDate -lt $Now.AddDays(30) -and $ExpiryDate -gt $Now.AddDays(-7)) {
50+
@{
51+
DisplayName = $ServicePrincipal.displayName
52+
Expires = $ExpiryDate
53+
AppId = $ServicePrincipal.appId
54+
ServicePrincipalId = $ServicePrincipal.id
55+
Type = 'SamlServicePrincipal'
56+
}
57+
}
58+
}
59+
60+
$AlertData = @(
61+
@($AppAlertData)
62+
@($SamlAlertData)
63+
) | Where-Object { $null -ne $_ }
3264
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
3365
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@ function Get-CIPPAlertSmtpAuthSuccess {
1212
)
1313

1414
try {
15+
$lookupDays = if ($InputValue.SmtpAuthSuccessDays) { [int]$InputValue.SmtpAuthSuccessDays } else { 7 }
16+
$lookupDays = [Math]::Min($lookupDays, 30)
17+
18+
$endDateTime = (Get-Date).ToUniversalTime()
19+
$startDateTime = $endDateTime.AddDays(-$lookupDays)
20+
$startDateTimeString = $startDateTime.ToString('yyyy-MM-ddTHH:mm:ssZ')
21+
$endDateTimeString = $endDateTime.ToString('yyyy-MM-ddTHH:mm:ssZ')
22+
1523
# Graph API endpoint for sign-ins
16-
$uri = "https://graph.microsoft.com/v1.0/auditLogs/signIns?`$filter=(clientAppUsed eq 'Authenticated SMTP' or clientAppUsed eq 'SMTP') and status/errorCode eq 0"
24+
$uri = "https://graph.microsoft.com/v1.0/auditLogs/signIns?`$filter=createdDateTime ge $startDateTimeString and createdDateTime le $endDateTimeString and (clientAppUsed eq 'Authenticated SMTP' or clientAppUsed eq 'SMTP') and status/errorCode eq 0"
1725

1826
# Call Graph API for the given tenant
1927
$SignIns = New-GraphGetRequest -uri $uri -tenantid $TenantFilter

Modules/CIPPCore/Public/Compare-CIPPIntuneObject.ps1

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,19 @@ function Compare-CIPPIntuneObject {
514514
Value = $value
515515
Source = 'Reference'
516516
}
517+
} elseif ($settingInstance.simpleSettingCollectionValue) {
518+
$label = if ($intuneObj?.displayName) {
519+
$intuneObj.displayName
520+
} else {
521+
$settingInstance.settingDefinitionId
522+
}
523+
$values = @($settingInstance.simpleSettingCollectionValue | ForEach-Object { $_.value })
524+
[PSCustomObject]@{
525+
Key = "Simple-$($settingInstance.settingDefinitionId)"
526+
Label = $label
527+
Value = ($values | Sort-Object) -join ', '
528+
Source = 'Reference'
529+
}
517530
} elseif ($settingInstance.choiceSettingValue?.value) {
518531
$label = if ($intuneObj?.displayName) {
519532
$intuneObj.displayName
@@ -536,6 +549,30 @@ function Compare-CIPPIntuneObject {
536549
Value = $value
537550
Source = 'Reference'
538551
}
552+
553+
# Recurse into children of choice settings (e.g. firewall profile sub-settings)
554+
if ($settingInstance.choiceSettingValue.children) {
555+
$childResults = Process-GroupSettingChildren -Children $settingInstance.choiceSettingValue.children -Source 'Reference' -IntuneCollectionIndex $intuneCollectionIndex
556+
foreach ($cr in $childResults) { $cr }
557+
}
558+
} elseif ($settingInstance.choiceSettingCollectionValue) {
559+
$label = if ($intuneObj?.displayName) {
560+
$intuneObj.displayName
561+
} else {
562+
$settingInstance.settingDefinitionId
563+
}
564+
$values = [System.Collections.Generic.List[string]]::new()
565+
foreach ($choiceValue in $settingInstance.choiceSettingCollectionValue) {
566+
$option = $intuneObj.options | Where-Object { $_.id -eq $choiceValue.value }
567+
$displayValue = if ($option?.displayName) { $option.displayName } else { $choiceValue.value }
568+
$values.Add($displayValue)
569+
}
570+
[PSCustomObject]@{
571+
Key = "Choice-$($settingInstance.settingDefinitionId)"
572+
Label = $label
573+
Value = ($values | Sort-Object) -join ', '
574+
Source = 'Reference'
575+
}
539576
} else {
540577
$label = if ($intuneObj?.displayName) {
541578
$intuneObj.displayName
@@ -586,6 +623,19 @@ function Compare-CIPPIntuneObject {
586623
Value = $value
587624
Source = 'Difference'
588625
}
626+
} elseif ($settingInstance.simpleSettingCollectionValue) {
627+
$label = if ($intuneObj?.displayName) {
628+
$intuneObj.displayName
629+
} else {
630+
$settingInstance.settingDefinitionId
631+
}
632+
$values = @($settingInstance.simpleSettingCollectionValue | ForEach-Object { $_.value })
633+
[PSCustomObject]@{
634+
Key = "Simple-$($settingInstance.settingDefinitionId)"
635+
Label = $label
636+
Value = ($values | Sort-Object) -join ', '
637+
Source = 'Difference'
638+
}
589639
} elseif ($settingInstance.choiceSettingValue?.value) {
590640
$label = if ($intuneObj?.displayName) {
591641
$intuneObj.displayName
@@ -608,6 +658,30 @@ function Compare-CIPPIntuneObject {
608658
Value = $value
609659
Source = 'Difference'
610660
}
661+
662+
# Recurse into children of choice settings (e.g. firewall profile sub-settings)
663+
if ($settingInstance.choiceSettingValue.children) {
664+
$childResults = Process-GroupSettingChildren -Children $settingInstance.choiceSettingValue.children -Source 'Difference' -IntuneCollectionIndex $intuneCollectionIndex
665+
foreach ($cr in $childResults) { $cr }
666+
}
667+
} elseif ($settingInstance.choiceSettingCollectionValue) {
668+
$label = if ($intuneObj?.displayName) {
669+
$intuneObj.displayName
670+
} else {
671+
$settingInstance.settingDefinitionId
672+
}
673+
$values = [System.Collections.Generic.List[string]]::new()
674+
foreach ($choiceValue in $settingInstance.choiceSettingCollectionValue) {
675+
$option = $intuneObj.options | Where-Object { $_.id -eq $choiceValue.value }
676+
$displayValue = if ($option?.displayName) { $option.displayName } else { $choiceValue.value }
677+
$values.Add($displayValue)
678+
}
679+
[PSCustomObject]@{
680+
Key = "Choice-$($settingInstance.settingDefinitionId)"
681+
Label = $label
682+
Value = ($values | Sort-Object) -join ', '
683+
Source = 'Difference'
684+
}
611685
} else {
612686
$label = if ($intuneObj?.displayName) {
613687
$intuneObj.displayName
@@ -628,11 +702,16 @@ function Compare-CIPPIntuneObject {
628702

629703
$result = [System.Collections.Generic.List[PSObject]]::new()
630704

631-
$allKeys = @($referenceItems | Select-Object -ExpandProperty Key) + @($differenceItems | Select-Object -ExpandProperty Key) | Sort-Object -Unique
705+
$refItemsByKey = @{}
706+
foreach ($item in $referenceItems) { $refItemsByKey[$item.Key] = $item }
707+
$diffItemsByKey = @{}
708+
foreach ($item in $differenceItems) { $diffItemsByKey[$item.Key] = $item }
709+
710+
$allKeys = @($refItemsByKey.Keys) + @($diffItemsByKey.Keys) | Sort-Object -Unique
632711

633712
foreach ($key in $allKeys) {
634-
$refItem = $referenceItems | Where-Object { $_.Key -eq $key } | Select-Object -First 1
635-
$diffItem = $differenceItems | Where-Object { $_.Key -eq $key } | Select-Object -First 1
713+
$refItem = $refItemsByKey[$key]
714+
$diffItem = $diffItemsByKey[$key]
636715

637716
$settingId = $key
638717
if ($key -like 'Simple-*') {
@@ -654,14 +733,14 @@ function Compare-CIPPIntuneObject {
654733
$diffValue = $diffRawValue
655734

656735
if ($null -ne $settingDefinition -and $null -ne $settingDefinition.options) {
657-
if ($null -ne $refRawValue -and $refRawValue -match '_\d+$') {
736+
if ($null -ne $refRawValue -and $refRawValue -is [string]) {
658737
$option = $settingDefinition.options | Where-Object { $_.id -eq $refRawValue }
659738
if ($null -ne $option -and $null -ne $option.displayName) {
660739
$refValue = $option.displayName
661740
}
662741
}
663742

664-
if ($null -ne $diffRawValue -and $diffRawValue -match '_\d+$') {
743+
if ($null -ne $diffRawValue -and $diffRawValue -is [string]) {
665744
$option = $settingDefinition.options | Where-Object { $_.id -eq $diffRawValue }
666745
if ($null -ne $option -and $null -ne $option.displayName) {
667746
$diffValue = $option.displayName

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Standards/Push-CIPPStandardsApplyBatch.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ function Push-CIPPStandardsApplyBatch {
2727
OrchestratorName = 'StandardsApply'
2828
Batch = @($AllStandards)
2929
SkipLog = $true
30-
} | ConvertTo-Json -Depth 25 -Compress
31-
Write-Host "Standards InputObject: $InputObject"
30+
}
31+
Write-Host "Standards InputObject: $($InputObject | ConvertTo-Json -Depth 25 -Compress)"
3232
$InstanceId = Start-CIPPOrchestrator -InputObject $InputObject
3333
Write-Information "Started standards apply orchestrator with ID = '$InstanceId'"
3434
} catch {
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
function Invoke-AddAppTemplate {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint,AnyTenant
5+
.ROLE
6+
Endpoint.Application.ReadWrite
7+
#>
8+
[CmdletBinding()]
9+
param($Request, $TriggerMetadata)
10+
11+
$APIName = $Request.Params.CIPPEndpoint
12+
$Headers = $Request.Headers
13+
14+
try {
15+
$Body = $Request.Body
16+
if (!$Body.displayName) { throw 'You must enter a display name' }
17+
18+
$RawApps = $Body.apps
19+
if (!$RawApps -or ($RawApps | Measure-Object).Count -eq 0) {
20+
throw 'You must add at least one application'
21+
}
22+
23+
$AppsList = [System.Collections.Generic.List[hashtable]]::new()
24+
foreach ($App in @($RawApps)) {
25+
$ConfigValue = if ($App.config -is [string]) { $App.config } else { $App.config | ConvertTo-Json -Depth 15 -Compress }
26+
$AppsList.Add(@{
27+
appType = [string]$App.appType
28+
appName = [string]$App.appName
29+
config = [string]$ConfigValue
30+
})
31+
}
32+
33+
$Table = Get-CippTable -tablename 'templates'
34+
35+
# Upsert: if GUID provided, update existing template
36+
if ($Body.GUID) {
37+
$Filter = "PartitionKey eq 'AppTemplate' and RowKey eq '$($Body.GUID)'"
38+
$ExistingEntity = Get-CIPPAzDataTableEntity @Table -Filter $Filter
39+
}
40+
41+
if ($ExistingEntity) {
42+
$GUID = $ExistingEntity.RowKey
43+
} else {
44+
$GUID = (New-Guid).GUID
45+
}
46+
47+
$AppsJSON = ConvertTo-Json -InputObject @($AppsList.ToArray()) -Depth 15 -Compress -AsArray
48+
$TemplateJSON = ConvertTo-Json -InputObject @{
49+
Displayname = $Body.displayName
50+
Description = $Body.description ?? ''
51+
GUID = $GUID
52+
} -Depth 15 -Compress
53+
$TemplateJSON = $TemplateJSON.TrimEnd('}') + ',"Apps":' + $AppsJSON + '}'
54+
55+
$Table.Force = $true
56+
Add-CIPPAzDataTableEntity @Table -Entity @{
57+
JSON = [string]$TemplateJSON
58+
RowKey = [string]$GUID
59+
PartitionKey = 'AppTemplate'
60+
}
61+
62+
$AppCount = $AppsList.Count
63+
Write-LogMessage -headers $Headers -API $APIName -message "Saved app template '$($Body.displayName)' with $AppCount app(s)" -Sev 'Info'
64+
$Result = "Successfully saved app template '$($Body.displayName)' with $AppCount app(s)"
65+
$StatusCode = [HttpStatusCode]::OK
66+
} catch {
67+
$ErrorMessage = Get-CippException -Exception $_
68+
$Result = "Failed to add app template: $($ErrorMessage.NormalizedMessage)"
69+
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev 'Error' -LogData $ErrorMessage
70+
$StatusCode = [HttpStatusCode]::InternalServerError
71+
}
72+
73+
return ([HttpResponseContext]@{
74+
StatusCode = $StatusCode
75+
Body = @{ Results = $Result }
76+
})
77+
}

0 commit comments

Comments
 (0)