アスタリスクとTruecaller。 着信コールの不明なサブスクライバーの名前の判別

TrueCallerは、着信コールのサブスクライバーの名前を判別し、スパムをブロックするためのサービスです。 CyanogenOS 12.1を搭載したスマートフォンでは、通常のダイヤラーに縫い付けられます。 また、GooglePlay / AppStore / BlackBerryWorld / WindowsPhoneStoreとともにTrueDialler / TrueCallerをインストールすることもできます。



スマートフォンでこの機能を有効にしている場合、連絡先帳はTruecallerのサーバーに完全に統合されていますか? たとえば、 https//www.truecaller.com/en/74996813210 (認証が必要です)などのリンクを使用して、番号がデータベースにあるかどうかを確認できます。



現在、このサービスには世界中で16億の数字があります。 https://www.truecaller.com/unlistのデータベースから番号を書き出すことができます



Truecallerをアスタリスクに固定します



Truecaller Webサイトでは、電話番号で加入者の名前を判別できます。 サイトへのアクセスは、サードパーティのサービスとソーシャルネットワークを介してのみ可能です。 認証には、Vkontakte(Oauthプロトコル)を選択しました。



1.アクセスを許可するために、以前に登録されたVKontakteアカウントを使用してtruecaller.comに手動でログインします。

2.一度呼び出した連絡先を保存するために、内部データベースを作成する必要があります。 これは、truecallerサービスにアクセスしないたびに必要です。

3. VKontakteネットワークを介してtruecaller.com Webサイトで認証用のスクリプトを作成し、サブスクライバー名の存在を確認するための関数を作成します。



スクリプトは、AGIおよび一般的な読みやすさの下での実装を容易にするためにPHPで記述されています。



MySQLでデータベースを作成します。



USE asterisk; CREATE TABLE asterisk.phonebook ( id int(11) NOT NULL AUTO_INCREMENT, create_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, number varchar(20) NOT NULL, name varchar(80) NOT NULL, temporary_contact tinyint(1) NOT NULL DEFAULT 1, PRIMARY KEY (id) ) ENGINE = INNODB AUTO_INCREMENT = 9 AVG_ROW_LENGTH = 8192 CHARACTER SET utf8 COLLATE utf8_general_ci;
      
      





