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
Jcblmao authored Jun 13, 2023
2 parents 286e821 + b83cf7d commit 2f7f6a5
Show file tree
Hide file tree
Showing 57 changed files with 3,184 additions and 208 deletions.
47 changes: 23 additions & 24 deletions AddAlert/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ $Results = foreach ($Tenant in $tenants) {
try {
$TenantID = if ($tenant -ne 'AllTenants') {
(get-tenants | Where-Object -Property defaultDomainName -EQ $Tenant).customerId
}
else {
} else {
'AllTenants'
}
$CompleteObject = @{
tenant = $tenant
tenantid = $TenantID
AdminPassword = [bool]$Request.body.AdminPassword
DefenderMalware = [bool]$Request.body.DefenderMalware
DefenderStatus = [bool]$Request.body.DefenderStatus
MFAAdmins = [bool]$Request.body.MFAAdmins
MFAAlertUsers = [bool]$Request.body.MFAAlertUsers
NewGA = [bool]$Request.body.NewGA
NewRole = [bool]$Request.body.NewRole
QuotaUsed = [bool]$Request.body.QuotaUsed
UnusedLicenses = [bool]$Request.body.UnusedLicenses
OverusedLicenses = [bool]$Request.body.OverusedLicenses
AppSecretExpiry = [bool]$Request.body.AppSecretExpiry
ApnCertExpiry = [bool]$Request.body.ApnCertExpiry
VppTokenExpiry = [bool]$Request.body.VppTokenExpiry
DepTokenExpiry = [bool]$Request.body.DepTokenExpiry
NoCAConfig = [bool]$Request.body.NoCAConfig
type = 'Alert'
RowKey = $TenantID
PartitionKey = 'Alert'
tenant = $tenant
tenantid = $TenantID
AdminPassword = [bool]$Request.body.AdminPassword
DefenderMalware = [bool]$Request.body.DefenderMalware
DefenderStatus = [bool]$Request.body.DefenderStatus
MFAAdmins = [bool]$Request.body.MFAAdmins
MFAAlertUsers = [bool]$Request.body.MFAAlertUsers
NewGA = [bool]$Request.body.NewGA
NewRole = [bool]$Request.body.NewRole
QuotaUsed = [bool]$Request.body.QuotaUsed
UnusedLicenses = [bool]$Request.body.UnusedLicenses
OverusedLicenses = [bool]$Request.body.OverusedLicenses
AppSecretExpiry = [bool]$Request.body.AppSecretExpiry
ApnCertExpiry = [bool]$Request.body.ApnCertExpiry
VppTokenExpiry = [bool]$Request.body.VppTokenExpiry
DepTokenExpiry = [bool]$Request.body.DepTokenExpiry
NoCAConfig = [bool]$Request.body.NoCAConfig
SecDefaultsUpsell = [bool]$Request.body.SecDefaultsUpsell
type = 'Alert'
RowKey = $TenantID
PartitionKey = 'Alert'
}

$Table = get-cipptable -TableName 'SchedulerConfig'
Expand All @@ -49,8 +49,7 @@ $Results = foreach ($Tenant in $tenants) {
Add-AzDataTableEntity @Table -Entity $CompleteObject -Force
"Successfully added Alert for $($Tenant) to queue."
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenant -message "Successfully added Alert for $($Tenant) to queue." -Sev 'Info'
}
catch {
} catch {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenant -message "Failed to add Alert for for $($Tenant) to queue" -Sev 'Error'
"Failed to add Alert for for $($Tenant) to queue $($_.Exception.message)"
}
Expand Down
19 changes: 19 additions & 0 deletions ExecExtensionMapping/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "Request",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "Response"
}
]
}
76 changes: 76 additions & 0 deletions ExecExtensionMapping/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using namespace System.Net

# Input bindings are passed in via param block.
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.'
$Table = Get-CIPPTable -TableName CippMapping

