Skip to content

Commit 475bdac

Browse files
authored
Merge pull request #279 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 57bff3c + 5481e11 commit 475bdac

File tree

142 files changed

+1275
-234
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+1275
-234
lines changed

ConversionTable.csv

Lines changed: 122 additions & 1 deletion
Large diffs are not rendered by default.

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertHuntressRogueApps.ps1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ function Get-CIPPAlertHuntressRogueApps {
1414
[Parameter(Mandatory = $false)]
1515
[Alias('input')]
1616
$InputValue,
17-
$TenantFilter
17+
$TenantFilter,
18+
[Parameter(Mandatory = $false)]
19+
[bool]$IgnoreDisabledApps = $false
1820
)
1921

2022
try {
2123
$RogueApps = Invoke-RestMethod -Uri 'https://raw.githubusercontent.com/huntresslabs/rogueapps/main/public/rogueapps.json'
2224
$RogueAppFilter = $RogueApps.appId -join "','"
2325
$ServicePrincipals = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/servicePrincipals?`$filter=appId in ('$RogueAppFilter')" -tenantid $TenantFilter
26+
# If IgnoreDisabledApps is true, filter out disabled service principals
27+
if ($IgnoreDisabledApps) {
28+
$ServicePrincipals = $ServicePrincipals | Where-Object { $_.accountEnabled -eq $true }
29+
}
2430

2531
if (($ServicePrincipals | Measure-Object).Count -gt 0) {
2632
$AlertData = foreach ($ServicePrincipal in $ServicePrincipals) {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function Get-CIPPAlertTERRL {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint
5+
#>
6+
[CmdletBinding()]
7+
Param (
8+
[Parameter(Mandatory = $false)]
9+
[Alias('input')]
10+
$InputValue,
11+
$TenantFilter
12+
)
13+
14+
try {
15+
# Set threshold with fallback to 80%
16+
$Threshold = if ([string]::IsNullOrWhiteSpace($InputValue)) { 80 } else { [int]$InputValue }
17+
18+
# Get TERRL status
19+
$TerrlStatus = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Get-LimitsEnforcementStatus'
20+
21+
if ($TerrlStatus) {
22+
$UsagePercentage = [math]::Round(($TerrlStatus.ObservedValue / $TerrlStatus.Threshold) * 100, 2)
23+
24+
if ($UsagePercentage -gt $Threshold) {
25+
$AlertData = [PSCustomObject]@{
26+
UsagePercentage = $UsagePercentage
27+
CurrentVolume = $TerrlStatus.ObservedValue
28+
ThresholdLimit = $TerrlStatus.Threshold
29+
EnforcementEnabled = $TerrlStatus.EnforcementEnabled
30+
Verdict = $TerrlStatus.Verdict
31+
Message = 'Tenant is at {0}% of their TERRL limit (using {1} of {2} messages). Tenant Enforcement Status: {3}' -f $UsagePercentage, $TerrlStatus.ObservedValue, $TerrlStatus.Threshold, $TerrlStatus.Verdict
32+
}
33+
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
34+
}
35+
}
36+
} catch {
37+
Write-AlertMessage -tenant $($TenantFilter) -message "Could not get TERRL status for $($TenantFilter): $(Get-NormalizedError -message $_.Exception.message)"
38+
}
39+
}

Modules/CIPPCore/Public/ConversionTable.csv

Lines changed: 122 additions & 1 deletion
Large diffs are not rendered by default.

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Administration/Invoke-ExecGroupsDelete.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Function Invoke-ExecGroupsDelete {
2121
$DisplayName = $Request.Query.displayName ?? $Request.Body.displayName
2222

2323
Try {
24-
$Result = Remove-CIPPGroup -ID $ID -Grouptype $GroupType -TenantFilter $TenantFilter -DisplayName $DisplayName -APIName $APIName -Headers $Headers
24+
$Result = Remove-CIPPGroup -ID $ID -GroupType $GroupType -TenantFilter $TenantFilter -DisplayName $DisplayName -APIName $APIName -Headers $Headers
2525
$StatusCode = [HttpStatusCode]::OK
2626
} catch {
2727
$Result = "$($_.Exception.Message)"
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
using namespace System.Net
2+
3+
Function Invoke-SetUserAliases {
4+
<#
5+
.FUNCTIONALITY
6+
Entrypoint
7+
.ROLE
8+
Identity.User.ReadWrite
9+
#>
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
12+
13+
$APIName = $Request.Params.CIPPEndpoint
14+
$Headers = $Request.Headers
15+
Write-LogMessage -headers $Headers -API $ApiName -message 'Accessed this API' -Sev 'Debug'
16+
17+
$UserObj = $Request.Body
18+
if ([string]::IsNullOrWhiteSpace($UserObj.id)) {
19+
$body = @{'Results' = @('Failed to manage aliases. No user ID provided') }
20+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
21+
StatusCode = [HttpStatusCode]::BadRequest
22+
Body = $Body
23+
})
24+
return
25+
}
26+
27+
$Results = [System.Collections.Generic.List[object]]::new()
28+
$Aliases = if ($UserObj.AddedAliases) { ($UserObj.AddedAliases -split ',').ForEach({ $_.Trim() }) }
29+
$RemoveAliases = if ($UserObj.RemovedAliases) { ($UserObj.RemovedAliases -split ',').ForEach({ $_.Trim() }) }
30+
31+
try {
32+
if ($Aliases -or $RemoveAliases -or $UserObj.MakePrimary) {
33+
# Get current mailbox
34+
$CurrentMailbox = New-ExoRequest -tenantid $UserObj.tenantFilter -cmdlet 'Get-Mailbox' -cmdParams @{ Identity = $UserObj.id } -UseSystemMailbox $true
35+
36+
if (-not $CurrentMailbox) {
37+
throw 'Could not find mailbox for user'
38+
}
39+
40+
$CurrentProxyAddresses = @($CurrentMailbox.EmailAddresses)
41+
Write-Host "Current proxy addresses: $($CurrentProxyAddresses -join ', ')"
42+
$NewProxyAddresses = @($CurrentProxyAddresses)
43+
44+
# Handle setting primary address
45+
if ($UserObj.MakePrimary) {
46+
$PrimaryAddress = $UserObj.MakePrimary
47+
Write-Host "Attempting to set primary address: $PrimaryAddress"
48+
49+
# Normalize the primary address format
50+
if ($PrimaryAddress -notlike 'SMTP:*') {
51+
$PrimaryAddress = "SMTP:$($PrimaryAddress -replace '^smtp:', '')"
52+
}
53+
Write-Host "Normalized primary address: $PrimaryAddress"
54+
55+
# Check if the address exists in the current addresses (case-insensitive)
56+
$ExistingAddress = $CurrentProxyAddresses | Where-Object {
57+
$current = $_.ToLower()
58+
$target = $PrimaryAddress.ToLower()
59+
Write-Host "Comparing: '$current' with '$target'"
60+
$current -eq $target
61+
}
62+
63+
if (-not $ExistingAddress) {
64+
Write-Host "Available addresses: $($CurrentProxyAddresses -join ', ')"
65+
throw "Cannot set primary address. Address $($PrimaryAddress -replace '^SMTP:', '') not found in user's addresses."
66+
}
67+
68+
# Convert all current SMTP addresses to lowercase (secondary)
69+
$NewProxyAddresses = $NewProxyAddresses | ForEach-Object {
70+
if ($_ -like 'SMTP:*') {
71+
$_.ToLower()
72+
}
73+
else {
74+
$_
75+
}
76+
}
77+
78+
# Remove any existing version of the address (case-insensitive)
79+
$NewProxyAddresses = $NewProxyAddresses | Where-Object {
80+
$_.ToLower() -ne $PrimaryAddress.ToLower()
81+
}
82+
# Add the new primary address at the beginning
83+
$NewProxyAddresses = @($PrimaryAddress) + $NewProxyAddresses
84+
85+
Write-LogMessage -API $ApiName -tenant ($UserObj.tenantFilter) -headers $Headers -message "Set primary address for $($CurrentMailbox.DisplayName)" -Sev Info
86+
$null = $results.Add('Success. Set new primary address.')
87+
}
88+
89+
# Remove specified aliases
90+
if ($RemoveAliases) {
91+
foreach ($Alias in $RemoveAliases) {
92+
# Normalize the alias format
93+
if ($Alias -notlike 'smtp:*') {
94+
$Alias = "smtp:$Alias"
95+
}
96+
# Remove the alias case-insensitively
97+
$NewProxyAddresses = $NewProxyAddresses | Where-Object {
98+
$_.ToLower() -ne $Alias.ToLower()
99+
}
100+
}
101+
Write-LogMessage -API $ApiName -tenant ($UserObj.tenantFilter) -headers $Headers -message "Removed Aliases from $($CurrentMailbox.DisplayName)" -Sev Info
102+
$null = $results.Add('Success. Removed specified aliases from user.')
103+
}
104+
105+
# Add new aliases
106+
if ($Aliases) {
107+
$AliasesToAdd = @()
108+
foreach ($Alias in $Aliases) {
109+
# Normalize the alias format
110+
if ($Alias -notlike 'smtp:*') {
111+
$Alias = "smtp:$Alias"
112+
}
113+
# Check if the alias exists case-insensitively
114+
if (-not ($NewProxyAddresses | Where-Object { $_.ToLower() -eq $Alias.ToLower() })) {
115+
$AliasesToAdd = $AliasesToAdd + $Alias
116+
}
117+
}
118+
if ($AliasesToAdd.Count -gt 0) {
119+
$NewProxyAddresses = $NewProxyAddresses + $AliasesToAdd
120+
Write-LogMessage -API $ApiName -tenant ($UserObj.tenantFilter) -headers $Headers -message "Added Aliases to $($CurrentMailbox.DisplayName)" -Sev Info
121+
$null = $results.Add('Success. Added new aliases to user.')
122+
}
123+
}
124+
125+
# Update the mailbox with new proxy addresses
126+
$Params = @{
127+
Identity = $UserObj.id
128+
EmailAddresses = $NewProxyAddresses
129+
}
130+
$null = New-ExoRequest -tenantid $UserObj.tenantFilter -cmdlet 'Set-Mailbox' -cmdParams $Params -UseSystemMailbox $true
131+
}
132+
else {
133+
$null = $results.Add('No alias changes specified.')
134+
}
135+
}
136+
catch {
137+
$ErrorMessage = Get-CippException -Exception $_
138+
Write-LogMessage -API $ApiName -tenant ($UserObj.tenantFilter) -headers $Headers -message "Alias management failed. $($ErrorMessage.NormalizedError)" -Sev Error -LogData $ErrorMessage
139+
$null = $results.Add("Failed to manage aliases: $($ErrorMessage.NormalizedError)")
140+
}
141+
142+
$body = @{'Results' = @($results) }
143+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
144+
StatusCode = [HttpStatusCode]::OK
145+
Body = $Body
146+
})
147+
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Teams-Sharepoint/Invoke-AddTeam.ps1

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ Function Invoke-AddTeam {
1414
$Headers = $Request.Headers
1515
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
1616

17-
$userobj = $Request.body
17+
# Interact with the body of the request
18+
$TeamObj = $Request.Body
19+
$TenantID = $TeamObj.tenantid
1820

19-
20-
21-
$Owners = ($userobj.owner)
21+
$Owners = ($TeamObj.owner)
2222
try {
2323
if ($null -eq $Owners) {
24-
throw "You have to add at least one owner to the team"
24+
throw 'You have to add at least one owner to the team'
2525
}
2626
$Owners = $Owners | ForEach-Object {
2727
$OwnerID = "https://graph.microsoft.com/beta/users('$($_)')"
@@ -34,28 +34,31 @@ Function Invoke-AddTeam {
3434

3535
$TeamsSettings = [PSCustomObject]@{
3636
'[email protected]' = "https://graph.microsoft.com/v1.0/teamsTemplates('standard')"
37-
'visibility' = $userobj.visibility
38-
'displayName' = $userobj.displayname
39-
'description' = $userobj.description
40-
'members' = @($owners)
37+
'visibility' = $TeamObj.visibility
38+
'displayName' = $TeamObj.displayName
39+
'description' = $TeamObj.description
40+
'members' = @($Owners)
4141

4242
} | ConvertTo-Json -Depth 10
43+
# Write-Host $TeamsSettings
4344

44-
Write-Host $TeamsSettings
45-
New-GraphPostRequest -AsApp $true -uri 'https://graph.microsoft.com/beta/teams' -tenantid $Userobj.tenantid -type POST -body $TeamsSettings -verbose
46-
Write-LogMessage -headers $Request.Headers -API $APINAME -tenant $($userobj.tenantid) -message "Added Team $($userobj.displayname)" -Sev 'Info'
47-
$body = [pscustomobject]@{'Results' = 'Success. Team has been added' }
45+
$null = New-GraphPostRequest -AsApp $true -uri 'https://graph.microsoft.com/beta/teams' -tenantid $TenantID -type POST -body $TeamsSettings -Verbose
46+
$Message = "Successfully created Team: '$($TeamObj.displayName)'"
47+
Write-LogMessage -headers $Headers -API $APINAME -tenant $TenantID -message $Message -Sev Info
48+
$StatusCode = [HttpStatusCode]::OK
4849

4950
} catch {
50-
Write-LogMessage -headers $Request.Headers -API $APINAME -tenant $($userobj.tenantid) -message "Adding Team failed. Error: $($_.Exception.Message)" -Sev 'Error'
51-
$body = [pscustomobject]@{'Results' = "Failed. Error message: $($_.Exception.Message)" }
51+
$ErrorMessage = Get-CippException -Exception $_
52+
$Message = "Failed to create Team: '$($TeamObj.displayName)'. Error: $($ErrorMessage.NormalizedError)"
53+
Write-LogMessage -headers $Headers -API $APINAME -tenant $TenantID -message $Message -Sev Error -LogData $ErrorMessage
54+
$StatusCode = [HttpStatusCode]::InternalServerError
5255
}
5356

5457

5558
# Associate values to output bindings by calling 'Push-OutputBinding'.
5659
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
57-
StatusCode = [HttpStatusCode]::OK
58-
Body = $Body
60+
StatusCode = $StatusCode
61+
Body = @{ Results = $Message }
5962
})
6063

6164
}

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardActivityBasedTimeout.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function Invoke-CIPPStandardActivityBasedTimeout {
2828
UPDATECOMMENTBLOCK
2929
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
3030
.LINK
31-
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/global-standards#medium-impact
31+
https://docs.cipp.app/user-documentation/tenant/standards/list-standards
3232
#>
3333

3434
param($Tenant, $Settings)

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAddDKIM.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function Invoke-CIPPStandardAddDKIM {
2727
UPDATECOMMENTBLOCK
2828
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
2929
.LINK
30-
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/exchange-standards#low-impact
30+
https://docs.cipp.app/user-documentation/tenant/standards/list-standards
3131
#>
3232

3333
param($Tenant, $Settings)

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAnonReportDisable.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Invoke-CIPPStandardAnonReportDisable {
2525
UPDATECOMMENTBLOCK
2626
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
2727
.LINK
28-
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/global-standards#low-impact
28+
https://docs.cipp.app/user-documentation/tenant/standards/list-standards
2929
#>
3030

3131
param($Tenant, $Settings)

0 commit comments

Comments
 (0)