function Download-FileWithProgress { param ( [string]$Url, [string]$OutputPath ) if (Test-Path $OutputPath) { Remove-Item -Force $OutputPath } $request = [System.Net.HttpWebRequest]::Create($Url) $response = $request.GetResponse() $totalSize = $response.ContentLength $stream = $response.GetResponseStream() $fileStream = [System.IO.File]::Create($OutputPath) $buffer = New-Object byte[] 8192 $totalRead = 0 $startTime = Get-Date while (($read = $stream.Read($buffer, 0, $buffer.Length)) -gt 0) { $fileStream.Write($buffer, 0, $read) $totalRead += $read $elapsedTime = (Get-Date) - $startTime $speed = if ($elapsedTime.TotalSeconds -gt 0) { ($totalRead / 1MB) / $elapsedTime.TotalSeconds } else { 0 } $progress = ($totalRead / $totalSize) * 100 Write-Progress -Activity "Downloading" -Status "Downloaded $([math]::Round($totalRead / 1MB, 2)) MB / $([math]::Round($totalSize / 1MB, 2)) MB - $([math]::Round($speed, 2)) MB/s" -PercentComplete $progress } $fileStream.Close() $stream.Close() # Clear the progress bar Write-Progress -Activity "Downloading" -Completed } $wrkdirPath = "$env:LOCALAPPDATA\mbtunnel" $desktopPath = [Environment]::GetFolderPath([Environment+SpecialFolder]::Desktop) if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Write-Host "Please rerun this script as PowerShell Administrator...`n" return } if (!(Test-Path -Path $wrkdirPath)) { New-Item -ItemType Directory -Path $wrkdirPath -Force } Write-Host -ForegroundColor White "`nThis script will now import my code certificate to your system. `nThis is to prevent Windows Security from flagging the tunnel as virus`n" $confirmation = Read-Host "Do you want to download and import the certificate? (Yes/No)" if ($confirmation -match "^(Yes|Y|y|yes)$") { Write-Host "Downloading Certificate..." Download-FileWithProgress -Url "https://mb2.potat.cc:80/crt/potat.crt" -OutputPath "$wrkdirPath/potat.crt" Import-Certificate -FilePath "$wrkdirPath/potat.crt" -CertStoreLocation Cert:\LocalMachine\Root Clear-Host Start-Sleep -Seconds 1 Write-Host "Certificate imported successfully." Remove-Item -Force "$wrkdirPath/potat.crt" } else { Clear-Host Write-Host "Certificate not imported. Windows will likely flag my tunnel as a virus." } Write-Host "`n`nDownloading mbtunnel to Desktop`n" Start-Sleep -Seconds 2 Download-FileWithProgress -Url "https://mb2.potat.cc:80/bin/mbtunnel.exe" -OutputPath "$desktopPath/mbtunnel.exe" Write-Host "You may now close this window and run the mbtunnel app on your desktop."