Before importing I try to make an export of the current filters. I get a 2 byte file!!!
I think something in this app is broken.....
I think something in this app is broken.....
## ## 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 = @' blocked,flagged,string,javaClass,name,description,readOnly,id,category,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 += "true,true,$line,com.untangle.uvm.app.GenericRule,null,null,null,null,null,true`r`n" $counter++ } } #Tempstore as CSV $hash | Set-Content -Path $filenamecsv function Split-CsvFile { param ( [string]$sourceCSV, [int]$size ) $exportPath = $sourceCSV.Substring(0, $sourceCSV.LastIndexOf('.')) $count = (Import-Csv $sourceCSV).count $startrow = 0; $counter = 1; while ($startrow -lt $count) { $filename = "$($exportPath)_$($counter)" Write-host "Filename:" $filename Import-CSV $sourceCSV | select-object -skip $startrow -first $size | Export-CSV "$filename.csv" -NoClobber -Encoding UTF8 -NoTypeInformation #Convert to Json import-csv "$filename.csv" | ConvertTo-Json -Compress | Set-Content -Path "$filename.json" if (Test-Path "$filename.csv") { Remove-Item "$filename.csv" } $startrow += $size $counter++ } } Split-CsvFile -sourceCSV $filenamecsv -size 500 #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 few $filenamejson with $numberoflines lines from $easylistsource"
$original_file = 'c:\temp\ADImport.json' $destination_file = 'c:\temp\ADImport.json' (Get-Content $original_file) | Foreach-Object { $_ -replace '"true"', 'true' ` -replace '"false"', 'false' } | Set-Content $destination_file
Comment