Skip to content

Commit fa6c4a4

Browse files
Merge pull request KelvinTegelaar#1003 from KelvinTegelaar/dev
Dev to release
2 parents bd57189 + cf0514e commit fa6c4a4

65 files changed

Lines changed: 1471 additions & 750 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.

Applications_Upload/run.ps1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,31 @@ foreach ($tenant in $tenants) {
8080
if ($AZfileuri.uploadState -like '*fail*') { break }
8181
Start-Sleep -Milliseconds 300
8282
} while ($AzFileUri.AzureStorageUri -eq $null)
83-
83+
Write-Host "Uploading file to $($AzFileUri.azureStorageUri)"
84+
Write-Host "Complete AZ file uri data: $($AzFileUri | ConvertTo-Json -Depth 10)"
8485
$chunkSizeInBytes = 4mb
8586
[byte[]]$bytes = [System.IO.File]::ReadAllBytes($($intunewinFilesize.fullname))
8687
$chunks = [Math]::Ceiling($bytes.Length / $chunkSizeInBytes)
8788
$id = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($chunks.ToString('0000')))
8889
#For anyone that reads this, The maximum chunk size is 100MB for blob storage, so we can upload it as one part and just give it the single ID. Easy :)
8990
$Upload = Invoke-RestMethod -Uri "$($AzFileUri.azureStorageUri)&comp=block&blockid=$id" -Method Put -Headers @{'x-ms-blob-type' = 'BlockBlob' } -InFile $inFile -ContentType 'application/octet-stream'
91+
Write-Host "Upload data: $($Upload | ConvertTo-Json -Depth 10)"
9092
$ConfirmUpload = Invoke-RestMethod -Uri "$($AzFileUri.azureStorageUri)&comp=blocklist" -Method Put -Body "<?xml version=`"1.0`" encoding=`"utf-8`"?><BlockList><Latest>$id</Latest></BlockList>"
93+
Write-Host "Confirm Upload data: $($ConfirmUpload | ConvertTo-Json -Depth 10)"
9194
$CommitReq = New-graphPostRequest -Uri "$($BaseURI)/$($NewApp.id)/microsoft.graph.win32lobapp/contentVersions/1/files/$($ContentReq.id)/commit" -Body $EncBody -Type POST -tenantid $tenant
95+
Write-Host "Commit Request: $($CommitReq | ConvertTo-Json -Depth 10)"
9296

9397
do {
9498
$CommitStateReq = New-graphGetRequest -Uri "$($BaseURI)/$($NewApp.id)/microsoft.graph.win32lobapp/contentVersions/1/files/$($ContentReq.id)" -tenantid $tenant
99+
Write-Host "Commit State Request: $($CommitStateReq | ConvertTo-Json -Depth 10)"
95100
if ($CommitStateReq.uploadState -like '*fail*') {
96101
Write-LogMessage -api 'AppUpload' -tenant $($Tenant) -message "$($ChocoApp.ApplicationName) Commit failed. Please check if app uploaded succesful" -Sev 'Warning'
97102
break
98103
}
99104
Start-Sleep -Milliseconds 300
100105
} while ($CommitStateReq.uploadState -eq 'commitFilePending')
101106
$CommitFinalizeReq = New-graphPostRequest -Uri "$($BaseURI)/$($NewApp.id)" -tenantid $tenant -Body '{"@odata.type":"#microsoft.graph.win32lobapp","committedContentVersion":"1"}' -type PATCH
107+
Write-Host "Commit Finalize Request: $($CommitFinalizeReq | ConvertTo-Json -Depth 10)"
102108
Write-LogMessage -api 'AppUpload' -tenant $($Tenant) -message "Added Application $($chocoApp.ApplicationName)" -Sev 'Info'
103109
if ($AssignTo -ne 'On') {
104110
$intent = if ($AssignToIntent) { 'Uninstall' } else { 'Required' }
@@ -112,4 +118,4 @@ foreach ($tenant in $tenants) {
112118
continue
113119
}
114120

115-
}
121+
}

ConversionTable.csv

Lines changed: 365 additions & 226 deletions
Large diffs are not rendered by default.

Modules/CIPPCore/Public/ConversionTable.csv

