Skip to content

Commit

Permalink
Merge pull request #33 from KelvinTegelaar/master
Browse files Browse the repository at this point in the history
[pull] master from KelvinTegelaar:master
  • Loading branch information
pull[bot] authored May 25, 2024
2 parents 8a3aa50 + 494ca06 commit fe260b3
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 18 deletions.
1 change: 0 additions & 1 deletion DomainAnalyser_OrchestrationStarter/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ $InputObject = [PSCustomObject]@{
}
OrchestratorName = 'DomainAnalyser_Tenants'
SkipLog = $true
DurableMode = 'Sequence'
}
Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Compress -Depth 5)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ function Push-DomainAnalyserDomain {
}
} catch {
$Message = 'SPF Error'
Write-LogMessage -API 'DomainAnalyser' -tenant $tenant.tenant -message $Message -LogData (Get-CippException -Exception $_) -sev Error
throw $Message
Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message $Message -LogData (Get-CippException -Exception $_) -sev Error
return $Message
}

# Check SPF Record
Expand Down Expand Up @@ -185,8 +185,8 @@ function Push-DomainAnalyserDomain {
}
} catch {
$Message = 'DMARC Error'
Write-LogMessage -API 'DomainAnalyser' -tenant $tenant.tenant -message $Message -LogData (Get-CippException -Exception $_) -sev Error
throw $Message
Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message $Message -LogData (Get-CippException -Exception $_) -sev Error
return $Message
}

# DNS Sec Check
Expand All @@ -203,8 +203,8 @@ function Push-DomainAnalyserDomain {
}
} catch {
$Message = 'DNSSEC Error'
Write-LogMessage -API 'DomainAnalyser' -tenant $tenant.tenant -message $Message -LogData (Get-CippException -Exception $_) -sev Error
throw $Message
Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message $Message -LogData (Get-CippException -Exception $_) -sev Error
return $Message
}

# DKIM Check
Expand Down Expand Up @@ -232,8 +232,8 @@ function Push-DomainAnalyserDomain {
}
} catch {
$Message = 'DKIM Exception'
Write-LogMessage -API 'DomainAnalyser' -tenant $tenant.tenant -message $Message -LogData (Get-CippException -Exception $_) -sev Error
throw $Message
Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message $Message -LogData (Get-CippException -Exception $_) -sev Error
return $Message
}
# Final Score
$Result.Score = $ScoreDomain
Expand All @@ -248,9 +248,9 @@ function Push-DomainAnalyserDomain {
Add-CIPPAzDataTableEntity @DomainTable -Entity $DomainObject -Force

# Final Write to Output
Write-LogMessage -API 'DomainAnalyser' -tenant $tenant.tenant -message "DNS Analyser Finished For $Domain" -sev Info
Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message "DNS Analyser Finished For $Domain" -sev Info
} catch {
Write-LogMessage -API -API 'DomainAnalyser' -tenant $tenant.tenant -message "Error saving domain $Domain to table " -sev Error -LogData (Get-CippException -Exception $_)
Write-LogMessage -API -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message "Error saving domain $Domain to table " -sev Error -LogData (Get-CippException -Exception $_)
}
return $null
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ function Push-DomainAnalyserTenant {
$DomainCount = ($TenantDomains | Measure-Object).Count
if ($DomainCount -gt 0) {
Write-Host "$DomainCount tenant Domains"
$TenantDomainObjects = [System.Collections.Generic.List[object]]::new()
try {
$TenantDomainObjects = foreach ($TenantDomain in $TenantDomains) {
foreach ($TenantDomain in $TenantDomains) {
$TenantDetails = ($TenantDomain | ConvertTo-Json -Compress).ToString()
$Filter = "PartitionKey eq '{0}' and RowKey eq '{1}'" -f $TenantDomain.Tenant, $TenantDomain.Domain
$OldDomain = Get-CIPPAzDataTableEntity @DomainTable -Filter $Filter
Expand Down Expand Up @@ -78,19 +79,23 @@ function Push-DomainAnalyserTenant {
}
}
# Return domain object to list
$Domain
$TenantDomainObjects.Add($Domain)
}

# Batch insert tenant domains
try {
Add-CIPPAzDataTableEntity @DomainTable -Entity $TenantDomainObjects -Force
$InputObject = [PSCustomObject]@{
Batch = $TenantDomainObjects | Select-Object RowKey, @{n = 'FunctionName'; exp = { 'DomainAnalyserDomain' } }
QueueFunction = @{
FunctionName = 'GetTenantDomains'
TenantGUID = $Tenant.customerId
}
OrchestratorName = "DomainAnalyser_$($Tenant.defaultDomainName)"
SkipLog = $true
DurableMode = 'Sequence'
}
Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Compress -Depth 5)
Write-Host "Started analysis for $DomainCount tenant domains in $($Tenant.defaultDomainName)"
Write-LogMessage -API 'DomainAnalyser' -tenant $Tenant.defaultDomainName -message "Started analysis for $DomainCount tenant domains" -sev Info
} catch {
Write-LogMessage -API 'DomainAnalyser' -message 'Domain Analyser GetTenantDomains error' -sev info -LogData (Get-CippException -Exception $_)
}
Expand All @@ -99,7 +104,7 @@ function Push-DomainAnalyserTenant {
}
}
} catch {
Write-Host (Get-CippException -Exception $_ | ConvertTo-Json)
#Write-Host (Get-CippException -Exception $_ | ConvertTo-Json)
Write-LogMessage -API 'DomainAnalyser' -tenant $tenant.defaultDomainName -message 'DNS Analyser GraphGetRequest' -LogData (Get-CippException -Exception $_) -sev Error
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function Push-GetTenantDomains {
Param($Item)
$DomainTable = Get-CippTable -tablename 'Domains'
$Filter = "PartitionKey eq 'TenantDomains' and TenantGUID eq '{0}'" -f $Item.TenantGUID
$Domains = Get-CIPPAzDataTableEntity @DomainTable -Filter $Filter -Property RowKey | Select-Object RowKey, @{n = 'FunctionName'; exp = { 'DomainAnalyserDomain' } }
return @($Domains)
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,7 @@ function Push-ExecScheduledCommand {
ScheduledTime = "$nextRunUnixTime"
}
}
Write-LogMessage -API 'Scheduler_UserTasks' -tenant $tenant -message "Successfully executed task: $($task.Name)" -sev Info
if ($TaskType -ne 'Alert') {
Write-LogMessage -API 'Scheduler_UserTasks' -tenant $tenant -message "Successfully executed task: $($task.Name)" -sev Info
}
}
2 changes: 1 addition & 1 deletion version_latest.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.7.2
5.7.3

0 comments on commit fe260b3

Please sign in to comment.