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 #51 from KelvinTegelaar/master
[pull] master from KelvinTegelaar:master
- Loading branch information
Showing
29 changed files
with
547 additions
and
298 deletions.
There are no files selected for viewing
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
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
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
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
50 changes: 50 additions & 0 deletions
50
...Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ListPerUserMFA.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,50 @@ | ||
using namespace System.Net | ||
|
||
function Invoke-ListPerUserMFA { | ||
<# | ||
.FUNCTIONALITY | ||
Entrypoint | ||
.ROLE | ||
Identity.User.Read | ||
#> | ||
[CmdletBinding()] | ||
param($Request, $TriggerMetadata) | ||
|
||
$APIName = $TriggerMetadata.FunctionName | ||
$User = $request.headers.'x-ms-client-principal' | ||
Write-LogMessage -user $User -API $APINAME -message 'Accessed this API' -Sev 'Debug' | ||
|
||
# Write to the Azure Functions log stream. | ||
Write-Host 'PowerShell HTTP trigger function processed a request.' | ||
|
||
# Parse query parameters | ||
$Tenant = $Request.query.tenantFilter | ||
try { | ||
$AllUsers = [System.Convert]::ToBoolean($Request.query.allUsers) | ||
} catch { | ||
$AllUsers = $false | ||
} | ||
$UserId = $Request.query.userId | ||
|
||
# Get the MFA state for the user/all users | ||
try { | ||
if ($AllUsers -eq $true) { | ||
$Results = Get-CIPPPerUserMFA -TenantFilter $Tenant -AllUsers $true | ||
} else { | ||
$Results = Get-CIPPPerUserMFA -TenantFilter $Tenant -userId $UserId | ||
} | ||
$StatusCode = [HttpStatusCode]::OK | ||
} catch { | ||
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message | ||
$Results = "Failed to get MFA State for $UserId : $ErrorMessage" | ||
$StatusCode = [HttpStatusCode]::Forbidden | ||
} | ||
|
||
# Associate values to output bindings by calling 'Push-OutputBinding'. | ||
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | ||
StatusCode = $StatusCode | ||
Body = @($Results) | ||
}) | ||
|
||
|
||
} |
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
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
82 changes: 82 additions & 0 deletions
82
Modules/CIPPCore/Public/Entrypoints/Timer Functions/Start-TableCleanup.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,82 @@ | ||
function Start-TableCleanup { | ||
<# | ||
.SYNOPSIS | ||
Start the Table Cleanup Timer | ||
#> | ||
[CmdletBinding(SupportsShouldProcess = $true)] | ||
param() | ||
|
||
$CleanupRules = @( | ||
@{ | ||
DataTableProps = @{ | ||
Context = (Get-CIPPTable -tablename 'webhookTable').Context | ||
Property = @('PartitionKey', 'RowKey', 'ETag', 'Resource') | ||
} | ||
Where = "`$_.Resource -match '^Audit'" | ||
} | ||
@{ | ||
DataTableProps = @{ | ||
Context = (Get-CIPPTable -tablename 'AuditLogSearches').Context | ||
Filter = "Timestamp lt datetime'$((Get-Date).AddDays(-7).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ'))'" | ||
First = 10000 | ||
Property = @('PartitionKey', 'RowKey', 'ETag') | ||
} | ||
} | ||
@{ | ||
DataTableProps = @{ | ||
Context = (Get-CIPPTable -tablename 'CippFunctionStats').Context | ||
Filter = "Timestamp lt datetime'$((Get-Date).AddDays(-7).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ'))'" | ||
First = 10000 | ||
Property = @('PartitionKey', 'RowKey', 'ETag') | ||
} | ||
} | ||
@{ | ||
DataTableProps = @{ | ||
Context = (Get-CIPPTable -tablename 'CippQueue').Context | ||
Filter = "Timestamp lt datetime'$((Get-Date).AddDays(-7).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ'))'" | ||
First = 10000 | ||
Property = @('PartitionKey', 'RowKey', 'ETag') | ||
} | ||
} | ||
@{ | ||
DataTableProps = @{ | ||
Context = (Get-CIPPTable -tablename 'CippQueueTasks').Context | ||
Filter = "Timestamp lt datetime'$((Get-Date).AddDays(-7).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ'))'" | ||
First = 10000 | ||
Property = @('PartitionKey', 'RowKey', 'ETag') | ||
} | ||
} | ||
) | ||
|
||
if ($PSCmdlet.ShouldProcess('Start-TableCleanup', 'Starting Table Cleanup')) { | ||
Write-Information 'Starting table cleanup' | ||
foreach ($Rule in $CleanupRules) { | ||
if ($Rule.Where) { | ||
$Where = [scriptblock]::Create($Rule.Where) | ||
} else { | ||
$Where = { $true } | ||
} | ||
$DataTableProps = $Rule.DataTableProps | ||
|
||
$CleanupCompleted = $false | ||
do { | ||
$Entities = Get-AzDataTableEntity @DataTableProps | Where-Object $Where | ||
if ($Entities) { | ||
Write-Information "Removing $($Entities.Count) entities from $($Rule.DataTableProps.Context.TableName)" | ||
try { | ||
Remove-AzDataTableEntity -Context $DataTableProps.Context -Entity $Entities -Force | ||
if ($DataTableProps.First -and $Entities.Count -lt $DataTableProps.First) { | ||
$CleanupCompleted = $true | ||
} | ||
} catch { | ||
Write-LogMessage -API 'TableCleanup' -message "Failed to remove entities from $($DataTableProps.Context.TableName)" -sev Error -LogData (Get-CippException -Exception $_) | ||
$CleanupCompleted = $true | ||
} | ||
} else { | ||
$CleanupCompleted = $true | ||
} | ||
} while (!$CleanupCompleted) | ||
} | ||
Write-Information 'Table cleanup complete' | ||
} | ||
} |
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.