forked from KelvinTegelaar/CIPP-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'KelvinTegelaar:master' into master
- Loading branch information
Showing
65 changed files
with
1,471 additions
and
750 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Invoke-AddRoomMailbox.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Invoke-EditContact.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...Core/Public/Entrypoints/HTTP Functions/Email-Exchange/Invoke-ExecConverttoRoomMailbox.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Invoke-ExecSetMailboxLocale.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
}) | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...blic/Entrypoints/HTTP Functions/Email-Exchange/Invoke-ExecStartManagedFolderAssistant.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
} |
Oops, something went wrong.