Skip to content

Commit

Permalink
Merge branch 'KelvinTegelaar:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ictsinfx authored Apr 29, 2024
2 parents f7e9e11 + 2c49359 commit 6df5698
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Modules/CIPPCore/Public/Add-CIPPScheduledTask.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ function Add-CIPPScheduledTask {
} catch {
return "Could not add task: $($_.Exception.Message)"
}
return 'Successfully added task'
return "Successfully added task: $($entity.Name)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ function Push-ExecScheduledCommand {
Entrypoint
#>
param($Item)
Write-Host "We are going to be running a scheduled task: $($Item.TaskInfo | ConvertTo-Json)"

$Table = Get-CippTable -tablename 'ScheduledTasks'
$task = $Item.TaskInfo
$commandParameters = $Item.Parameters
$commandParameters = $Item.Parameters | ConvertTo-Json | ConvertFrom-Json -AsHashtable

$tenant = $Item.Parameters['TenantFilter']
Write-Host 'started task'
Write-Host "Started Task: $($Item.Command) for tenant: $tenant"
try {
try {
$results = & $Item.command @commandParameters
$results = & $Item.Command @commandParameters
} catch {
$results = "Task Failed: $($_.Exception.Message)"

}

Write-Host 'ran the command'
Expand All @@ -28,9 +28,13 @@ function Push-ExecScheduledCommand {
$results = $results | ForEach-Object { @{ Results = $_ } }
}

$results = $results | Select-Object * -ExcludeProperty RowKey, PartitionKey
if ($results -is [string]) {
$StoredResults = $results
} else {
$results = $results | Select-Object * -ExcludeProperty RowKey, PartitionKey
$StoredResults = $results | ConvertTo-Json -Compress -Depth 20 | Out-String
}

$StoredResults = $results | ConvertTo-Json -Compress -Depth 20 | Out-String
if ($StoredResults.Length -gt 64000 -or $task.Tenant -eq 'AllTenants') {
$StoredResults = @{ Results = 'The results for this query are too long to store in this table, or the query was meant for All Tenants. Please use the options to send the results to another target to be able to view the results. ' } | ConvertTo-Json -Compress
}
Expand All @@ -49,7 +53,7 @@ function Push-ExecScheduledCommand {

$TableDesign = '<style>table.blueTable{border:1px solid #1C6EA4;background-color:#EEE;width:100%;text-align:left;border-collapse:collapse}table.blueTable td,table.blueTable th{border:1px solid #AAA;padding:3px 2px}table.blueTable tbody td{font-size:13px}table.blueTable tr:nth-child(even){background:#D0E4F5}table.blueTable thead{background:#1C6EA4;background:-moz-linear-gradient(top,#5592bb 0,#327cad 66%,#1C6EA4 100%);background:-webkit-linear-gradient(top,#5592bb 0,#327cad 66%,#1C6EA4 100%);background:linear-gradient(to bottom,#5592bb 0,#327cad 66%,#1C6EA4 100%);border-bottom:2px solid #444}table.blueTable thead th{font-size:15px;font-weight:700;color:#FFF;border-left:2px solid #D0E4F5}table.blueTable thead th:first-child{border-left:none}table.blueTable tfoot{font-size:14px;font-weight:700;color:#FFF;background:#D0E4F5;background:-moz-linear-gradient(top,#dcebf7 0,#d4e6f6 66%,#D0E4F5 100%);background:-webkit-linear-gradient(top,#dcebf7 0,#d4e6f6 66%,#D0E4F5 100%);background:linear-gradient(to bottom,#dcebf7 0,#d4e6f6 66%,#D0E4F5 100%);border-top:2px solid #444}table.blueTable tfoot td{font-size:14px}table.blueTable tfoot .links{text-align:right}table.blueTable tfoot .links a{display:inline-block;background:#1C6EA4;color:#FFF;padding:2px 8px;border-radius:5px}</style>'
$HTML = ($results | Select-Object * -ExcludeProperty RowKey, PartitionKey | ConvertTo-Html -Fragment) -replace '<table>', "$TableDesign<table class=blueTable>" | Out-String
$title = "Scheduled Task $($task.Name) - $($task.ExpectedRunTime)"
$title = "Scheduled Task $($task.Name)"
Write-Host $title
switch -wildcard ($task.PostExecution) {
'*psa*' { Send-CIPPAlert -Type 'psa' -Title $title -HTMLContent $HTML }
Expand Down Expand Up @@ -84,5 +88,5 @@ function Push-ExecScheduledCommand {
ScheduledTime = "$nextRunUnixTime"
}
}
Write-LogMessage -API 'Scheduler_UserTasks' -tenant $tenant -message "Successfully executed task: $($task.name)" -sev Info
Write-LogMessage -API 'Scheduler_UserTasks' -tenant $tenant -message "Successfully executed task: $($task.Name)" -sev Info
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ Function Invoke-RemoveScheduledItem {
RowKey = $Request.Query.ID
PartitionKey = 'ScheduledTask'
}


$Table = Get-CIPPTable -TableName 'ScheduledTasks'
Remove-AzDataTableEntity @Table -Entity $task

Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Task removed: $($task.Name)" -Sev 'Info'

Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = @{ Results = 'Task removed successfully.' }
})
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Task removed' -Sev 'Debug'


}
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ Function Invoke-ExecNotificationConfig {
# Write to the Azure Functions log stream.
Write-Host 'PowerShell HTTP trigger function processed a request.'
$sev = ([pscustomobject]$Request.body.Severity).value -join (',')
$results = try {
$results = try {
$Table = Get-CIPPTable -TableName SchedulerConfig
$SchedulerConfig = @{
'tenant' = 'Any'
'tenantid' = 'TenantId'
'type' = 'CIPPNotifications'
'schedule' = 'Every 15 minutes'
'Severity' = [string]$sev
'email' = "$($Request.Body.Email)"
'webhook' = "$($Request.Body.Webhook)"
'email' = "$($Request.Body.email)"
'webhook' = "$($Request.Body.webhook)"
'onePerTenant' = [boolean]$Request.Body.onePerTenant
'sendtoIntegration' = [boolean]$Request.Body.sendtoIntegration
'includeTenantId' = [boolean]$Request.Body.includeTenantId
'PartitionKey' = 'CippNotifications'
'RowKey' = 'CippNotifications'
}
foreach ($logvalue in [pscustomobject]$Request.body.logsToInclude) {
$SchedulerConfig[([pscustomobject]$logvalue.value)] = $true
$SchedulerConfig[([pscustomobject]$logvalue.value)] = $true
}

Add-CIPPAzDataTableEntity @Table -Entity $SchedulerConfig -Force | Out-Null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Function Invoke-ListCalendarPermissions {

try {
$GetCalParam = @{Identity = $UserID; FolderScope = 'Calendar' }
$CalendarFolder = New-ExoRequest -tenantid $Tenantfilter -cmdlet 'Get-MailboxFolderStatistics' -cmdParams $GetCalParam -UseSystemMailbox $true | Select-Object -First 1
$CalendarFolder = New-ExoRequest -tenantid $Tenantfilter -cmdlet 'Get-MailboxFolderStatistics' -cmdParams $GetCalParam | Select-Object -First 1
$CalParam = @{Identity = "$($UserID):\$($CalendarFolder.name)" }
$GraphRequest = New-ExoRequest -tenantid $Tenantfilter -cmdlet 'Get-MailboxFolderPermission' -cmdParams $CalParam -UseSystemMailbox $true | Select-Object Identity, User, AccessRights, FolderName
Write-LogMessage -API 'List Calendar Permissions' -tenant $tenantfilter -message "Calendar permissions listed for $($tenantfilter)" -sev Debug
Expand Down
41 changes: 41 additions & 0 deletions Modules/CIPPCore/Public/Entrypoints/Invoke-ListRoomLists.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using namespace System.Net

Function Invoke-ListRoomLists {
<#
.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.'

# Interact with query parameters or the body of the request.
$TenantFilter = $Request.Query.TenantFilter

try {
$params = @{
uri = 'https://graph.microsoft.com/beta/places/microsoft.graph.roomlist'
tenantid = $TenantFilter
AsApp = $true
}
$GraphRequest = New-GraphGetRequest @params

$StatusCode = [HttpStatusCode]::OK
} catch {
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
$StatusCode = [HttpStatusCode]::Forbidden
$GraphRequest = $ErrorMessage
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = $StatusCode
Body = @($GraphRequest | Sort-Object displayName)
})

}
41 changes: 41 additions & 0 deletions Modules/CIPPCore/Public/Entrypoints/Invoke-ListRooms.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using namespace System.Net

Function Invoke-ListRooms {
<#
.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.'

# Interact with query parameters or the body of the request.
$TenantFilter = $Request.Query.TenantFilter

try {
$params = @{
uri = 'https://graph.microsoft.com/beta/places/microsoft.graph.room'
tenantid = $TenantFilter
AsApp = $true
}
$GraphRequest = New-GraphGetRequest @params

$StatusCode = [HttpStatusCode]::OK
} catch {
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
$StatusCode = [HttpStatusCode]::Forbidden
$GraphRequest = $ErrorMessage
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = $StatusCode
Body = @($GraphRequest | Sort-Object displayName)
})

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using namespace System.Net

Function Invoke-ListTenantAllowBlockList {
<#
.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.'

# Interact with query parameters or the body of the request.
$TenantFilter = $Request.Query.TenantFilter
$ListTypes = 'Sender','Url','FileHash'
try {
$Request = ForEach ($_ in $ListTypes) {
@{
CmdletInput = @{
CmdletName = 'Get-TenantAllowBlockListItems'
Parameters = @{ListType = $_ }
}
}
}
$BatchResults = New-ExoBulkRequest -tenantid $TenantFilter -cmdletArray $Request

$StatusCode = [HttpStatusCode]::OK
} catch {
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
$StatusCode = [HttpStatusCode]::Forbidden
$BatchResults = $ErrorMessage
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = $StatusCode
Body = @($BatchResults)
})
}
2 changes: 1 addition & 1 deletion Modules/CIPPCore/Public/Get-CIPPDomainAnalyser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function Get-CIPPDomainAnalyser {

# Get all the things

if ($TenantFilter -ne 'AllTenants') {
if ($TenantFilter -ne 'AllTenants' -and ![string]::IsNullOrEmpty($TenantFilter)) {
$DomainTable.Filter = "TenantGUID eq '{0}'" -f $TenantFilter
}

Expand Down
5 changes: 2 additions & 3 deletions Modules/CIPPCore/Public/Set-CIPPSignInState.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ function Set-CIPPSignInState {
$APIName = 'Disable User Sign-in',
$ExecutingUser
)
0
try {
if ($userid -like '*#EXT#*') { $userid = [System.Web.HttpUtility]::UrlEncode($userid) }

try {
$body = @{
accountEnabled = [bool]$AccountEnabled
} | ConvertTo-Json -Compress -Depth 1
Expand All @@ -22,3 +20,4 @@ function Set-CIPPSignInState {
return "Could not disable $userid. Error: $($_.Exception.Message)"
}
}

2 changes: 1 addition & 1 deletion version_latest.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.6.0
5.6.2

0 comments on commit 6df5698

Please sign in to comment.