forked from WebFooL-se/Untangle-Easylist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UTJSEasyList.ps1
42 lines (40 loc) · 1.44 KB
/
UTJSEasyList.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
##
## Script Create by WebFooL for The Untangle Community
##
$easylistsource = "https://easylist.to/easylist/easylist.txt"
$Request = Invoke-WebRequest $easylistsource
$EasyList = $Request.Content
$filenamejson = "ADImport.json"
$filenamecsv = "ADImport.csv"
$easylistsourcecount=($EasyList | Measure-Object –Line).Lines
$hash = $null
$counter = 0
$hash = @'
string,blocked,javaClass,markedForNew,markedForDelete,enabled
'@
write-host "Will now work for a while do not panic!"
ForEach ($line in $($EasyList -split "`n"))
{
#Add Nice Progress bar..
Write-Progress -Activity "Processing Easylist" -CurrentOperation $line -PercentComplete (($counter / $easylistsourcecount) * 100)
#Remove all Commented lines (They all start with !)
if($line -clike '!*') {
#Do Nothing
} elseif($line -eq "[Adblock Plus 2.0]"){
#Do Nothing
}elseif($line -eq ""){
#Do Nothing
}else {
#Create Untangle JSON
$hash += "`n$line,true,com.untangle.uvm.app.GenericRule,true,false,true`r"
$counter++
}
}
#Tempstore as CSV
$hash | Set-Content -Path $filenamecsv
#Convert to Json
import-csv $filenamecsv | ConvertTo-Json -Compress | Set-Content -Path $filenamejson
#Count lines in the CSV
$numberoflines = (Import-Csv $filenamecsv | Measure-Object -Property string).Count
#Write friendly exit message
Write-Host "Done you now have a $filenamejson with $numberoflines lines from $easylistsource"