2023-03-31 15:56:07 +00:00
|
|
|
#Function to check the connectivity
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
function Test-Network {
|
2022-10-25 15:18:58 +00:00
|
|
|
|
2022-03-22 13:39:01 +00:00
|
|
|
#Init
|
2022-03-14 13:55:02 +00:00
|
|
|
$timeout = 0
|
|
|
|
|
2022-03-22 13:39:01 +00:00
|
|
|
#Test connectivity during 30 min then timeout
|
2023-04-01 14:08:52 +00:00
|
|
|
Write-ToLog "Checking internet connection..." "Yellow"
|
2022-06-10 08:26:41 +00:00
|
|
|
While ($timeout -lt 1800) {
|
2022-10-21 11:31:35 +00:00
|
|
|
|
|
|
|
$URLtoTest = "https://raw.githubusercontent.com/Romanitho/Winget-AutoUpdate/main/LICENSE"
|
2022-10-24 09:51:26 +00:00
|
|
|
$URLcontent = ((Invoke-WebRequest -URI $URLtoTest -UseBasicParsing).content)
|
2022-10-25 15:18:58 +00:00
|
|
|
|
2022-10-21 11:31:35 +00:00
|
|
|
if ($URLcontent -like "*MIT License*") {
|
2022-10-25 15:18:58 +00:00
|
|
|
|
2023-04-01 14:08:52 +00:00
|
|
|
Write-ToLog "Connected !" "Green"
|
2022-06-29 15:32:03 +00:00
|
|
|
|
|
|
|
#Check for metered connection
|
|
|
|
[void][Windows.Networking.Connectivity.NetworkInformation, Windows, ContentType = WindowsRuntime]
|
|
|
|
$cost = [Windows.Networking.Connectivity.NetworkInformation]::GetInternetConnectionProfile().GetConnectionCost()
|
2022-10-25 15:18:58 +00:00
|
|
|
|
2022-10-18 13:23:39 +00:00
|
|
|
if ($cost.ApproachingDataLimit -or $cost.OverDataLimit -or $cost.Roaming -or $cost.BackgroundDataUsageRestricted -or ($cost.NetworkCostType -ne "Unrestricted")) {
|
2022-10-25 15:18:58 +00:00
|
|
|
|
2023-04-01 14:08:52 +00:00
|
|
|
Write-ToLog "Metered connection detected." "Yellow"
|
2022-10-25 15:18:58 +00:00
|
|
|
|
2022-06-29 15:32:03 +00:00
|
|
|
if ($WAUConfig.WAU_DoNotRunOnMetered -eq 1) {
|
2022-10-25 15:18:58 +00:00
|
|
|
|
2023-04-01 14:08:52 +00:00
|
|
|
Write-ToLog "WAU is configured to bypass update checking on metered connection"
|
2022-06-29 15:32:03 +00:00
|
|
|
return $false
|
2022-10-25 15:18:58 +00:00
|
|
|
|
2022-06-29 15:32:03 +00:00
|
|
|
}
|
2022-10-18 13:23:39 +00:00
|
|
|
else {
|
2022-10-25 15:18:58 +00:00
|
|
|
|
2023-04-01 14:08:52 +00:00
|
|
|
Write-ToLog "WAU is configured to force update checking on metered connection"
|
2022-06-29 15:32:03 +00:00
|
|
|
return $true
|
2022-10-25 15:18:58 +00:00
|
|
|
|
2022-06-29 15:32:03 +00:00
|
|
|
}
|
2022-10-25 15:18:58 +00:00
|
|
|
|
2022-06-29 15:32:03 +00:00
|
|
|
}
|
2022-10-18 13:23:39 +00:00
|
|
|
else {
|
2022-06-29 15:32:03 +00:00
|
|
|
|
|
|
|
return $true
|
|
|
|
|
|
|
|
}
|
2022-10-25 15:18:58 +00:00
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
}
|
2022-06-10 08:26:41 +00:00
|
|
|
else {
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
Start-Sleep 10
|
|
|
|
$timeout += 10
|
2022-10-25 15:18:58 +00:00
|
|
|
|
2022-03-22 13:39:01 +00:00
|
|
|
#Send Warning Notif if no connection for 5 min
|
2022-06-10 08:26:41 +00:00
|
|
|
if ($timeout -eq 300) {
|
2022-10-26 22:49:10 +00:00
|
|
|
#Log
|
2023-04-01 14:08:52 +00:00
|
|
|
Write-ToLog "Notify 'No connection' sent." "Yellow"
|
2022-10-26 22:49:10 +00:00
|
|
|
|
|
|
|
#Notif
|
2022-03-14 13:55:02 +00:00
|
|
|
$Title = $NotifLocale.local.outputs.output[0].title
|
|
|
|
$Message = $NotifLocale.local.outputs.output[0].message
|
|
|
|
$MessageType = "warning"
|
2022-10-26 22:49:10 +00:00
|
|
|
$Balise = "Connection"
|
|
|
|
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Balise $Balise
|
2022-03-14 13:55:02 +00:00
|
|
|
}
|
2022-10-25 15:18:58 +00:00
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
}
|
2022-10-25 15:18:58 +00:00
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
}
|
2022-10-25 15:18:58 +00:00
|
|
|
|
2022-03-22 13:39:01 +00:00
|
|
|
#Send Timeout Notif if no connection for 30 min
|
2023-04-01 14:08:52 +00:00
|
|
|
Write-ToLog "Timeout. No internet connection !" "Red"
|
2022-10-26 22:49:10 +00:00
|
|
|
|
|
|
|
#Notif
|
2022-03-14 13:55:02 +00:00
|
|
|
$Title = $NotifLocale.local.outputs.output[1].title
|
|
|
|
$Message = $NotifLocale.local.outputs.output[1].message
|
|
|
|
$MessageType = "error"
|
2022-10-26 22:49:10 +00:00
|
|
|
$Balise = "Connection"
|
|
|
|
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Balise $Balise
|
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
return $false
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-10-24 09:51:26 +00:00
|
|
|
}
|