#!/usr/bin/php $v) { if ( strlen(trim($v)) == 0 ) { continue; } if ( ip2long(preg_replace("/\/.*/","",$v)) == 0 || preg_match("/:/",$v) ) { unset($tmp[$k]); } list($net,$mask)=explode("/",$v); if ( $mask <= 19 ) { unset($tmp[$k]); } $bad_nets[$v]=TRUE; } if ( count($bad_nets) == 0 ) { logtofile("EMPTY_LST"); $sleeptime=10; logtofile("SLEEP: ".$sleeptime."s"); sleep($sleeptime); continue; } foreach(array_keys($bad_nets) as $k) { if ( !array_key_exists($k,$prev_bad) ) { passthru("ip route add prohibit ".$k); logtofile("ROUTE + ".$k); } } foreach(array_keys($prev_bad) as $k) { if ( !array_key_exists($k,$bad_nets) ) { passthru("ip route del prohibit ".$k); logtofile("ROUTE - ".$k); } } $prev_bad=$bad_nets; gc_collect_cycles(); $cycle_end=microtime(TRUE); logtofile("CYCLE_END"); $cycle_len=number_format($cycle_end-$cycle_beg,3,".",""); logtofile("CYCLE_LEN: ".$cycle_len."s"); $sleeptime=30*ceil($cycle_len); if ( $sleeptime < 10 ) { $sleeptime=10; } if ( $sleeptime > 300 ) { $sleeptime=300; } logtofile("SLEEP: ".$sleeptime."s"); sleep($sleeptime); } function mirror_data() { global $full_url; global $mytmp; passthru("cd ".escapeshellcmd($mytmp)."; wget --mirror --no-directories --no-host-directories -q ".escapeshellcmd($full_url)); } function logtofile($text) { global $logfile; $data=gmdate("Y-m-d H:i:s")." | ".$text."\n"; file_put_contents($logfile,$data,FILE_APPEND); } function sig_handler($sig) { clear_routes(); exit_die(); } function clear_routes() { logtofile("CLEANING_RT"); passthru("ip route show | grep '^prohibit ' | awk '{print $2}' | xargs -I '{}' ip route del prohibit '{}'"); } function exit_die() { logtofile("EXITING..."); die(); }