<?php

echo "Downloading...\n";
file_put_contents(__DIR__ . "/bannedips.zip", file_get_contents("https://www.stopforumspam.com/downloads/bannedips.zip"));
file_put_contents(__DIR__ . "/toxic_ip_cidr.txt", file_get_contents("https://www.stopforumspam.com/downloads/toxic_ip_cidr.txt"));

$zip = new ZipArchive;
$res = $zip->open(__DIR__ . "/bannedips.zip");
if ($res === TRUE) {
  $zip->extractTo(__DIR__ . "/");
  $zip->close();
  echo 'Unzipped.';
} else {
  echo 'Unzip failed.';
}
unlink(__DIR__ . "/bannedips.zip");

$csv = file_get_contents(__DIR__ . "/bannedips.csv");
$ips = explode(",", $csv);
file_put_contents("bannedips.txt", implode("\n", $ips));
echo "\nConverted.\n";
unlink(__DIR__ . "/bannedips.csv");
