Skip to content

Commit 1c82197

Browse files
authored
Merge branch 'dev' into groupinfo-single-group
2 parents ffa67d4 + fe39335 commit 1c82197

File tree

54 files changed

+1407
-365
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1407
-365
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
function Convert-QuarantinePermissionsValue {
2+
[CmdletBinding(DefaultParameterSetName = 'DecimalValue')]
3+
param (
4+
[Parameter(Mandatory, Position = 0, ParameterSetName = "StringValue")]
5+
[ValidateNotNullOrEmpty()]
6+
[string]$InputObject,
7+
8+
[Parameter(Position = 0, ParameterSetName = "DecimalValue")]
9+
[int]$PermissionToViewHeader = 0,
10+
[Parameter(Position = 1, ParameterSetName = "DecimalValue")]
11+
[int]$PermissionToDownload = 0,
12+
[Parameter(Mandatory, Position = 2, ParameterSetName = "DecimalValue")]
13+
[int]$PermissionToAllowSender,
14+
[Parameter(Mandatory, Position = 3, ParameterSetName = "DecimalValue")]
15+
[int]$PermissionToBlockSender,
16+
[Parameter(Mandatory, Position = 4, ParameterSetName = "DecimalValue")]
17+
[int]$PermissionToRequestRelease,
18+
[Parameter(Mandatory, Position = 5, ParameterSetName = "DecimalValue")]
19+
[int]$PermissionToRelease,
20+
[Parameter(Mandatory, Position = 6, ParameterSetName = "DecimalValue")]
21+
[int]$PermissionToPreview,
22+
[Parameter(Mandatory, Position = 7, ParameterSetName = "DecimalValue")]
23+
[int]$PermissionToDelete
24+
)
25+
26+
#Converts string value with EndUserQuarantinePermissions received from Get-QuarantinePolicy
27+
if (($PSCmdlet.ParameterSetName) -eq "StringValue") {
28+
try {
29+
# Remove square brackets and split into lines
30+
$InputObject = $InputObject.Trim('[', ']')
31+
$hashtable = @{}
32+
$InputObject -split "`n" | ForEach-Object {
33+
$key, $value = $_ -split ":\s*"
34+
$hashtable[$key.Trim()] = [System.Convert]::ToBoolean($value.Trim())
35+
}
36+
return $hashtable
37+
}
38+
catch {
39+
throw "Convert-QuarantinePermissionsValue: Failed to convert string to hashtable."
40+
}
41+
}
42+
43+
#Converts selected end user quarantine permissions to decimal value used by EndUserQuarantinePermissionsValue property in New-QuarantinePolicy and Set-QuarantinePolicy
44+
elseif (($PSCmdlet.ParameterSetName) -eq "DecimalValue") {
45+
try {
46+
# both PermissionToRequestRelease and PermissionToRelease cannot be set to true at the same time
47+
if($PermissionToRequestRelease -eq 1 -and $PermissionToRelease -eq 1) {
48+
throw "PermissionToRequestRelease and PermissionToRelease cannot both be set to true."
49+
}
50+
51+
# Convert each permission to a binary string
52+
$BinaryValue = [string]@(
53+
$PermissionToViewHeader,
54+
$PermissionToDownload,
55+
$PermissionToAllowSender,
56+
$PermissionToBlockSender,
57+
$PermissionToRequestRelease,
58+
$PermissionToRelease,
59+
$PermissionToPreview,
60+
$PermissionToDelete
61+
) -replace '\s',''
62+
63+
# Convert the binary string to an Decimal value
64+
return [convert]::ToInt32($BinaryValue,2)
65+
}
66+
catch {
67+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
68+
throw "Convert-QuarantinePermissionsValue: Failed to convert QuarantinePermissions to QuarantinePermissionsValue. Error: $ErrorMessage"
69+
}
70+
}
71+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
function Push-ListTransportRulesAllTenants {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint
5+
#>
6+
param($Item)
7+
8+
$Tenant = Get-Tenants -TenantFilter $Item.customerId
9+
$DomainName = $Tenant.defaultDomainName
10+
$Table = Get-CIPPTable -TableName CacheTransportRules
11+
12+
try {
13+
$TransportRules = New-ExoRequest -tenantid $DomainName -cmdlet 'Get-TransportRule'
14+
$Results = foreach ($rule in $TransportRules) {
15+
$GUID = (New-Guid).Guid
16+
$Results = @{
17+
TransportRule = [string]($rule | ConvertTo-Json -Depth 10)
18+
RowKey = [string]$GUID
19+
PartitionKey = 'TransportRule'
20+
Tenant = [string]$DomainName
21+
}
22+
Add-CIPPAzDataTableEntity @Table -Entity $Results -Force | Out-Null
23+
}
24+
25+
} catch {
26+
$GUID = (New-Guid).Guid
27+
$ErrorText = ConvertTo-Json -InputObject @{
28+
Tenant = $DomainName
29+
Name = "Could not connect to Tenant: $($_.Exception.Message)"
30+
State = 'Error'
31+
Priority = 0
32+
Description = "Error retrieving transport rules: $($_.Exception.Message)"
33+
}
34+
$Results = @{
35+
TransportRule = [string]$ErrorText
36+
RowKey = [string]$GUID
37+
PartitionKey = 'TransportRule'
38+
Tenant = [string]$DomainName
39+
}
40+
Add-CIPPAzDataTableEntity @Table -Entity $Results -Force | Out-Null
41+
}
42+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ function Push-UpdatePermissionsQueue {
1616
$Table = Get-CIPPTable -TableName cpvtenants
1717
$CPVRows = Get-CIPPAzDataTableEntity @Table | Where-Object -Property Tenant -EQ $Item.customerId
1818

19-
if (!$CPVRows -or $env:ApplicationID -notin $CPVRows.applicationId) {
19+
$Tenant = Get-Tenants -TenantFilter $Item.customerId -IncludeErrors
20+
21+
if ((!$CPVRows -or $env:ApplicationID -notin $CPVRows.applicationId) -and $Tenant.delegatedPrivilegeStatus -ne 'directTenant') {
2022
Write-LogMessage -tenant $Item.defaultDomainName -tenantId $Item.customerId -message 'A New tenant has been added, or a new CIPP-SAM Application is in use' -Sev 'Warn' -API 'NewTenant'
2123
Write-Information 'Adding CPV permissions'
2224
Set-CIPPCPVConsent -Tenantfilter $Item.customerId

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecCPVPermissions.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using namespace System.Net
22

3-
Function Invoke-ExecCPVPermissions {
3+
function Invoke-ExecCPVPermissions {
44
<#
55
.FUNCTIONALITY
66
Entrypoint
@@ -15,7 +15,7 @@ Function Invoke-ExecCPVPermissions {
1515
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
1616
$TenantFilter = $Request.Body.tenantFilter
1717

18-
$Tenant = Get-Tenants -IncludeAll | Where-Object -Property customerId -EQ $TenantFilter | Select-Object -First 1
18+
$Tenant = Get-Tenants -TenantFilter $TenantFilter -IncludeErrors
1919

2020
if ($Tenant) {
2121
Write-Host "Our tenant is $($Tenant.displayName) - $($Tenant.defaultDomainName)"

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Setup/Invoke-ExecAddTenant.ps1

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using namespace System.Net
22

3-
Function Invoke-ExecAddTenant {
3+
function Invoke-ExecAddTenant {
44
<#
55
.FUNCTIONALITY
66
Entrypoint,AnyTenant
77
.ROLE
8-
CIPP.AppSettings.ReadWrite.
8+
CIPP.AppSettings.ReadWrite
99
#>
1010
[CmdletBinding()]
1111
param($Request, $TriggerMetadata)
@@ -31,7 +31,7 @@ Function Invoke-ExecAddTenant {
3131
# Create new tenant entry
3232
try {
3333
# Get tenant information from Microsoft Graph
34-
$headers = @{ Authorization = "Bearer $($request.body.access_token)" }
34+
$headers = @{ Authorization = "Bearer $($request.body.accessToken)" }
3535
$Organization = (Invoke-RestMethod -Uri 'https://graph.microsoft.com/v1.0/organization' -Headers $headers -Method GET -ContentType 'application/json' -ErrorAction Stop).value
3636
$displayName = $Organization.displayName
3737
$Domains = (Invoke-RestMethod -Uri 'https://graph.microsoft.com/v1.0/domains?$top=999' -Headers $headers -Method GET -ContentType 'application/json' -ErrorAction Stop).value
@@ -63,7 +63,8 @@ Function Invoke-ExecAddTenant {
6363

6464
# Add tenant to table
6565
Add-CIPPAzDataTableEntity @TenantsTable -Entity $NewTenant -Force | Out-Null
66-
$Results = @{'message' = "Successfully added tenant $tenantId to the tenant list with directTenant status."; 'severity' = 'success' }
66+
$Results = @{'message' = "Successfully added tenant $displayName ($defaultDomainName) to the tenant list with Direct Tenant status."; 'severity' = 'success' }
67+
Write-LogMessage -tenant $defaultDomainName -tenantid $tenantId -API 'Add-Tenant' -message "Added tenant $displayName ($defaultDomainName) with Direct Tenant status." -Sev 'Info'
6768
}
6869
} catch {
6970
$Results = @{'message' = "Failed to add tenant: $($_.Exception.Message)"; 'state' = 'error'; 'severity' = 'error' }
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using namespace System.Net
2+
3+
Function Invoke-ExecCombinedSetup {
4+
<#
5+
.FUNCTIONALITY
6+
Entrypoint,AnyTenant
7+
.ROLE
8+
CIPP.AppSettings.ReadWrite
9+
#>
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
12+
#Make arraylist of Results
13+
$Results = [System.Collections.ArrayList]::new()
14+
try {
15+
if ($request.body.selectedBaselines -and $request.body.baselineOption -eq 'downloadBaselines') {
16+
#do a single download of the selected baselines.
17+
foreach ($template in $request.body.selectedBaselines) {
18+
$object = @{
19+
TenantFilter = 'No tenant'
20+
Name = "Download Single Baseline: $($template.value)"
21+
Command = @{
22+
value = 'New-CIPPTemplateRun'
23+
}
24+
Parameters = @{
25+
TemplateSettings = @{
26+
ca = $false
27+
intuneconfig = $false
28+
intunecompliance = $false
29+
intuneprotection = $false
30+
templateRepo = @{
31+
label = $Template.label
32+
value = $template.value
33+
addedFields = @{
34+
branch = 'main'
35+
}
36+
}
37+
templateRepoBranch = @{
38+
label = 'main'
39+
value = 'main'
40+
}
41+
standardsconfig = $true
42+
groupTemplates = $true
43+
policyTemplates = $true
44+
caTemplates = $true
45+
}
46+
}
47+
ScheduledTime = 0
48+
}
49+
$null = Add-CIPPScheduledTask -task $object -hidden $false -DisallowDuplicateName $true -Headers $Request.Headers
50+
$Results.add("Scheduled download of baseline: $($template.value)")
51+
}
52+
}
53+
if ($Request.body.email -or $Request.body.webhook) {
54+
#create hashtable from pscustomobject
55+
$notificationConfig = $request.body | Select-Object email, webhook, onepertenant, logsToInclude, sendtoIntegration, sev | ConvertTo-Json | ConvertFrom-Json -AsHashtable
56+
$notificationResults = Set-CIPPNotificationConfig @notificationConfig
57+
$Results.add($notificationResults)
58+
}
59+
$Results.add('Setup is now complete. You may navigate away from this page and start using CIPP.')
60+
#one more force of reauth so env vars update.
61+
$auth = Get-CIPPAuthentication
62+
} catch {
63+
$Results = [pscustomobject]@{'Results' = "Failed. $($_.InvocationInfo.ScriptLineNumber): $($_.Exception.message)"; severity = 'failed' }
64+
}
65+
66+
# Associate values to output bindings by calling 'Push-OutputBinding'.
67+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
68+
StatusCode = [HttpStatusCode]::OK
69+
Body = $Results
70+
})
71+
72+
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Setup/Invoke-ExecCreateSAMApp.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Function Invoke-ExecCreateSAMApp {
55
.FUNCTIONALITY
66
Entrypoint,AnyTenant
77
.ROLE
8-
CIPP.AppSettings.ReadWrite.
8+
CIPP.AppSettings.ReadWrite
99
#>
1010
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
1111
[CmdletBinding()]
@@ -84,10 +84,19 @@ Function Invoke-ExecCreateSAMApp {
8484
Write-Information ($Secret | ConvertTo-Json -Depth 5)
8585
Add-CIPPAzDataTableEntity @DevSecretsTable -Entity $Secret -Force
8686
} else {
87+
8788
Set-AzKeyVaultSecret -VaultName $kv -Name 'tenantid' -SecretValue (ConvertTo-SecureString -String $TenantId -AsPlainText -Force)
8889
Set-AzKeyVaultSecret -VaultName $kv -Name 'applicationid' -SecretValue (ConvertTo-SecureString -String $Appid.appId -AsPlainText -Force)
8990
Set-AzKeyVaultSecret -VaultName $kv -Name 'applicationsecret' -SecretValue (ConvertTo-SecureString -String $AppPassword -AsPlainText -Force)
9091
}
92+
$ConfigTable = Get-CippTable -tablename 'Config'
93+
#update the ConfigTable with the latest appId, for caching compare.
94+
$NewConfig = @{
95+
PartitionKey = 'AppCache'
96+
RowKey = 'AppCache'
97+
ApplicationId = $AppId.appId
98+
}
99+
Add-CIPPAzDataTableEntity @ConfigTable -Entity $NewConfig -Force | Out-Null
91100
$Results = @{'message' = "Succesfully $state the application registration. The application ID is $($AppId.appid). You may continue to the next step."; severity = 'success' }
92101
}
93102

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Setup/Invoke-ExecTokenExchange.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Function Invoke-ExecTokenExchange {
4141
Write-LogMessage -API $APIName -message 'Retrieved client secret from development secrets' -Sev 'Info'
4242
} else {
4343
try {
44-
$ClientSecret = (Get-AzKeyVaultSecret -VaultName $kv -Name 'applicationsecret' -AsPlainText).SecretValue
44+
$ClientSecret = (Get-AzKeyVaultSecret -VaultName $kv -Name 'applicationsecret' -AsPlainText)
4545
Write-LogMessage -API $APIName -message 'Retrieved client secret from key vault' -Sev 'Info'
4646
} catch {
4747
Write-LogMessage -API $APIName -message "Failed to retrieve client secret: $($_.Exception.Message)" -Sev 'Error'

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Setup/Invoke-ExecUpdateRefreshToken.ps1

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Function Invoke-ExecUpdateRefreshToken {
55
.FUNCTIONALITY
66
Entrypoint,AnyTenant
77
.ROLE
8-
CIPP.AppSettings.ReadWrite.
8+
CIPP.AppSettings.ReadWrite
99
#>
1010
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
1111
[CmdletBinding()]
@@ -29,11 +29,17 @@ Function Invoke-ExecUpdateRefreshToken {
2929
}
3030
Add-CIPPAzDataTableEntity @DevSecretsTable -Entity $Secret -Force
3131
} else {
32-
if ($env:ApplicationId -eq $Request.body.tenantId) {
32+
if ($env:TenantID -eq $Request.body.tenantId) {
3333
Set-AzKeyVaultSecret -VaultName $kv -Name 'RefreshToken' -SecretValue (ConvertTo-SecureString -String $Request.body.refreshtoken -AsPlainText -Force)
3434
} else {
35-
$name = $Request.body.tenantId -replace '-', '_'
36-
Set-AzKeyVaultSecret -VaultName $kv -Name $name -SecretValue (ConvertTo-SecureString -String $Request.body.refreshtoken -AsPlainText -Force)
35+
Write-Host "$($env:TenantID) does not match $($Request.body.tenantId) - we're adding a new secret for the tenant."
36+
$name = $Request.body.tenantId
37+
try {
38+
Set-AzKeyVaultSecret -VaultName $kv -Name $name -SecretValue (ConvertTo-SecureString -String $Request.body.refreshtoken -AsPlainText -Force)
39+
} catch {
40+
Write-Host "Failed to set secret $name in KeyVault. $($_.Exception.Message)"
41+
throw $_
42+
}
3743
}
3844
}
3945
$InstanceId = Start-UpdatePermissionsOrchestrator #start the CPV refresh immediately while wizard still runs.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using namespace System.Net
2+
3+
Function Invoke-AddQuarantinePolicy {
4+
<#
5+
.FUNCTIONALITY
6+
Entrypoint
7+
.ROLE
8+
Exchange.Spamfilter.ReadWrite
9+
#>
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
12+
13+
$APIName = $Request.Params.CIPPEndpoint
14+
$Headers = $Request.Headers
15+
Write-LogMessage -Headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
16+
17+
$Tenants = ($Request.body.selectedTenants).value
18+
19+
# If allTenants is selected, get all tenants and overwrite any other tenant selection
20+
if ("AllTenants" -in $Tenants) {
21+
$tenants = (Get-Tenants).defaultDomainName
22+
}
23+
24+
$Result = foreach ($TenantFilter in $tenants) {
25+
try {
26+
$ReleaseActionPreference = $Request.Body.ReleaseActionPreference.value ?? $Request.Body.ReleaseActionPreference
27+
28+
$EndUserQuarantinePermissions = @{
29+
PermissionToBlockSender = $Request.Body.BlockSender
30+
PermissionToDelete = $Request.Body.Delete
31+
PermissionToPreview = $Request.Body.Preview
32+
PermissionToRelease = $ReleaseActionPreference -eq "Release" ? $true : $false
33+
PermissionToRequestRelease = $ReleaseActionPreference -eq "RequestRelease" ? $true : $false
34+
PermissionToAllowSender = $Request.Body.AllowSender
35+
}
36+
37+
$Params = @{
38+
Identity = $Request.Body.Name
39+
EndUserQuarantinePermissions = $EndUserQuarantinePermissions
40+
ESNEnabled = $Request.Body.QuarantineNotification
41+
IncludeMessagesFromBlockedSenderAddress = $Request.Body.IncludeMessagesFromBlockedSenderAddress
42+
action = "New"
43+
tenantFilter = $TenantFilter
44+
APIName = $APIName
45+
}
46+
47+
Set-CIPPQuarantinePolicy @Params
48+
$Message = "Created Quarantine policy '$($Request.Body.Name)' for tenant '$($TenantFilter)'"
49+
Write-LogMessage -Headers $Headers -API $APIName -tenant $TenantFilter -message $Message -Sev Info
50+
$Message
51+
52+
}
53+
catch {
54+
$ErrorMessage = Get-CippException -Exception $_
55+
$Message = "Failed to create Quarantine policy '$($Request.Body.Name)' for tenant '$($TenantFilter)' - $($ErrorMessage.NormalizedError)"
56+
Write-LogMessage -Headers $Headers -API $APIName -tenant $TenantFilter -message $Message -Sev Error -LogData $ErrorMessage
57+
$Message
58+
}
59+
}
60+
61+
# Associate values to output bindings by calling 'Push-OutputBinding'.
62+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
63+
StatusCode = [HttpStatusCode]::OK
64+
Body = @{Results = @($Result) }
65+
})
66+
67+
}

0 commit comments

Comments
 (0)