PHPスクリプト/var/lib/asterisk/agi-bin/phonebook.php(PHP-AGIを介して行う場合、対応する行のコメントを外すことを忘れないでください。結果はチャンネル変数CID_NAMEで取得されます):



 #!/usr/bin/php -q <?php $error_level = error_reporting(0); set_time_limit(30); //require('phpagi.php'); //$agi = new AGI(); if (isset($argv[1])) {$num=$argv[1];} else {$num=NULL;} $cookie_file='/tmp/asterisk_truecaller_vk.cookie'; $vk = array("login"=> "_", "password"=> "_"); $mysql = array("hostname" => "localhost", "login"=> "root", "password"=> "_mysql", "database"=> "asterisk"); if (!is_null($num)) { $callerid_name=get_num($num,$vk,$mysql,$cookie_file,true); return $callerid_name; } else { echo "   \n"; //$agi->set_variable("CID_NAME", ""); return false; } //     truecaller function get_num($num,$vk,$mysql,$cookie_file,$isauth) { //     mysql_connect($mysql['hostname'],$mysql['login'],$mysql['password']); mysql_select_db($mysql['database']) or die(mysql_error()); mysql_query("SET NAMES 'utf8'"); mysql_query("SET CHARACTER SET 'utf8'"); mysql_query("SET SESSION collation_connection = 'utf8_general_ci'"); $query = "SELECT * FROM phonebook WHERE `number`=$num"; $res = mysql_query($query); $count = mysql_num_rows($res); if ($count>0) while ($row=mysql_fetch_array($res)) { $name=$row['name']; echo "   MySQL '".$name."'\n"; //$agi->set_variable("CID_NAME", "$name"); return $name; } mysql_close(); //   truecaller if ($isauth) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.truecaller.com/ru/'.$num ); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); $data = curl_exec($ch); curl_close($ch); if (preg_match("/You need to sign in to view the result/i", $data)) { echo "  TC\n"; $isauth = oauth_vk($vk, $cookie_file); get_num($num,$vk,$mysql,$cookie_file,$isauth); } else { preg_match("/<div class=\"detailView__nameText\">\n\s*(.+)\s\n\s*<\/div>/i", $data, $matches); if (count($matches)>0) { $name=$matches[1]; echo "   TC '".$name."'\n"; mysql_connect($mysql['hostname'],$mysql['login'],$mysql['password']); mysql_select_db($mysql['database']) or die(mysql_error()); mysql_query("SET NAMES 'utf8'"); mysql_query("SET CHARACTER SET 'utf8'"); mysql_query("SET SESSION collation_connection = 'utf8_general_ci'"); $query = "INSERT INTO phonebook (`name`,`number`) VALUE ('".$name."','".$num."')"; $res = mysql_query($query); mysql_close(); //$agi->set_variable("CID_NAME", "$name"); return $name; } else { echo "  TC  \n"; //$agi->set_variable("CID_NAME", ""); return false; } } } else { echo " TC   ,    \n"; //$agi->set_variable("CID_NAME", ""); return false; } } //    "  " function oauth_vk($vk, $cookie_file) { unlink($cookie_file); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://oauth.vk.com/authorize?client_id=4951501&scope=friends%2Coffline&redirect_uri=http%3A%2F%2Fwww.truecaller.com%2Fsign-in%2Fvk&response_type=code&state=KKoLuT0vbWEOXfqIW9C0yAvoX7uoEDszIrVOxYSr'); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); //     curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); $data = curl_exec($ch); curl_close($ch); preg_match("/<form method=\"post\" action=\"(.+)\">/i", $data, $matches); if (count($matches)>0) $action=$matches[1]; preg_match("/<input type=\"hidden\" name=\"_origin\" value=\"(.+)\">/i", $data, $matches); if (count($matches)>0) $origin=$matches[1]; preg_match("/<input type=\"hidden\" name=\"ip_h\" value=\"(.+)\" \/>/i", $data, $matches); if (count($matches)>0) $ip_h=$matches[1]; preg_match("/<input type=\"hidden\" name=\"lg_h\" value=\"(.+)\" \/>/i", $data, $matches); if (count($matches)>0) $lg_h=$matches[1]; preg_match("/<input type=\"hidden\" name=\"to\" value=\"(.+)\">/i", $data, $matches); if (count($matches)>0) $to=$matches[1]; if (isset($action) && isset($origin) && isset($ip_h) && isset($lg_h) && isset($to)) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $action ); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, array( '_origin'=>$origin, 'ip_h'=>$ip_h, 'lg_h'=>$lg_h, 'to'=>$to, 'email'=>$vk['login'], 'pass'=>$vk['password'] )); $data = curl_exec($ch); curl_close($ch); preg_match('/Location: (http\:\/\/www\.truecaller\.com\/sign\-in\/vk\?code\=.+)\&state.+/', $data, $matches); if (count($matches)>0) $location=$matches[1]; if (isset($location)) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $location); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); $data = curl_exec($ch); curl_close($ch); if (preg_match("/\<title\>Signed In \| Truecaller\<\/title\>/i", $data)) { echo " VK  \n"; return true; } else { echo "     VK /      \n"; return false; } } else { echo "     VK /  location  \n"; return false; } } else { echo "     VK /     action='".$action."', origin='".$origin."', ip_h='".$ip_h."', lg_h='".$lg_h."', to='".$to."'\n"; return false; } } ?>
      
      



