Skip to content

Commit

Permalink
Merge pull request #42 from KelvinTegelaar/master
Browse files Browse the repository at this point in the history
[pull] master from KelvinTegelaar:master
  • Loading branch information
pull[bot] authored Jul 21, 2024
2 parents 3e3e2f4 + fa6c4a4 commit 1bb76c6
Show file tree
Hide file tree
Showing 65 changed files with 1,471 additions and 750 deletions.
10 changes: 8 additions & 2 deletions Applications_Upload/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,31 @@ foreach ($tenant in $tenants) {
if ($AZfileuri.uploadState -like '*fail*') { break }
Start-Sleep -Milliseconds 300
} while ($AzFileUri.AzureStorageUri -eq $null)

Write-Host "Uploading file to $($AzFileUri.azureStorageUri)"
Write-Host "Complete AZ file uri data: $($AzFileUri | ConvertTo-Json -Depth 10)"
$chunkSizeInBytes = 4mb
[byte[]]$bytes = [System.IO.File]::ReadAllBytes($($intunewinFilesize.fullname))
$chunks = [Math]::Ceiling($bytes.Length / $chunkSizeInBytes)
$id = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($chunks.ToString('0000')))
#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 :)
$Upload = Invoke-RestMethod -Uri "$($AzFileUri.azureStorageUri)&comp=block&blockid=$id" -Method Put -Headers @{'x-ms-blob-type' = 'BlockBlob' } -InFile $inFile -ContentType 'application/octet-stream'
Write-Host "Upload data: $($Upload | ConvertTo-Json -Depth 10)"
$ConfirmUpload = Invoke-RestMethod -Uri "$($AzFileUri.azureStorageUri)&comp=blocklist" -Method Put -Body "<?xml version=`"1.0`" encoding=`"utf-8`"?><BlockList><Latest>$id</Latest></BlockList>"
Write-Host "Confirm Upload data: $($ConfirmUpload | ConvertTo-Json -Depth 10)"
$CommitReq = New-graphPostRequest -Uri "$($BaseURI)/$($NewApp.id)/microsoft.graph.win32lobapp/contentVersions/1/files/$($ContentReq.id)/commit" -Body $EncBody -Type POST -tenantid $tenant
Write-Host "Commit Request: $($CommitReq | ConvertTo-Json -Depth 10)"

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

}
}
591 changes: 365 additions & 226 deletions ConversionTable.csv

Large diffs are not rendered by default.

320 changes: 194 additions & 126 deletions Modules/CIPPCore/Public/ConversionTable.csv

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using namespace System.Net

