Last active
August 24, 2020 21:17
-
-
Save jfinstrom/d0298f72a3e790b1707ad6c85b368695 to your computer and use it in GitHub Desktop.
ipban.org with freepbx firewall **(Untested)**
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
$restrict_mods = array('firewall' => true); | |
$bootstrap_settings['freepbx_auth'] = false; | |
include '/etc/freepbx.conf'; | |
$freepbx = FreePBX::Create(); | |
$firewall = $freepbx->Firewall; | |
define('API_KEY', ''); | |
function getBatch($lastid = '') | |
{ | |
$url = 'https://apiban.org/api/' . API_KEY . '/banned'; | |
if (!empty($lastid)) { | |
$url = $url . '/' . $lastid; | |
} | |
$raw = file_get_contents($url); | |
$out = json_decode($raw, true); | |
return $out; | |
} | |
$id = ''; | |
$final = []; | |
while (true) { | |
$ips = getBatch($id); | |
echo $ips['ID'] . PHP_EOL; | |
if ($ips['ID'] == 'none' || !is_array($ips['ipaddress'])) { | |
break; | |
} | |
foreach ($ips['ipaddress'] as $ip) { | |
$final[] = $ip; | |
} | |
$id = $ips['ID']; | |
} | |
$blacklist = $firewall->getBlacklist(); | |
foreach ($final as $ip) { | |
if (!isset($blacklist[$ip])) { | |
$firewall->addToBlacklist($ip); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@lgaetz a poc, untested but that should put them all in the FreePBX Firewall without duplicates....
Probably should do some sanity checking like "do we have firewall" etc....