https://oauth.vk.com/authorize?client_id=4951501&scope=friends%2Coffline&redirect_uri=http%3A%2F%2Fwww.truecaller.com%2Fsign-in%2Fvk&response_type=code&state=KKoLuT0vbWEOXfqIW9C0yAvoX7uoEDszIrVOxYSr' #!/usr/bin/php -q <?php $error_level = error_reporting(0); set_time_limit(30); //require('phpagi.php'); //$agi = new AGI(); if (isset($argv[1])) {$num=$argv[1];} else {$num=NULL;} $cookie_file='/tmp/asterisk_truecaller_vk.cookie'; $vk = array("login"=> "_", "password"=> "_"); $mysql = array("hostname" => "localhost", "login"=> "root", "password"=> "_mysql", "database"=> "asterisk"); if (!is_null($num)) { $callerid_name=get_num($num,$vk,$mysql,$cookie_file,true); return $callerid_name; } else { echo " \n"; //$agi->set_variable("CID_NAME", ""); return false; } // truecaller function get_num($num,$vk,$mysql,$cookie_file,$isauth) { // mysql_connect($mysql['hostname'],$mysql['login'],$mysql['password']); mysql_select_db($mysql['database']) or die(mysql_error()); mysql_query("SET NAMES 'utf8'"); mysql_query("SET CHARACTER SET 'utf8'"); mysql_query("SET SESSION collation_connection = 'utf8_general_ci'"); $query = "SELECT * FROM phonebook WHERE `number`=$num"; $res = mysql_query($query); $count = mysql_num_rows($res); if ($count>0) while ($row=mysql_fetch_array($res)) { $name=$row['name']; echo " MySQL '".$name."'\n"; //$agi->set_variable("CID_NAME", "$name"); return $name; } mysql_close(); // truecaller if ($isauth) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.truecaller.com/ru/'.$num ); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); $data = curl_exec($ch); curl_close($ch); if (preg_match("/You need to sign in to view the result/i", $data)) { echo " TC\n"; $isauth = oauth_vk($vk, $cookie_file); get_num($num,$vk,$mysql,$cookie_file,$isauth); } else { preg_match("/<div class=\"detailView__nameText\">\n\s*(.+)\s\n\s*<\/div>/i", $data, $matches); if (count($matches)>0) { $name=$matches[1]; echo " TC '".$name."'\n"; mysql_connect($mysql['hostname'],$mysql['login'],$mysql['password']); mysql_select_db($mysql['database']) or die(mysql_error()); mysql_query("SET NAMES 'utf8'"); mysql_query("SET CHARACTER SET 'utf8'"); mysql_query("SET SESSION collation_connection = 'utf8_general_ci'"); $query = "INSERT INTO phonebook (`name`,`number`) VALUE ('".$name."','".$num."')"; $res = mysql_query($query); mysql_close(); //$agi->set_variable("CID_NAME", "$name"); return $name; } else { echo " TC \n"; //$agi->set_variable("CID_NAME", ""); return false; } } } else { echo " TC , \n"; //$agi->set_variable("CID_NAME", ""); return false; } } // " " function oauth_vk($vk, $cookie_file) { unlink($cookie_file); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://oauth.vk.com/authorize?client_id=4951501&scope=friends%2Coffline&redirect_uri=http%3A%2F%2Fwww.truecaller.com%2Fsign-in%2Fvk&response_type=code&state=KKoLuT0vbWEOXfqIW9C0yAvoX7uoEDszIrVOxYSr'); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); // curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); $data = curl_exec($ch); curl_close($ch); preg_match("/<form method=\"post\" action=\"(.+)\">/i", $data, $matches); if (count($matches)>0) $action=$matches[1]; preg_match("/<input type=\"hidden\" name=\"_origin\" value=\"(.+)\">/i", $data, $matches); if (count($matches)>0) $origin=$matches[1]; preg_match("/<input type=\"hidden\" name=\"ip_h\" value=\"(.+)\" \/>/i", $data, $matches); if (count($matches)>0) $ip_h=$matches[1]; preg_match("/<input type=\"hidden\" name=\"lg_h\" value=\"(.+)\" \/>/i", $data, $matches); if (count($matches)>0) $lg_h=$matches[1]; preg_match("/<input type=\"hidden\" name=\"to\" value=\"(.+)\">/i", $data, $matches); if (count($matches)>0) $to=$matches[1]; if (isset($action) && isset($origin) && isset($ip_h) && isset($lg_h) && isset($to)) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $action ); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, array( '_origin'=>$origin, 'ip_h'=>$ip_h, 'lg_h'=>$lg_h, 'to'=>$to, 'email'=>$vk['login'], 'pass'=>$vk['password'] )); $data = curl_exec($ch); curl_close($ch); preg_match('/Location: (http\:\/\/www\.truecaller\.com\/sign\-in\/vk\?code\=.+)\&state.+/', $data, $matches); if (count($matches)>0) $location=$matches[1]; if (isset($location)) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $location); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); $data = curl_exec($ch); curl_close($ch); if (preg_match("/\<title\>Signed In \| Truecaller\<\/title\>/i", $data)) { echo " VK \n"; return true; } else { echo " VK / \n"; return false; } } else { echo " VK / location \n"; return false; } } else { echo " VK / action='".$action."', origin='".$origin."', ip_h='".$ip_h."', lg_h='".$lg_h."', to='".$to."'\n"; return false; } } ?>





LUAのダイヤルプランがあるので、extensions.luaで次のようにします。



 local call = {} call.cid_num = channel["CALLERID(num)"]:get() call.cid_name = "" --      local handle = io.popen("/var/lib/asterisk/agi-bin/phonebook.php "..call.cid_num) local founded_name = handle:read("*a") handle:close() app.Noop(founded_name) _, _, call.cid_name = string.find(founded_name,"%s%s.+%s'(.+)'") channel["CALLERID(name)"]:set(call.cid_name)
      
      





このスクリプトには、スパム連絡先をブロックするためのアカウントはありません。 この記事は、このような素晴らしいTruecallerサービスとPBXの統合の可能性の概要として説明されています。



All Articles