Function Invoke-AddRoomMailbox {
<#
.FUNCTIONALITY
Entrypoint
.ROLE
Exchange.Room.ReadWrite
#>
[CmdletBinding()]
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
$User = $request.headers.'x-ms-client-principal'
Write-LogMessage -user $User -API $APINAME -message 'Accessed this API' -Sev 'Debug'

# Write to the Azure Functions log stream.
Write-Host 'PowerShell HTTP trigger function processed a request.'


$Results = [System.Collections.Generic.List[Object]]::new()
$MailboxObject = $Request.body
$AddRoomParams = [pscustomobject]@{
Name = $MailboxObject.username
DisplayName = $MailboxObject.displayName
Room = $true
PrimarySMTPAddress = $MailboxObject.userPrincipalName
ResourceCapacity = if (![string]::IsNullOrWhiteSpace($MailboxObject.ResourceCapacity)) { $MailboxObject.ResourceCapacity } else { $null }

}
# Interact with query parameters or the body of the request.
try {
$AddRoomRequest = New-ExoRequest -tenantid $($MailboxObject.tenantid) -cmdlet 'New-Mailbox' -cmdparams $AddRoomParams
$Results.Add("Successfully created room: $($MailboxObject.DisplayName).")
Write-LogMessage -user $User -API $APINAME -tenant $($MailboxObject.tenantid) -message "Created room $($MailboxObject.DisplayName) with id $($AddRoomRequest.id)" -Sev 'Info'

# Block sign-in for the mailbox
try {
$Request = Set-CIPPSignInState -userid $AddRoomRequest.ExternalDirectoryObjectId -TenantFilter $($MailboxObject.tenantid) -APIName $APINAME -ExecutingUser $User -AccountEnabled $false
$Results.add("Blocked sign-in for Room mailbox; $($MailboxObject.userPrincipalName)")
} catch {
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
$Results.add("Failed to block sign-in for Room mailbox: $($MailboxObject.userPrincipalName). Error: $ErrorMessage")
}

} catch {
$ErrorMessage = Get-CippException -Exception $_
Write-LogMessage -user $User -API $APINAME -tenant $($MailboxObject.tenantid) -message "Failed to create room: $($MailboxObject.DisplayName). Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -LogData $ErrorMessage
$Results.Add("Failed to create Room mailbox $($MailboxObject.userPrincipalName). $($ErrorMessage.NormalizedError)")
}


$Body = [pscustomobject] @{ 'Results' = @($Results) }
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $Body
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,21 @@ Function Invoke-AddSharedMailbox {
$Body = $Results.add("Successfully created shared mailbox: $Email.")
Write-LogMessage -user $User -API $APINAME -tenant $($MailboxObject.tenantid) -message "Created shared mailbox $($MailboxObject.displayname) with email $Email" -Sev 'Info'

# Block sign-in for the mailbox
try {
$null = Set-CIPPSignInState -userid $AddSharedRequest.ExternalDirectoryObjectId -TenantFilter $($MailboxObject.tenantid) -APIName $APINAME -ExecutingUser $User -AccountEnabled $false
$Body = $Results.add("Blocked sign-in for shared mailbox $Email")
} catch {
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
$Body = $Results.add("Failed to block sign-in for shared mailbox $Email. Error: $ErrorMessage")
}

} catch {
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
Write-LogMessage -user $User -API $APINAME -tenant $($MailboxObject.tenantid) -message "Failed to create shared mailbox. Error: $ErrorMessage" -Sev 'Error'
$Body = $Results.add("Failed to create Shared Mailbox. $ErrorMessage")
}

# Block sign-in for the mailbox
try {
$null = Set-CIPPSignInState -userid $AddSharedRequest.ExternalDirectoryObjectId -TenantFilter $($MailboxObject.tenantid) -APIName $APINAME -ExecutingUser $User -AccountEnabled $false
Write-LogMessage -user $User -API $APINAME -tenant $($MailboxObject.tenantid) -message "Blocked sign-in for shared mailbox $Email" -Sev 'Info'
$Body = $Results.add("Blocked sign-in for shared mailbox $Email")
} catch {
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
Write-LogMessage -user $User -API $APINAME -tenant $($MailboxObject.tenantid) -message "Failed to block sign-in for shared mailbox $Email. Error: $ErrorMessage" -Sev 'Error'
$Body = $Results.add("Failed to block sign-in for shared mailbox $Email. Error: $ErrorMessage")
}

# Add aliases to the mailbox if any are provided
if ($Aliases) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using namespace System.Net

Function Invoke-EditContact {
<#
.FUNCTIONALITY
Entrypoint
.ROLE
Exchange.Contact.ReadWrite
#>
[CmdletBinding()]
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'

$contactobj = $Request.body
write-host "This is the contact object: $contactobj"
# Write to the Azure Functions log stream.
Write-Host 'PowerShell HTTP trigger function processed a request.'
try {

$BodyToship = [pscustomobject] @{
'DisplayName' = $contactobj.DisplayName
'WindowsEmailAddress' = $contactobj.mail
'FirstName' = $contactObj.firstName
'LastName' = $contactobj.LastName
"Title" = $contactobj.jobTitle
"StreetAddress" = $contactobj.StreetAddress
"PostalCode" = $contactobj.PostalCode
"City" = $contactobj.City
"CountryOrRegion" = $contactobj.Country
"Company" = $contactobj.companyName
"mobilePhone" = $contactobj.MobilePhone
"phone" = $contactobj.BusinessPhone
'identity' = $contactobj.ContactID
}
$EditContact = New-ExoRequest -tenantid $Request.body.tenantID -cmdlet 'Set-Contact' -cmdparams $BodyToship -UseSystemMailbox $true
$Results = [pscustomobject]@{'Results' = "Successfully edited contact $($contactobj.Displayname)" }
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($contactobj.tenantid) -message "Created contact $($contactobj.displayname)" -Sev 'Info'

} catch {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($contactobj.tenantid) -message "Contact creation API failed. $($_.Exception.Message)" -Sev 'Error'
$Results = [pscustomobject]@{'Results' = "Failed to edit contact. $($_.Exception.Message)" }

}

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $Results
})

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Function Invoke-EditTransportRule {
param($Request, $TriggerMetadata)

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


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

try {
$cmdlet = if ($request.query.state -eq 'enable') { 'Enable-TransportRule' } else { 'Disable-TransportRule' }
$GraphRequest = New-ExoRequest -tenantid $Tenantfilter -cmdlet $cmdlet -cmdParams $params -UseSystemMailbox $true
$null = New-ExoRequest -tenantid $Tenantfilter -cmdlet $cmdlet -cmdParams $params -UseSystemMailbox $true
$Result = "Set transport rule $($Request.query.guid) to $($request.query.State)"
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
}
catch {
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'
$ErrorMessage = Get-NormalizedError -Message $_.Exception
$Result = $ErrorMessage
Write-LogMessage -user $User -API $APINAME -tenant $tenantfilter -message "Set transport rule $($Request.query.guid) to $($request.query.State)" -sev Info
} catch {
$ErrorMessage = Get-CippException -Exception $_
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
$Result = $ErrorMessage.NormalizedError
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using namespace System.Net

Function Invoke-ExecConvertToRoomMailbox {
<#
.FUNCTIONALITY
Entrypoint
.ROLE
Exchange.Mailbox.ReadWrite
#>
[CmdletBinding()]
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
$User = $request.headers.'x-ms-client-principal'
Write-LogMessage -user $User -API $APINAME -message 'Accessed this API' -Sev 'Debug'

# Write to the Azure Functions log stream.
Write-Host 'PowerShell HTTP trigger function processed a request.'

# Interact with query parameters or the body of the request.
Try {
$ConvertedMailbox = Set-CIPPMailboxType -userid $Request.query.id -tenantFilter $Request.query.TenantFilter -APIName $APINAME -ExecutingUser $User -MailboxType 'Room'
$Results = [pscustomobject]@{'Results' = "$ConvertedMailbox" }
$StatusCode = [HttpStatusCode]::OK
} catch {
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
$Results = [pscustomobject]@{'Results' = "Failed to convert $($request.query.id) - $ErrorMessage" }
$StatusCode = [HttpStatusCode]::Forbidden
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = $StatusCode
Body = $Results
})

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ Function Invoke-ExecConverttoSharedMailbox {
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'

$Tenant = $Request.query.TenantFilter
$User = $request.headers.'x-ms-client-principal'
Write-LogMessage -user $User -API $APINAME -message 'Accessed this API' -Sev 'Debug'

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using namespace System.Net

Function Invoke-ExecSetMailboxLocale {
<#
.FUNCTIONALITY
Entrypoint
.ROLE
Exchange.Mailbox.ReadWrite
#>
[CmdletBinding()]
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
$Tenant = $Request.body.TenantFilter
$User = $request.headers.'x-ms-client-principal'
Write-LogMessage -user $User -API $APINAME -message 'Accessed this API' -Sev 'Debug'

# Write to the Azure Functions log stream.
Write-Host 'PowerShell HTTP trigger function processed a request.'


# Interact with query parameters or the body of the request.
$Results = Set-CippMailboxLocale -username $Request.Body.user -locale $Request.body.input -tenantFilter $Tenant -APIName $APINAME -ExecutingUser $User
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = @{ Results = $Results }
})

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using namespace System.Net

Function Invoke-ExecStartManagedFolderAssistant {
<#
.FUNCTIONALITY
Entrypoint
.ROLE
Exchange.Mailbox.ReadWrite
#>
[CmdletBinding()]
param($Request, $TriggerMetadata)

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

# Write to the Azure Functions log stream.
Write-Host 'PowerShell HTTP trigger function processed a request.'
$Results = [System.Collections.Generic.List[Object]]::new()

# Interact with query parameters or the body of the request.

try {
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Start-ManagedFolderAssistant' -cmdparams @{Identity = $Request.query.id }
$Results.Add("Successfully started Managed Folder Assistant for mailbox $($Request.query.id).")
$StatusCode = [HttpStatusCode]::OK
} catch {
$ErrorMessage = Get-CippException -Exception $_
Write-LogMessage -user $User -API $APINAME -tenant $Tenant -message "Failed to create room: $($MailboxObject.DisplayName). Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -LogData $ErrorMessage
$Results.Add("Failed to start Managed Folder Assistant for mailbox $($Request.query.id). Error: $($ErrorMessage.NormalizedError)")
$StatusCode = [HttpStatusCode]::Forbidden
}

$Body = [pscustomobject] @{ 'Results' = @($Results) }
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = $StatusCode
Body = $Body
})
}
Loading

0 comments on commit 1bb76c6

Please sign in to comment.