sudo apt-get install php5-cli php5-sqlite
<?php $rules = array( 60 => 2, // 2 ( 60 ) 3600 => 10 // 10 ( 3600 ) ); if (!$argv[1] ) die("please use: '" . $argv[0] . " phone_number' \nfor example: ".$argv[0]." 88121234567\n"); // $db = new SQLite3('/tmp/sqlite.db'); $db->exec('CREATE TABLE IF NOT EXISTS logs (phone bigint(12), datetime int(12))'); // $phone = preg_replace('/[^0-9]/','', $argv[1]); $db->exec("INSERT INTO logs (phone, datetime) VALUES ( '".$phone."','".time()."' )"); foreach( $rules as $secs => $limit ) { $res = $db->query( "SELECT count(*) as `c` FROM logs WHERE `phone` = '".$phone."' AND `datetime` >= " .( time() - $secs ) ); $row = $res->fetchArray(); // if ( $row['c'] > $limit ) { die('stop'); // stop } } // - , $max_period = max(array_keys($rules) ); $db->exec("DELETE FROM logs WHERE `datetime` < " .( time() - $max_period )); // continue die('continue'); ?>
exten => 8800XXXXXXX,1,Set(resp=${SHELL(php /home/scripts/antiddos.php ${CALLERID(num)})}); exten => 8800XXXXXXX,2,Gosubif($[${resp}==stop]?${EXTEN},${MATH(${PRIORITY}+1),int}:${EXTEN},${MATH(${PRIORITY}+2),int}); exten => 8800XXXXXXX,3,HangUp(); exten => 8800XXXXXXX,4,Answer(); ...
sip provider me invite => <= trying <= OK ack =>
sip provider me invite => <= trying <= DECLINE ack =>
Source: https://habr.com/ru/post/144039/
All Articles