Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to use new network tester method #99

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 62 additions & 26 deletions Datto-RMM/scripts/InstallHuntress.dattormm.comstore.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Huntress Labs, Inc.
# Copyright (c) 2024 Huntress Labs, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -78,8 +78,8 @@
##############################################################################

# These are used by the Huntress support team when troubleshooting.
$ScriptVersion = "Version 2, major revision 7, 2024 January 24"
$ScriptType = "PowerShell"
$ScriptVersion = "Version 2, major revision 7, 2024 November 1"
$ScriptType = "Datto"

# variables used throughout this script
$X64 = 64
Expand Down Expand Up @@ -762,31 +762,67 @@
# Agent will not function when communication is blocked so exit the script if too much communication is blocked AB
# return true if connectivity is acceptable, false if too many connections fail
function testNetworkConnectivity {
# number of URL's that can fail the connectivity before the agent refuses to install (the test fails incorrectly sometimes, so 1 failure is acceptable)
$connectivityTolerance = 1

$URLs = @("huntress.io", "huntresscdn.com", "update.huntress.io", "eetee.huntress.io", "huntress-installers.s3.amazonaws.com", "huntress-updates.s3.amazonaws.com", "huntress-uploads.s3.us-west-2.amazonaws.com",
"huntress-user-uploads.s3.amazonaws.com", "huntress-rio.s3.amazonaws.com", "huntress-survey-results.s3.amazonaws.com")
foreach ($URL in $URLs) {
if (! (Test-NetConnection $URL -Port 443).TcpTestSucceeded) {
$err = "WARNING, connectivity to Huntress URL's is being interrupted. You MUST open port 443 for $($URL) in order for the Huntress agent to function."
Write-Output $err -ForegroundColor white -BackgroundColor red
LogMessage $err
$connectivityTolerance --
} else {
LogMessage "Connection succeeded to $($URL) on port 443!"
}
}
if ($connectivityTolerance -lt 0) {
Write-Output "Please fix the closed port 443 for the above domains before attempting to install" -ForegroundColor white -BackgroundColor red
$err = "Too many connections failed $($connectivityTolerance), exiting"
LogMessage $err
Write-Output "$($err), $($SupportMessage)" -ForegroundColor white -BackgroundColor red
return $false
}
return $true
# number of URL's that can fail the connectivity before the agent refuses to install (the test fails incorrectly sometimes, so 1 failure is acceptable)
$connectivityTolerance = 1

$file_name = "96bca0cef10f45a8f7cf68c4485f23a4.txt"

$URLs = @(("https://eetee.huntress.io/{0}"-f $file_name),
("https://huntress-installers.s3.us-east-1.amazonaws.com/agent/connectivity/{0}" -f $file_name),
("https://huntress-rio.s3.amazonaws.com/agent/connectivity/{0}" -f $file_name),
("https://huntress-survey-results.s3.amazonaws.com/agent/connectivity/{0}" -f $file_name),
("https://huntress-updates.s3.amazonaws.com/agent/connectivity/{0}" -f $file_name),
("https://huntress-uploads.s3.us-west-2.amazonaws.com/agent/connectivity/{0}" -f $file_name),
("https://huntress-user-uploads.s3.amazonaws.com/agent/connectivity/{0}" -f $file_name),
("https://huntress.io/agent/connectivity/{0}" -f $file_name),
("https://huntresscdn.com/agent/connectivity/{0}" -f $file_name),
("https://update.huntress.io/agent/connectivity/{0}" -f $file_name))

foreach ($URL in $URLs) {
$StatusCode = 0
try {
$Response = Invoke-WebRequest -Uri $URL -TimeoutSec 5 -ErrorAction Stop -ContentType "text/plain"
# This will only execute if the Invoke-WebRequest is successful.
$StatusCode = $Response.StatusCode

# Convert from bytes, if necessary
if ($Response.Content.GetType() -eq [System.Byte[]]) {
$StrContent = [System.Text.Encoding]::UTF8.GetString($Response.Content)

Check warning

Code scanning / Psscriptanalyzer (reported by Codacy)

Line has trailing whitespace Warning

Line has trailing whitespace
} else {
$StrContent = $Response.Content.ToString().Trim()
}

# Remove all newlines from the content
$StrContent = [string]::join("",($StrContent.Split("`n")))

Check warning

Code scanning / Psscriptanalyzer (reported by Codacy)

Line has trailing whitespace Warning

Line has trailing whitespace
$ContentMatch = $StrContent -eq "96bca0cef10f45a8f7cf68c4485f23a4"
} catch {
LogMessage "Error: $($_.Exception.Message)"
}

if ($StatusCode -ne 200) {
$err = "WARNING, connectivity to Huntress URL's is being interrupted. You MUST open port 443 for $($URL) in order for the Huntress agent to function."
LogMessage $err

Check warning

Code scanning / Psscriptanalyzer (reported by Codacy)

Line has trailing whitespace Warning

Line has trailing whitespace
$connectivityTolerance --
} elseif (!$ContentMatch) {
$err = "WARNING, successful connection to Huntress URL, however, content did not match expected. Ensure no proxy or content filtering is preventing access!"
LogMessage $err

Check warning

Code scanning / Psscriptanalyzer (reported by Codacy)

Line has trailing whitespace Warning

Line has trailing whitespace
$connectivityTolerance --
LogMessage "Content: $($StrContent)"
} else {
LogMessage "Connection succeeded to $($URL)"
}
}
if ($connectivityTolerance -lt 0) {
Write-Output "Please fix the closed port 443 for the above domains before attempting to install" -ForegroundColor white -BackgroundColor red
$err = "Too many connections failed $($connectivityTolerance), exiting"
LogMessage "$($err), $($SupportMessage)"

Check warning

Code scanning / Psscriptanalyzer (reported by Codacy)

Line has trailing whitespace Warning

Line has trailing whitespace
return $false
}
return $true
}


# Log useful data about the machine for troubleshooting AB
function logInfo {
# gather info on the host for logging purposes
Expand Down
Loading