Lines changed: 194 additions & 126 deletions
Large diffs are not rendered by default.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using namespace System.Net
2+
3+
Function Invoke-AddRoomMailbox {
4+
<#
5+
.FUNCTIONALITY
6+
Entrypoint
7+
.ROLE
8+
Exchange.Room.ReadWrite
9+
#>
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
12+
13+
$APIName = $TriggerMetadata.FunctionName
14+
$User = $request.headers.'x-ms-client-principal'
15+
Write-LogMessage -user $User -API $APINAME -message 'Accessed this API' -Sev 'Debug'
16+
17+
# Write to the Azure Functions log stream.
18+
Write-Host 'PowerShell HTTP trigger function processed a request.'
19+
20+
21+
$Results = [System.Collections.Generic.List[Object]]::new()
22+
$MailboxObject = $Request.body
23+
$AddRoomParams = [pscustomobject]@{
24+
Name = $MailboxObject.username
25+
DisplayName = $MailboxObject.displayName
26+
Room = $true
27+
PrimarySMTPAddress = $MailboxObject.userPrincipalName
28+
ResourceCapacity = if (![string]::IsNullOrWhiteSpace($MailboxObject.ResourceCapacity)) { $MailboxObject.ResourceCapacity } else { $null }
29+
30+
}
31+
# Interact with query parameters or the body of the request.
32+
try {
33+
$AddRoomRequest = New-ExoRequest -tenantid $($MailboxObject.tenantid) -cmdlet 'New-Mailbox' -cmdparams $AddRoomParams
34+
$Results.Add("Successfully created room: $($MailboxObject.DisplayName).")
35+
Write-LogMessage -user $User -API $APINAME -tenant $($MailboxObject.tenantid) -message "Created room $($MailboxObject.DisplayName) with id $($AddRoomRequest.id)" -Sev 'Info'
36+
37+
# Block sign-in for the mailbox
38+
try {
39+
$Request = Set-CIPPSignInState -userid $AddRoomRequest.ExternalDirectoryObjectId -TenantFilter $($MailboxObject.tenantid) -APIName $APINAME -ExecutingUser $User -AccountEnabled $false
40+
$Results.add("Blocked sign-in for Room mailbox; $($MailboxObject.userPrincipalName)")
41+
} catch {
42+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
43+
$Results.add("Failed to block sign-in for Room mailbox: $($MailboxObject.userPrincipalName). Error: $ErrorMessage")
44+
}
45+
46+
} catch {
47+
$ErrorMessage = Get-CippException -Exception $_
48+
Write-LogMessage -user $User -API $APINAME -tenant $($MailboxObject.tenantid) -message "Failed to create room: $($MailboxObject.DisplayName). Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -LogData $ErrorMessage
49+
$Results.Add("Failed to create Room mailbox $($MailboxObject.userPrincipalName). $($ErrorMessage.NormalizedError)")
50+
}
51+
52+
53+
$Body = [pscustomobject] @{ 'Results' = @($Results) }
54+
# Associate values to output bindings by calling 'Push-OutputBinding'.
55+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
56+
StatusCode = [HttpStatusCode]::OK
57+
Body = $Body
58+
})
59+
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Invoke-AddSharedMailbox.ps1

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,21 @@ Function Invoke-AddSharedMailbox {
3434
$Body = $Results.add("Successfully created shared mailbox: $Email.")
3535
Write-LogMessage -user $User -API $APINAME -tenant $($MailboxObject.tenantid) -message "Created shared mailbox $($MailboxObject.displayname) with email $Email" -Sev 'Info'
3636

37+
# Block sign-in for the mailbox
38+
try {
39+
$null = Set-CIPPSignInState -userid $AddSharedRequest.ExternalDirectoryObjectId -TenantFilter $($MailboxObject.tenantid) -APIName $APINAME -ExecutingUser $User -AccountEnabled $false
40+
$Body = $Results.add("Blocked sign-in for shared mailbox $Email")
41+
} catch {
42+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
43+
$Body = $Results.add("Failed to block sign-in for shared mailbox $Email. Error: $ErrorMessage")
44+
}
45+
3746
} catch {
3847
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
3948
Write-LogMessage -user $User -API $APINAME -tenant $($MailboxObject.tenantid) -message "Failed to create shared mailbox. Error: $ErrorMessage" -Sev 'Error'
4049
$Body = $Results.add("Failed to create Shared Mailbox. $ErrorMessage")
4150
}
4251

