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 pull request #26 from KelvinTegelaar/master
[pull] master from KelvinTegelaar:master
- Loading branch information
Showing
40 changed files
with
1,008 additions
and
386 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
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
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
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 |
---|---|---|
|
@@ -24,6 +24,27 @@ Function Invoke-AddPolicy { | |
} | ||
try { | ||
switch ($Request.body.TemplateType) { | ||
'AppProtection' { | ||
$TemplateType = ($RawJSON | ConvertFrom-Json).'@odata.type' -replace '#microsoft.graph.', '' | ||
$TemplateTypeURL = "$($TemplateType)s" | ||
$CheckExististing = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/deviceAppManagement/$TemplateTypeURL" -tenantid $tenant | ||
if ($displayname -in $CheckExististing.displayName) { | ||
Throw "Policy with Display Name $($Displayname) Already exists" | ||
} | ||
$CreateRequest = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceAppManagement/$TemplateTypeURL" -tenantid $tenant -type POST -body $RawJSON | ||
} | ||
'deviceCompliancePolicies' { | ||
$TemplateTypeURL = 'deviceCompliancePolicies' | ||
$CheckExististing = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/deviceManagement/$TemplateTypeURL" -tenantid $tenant | ||
if ($displayname -in $CheckExististing.displayName) { | ||
Throw "Policy with Display Name $($Displayname) Already exists" | ||
} | ||
$JSON = $RawJSON | ConvertFrom-Json | Select-Object * -ExcludeProperty id, createdDateTime, lastModifiedDateTime, version, '[email protected]', '@odata.context' | ||
$JSON.scheduledActionsForRule = @($JSON.scheduledActionsForRule | Select-Object * -ExcludeProperty '[email protected]') | ||
$RawJSON = ConvertTo-Json -InputObject $JSON -Depth 20 -Compress | ||
Write-Host $RawJSON | ||
$CreateRequest = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/$TemplateTypeURL" -tenantid $tenant -type POST -body $RawJson | ||
} | ||
'Admin' { | ||
$TemplateTypeURL = 'groupPolicyConfigurations' | ||
$CreateBody = '{"description":"' + $description + '","displayName":"' + $displayname + '","roleScopeTagIds":["0"]}' | ||
|
52 changes: 52 additions & 0 deletions
52
Modules/CIPPCore/Public/Entrypoints/Invoke-AddUserBulk.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,52 @@ | ||
using namespace System.Net | ||
|
||
Function Invoke-AddUserBulk { | ||
<# | ||
.FUNCTIONALITY | ||
Entrypoint | ||
#> | ||
[CmdletBinding()] | ||
param($Request, $TriggerMetadata) | ||
|
||
$APIName = 'AddUserBulk' | ||
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug' | ||
$TenantFilter = $Request.body.TenantFilter | ||
$Results = [System.Collections.ArrayList]@() | ||
foreach ($userobj in $request.body.BulkUser) { | ||
Write-Host 'PowerShell HTTP trigger function processed a request.' | ||
try { | ||
$password = if ($userobj.password) { $userobj.password } else { New-passwordString } | ||
$UserprincipalName = "$($UserObj.mailNickName)@$($UserObj.domain)" | ||
$BodyToship = $userobj | ||
#Remove domain from body to ship | ||
$BodyToship = $BodyToship | Select-Object * -ExcludeProperty password, domain | ||
$BodyToship | Add-Member -NotePropertyName accountEnabled -NotePropertyValue $true -Force | ||
$BodyToship | Add-Member -NotePropertyName userPrincipalName -NotePropertyValue $UserprincipalName -Force | ||
$BodyToship | Add-Member -NotePropertyName passwordProfile -NotePropertyValue @{'password' = $password; 'forceChangePasswordNextSignIn' = $true } -Force | ||
Write-Host "body is now: $($BodyToship | ConvertTo-Json -Depth 10 -Compress)" | ||
if ($userobj.businessPhones) { $bodytoShip.businessPhones = @($userobj.businessPhones) } | ||
$bodyToShip = ConvertTo-Json -Depth 10 -InputObject $BodyToship -Compress | ||
Write-Host "Our body to ship is $bodyToShip" | ||
$GraphRequest = New-GraphPostRequest -uri 'https://graph.microsoft.com/beta/users' -tenantid $TenantFilter -type POST -body $BodyToship -verbose | ||
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($TenantFilter) -message "Created user $($userobj.displayname) with id $($GraphRequest.id) " -Sev 'Info' | ||
$results.add("Created user $($UserprincipalName). Password is $password") | ||
} catch { | ||
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($TenantFilter) -message "Failed to create user. Error:$($_.Exception.Message)" -Sev 'Error' | ||
$body = $results.add("Failed to create user. $($_.Exception.Message)" ) | ||
} | ||
} | ||
$body = [pscustomobject] @{ | ||
'Results' = @($results) | ||
'Username' = $UserprincipalName | ||
'Password' = $password | ||
'CopyFrom' = $copyFromResults | ||
} | ||
|
||
|
||
# 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
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
82 changes: 82 additions & 0 deletions
82
Modules/CIPPCore/Public/Entrypoints/Invoke-ExecMailTest.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,82 @@ | ||
using namespace System.Net | ||
Function Invoke-ExecMailTest { | ||
<# | ||
.FUNCTIONALITY | ||
Entrypoint | ||
#> | ||
[CmdletBinding()] | ||
param($Request, $TriggerMetadata) | ||
|
||
$APIName = $TriggerMetadata.FunctionName | ||
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug' | ||
|
||
# Write to the Azure Functions log stream. | ||
Write-Host 'PowerShell HTTP trigger function processed a request.' | ||
|
||
try { | ||
switch ($Request.Query.Action) { | ||
'CheckConfig' { | ||
$GraphToken = Get-GraphToken -returnRefresh $true -SkipCache $true | ||
$AccessTokenDetails = Read-JwtAccessDetails -Token $GraphToken.access_token | ||
$Me = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/me?$select=displayName,proxyAddresses' -NoAuthCheck $true | ||
if ($AccessTokenDetails.Scope -contains 'Mail.Read') { | ||
$Message = 'Mail.Read - Delegated was found in the token scope.' | ||
$HasMailRead = $true | ||
} else { | ||
$Message = 'Please add Mail.Read - Delegated to the API permissions for CIPP-SAM.' | ||
$HasMailRead = $false | ||
} | ||
|
||
$Body = [PSCustomObject]@{ | ||
Message = $Message | ||
HasMailRead = $HasMailRead | ||
MailUser = $Me.displayName | ||
MailAddresses = $Me.proxyAddresses | Select-Object @{n = 'Address'; exp = { ($_ -split ':')[1] } }, @{n = 'IsPrimary'; exp = { $_ -cmatch 'SMTP' } } | ||
} | ||
} | ||
default { | ||
$Messages = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/me/mailFolders/Inbox/messages?`$select=receivedDateTime,subject,sender,internetMessageHeaders,webLink" -NoAuthCheck $true | ||
$Results = foreach ($Message in $Messages) { | ||
$AuthResult = ($Message.internetMessageHeaders | Where-Object -Property name -EQ 'Authentication-Results').value | ||
$AuthResult = $AuthResult -split ';\s*' | ||
$AuthResult = $AuthResult | ForEach-Object { | ||
if ($_ -match '^(?<Name>.+?)=\s*(?<Status>.+?)\s(?<Info>.+)$') { | ||
[PSCustomObject]@{ | ||
Name = $Matches.Name | ||
Status = $Matches.Status | ||
Info = $Matches.Info | ||
} | ||
} | ||
} | ||
[PSCustomObject]@{ | ||
Received = $Message.receivedDateTime | ||
Subject = $Message.subject | ||
Sender = $Message.sender.emailAddress.name | ||
From = $Message.sender.emailAddress.address | ||
Link = $Message.webLink | ||
Headers = $Message.internetMessageHeaders | ||
AuthResult = $AuthResult | ||
} | ||
} | ||
$Body = [PSCustomObject]@{ | ||
Results = @($Results) | ||
Metadata = [PSCustomObject]@{ | ||
Count = ($Results | Measure-Object).Count | ||
} | ||
} | ||
} | ||
} | ||
$StatusCode = [HttpStatusCode]::OK | ||
} catch { | ||
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message | ||
$StatusCode = [HttpStatusCode]::BadRequest | ||
$Body = [PSCustomObject]@{ | ||
Results = @($ErrorMessage) | ||
} | ||
} | ||
# Associate values to output bindings by calling 'Push-OutputBinding'. | ||
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | ||
StatusCode = $StatusCode | ||
Body = $Body | ||
}) | ||
} |
Oops, something went wrong.