Skip to content

Commit 0fec19b

Browse files
authored
Merge pull request #423 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 983a8bd + 350678e commit 0fec19b

File tree

7 files changed

+294
-209
lines changed

7 files changed

+294
-209
lines changed

Modules/CIPPCore/Public/Add-CIPPAzDataTableEntity.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ function Add-CIPPAzDataTableEntity {
102102

103103
$propertiesToRemove = [System.Collections.Generic.List[object]]::new()
104104
foreach ($key in $SingleEnt.Keys) {
105+
if ($key -in @('RowKey', 'PartitionKey')) { continue }
105106
$newEntitySize = [System.Text.Encoding]::UTF8.GetByteCount($($newEntity | ConvertTo-Json -Compress))
106107
if ($newEntitySize -lt $MaxRowSize) {
107108
$propertySize = [System.Text.Encoding]::UTF8.GetByteCount($SingleEnt[$key].ToString())
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function Get-CIPPAlertSmtpAuthSuccess {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint – Check sign-in logs for SMTP AUTH with success status
5+
#>
6+
[CmdletBinding()]
7+
Param (
8+
[Parameter(Mandatory = $false)]
9+
[Alias('input')]
10+
$InputValue,
11+
$TenantFilter
12+
)
13+
14+
try {
15+
# Graph API endpoint for sign-ins
16+
$uri = "https://graph.microsoft.com/v1.0/auditLogs/signIns?`$filter=clientAppUsed eq 'SMTP' and status/errorCode eq 0"
17+
18+
# Call Graph API for the given tenant
19+
$SignIns = New-GraphGetRequest -uri $uri -tenantid $TenantFilter
20+
21+
# Select only the properties you care about
22+
$AlertData = $SignIns.value | Select-Object userPrincipalName, createdDateTime, clientAppUsed, ipAddress, status
23+
24+
# Write results into the alert pipeline
25+
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
26+
27+
} catch {
28+
# Suppress errors if no data returned
29+
# Uncomment if you want explicit error logging
30+
# Write-AlertMessage -tenant $($TenantFilter) -message "Failed to query SMTP AUTH sign-ins for $($TenantFilter): $(Get-NormalizedError -message $_.Exception.message)"
31+
}
32+
}
Lines changed: 105 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,127 @@
11
using namespace System.Net
22

33
Function Invoke-ExecExtensionMapping {
4-
<#
4+
<#
55
.FUNCTIONALITY
66
Entrypoint
77
.ROLE
88
CIPP.Extension.ReadWrite
99
#>
10-
[CmdletBinding()]
11-
param($Request, $TriggerMetadata)
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
1212

13-
$APIName = $Request.Params.CIPPEndpoint
14-
$Headers = $Request.Headers
15-
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
13+
$APIName = $Request.Params.CIPPEndpoint
14+
$Headers = $Request.Headers
15+
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
1616

17-
$Table = Get-CIPPTable -TableName CippMapping
17+
$Table = Get-CIPPTable -TableName CippMapping
1818

19-
if ($Request.Query.List) {
20-
switch ($Request.Query.List) {
21-
'HaloPSA' {
22-
$Result = Get-HaloMapping -CIPPMapping $Table
23-
}
24-
'NinjaOne' {
25-
$Result = Get-NinjaOneOrgMapping -CIPPMapping $Table
26-
}
27-
'NinjaOneFields' {
28-
$Result = Get-NinjaOneFieldMapping -CIPPMapping $Table
29-
}
30-
'Hudu' {
31-
$Result = Get-HuduMapping -CIPPMapping $Table
32-
}
33-
'HuduFields' {
34-
$Result = Get-HuduFieldMapping -CIPPMapping $Table
35-
}
36-
'Sherweb' {
37-
$Result = Get-SherwebMapping -CIPPMapping $Table
38-
}
39-
'HaloPSAFields' {
40-
$TicketTypes = Get-HaloTicketType
41-
$Result = @{'TicketTypes' = $TicketTypes }
42-
}
43-
'PWPushFields' {
44-
$Accounts = Get-PwPushAccount
45-
$Result = @{
46-
'Accounts' = $Accounts
47-
}
48-
}
19+
if ($Request.Query.List) {
20+
switch ($Request.Query.List) {
21+
'HaloPSA' {
22+
$Result = Get-HaloMapping -CIPPMapping $Table
23+
}
24+
'NinjaOne' {
25+
$Result = Get-NinjaOneOrgMapping -CIPPMapping $Table
26+
}
27+
'NinjaOneFields' {
28+
$Result = Get-NinjaOneFieldMapping -CIPPMapping $Table
29+
}
30+
'Hudu' {
31+
$Result = Get-HuduMapping -CIPPMapping $Table
32+
}
33+
'HuduFields' {
34+
$Result = Get-HuduFieldMapping -CIPPMapping $Table
35+
}
36+
'Sherweb' {
37+
$Result = Get-SherwebMapping -CIPPMapping $Table
38+
}
39+
'HaloPSAFields' {
40+
$TicketTypes = Get-HaloTicketType
41+
$Outcomes = Get-HaloTicketOutcome
42+
$Result = @{
43+
'TicketTypes' = $TicketTypes
44+
'Outcomes' = $Outcomes
4945
}
46+
}
47+
'PWPushFields' {
48+
$Accounts = Get-PwPushAccount
49+
$Result = @{
50+
'Accounts' = $Accounts
51+
}
52+
}
5053
}
54+
}
5155

52-
try {
53-
if ($Request.Query.AddMapping) {
54-
switch ($Request.Query.AddMapping) {
55-
'Sherweb' {
56-
$Result = Set-SherwebMapping -CIPPMapping $Table -APIName $APIName -Request $Request
57-
}
58-
'HaloPSA' {
59-
$Result = Set-HaloMapping -CIPPMapping $Table -APIName $APIName -Request $Request
60-
}
61-
'NinjaOne' {
62-
$Result = Set-NinjaOneOrgMapping -CIPPMapping $Table -APIName $APIName -Request $Request
63-
Register-CIPPExtensionScheduledTasks
64-
}
65-
'NinjaOneFields' {
66-
$Result = Set-NinjaOneFieldMapping -CIPPMapping $Table -APIName $APIName -Request $Request -TriggerMetadata $TriggerMetadata
67-
Register-CIPPExtensionScheduledTasks
68-
}
69-
'Hudu' {
70-
$Result = Set-HuduMapping -CIPPMapping $Table -APIName $APIName -Request $Request
71-
Register-CIPPExtensionScheduledTasks
72-
}
73-
'HuduFields' {
74-
$Result = Set-ExtensionFieldMapping -CIPPMapping $Table -APIName $APIName -Request $Request -Extension 'Hudu'
75-
Register-CIPPExtensionScheduledTasks
76-
}
77-
}
56+
try {
57+
if ($Request.Query.AddMapping) {
58+
switch ($Request.Query.AddMapping) {
59+
'Sherweb' {
60+
$Result = Set-SherwebMapping -CIPPMapping $Table -APIName $APIName -Request $Request
61+
}
62+
'HaloPSA' {
63+
$Result = Set-HaloMapping -CIPPMapping $Table -APIName $APIName -Request $Request
64+
}
65+
'NinjaOne' {
66+
$Result = Set-NinjaOneOrgMapping -CIPPMapping $Table -APIName $APIName -Request $Request
67+
Register-CIPPExtensionScheduledTasks
68+
}
69+
'NinjaOneFields' {
70+
$Result = Set-NinjaOneFieldMapping -CIPPMapping $Table -APIName $APIName -Request $Request -TriggerMetadata $TriggerMetadata
71+
Register-CIPPExtensionScheduledTasks
7872
}
79-
$StatusCode = [HttpStatusCode]::OK
80-
} catch {
81-
$ErrorMessage = Get-CippException -Exception $_
82-
$Result = "Mapping API failed. $($ErrorMessage.NormalizedError)"
83-
Write-LogMessage -API $APIName -headers $Headers -message $Result -Sev 'Error' -LogData $ErrorMessage
84-
$StatusCode = [HttpStatusCode]::InternalServerError
73+
'Hudu' {
74+
$Result = Set-HuduMapping -CIPPMapping $Table -APIName $APIName -Request $Request
75+
Register-CIPPExtensionScheduledTasks
76+
}
77+
'HuduFields' {
78+
$Result = Set-ExtensionFieldMapping -CIPPMapping $Table -APIName $APIName -Request $Request -Extension 'Hudu'
79+
Register-CIPPExtensionScheduledTasks
80+
}
81+
}
8582
}
83+
$StatusCode = [HttpStatusCode]::OK
84+
}
85+
catch {
86+
$ErrorMessage = Get-CippException -Exception $_
87+
$Result = "Mapping API failed. $($ErrorMessage.NormalizedError)"
88+
Write-LogMessage -API $APIName -headers $Headers -message $Result -Sev 'Error' -LogData $ErrorMessage
89+
$StatusCode = [HttpStatusCode]::InternalServerError
90+
}
8691

87-
try {
88-
if ($Request.Query.AutoMapping) {
89-
switch ($Request.Query.AutoMapping) {
90-
'NinjaOne' {
91-
$Batch = [PSCustomObject]@{
92-
'NinjaAction' = 'StartAutoMapping'
93-
'FunctionName' = 'NinjaOneQueue'
94-
}
95-
$InputObject = [PSCustomObject]@{
96-
OrchestratorName = 'NinjaOneOrchestrator'
97-
Batch = @($Batch)
98-
}
99-
#Write-Host ($InputObject | ConvertTo-Json)
100-
$InstanceId = Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Depth 5 -Compress)
101-
Write-Host "Started permissions orchestration with ID = '$InstanceId'"
102-
$Result = 'AutoMapping Request has been queued. Exact name matches will appear first and matches on device names and serials will take longer. Please check the CIPP Logbook and refresh the page once complete.'
103-
}
104-
105-
}
92+
try {
93+
if ($Request.Query.AutoMapping) {
94+
switch ($Request.Query.AutoMapping) {
95+
'NinjaOne' {
96+
$Batch = [PSCustomObject]@{
97+
'NinjaAction' = 'StartAutoMapping'
98+
'FunctionName' = 'NinjaOneQueue'
99+
}
100+
$InputObject = [PSCustomObject]@{
101+
OrchestratorName = 'NinjaOneOrchestrator'
102+
Batch = @($Batch)
103+
}
104+
#Write-Host ($InputObject | ConvertTo-Json)
105+
$InstanceId = Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Depth 5 -Compress)
106+
Write-Host "Started permissions orchestration with ID = '$InstanceId'"
107+
$Result = 'AutoMapping Request has been queued. Exact name matches will appear first and matches on device names and serials will take longer. Please check the CIPP Logbook and refresh the page once complete.'
106108
}
107-
$StatusCode = [HttpStatusCode]::OK
108-
} catch {
109-
$ErrorMessage = Get-CippException -Exception $_
110-
$Result = "Mapping API failed. $($ErrorMessage.NormalizedError)"
111-
Write-LogMessage -API $APIName -headers $Headers -message $Result -Sev 'Error' -LogData $ErrorMessage
112-
$StatusCode = [HttpStatusCode]::InternalServerError
109+
110+
}
113111
}
112+
$StatusCode = [HttpStatusCode]::OK
113+
}
114+
catch {
115+
$ErrorMessage = Get-CippException -Exception $_
116+
$Result = "Mapping API failed. $($ErrorMessage.NormalizedError)"
117+
Write-LogMessage -API $APIName -headers $Headers -message $Result -Sev 'Error' -LogData $ErrorMessage
118+
$StatusCode = [HttpStatusCode]::InternalServerError
119+
}
114120

115-
# Associate values to output bindings by calling 'Push-OutputBinding'.
116-
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
117-
StatusCode = $StatusCode
118-
Body = $Result
119-
})
121+
# Associate values to output bindings by calling 'Push-OutputBinding'.
122+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
123+
StatusCode = $StatusCode
124+
Body = $Result
125+
})
120126

121127
}

Modules/CippExtensions/Public/HIBP/New-BreachTenantSearch.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function New-BreachTenantSearch {
66
)
77

88
$Table = Get-CIPPTable -TableName UserBreaches
9-
$LatestBreach = Get-BreachInfo -TenantFilter $TenantFilter | Group-Object -Property clientDomain
9+
$LatestBreach = Get-BreachInfo -TenantFilter $TenantFilter | Where-Object { $_.email } | Group-Object -Property clientDomain
1010

1111
$usersResults = foreach ($domain in $LatestBreach) {
1212
$ExistingBreaches = Get-CIPPAzDataTableEntity @Table -Filter "RowKey eq '$($domain.name)'"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
function Get-HaloTicketOutcome {
2+
<#
3+
.SYNOPSIS
4+
Get Halo Ticket Outcome
5+
.DESCRIPTION
6+
Get Halo Ticket Outcome
7+
.EXAMPLE
8+
Get-HaloTicketOutcome
9+
10+
#>
11+
[CmdletBinding()]
12+
param ()
13+
$Table = Get-CIPPTable -TableName Extensionsconfig
14+
try {
15+
$Configuration = ((Get-CIPPAzDataTableEntity @Table).config | ConvertFrom-Json -ea stop).HaloPSA
16+
$Token = Get-HaloToken -configuration $Configuration
17+
$TicketType = $Configuration.TicketType.value ?? $Configuration.TicketType
18+
if ($TicketType) {
19+
$WorkflowId = (Invoke-RestMethod -Uri "$($Configuration.ResourceURL)/tickettype/$TicketType" -ContentType 'application/json' -Method GET -Headers @{Authorization = "Bearer $($Token.access_token)" }).workflow_id
20+
$Workflow = Invoke-RestMethod -Uri "$($Configuration.ResourceURL)/workflow/$WorkflowId" -ContentType 'application/json' -Method GET -Headers @{Authorization = "Bearer $($Token.access_token)" }
21+
$Outcomes = Invoke-RestMethod -Uri "$($Configuration.ResourceURL)/outcome" -ContentType 'application/json' -Method GET -Headers @{Authorization = "Bearer $($Token.access_token)" }
22+
$Outcomes | Where-Object { $_.id -in $Workflow.steps.actions.action_id } | Sort-Object -Property buttonname
23+
}
24+
else {
25+
# Invoke-RestMethod -Uri "$($Configuration.ResourceURL)/outcome" -ContentType 'application/json' -Method GET -Headers @{Authorization = "Bearer $($Token.access_token)" }
26+
@(
27+
@{
28+
buttonname = 'Select and save a Ticket Type first to see available outcomes'
29+
value = -1
30+
}
31+
)
32+
}
33+
}
34+
catch {
35+
$Message = if ($_.ErrorDetails.Message) {
36+
Get-NormalizedError -Message $_.ErrorDetails.Message
37+
}
38+
else {
39+
$_.Exception.message
40+
}
41+
@(@{name = "Could not get HaloPSA Outcomes, error: $Message"; id = '' })
42+
}
43+
}
44+

0 commit comments

Comments
 (0)