43-
# Block sign-in for the mailbox
44-
try {
45-
$null = Set-CIPPSignInState -userid $AddSharedRequest.ExternalDirectoryObjectId -TenantFilter $($MailboxObject.tenantid) -APIName $APINAME -ExecutingUser $User -AccountEnabled $false
46-
Write-LogMessage -user $User -API $APINAME -tenant $($MailboxObject.tenantid) -message "Blocked sign-in for shared mailbox $Email" -Sev 'Info'
47-
$Body = $Results.add("Blocked sign-in for shared mailbox $Email")
48-
} catch {
49-
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
50-
Write-LogMessage -user $User -API $APINAME -tenant $($MailboxObject.tenantid) -message "Failed to block sign-in for shared mailbox $Email. Error: $ErrorMessage" -Sev 'Error'
51-
$Body = $Results.add("Failed to block sign-in for shared mailbox $Email. Error: $ErrorMessage")
52-
}
53-
5452
# Add aliases to the mailbox if any are provided
5553
if ($Aliases) {
5654
try {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using namespace System.Net
2+
3+
Function Invoke-EditContact {
4+
<#
5+
.FUNCTIONALITY
6+
Entrypoint
7+
.ROLE
8+
Exchange.Contact.ReadWrite
9+
#>
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
12+
13+
$APIName = $TriggerMetadata.FunctionName
14+
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
15+
16+
$contactobj = $Request.body
17+
write-host "This is the contact object: $contactobj"
18+
# Write to the Azure Functions log stream.
19+
Write-Host 'PowerShell HTTP trigger function processed a request.'
20+
try {
21+
22+
$BodyToship = [pscustomobject] @{
23+
'DisplayName' = $contactobj.DisplayName
24+
'WindowsEmailAddress' = $contactobj.mail
25+
'FirstName' = $contactObj.firstName
26+
'LastName' = $contactobj.LastName
27+
"Title" = $contactobj.jobTitle
28+
"StreetAddress" = $contactobj.StreetAddress
29+
"PostalCode" = $contactobj.PostalCode
30+
"City" = $contactobj.City
31+
"CountryOrRegion" = $contactobj.Country
32+
"Company" = $contactobj.companyName
33+
"mobilePhone" = $contactobj.MobilePhone
34+
"phone" = $contactobj.BusinessPhone
35+
'identity' = $contactobj.ContactID
36+
}
37+
$EditContact = New-ExoRequest -tenantid $Request.body.tenantID -cmdlet 'Set-Contact' -cmdparams $BodyToship -UseSystemMailbox $true
38+
$Results = [pscustomobject]@{'Results' = "Successfully edited contact $($contactobj.Displayname)" }
39+
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($contactobj.tenantid) -message "Created contact $($contactobj.displayname)" -Sev 'Info'
40+
41+
} catch {
42+
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($contactobj.tenantid) -message "Contact creation API failed. $($_.Exception.Message)" -Sev 'Error'
43+
$Results = [pscustomobject]@{'Results' = "Failed to edit contact. $($_.Exception.Message)" }
44+
45+
}
46+
47+
# Associate values to output bindings by calling 'Push-OutputBinding'.
48+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
49+
StatusCode = [HttpStatusCode]::OK
50+
Body = $Results
51+
})
52+
53+
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Invoke-EditTransportRule.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Function Invoke-EditTransportRule {
1111
param($Request, $TriggerMetadata)
1212

1313
$APIName = $TriggerMetadata.FunctionName
14-
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
14+
$User = $request.headers.'x-ms-client-principal'
15+
Write-LogMessage -user $User -API $APINAME -message 'Accessed this API' -Sev 'Debug'
1516
$Tenantfilter = $request.Query.tenantfilter
1617

1718

@@ -21,14 +22,13 @@ Function Invoke-EditTransportRule {
2122

2223
try {
2324
$cmdlet = if ($request.query.state -eq 'enable') { 'Enable-TransportRule' } else { 'Disable-TransportRule' }
24-
$GraphRequest = New-ExoRequest -tenantid $Tenantfilter -cmdlet $cmdlet -cmdParams $params -UseSystemMailbox $true
25+
$null = New-ExoRequest -tenantid $Tenantfilter -cmdlet $cmdlet -cmdParams $params -UseSystemMailbox $true
2526
$Result = "Set transport rule $($Request.query.guid) to $($request.query.State)"
26-
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenantfilter -message "Set transport rule $($Request.query.guid) to $($request.query.State)" -sev Info
27-
}
28-
catch {
29-
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenantfilter -message "Failed setting transport rule $($Request.query.guid) to $($request.query.State). Error:$($_.Exception.Message)" -Sev 'Error'
30-
$ErrorMessage = Get-NormalizedError -Message $_.Exception
31-
$Result = $ErrorMessage
27+
Write-LogMessage -user $User -API $APINAME -tenant $tenantfilter -message "Set transport rule $($Request.query.guid) to $($request.query.State)" -sev Info
28+
} catch {
29+
$ErrorMessage = Get-CippException -Exception $_
30+
Write-LogMessage -user $User -API $APINAME -tenant $tenantfilter -message "Failed setting transport rule $($Request.query.guid) to $($request.query.State). Error:$($ErrorMessage.NormalizedError)" -Sev 'Error' -LogData $ErrorMessage
31+
$Result = $ErrorMessage.NormalizedError
3232
}
3333
# Associate values to output bindings by calling 'Push-OutputBinding'.
3434
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using namespace System.Net
2+
3+
Function Invoke-ExecConvertToRoomMailbox {
4+
<#
5+
.FUNCTIONALITY
6+
Entrypoint
7+
.ROLE
8+
Exchange.Mailbox.ReadWrite
9+
#>
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
12+
13+
$APIName = $TriggerMetadata.FunctionName
14+
$User = $request.headers.'x-ms-client-principal'
15+
Write-LogMessage -user $User -API $APINAME -message 'Accessed this API' -Sev 'Debug'
16+
17+
# Write to the Azure Functions log stream.
18+
Write-Host 'PowerShell HTTP trigger function processed a request.'
19+
20+
# Interact with query parameters or the body of the request.
21+
Try {
22+
$ConvertedMailbox = Set-CIPPMailboxType -userid $Request.query.id -tenantFilter $Request.query.TenantFilter -APIName $APINAME -ExecutingUser $User -MailboxType 'Room'
23+
$Results = [pscustomobject]@{'Results' = "$ConvertedMailbox" }
24+
$StatusCode = [HttpStatusCode]::OK
25+
} catch {
26+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
27+
$Results = [pscustomobject]@{'Results' = "Failed to convert $($request.query.id) - $ErrorMessage" }
28+
$StatusCode = [HttpStatusCode]::Forbidden
29+
}
30+
# Associate values to output bindings by calling 'Push-OutputBinding'.
31+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
32+
StatusCode = $StatusCode
33+
Body = $Results
34+
})
35+
36+
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Invoke-ExecConverttoSharedMailbox.ps1

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ Function Invoke-ExecConverttoSharedMailbox {
1111
param($Request, $TriggerMetadata)
1212

1313
$APIName = $TriggerMetadata.FunctionName
14-
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
15-
14+
$Tenant = $Request.query.TenantFilter
15+
$User = $request.headers.'x-ms-client-principal'
16+
Write-LogMessage -user $User -API $APINAME -message 'Accessed this API' -Sev 'Debug'
1617

1718
# Write to the Azure Functions log stream.
1819
Write-Host 'PowerShell HTTP trigger function processed a request.'
@@ -21,14 +22,17 @@ Function Invoke-ExecConverttoSharedMailbox {
2122
# Interact with query parameters or the body of the request.
2223
Try {
2324
$MailboxType = if ($request.query.ConvertToUser -eq 'true') { 'Regular' } else { 'Shared' }
24-
$ConvertedMailbox = Set-CIPPMailboxType -userid $Request.query.id -tenantFilter $Request.query.TenantFilter -APIName $APINAME -ExecutingUser $request.headers.'x-ms-client-principal' -MailboxType $MailboxType
25+
$ConvertedMailbox = Set-CIPPMailboxType -userid $Request.query.id -tenantFilter $Tenant -APIName $APINAME -ExecutingUser $User -MailboxType $MailboxType
2526
$Results = [pscustomobject]@{'Results' = "$ConvertedMailbox" }
27+
$StatusCode = [HttpStatusCode]::OK
2628
} catch {
27-
$Results = [pscustomobject]@{'Results' = "Failed to convert $($request.query.id) - $($_.Exception.Message)" }
29+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
30+
$Results = [pscustomobject]@{'Results' = "Failed to convert $($request.query.id) - $ErrorMessage" }
31+
$StatusCode = [HttpStatusCode]::Forbidden
2832
}
2933
# Associate values to output bindings by calling 'Push-OutputBinding'.
3034
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
31-
StatusCode = [HttpStatusCode]::OK
35+
StatusCode = $StatusCode
3236
Body = $Results
3337
})
3438

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using namespace System.Net
2+
3+
Function Invoke-ExecSetMailboxLocale {
4+
<#
5+
.FUNCTIONALITY
6+
Entrypoint
7+
.ROLE
8+
Exchange.Mailbox.ReadWrite
9+
#>
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
12+
13+
$APIName = $TriggerMetadata.FunctionName
14+
$Tenant = $Request.body.TenantFilter
15+
$User = $request.headers.'x-ms-client-principal'
16+
Write-LogMessage -user $User -API $APINAME -message 'Accessed this API' -Sev 'Debug'
17+
18+
# Write to the Azure Functions log stream.
19+
Write-Host 'PowerShell HTTP trigger function processed a request.'
20+
21+
22+
# Interact with query parameters or the body of the request.
23+
$Results = Set-CippMailboxLocale -username $Request.Body.user -locale $Request.body.input -tenantFilter $Tenant -APIName $APINAME -ExecutingUser $User
24+
# Associate values to output bindings by calling 'Push-OutputBinding'.
25+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
26+
StatusCode = [HttpStatusCode]::OK
27+
Body = @{ Results = $Results }
28+
})
29+
30+
}

0 commit comments

Comments
 (0)