Skip to content

Commit 4d19121

Browse files
authored
Merge pull request #900 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents e4f6d8f + 4b6aa7c commit 4d19121

6 files changed

Lines changed: 175 additions & 22 deletions

File tree

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecSnoozeAlert.ps1

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ function Invoke-ExecSnoozeAlert {
2222

2323
if ([string]::IsNullOrWhiteSpace($CmdletName) -or [string]::IsNullOrWhiteSpace($TenantFilter) -or $null -eq $AlertItem) {
2424
return ([HttpResponseContext]@{
25-
StatusCode = [HttpStatusCode]::BadRequest
26-
Body = @{ Results = 'CmdletName, TenantFilter, and AlertItem are required.' }
27-
})
25+
StatusCode = [HttpStatusCode]::BadRequest
26+
Body = @{ Results = 'CmdletName, TenantFilter, and AlertItem are required.' }
27+
})
2828
}
2929

3030
if ($Duration -notin @(7, 14, 30, -1)) {
3131
return ([HttpResponseContext]@{
32-
StatusCode = [HttpStatusCode]::BadRequest
33-
Body = @{ Results = 'Duration must be 7, 14, 30, or -1 (forever).' }
34-
})
32+
StatusCode = [HttpStatusCode]::BadRequest
33+
Body = @{ Results = 'Duration must be 7, 14, 30, or -1 (forever).' }
34+
})
3535
}
3636

