<?php

echo "Downloading...\n";
file_put_contents(__DIR__ . "/bannedips.zip", file_get_contents("https://www.stopforumspam.com/downloads/listed_ip_7_ipv46.zip"));
file_put_contents(__DIR__ . "/toxic_ip_cidr.txt", file_get_contents("https://www.stopforumspam.com/downloads/toxic_ip_cidr.txt"));
file_put_contents(__DIR__ . "/toxic_domains_whole.txt", file_get_contents("https://www.stopforumspam.com/downloads/toxic_domains_whole.txt"));
file_put_contents(__DIR__ . "/toxic_domains_partial.txt", file_get_contents("https://www.stopforumspam.com/downloads/toxic_domains_partial.txt"));
file_put_contents(__DIR__ . "/matomoreferralspamdomains.txt", file_get_contents("https://raw.githubusercontent.com/matomo-org/referrer-spam-list/refs/heads/master/spammers.txt"));

$zip = new ZipArchive;
$res = $zip->open(__DIR__ . "/bannedips.zip");
if ($res === TRUE) {
    $zip->extractTo(__DIR__ . "/");
    $zip->close();
    unlink(__DIR__ . "/bannedips.zip");
    rename(__DIR__ . "/listed_ip_7_ipv46.txt", __DIR__ . "/bannedips.txt");
    echo "Unzipped.\n";
} else {
    echo "Unzip failed.\n";
}
echo "Done.\n";