if ($Request.Query.List) {
#Get available mappings
$Mappings = [pscustomobject]@{}
Get-AzDataTableEntity @Table | ForEach-Object {
$Mappings | Add-Member -NotePropertyName $_.RowKey -NotePropertyValue @{ label = "$($_.HaloPSAName)"; value = "$($_.HaloPSA)" }
}
#Get Available TEnants
$Tenants = Get-Tenants
#Get available halo clients
$Table = Get-CIPPTable -TableName Extensionsconfig
$Configuration = ((Get-AzDataTableEntity @Table).config | ConvertFrom-Json).HaloPSA
$Token = Get-HaloToken -configuration $Configuration
$i = 1
$RawHaloClients = do {
$Result = Invoke-RestMethod -Uri "$($Configuration.ResourceURL)/Client?page_no=$i&page_size=999&pageinate=true" -ContentType 'application/json' -Method GET -Headers @{Authorization = "Bearer $($token.access_token)" }
$Result.clients | Select-Object * -ExcludeProperty logo
$i++
$pagecount = [Math]::Ceiling($Result.record_count / 999)
} while ($i -le $pagecount)
$HaloClients = $RawHaloClients | ForEach-Object {
[PSCustomObject]@{
label = $_.name
value = $_.id
}
}
$HaloClients = $RawHaloClients | ForEach-Object {
[PSCustomObject]@{
name = $_.name
value = "$($_.id)"
}
}
$MappingObj = [PSCustomObject]@{
Tenants = @($Tenants)
HaloClients = @($HaloClients)
Mappings = $Mappings
}
$body = $MappingObj
}
try {
if ($Request.Query.AddMapping) {
foreach ($Mapping in ([pscustomobject]$Request.body.mappings).psobject.properties) {
$AddObject = @{
PartitionKey = 'Mapping'
RowKey = "$($mapping.name)"
'HaloPSA' = "$($mapping.value.value)"
'HaloPSAName' = "$($mapping.value.label)"
}
Add-AzDataTableEntity @Table -Entity $AddObject -Force
Write-LogMessage -API $APINAME -user $request.headers.'x-ms-client-principal' -message "Added mapping for $($mapping.name)." -Sev 'Info'
}
$body = [pscustomobject]@{'Results' = "Successfully edited mapping table." }
}
}
catch {
Write-LogMessage -API $APINAME -user $request.headers.'x-ms-client-principal' -message "mapping API failed. $($_.Exception.Message)" -Sev 'Error'
$body = [pscustomobject]@{'Results' = "Failed. $($_.Exception.Message)" }
}

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $body
})
22 changes: 22 additions & 0 deletions ExecExtensionSync/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "Request",
"methods": ["get", "post"]
},
{
"type": "http",
"direction": "out",
"name": "Response"
},
{
"type": "queue",
"direction": "out",
"name": "Msg",
"queueName": "billqueue"
}
]
}
34 changes: 34 additions & 0 deletions ExecExtensionSync/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'


try {
Write-LogMessage -API "Scheduler_Billing" -tenant "none" -message "Starting billing processing." -sev Info
$Table = Get-CIPPTable -TableName Extensionsconfig
$Configuration = (Get-AzDataTableEntity @Table).config | ConvertFrom-Json -Depth 10
foreach ($ConfigItem in $Configuration.psobject.properties.name) {
switch ($ConfigItem) {
"Gradient" {
If ($Configuration.Gradient.enabled -and $Configuration.Gradient.BillingEnabled) {
Push-OutputBinding -Name msg -Value "LetsGo"
$Results = [pscustomobject]@{"Results" = "Succesfully started Gradient Sync" }
}
}
}
}
}
catch {
$Results = [pscustomobject]@{"Results" = "Could not start Gradient Sync: $($_.Exception.Message)" }

Write-LogMessage -API "Scheduler_Billing" -tenant "none" -message "Could not start billing processing $($_.Exception.Message)" -sev Error
}

Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $Results
}) -clobber
19 changes: 19 additions & 0 deletions ExecExtensionTest/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "Request",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "Response"
}
]
}
37 changes: 37 additions & 0 deletions ExecExtensionTest/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"
$Table = Get-CIPPTable -TableName Extensionsconfig
$Configuration = ((Get-AzDataTableEntity @Table).config | ConvertFrom-Json)
# Interact with query parameters or the body of the request.
try {
switch ($Request.query.extensionName) {
"HaloPSA" {
$token = Get-HaloToken -configuration $Configuration.HaloPSA
$Results = [pscustomobject]@{"Results" = "Succesfully Connected to HaloPSA" }
}
"Gradient" {
$GradientToken = Get-GradientToken -Configuration $Configuration.Gradient
$ExistingIntegrations = Invoke-RestMethod -Uri 'https://app.usegradient.com/api/vendor-api/organization' -Method GET -Headers $GradientToken
if ($ExistingIntegrations.Status -ne "active") {
$ActivateRequest = Invoke-RestMethod -Uri 'https://app.usegradient.com/api/vendor-api/organization/status/active' -Method PATCH -Headers $GradientToken
}
$Results = [pscustomobject]@{"Results" = "Succesfully Connected to Gradient" }

}

}
}
catch {
$Results = [pscustomobject]@{"Results" = "Failed to connect: $($_.Exception.Message) $($_.InvocationInfo.ScriptLineNumber)" }
}

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $Results
})
19 changes: 19 additions & 0 deletions ExecExtensionsConfig/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "Request",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "Response"
}
]
}
47 changes: 47 additions & 0 deletions ExecExtensionsConfig/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'

