Skip to content

Commit

Permalink
Make updater a bit more secure
Browse files Browse the repository at this point in the history
  • Loading branch information
RainbowMiner committed Aug 18, 2018
1 parent 08cb42b commit ae204a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
14 changes: 7 additions & 7 deletions Include.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function Get-Version {

function Confirm-Version {
[CmdletBinding()]
param($RBMVersion, [Switch]$Force = $false)
param($RBMVersion, [Switch]$Force = $false, [Switch]$Silent = $false)

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Expand All @@ -32,12 +32,12 @@ function Confirm-Version {

$Version = Get-Version($Version)

if ($Version -gt $RBMVersion) {
Write-Log -Level Warn "$Name is out of date: lastest release version v$Version is available."
}

if ($Version -lt $RBMVersion) {
Write-Log -Level Warn "You are running $Name prerelease v$RBMVersion. Use at your own risk."
if (-not $Silent) {
if ($Version -gt $RBMVersion) {
Write-Log -Level Warn "$Name is out of date: lastest release version v$Version is available."
} elseif ($Version -lt $RBMVersion) {
Write-Log -Level Warn "You are running $Name prerelease v$RBMVersion. Use at your own risk."
}
}
}
catch {
Expand Down
7 changes: 6 additions & 1 deletion Updater.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (-not (Test-Path ".\Data\Version.json")) {
exit
}

$RBMVersion = Confirm-Version (Get-Content ".\Data\Version.json" | ConvertFrom-Json).Version -Force
$RBMVersion = Confirm-Version (Get-Content ".\Data\Version.json" | ConvertFrom-Json).Version -Force -Silent

$Name = "RainbowMiner"
try {
Expand All @@ -23,8 +23,13 @@ try {
if (-not (Test-Path ".\Downloads")) {New-Item "Downloads" -ItemType "directory" | Out-Null}
$FileName = Join-Path ".\Downloads" (Split-Path $RBMVersion.DownloadURI -Leaf)
if (Test-Path $FileName) {Remove-Item $FileName}

if ($RBMVersion.DownloadURI -eq "") {throw}

Invoke-WebRequest $RBMVersion.DownloadURI -OutFile $FileName -UseBasicParsing

if (-not (Test-Path $FileName) -or (Get-Item $FileName).Length -lt 2MB) {throw}

Write-Host " (2/3) Deleting old files .."

@("Miners","APIs","Balances","Pools") | Foreach-Object {if (Test-Path ".\$($_)") {Remove-Item ".\$($_)" -Recurse -Force}}
Expand Down

0 comments on commit ae204a1

Please sign in to comment.