3737
# Compute content hash for this alert item
@@ -67,20 +67,20 @@ function Invoke-ExecSnoozeAlert {
6767
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev 'Info' -tenant $TenantFilter
6868

6969
return ([HttpResponseContext]@{
70-
StatusCode = [HttpStatusCode]::OK
71-
Body = @{
72-
Results = $Result
73-
ContentHash = $HashResult.ContentHash
74-
SnoozeUntil = $SnoozeUntil
75-
SnoozedBy = $SnoozedBy
76-
}
77-
})
70+
StatusCode = [HttpStatusCode]::OK
71+
Body = @{
72+
Results = $Result
73+
ContentHash = $HashResult.ContentHash
74+
SnoozeUntil = $SnoozeUntil
75+
SnoozedBy = $SnoozedBy
76+
}
77+
})
7878
} catch {
7979
$ErrorMessage = Get-CippException -Exception $_
8080
Write-LogMessage -headers $Headers -API $APIName -message "Failed to snooze alert: $($ErrorMessage.NormalizedError)" -Sev 'Error' -tenant $TenantFilter
8181
return ([HttpResponseContext]@{
82-
StatusCode = [HttpStatusCode]::InternalServerError
83-
Body = @{ Results = "Failed to snooze alert: $($ErrorMessage.NormalizedError)" }
84-
})
82+
StatusCode = [HttpStatusCode]::InternalServerError
83+
Body = @{ Results = "Failed to snooze alert: $($ErrorMessage.NormalizedError)" }
84+
})
8585
}
8686
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ListSnoozedAlerts.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ function Invoke-ListSnoozedAlerts {
4343
SnoozedBy = $_.SnoozedBy
4444
SnoozedAt = $_.SnoozedAt
4545
SnoozeUntil = $_.SnoozeUntil
46-
IsForever = $IsForever
4746
IsExpired = $IsExpired
4847
RemainingDays = $RemainingDays
4948
Status = if ($IsForever) { 'Forever' } elseif ($IsExpired) { 'Expired' } else { 'Active' }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
function Invoke-ExecScheduleForwardingVacation {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint
5+
.ROLE
6+
Exchange.Mailbox.ReadWrite
7+
#>
8+
[CmdletBinding()]
9+
param($Request, $TriggerMetadata)
10+
11+
$APIName = $Request.Params.CIPPEndpoint
12+
$Headers = $Request.Headers
13+
14+
try {
15+
$TenantFilter = $Request.Body.tenantFilter
16+
$Users = @($Request.Body.Users)
17+
$ForwardOption = $Request.Body.forwardOption
18+
$ForwardInternal = $Request.Body.ForwardInternal.value ?? $Request.Body.ForwardInternal
19+
$ForwardExternal = $Request.Body.ForwardExternal
20+
$KeepCopy = if (-not [string]::IsNullOrWhiteSpace($Request.Body.KeepCopy)) { [System.Convert]::ToBoolean($Request.Body.KeepCopy) } else { $false }
21+
$StartDate = $Request.Body.startDate
22+
$EndDate = $Request.Body.endDate
23+
24+
$UserUPNs = @($Users | ForEach-Object { $_.addedFields.userPrincipalName ?? $_.value ?? $_ })
25+
26+
if ($UserUPNs.Count -eq 0) {
27+
throw 'At least one user is required.'
28+
}
29+
30+
$UserDisplay = ($UserUPNs | Select-Object -First 3) -join ', '
31+
if ($UserUPNs.Count -gt 3) { $UserDisplay += " (+$($UserUPNs.Count - 3) more)" }
32+
33+
$SharedParams = [PSCustomObject]@{
34+
TenantFilter = $TenantFilter
35+
Users = $UserUPNs
36+
ForwardOption = $ForwardOption
37+
KeepCopy = $KeepCopy
38+
APIName = $APIName
39+
}
40+
41+
switch ($ForwardOption) {
42+
'internalAddress' {
43+
if ([string]::IsNullOrWhiteSpace($ForwardInternal)) {
44+
throw 'Forwarding target is required for internal forwarding.'
45+
}
46+
$SharedParams.ForwardInternal = $ForwardInternal
47+
$TargetValue = $ForwardInternal
48+
}
49+
'ExternalAddress' {
50+
if ([string]::IsNullOrWhiteSpace($ForwardExternal)) {
51+
throw 'Forwarding target is required for external forwarding.'
52+
}
53+
$SharedParams.ForwardExternal = $ForwardExternal
54+
$TargetValue = $ForwardExternal
55+
}
56+
default {
57+
throw "$ForwardOption is not a valid forwarding option."
58+
}
59+
}
60+
61+
Add-CIPPScheduledTask -Task ([PSCustomObject]@{
62+
TenantFilter = $TenantFilter
63+
Name = "Add Forwarding Vacation Mode: $UserDisplay -> $TargetValue"
64+
Command = @{ value = 'Set-CIPPVacationForwarding'; label = 'Set-CIPPVacationForwarding' }
65+
Parameters = ($SharedParams | Select-Object *, @{ n = 'Action'; e = { 'Add' } })
66+
ScheduledTime = [int64]$StartDate
67+
PostExecution = $Request.Body.postExecution
68+
Reference = $Request.Body.reference
69+
}) -hidden $false
70+
71+
Add-CIPPScheduledTask -Task ([PSCustomObject]@{
72+
TenantFilter = $TenantFilter
73+
Name = "Remove Forwarding Vacation Mode: $UserDisplay"
74+
Command = @{ value = 'Set-CIPPVacationForwarding'; label = 'Set-CIPPVacationForwarding' }
75+
Parameters = [PSCustomObject]@{
76+
TenantFilter = $TenantFilter
77+
Users = $UserUPNs
78+
Action = 'Remove'
79+
APIName = $APIName
80+
}
81+
ScheduledTime = [int64]$EndDate
82+
PostExecution = $Request.Body.postExecution
83+
Reference = $Request.Body.reference
84+
}) -hidden $false
85+
86+
$Result = "Successfully scheduled forwarding vacation mode for $UserDisplay."
87+
$StatusCode = [HttpStatusCode]::OK
88+
} catch {
89+
$ErrorMessage = Get-CippException -Exception $_
90+
$Result = "Failed to schedule forwarding vacation mode: $($ErrorMessage.NormalizedError)"
91+
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev Error -tenant $TenantFilter -LogData $ErrorMessage
92+
$StatusCode = [HttpStatusCode]::InternalServerError
93+
}
94+
95+
return ([HttpResponseContext]@{
96+
StatusCode = $StatusCode
97+
Body = @{ Results = $Result }
98+
})
99+
}

Modules/CIPPCore/Public/Send-CIPPScheduledTaskAlert.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function Send-CIPPScheduledTaskAlert {
9292
<td style="padding:0 6px 0 0;"><table cellpadding="0" cellspacing="0" border="0"><tr><td style="background-color:#0078d4;padding:6px 14px;"><a href="${BaseLink}&duration=7" style="color:#ffffff;font-size:12px;font-weight:600;text-decoration:none;white-space:nowrap;">7 Days</a></td></tr></table></td>
9393
<td style="padding:0 6px 0 0;"><table cellpadding="0" cellspacing="0" border="0"><tr><td style="background-color:#0078d4;padding:6px 14px;"><a href="${BaseLink}&duration=14" style="color:#ffffff;font-size:12px;font-weight:600;text-decoration:none;white-space:nowrap;">14 Days</a></td></tr></table></td>
9494
<td style="padding:0 6px 0 0;"><table cellpadding="0" cellspacing="0" border="0"><tr><td style="background-color:#ff9800;padding:6px 14px;"><a href="${BaseLink}&duration=30" style="color:#ffffff;font-size:12px;font-weight:600;text-decoration:none;white-space:nowrap;">30 Days</a></td></tr></table></td>
95-
<td style="padding:0;"><table cellpadding="0" cellspacing="0" border="0"><tr><td style="background-color:#d32f2f;padding:6px 14px;"><a href="${BaseLink}&duration=-1" style="color:#ffffff;font-size:12px;font-weight:600;text-decoration:none;white-space:nowrap;">Forever</a></td></tr></table></td>
95+
<td style="padding:0;"><table cellpadding="0" cellspacing="0" border="0"><tr><td style="background-color:#d32f2f;padding:6px 14px;"><a href="${BaseLink}&duration=90" style="color:#ffffff;font-size:12px;font-weight:600;text-decoration:none;white-space:nowrap;">90 Days</a></td></tr></table></td>
9696
</tr></table>
9797
</td></tr>
9898
</table>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
function Set-CIPPVacationForwarding {
2+
[CmdletBinding()]
3+
param(
4+
[Parameter(Mandatory)] [string]$TenantFilter,
5+
[Parameter(Mandatory)] [ValidateSet('Add', 'Remove')] [string]$Action,
6+
[object[]]$Users,
7+
[ValidateSet('internalAddress', 'ExternalAddress')] [string]$ForwardOption,
8+
[string]$ForwardInternal,
9+
[string]$ForwardExternal,
10+
[bool]$KeepCopy,
11+
[string]$APIName = 'Forwarding Vacation Mode',
12+
$Headers
13+
)
14+
15+
$Results = [System.Collections.Generic.List[string]]::new()
16+
$Users = @($Users)
17+
18+
foreach ($upn in $Users) {
19+
if ([string]::IsNullOrWhiteSpace($upn)) { continue }
20+
21+
try {
22+
if ($Action -eq 'Remove') {
23+
$result = Set-CIPPForwarding -UserID $upn -Username $upn -TenantFilter $TenantFilter -Headers $Headers -APIName $APIName -Disable $true
24+
} else {
25+
switch ($ForwardOption) {
26+
'internalAddress' {
27+
if ([string]::IsNullOrWhiteSpace($ForwardInternal)) {
28+
throw 'ForwardInternal is required for internal forwarding.'
29+
}
30+
31+
$result = Set-CIPPForwarding -UserID $upn -Username $upn -TenantFilter $TenantFilter -Headers $Headers -APIName $APIName -Forward $ForwardInternal -KeepCopy $KeepCopy
32+
}
33+
'ExternalAddress' {
34+
if ([string]::IsNullOrWhiteSpace($ForwardExternal)) {
35+
throw 'ForwardExternal is required for external forwarding.'
36+
}
37+
38+
$result = Set-CIPPForwarding -UserID $upn -Username $upn -TenantFilter $TenantFilter -Headers $Headers -APIName $APIName -ForwardingSMTPAddress $ForwardExternal -KeepCopy $KeepCopy
39+
}
40+
default {
41+
throw "Unsupported forward option: $ForwardOption"
42+
}
43+
}
44+
}
45+
46+
$Results.Add($result)
47+
} catch {
48+
$ErrorMessage = Get-CippException -Exception $_
49+
$Results.Add("Failed to set forwarding for ${upn}: $($ErrorMessage.NormalizedError)")
50+
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantFilter -message "Failed to set forwarding for ${upn}: $($ErrorMessage.NormalizedError)" -Sev Error -LogData $ErrorMessage
51+
}
52+
}
53+
54+
return $Results
55+
}

Modules/CIPPCore/Public/Set-CIPPVacationOOO.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ function Set-CIPPVacationOOO {
7777
$result = Set-CIPPOutOfOffice @SplatParams
7878
$Results.Add($result)
7979
} catch {
80-
$err = (Get-CippException -Exception $_).NormalizedError
81-
$Results.Add("Failed to set OOO for ${upn}: $err")
82-
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantFilter -message "Failed OOO for ${upn}: $err" -Sev Error
80+
$err = Get-CippException -Exception $_
81+
$Results.Add("Failed to set OOO for ${upn}: $($err.NormalizedError)")
82+
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantFilter -message "Failed OOO for ${upn}: $($err.NormalizedError)" -Sev Error -LogData $err
8383
}
8484
}
8585
return $Results

0 commit comments

Comments
 (0)