#Connect-AzAccount -UseDeviceAuthentication
# Write to the Azure Functions log stream.
Write-Host 'PowerShell HTTP trigger function processed a request.'
$results = try {
$Table = Get-CIPPTable -TableName Extensionsconfig
foreach ($APIKey in ([pscustomobject]$request.body).psobject.properties.name) {
Write-Host "Working on $apikey"
if ($request.body.$APIKey.APIKey -eq "SentToKeyVault" -or $request.body.$APIKey.APIKey -eq "") {
Write-Host "Not sending to keyvault. Key previously set or left blank."
}
else {
Write-Host "writing API Key to keyvault, and clearing."
Write-Host "$ENV:WEBSITE_DEPLOYMENT_ID"
$null = Set-AzKeyVaultSecret -VaultName $ENV:WEBSITE_DEPLOYMENT_ID -Name $APIKey -SecretValue (ConvertTo-SecureString -String $request.body.$APIKey.APIKey -AsPlainText -Force)
$request.body.$APIKey.APIKey = "SentToKeyVault"
}
}
$body = $request.body | Select-Object * -ExcludeProperty APIKey, Enabled | ConvertTo-Json -Depth 10 -Compress
$Config = @{
'PartitionKey' = 'CippExtensions'
'RowKey' = 'Config'
'config' = [string]$body
}

Add-AzDataTableEntity @Table -Entity $Config -Force | Out-Null
"Successfully set the configuration"
}
catch {
"Failed to set configuration: $($_.Exception.message)"
}


$body = [pscustomobject]@{'Results' = $Results }

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $body
})
19 changes: 10 additions & 9 deletions ExecNotificationConfig/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ Write-Host 'PowerShell HTTP trigger function processed a request.'
$results = try {
$Table = Get-CIPPTable -TableName SchedulerConfig
$SchedulerConfig = @{
'tenant' = 'Any'
'tenantid' = 'TenantId'
'type' = 'CIPPNotifications'
'schedule' = 'Every 15 minutes'
'email' = "$($Request.Body.Email)"
'webhook' = "$($Request.Body.Webhook)"
'onePerTenant' = [boolean]$Request.Body.onePerTenant
'PartitionKey' = 'CippNotifications'
'RowKey' = 'CippNotifications'
'tenant' = 'Any'
'tenantid' = 'TenantId'
'type' = 'CIPPNotifications'
'schedule' = 'Every 15 minutes'
'email' = "$($Request.Body.Email)"
'webhook' = "$($Request.Body.Webhook)"
'onePerTenant' = [boolean]$Request.Body.onePerTenant
'sendtoIntegration' = [boolean]$Request.Body.sendtoIntegration
'PartitionKey' = 'CippNotifications'
'RowKey' = 'CippNotifications'
}
foreach ($logvalue in [pscustomobject]$Request.body.logsToInclude) {
$SchedulerConfig[([pscustomobject]$logvalue.value)] = $true
Expand Down
10 changes: 10 additions & 0 deletions ExecSchedulerBillingRun/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"bindings": [
{
"name": "QueueItem",
"type": "queueTrigger",
"direction": "in",
"queueName": "billqueue"
}
]
}
Loading

0 comments on commit 2f7f6a5

Please sign in to comment.