Improve blockShittyhost function

This commit is contained in:
Yorick 2016-10-18 11:33:42 +02:00
parent 7371507fd4
commit 278232165e

35
cleanW10.ps1 Executable file → Normal file
View file

@ -16,36 +16,31 @@ function blockShittyHost {
remove-host $filename $hostname
Write-Host -NoNewline -ForegroundColor White "Block shitty host $hostname"
try {
$ip + "`t`t" + $hostname | Out-File -encoding ASCII -append $filename
if ( ! $(is_host_present $filename $hostname) ){
$ip + "`t`t" + $hostname | Out-File -encoding ASCII -append $filename
}
else {
Write-Host -NoNewline -ForegroundColor Yellow " Already blocked "
}
}
catch {
Write-Host -ForegroundColor Red " Error "
return
}
Write-Host -ForegroundColor Green " OK "
Write-Host -ForegroundColor Green " done "
}
function remove-host {
function is_host_present {
param([string]$filename, [string]$hostname)
$c = Get-Content $filename
$newLines = @()
foreach ($line in $c) {
$bits = [regex]::Split($line, "\t+")
if ($bits.count -eq 2) {
if ($bits[1] -ne $hostname) {
$newLines += $line
}
} else {
$newLines += $line
if ($bits[1] -eq $hostname) {
return $true
}
}
# Write file
Clear-Content $filename
foreach ($line in $newLines) {
$line | Out-File -encoding ASCII -append $filename
}
return $false
}
function remove_shittyTasks () {
@ -162,10 +157,10 @@ Write-Output "I's time to kick ass and chew bubble gum"
Write-Output "________________________________________"
write-Output ""
$shittyFeatures | foreach { disableShitty $_ }
$shittyServices | Foreach { disableShittyService $_ }
$shittyModernApp | Foreach { disableModernShitty $_ }
$shittyHosts | Foreach { blockShittyHost $HOST_FILE $HOST_IP $_ }
#$shittyFeatures | foreach { disableShitty $_ }
#$shittyServices | Foreach { disableShittyService $_ }
#$shittyModernApp | Foreach { disableModernShitty $_ }
$shittyHosts | Foreach { blockShittyHost $HOST_FILE $HOST_IP $_ }
remove_shittyTasks $shittyTasks
$shittyIP | Foreach {