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 #22 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
- Loading branch information
Showing
32 changed files
with
485 additions
and
320 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
23 changes: 23 additions & 0 deletions
23
Modules/CIPPCore/Public/CippQueue/Invoke-ListCippQueue.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,23 @@ | ||
function Invoke-ListCippQueue { | ||
# Input bindings are passed in via param block. | ||
param($Request = $null, $TriggerMetadata) | ||
|
||
if ($Request) { | ||
$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.' | ||
} | ||
|
||
$CippQueue = Get-CippTable -TableName 'CippQueue' | ||
$CippQueueData = Get-CIPPAzDataTableEntity @CippQueue | Where-Object { ($_.Timestamp.DateTime) -ge (Get-Date).ToUniversalTime().AddHours(-1) } | Sort-Object -Property Timestamp -Descending | ||
if ($request) { | ||
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | ||
StatusCode = [HttpStatusCode]::OK | ||
Body = @($CippQueueData) | ||
}) | ||
} else { | ||
return $CippQueueData | ||
} | ||
} |
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,23 @@ | ||
function New-CippQueueEntry { | ||
Param( | ||
$Name, | ||
$Link, | ||
$Reference | ||
) | ||
|
||
$CippQueue = Get-CippTable -TableName CippQueue | ||
|
||
$QueueEntry = @{ | ||
PartitionKey = 'CippQueue' | ||
RowKey = (New-Guid).Guid.ToString() | ||
Name = $Name | ||
Link = $Link | ||
Reference = $Reference | ||
Status = 'Queued' | ||
} | ||
$CippQueue.Entity = $QueueEntry | ||
|
||
Add-CIPPAzDataTableEntity @CippQueue | ||
|
||
$QueueEntry | ||
} |
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,18 @@ | ||
function Remove-CippQueue { | ||
# Input bindings are passed in via param block. | ||
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.' | ||
|
||
$CippQueue = Get-CippTable -TableName 'CippQueue' | ||
Clear-AzDataTable @CippQueue | ||
|
||
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | ||
StatusCode = [HttpStatusCode]::OK | ||
Body = @{Results = @('History cleared') } | ||
}) | ||
} |
29 changes: 29 additions & 0 deletions
29
Modules/CIPPCore/Public/CippQueue/Update-CippQueueEntry.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,29 @@ | ||
function Update-CippQueueEntry { | ||
Param( | ||
[Parameter(Mandatory = $true)] | ||
$RowKey, | ||
$Status, | ||
$Name | ||
) | ||
|
||
$CippQueue = Get-CippTable -TableName CippQueue | ||
|
||
if ($RowKey) { | ||
$QueueEntry = Get-CIPPAzDataTableEntity @CippQueue -Filter ("RowKey eq '{0}'" -f $RowKey) | ||
|
||
if ($QueueEntry) { | ||
if ($Status) { | ||
$QueueEntry.Status = $Status | ||
} | ||
if ($Name) { | ||
$QueueEntry.Name = $Name | ||
} | ||
Update-AzDataTableEntity @CippQueue -Entity $QueueEntry | ||
$QueueEntry | ||
} else { | ||
return $false | ||
} | ||
} else { | ||
return $false | ||
} | ||
} |
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
90 changes: 90 additions & 0 deletions
90
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,90 @@ | ||
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,userPrincipalName,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 | ||
} | ||
|
||
if ($Me.proxyAddresses) { | ||
$Emails = $Me.proxyAddresses | Select-Object @{n = 'Address'; exp = { ($_ -split ':')[1] } }, @{n = 'IsPrimary'; exp = { $_ -cmatch 'SMTP' } } | ||
} else { | ||
$Emails = @(@{ Address = $Me.userPrincipalName; IsPrimary = $true }) | ||
} | ||
|
||
$Body = [PSCustomObject]@{ | ||
Message = $Message | ||
HasMailRead = $HasMailRead | ||
MailUser = $Me.displayName | ||
MailAddresses = @($Emails) | ||
} | ||
} | ||
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) { | ||
if ($Message.receivedDateTime) { | ||
$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 | ||
}) | ||
} |
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
Oops, something went wrong.