<?php #/ # FreePBX # "?r=0", PBX: "?r=1", : "?r=2" #vmcl****.ru #mysql settings $hostname = "localhost"; $username = "mysql_user"; $password = "mysql_password"; $dbName = "asterisk"; mysql_connect($hostname,$username,$password) or die("NO connect to MySQL: ".mysql_error()); mysql_select_db($dbName) or die("MySQL ERROR:".mysql_error()); mysql_query("set names 'utf8'"); date_default_timezone_set("Europe/Moscow"); if(isset($_GET['r'])) $r = $_GET['r']; else $r = '1'; // ?r=X, PBX //browser settings $header = array(); $header[] = 'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'; $header[] = 'Cache-Control: max-age=0'; $header[] = 'Connection: keep-alive'; $header[] = 'Keep-Alive: 300'; $header[] = 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7'; $header[] = 'Accept-Language: en-us,en;q=0.5'; $header[] = 'Pragma: '; //seach multifon trunks $mf_query = mysql_query('SELECT `data` FROM `sip` WHERE `keyword` = "register" AND `data` LIKE "%@multifon.ru%" ORDER BY `data`') or die("MySQL ERROR:".mysql_error()); while($mf_row = mysql_fetch_array($mf_query, MYSQL_ASSOC)) { $pre_data = explode("@", $mf_row['data']); $data = explode(":", $pre_data[0]); print " {$data[0]}..."; // $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://sm.megafon.ru/sm/client/routing?login={$data[0]}@multifon.ru&password={$data[1]}"); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)"); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_ENCODING, ''); curl_setopt($ch, CURLOPT_TIMEOUT, 20); $response = curl_exec($ch); curl_close ($ch); $routing = json_decode(json_encode(simplexml_load_string($response, "SimpleXMLElement", LIBXML_NOCDATA)), true); // if($routing['result']['code'] == 200) { // ok if($routing['routing'] == $r) { // print " {$routing['routing']}<br>"; } else { print " {$routing['routing']}, $r..."; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://sm.megafon.ru/sm/client/routing/set?login={$data[0]}@multifon.ru&password={$data[1]}&routing=$r"); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)"); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_ENCODING, ''); curl_setopt($ch, CURLOPT_TIMEOUT, 20); $response = curl_exec($ch); curl_close ($ch); $result = json_decode(json_encode(simplexml_load_string($response, "SimpleXMLElement", LIBXML_NOCDATA)), true); if($result['result']['code'] == 200) { print "{$result['result']['description']}<br>"; } else { print " sm.megafon.ru {$result['result']['code']} {$result['result']['description']}<br>"; } exec("amportal reload"); } } else { print " sm.megafon.ru {$routing['result']['code']} {$routing['result']['description']}<br>"; } } print ""; ?>
#!/bin/sh #move this file to cron folders cd /var/www/html/mf && /usr/bin/nohup /usr/bin/php -f index.php >/tmp/mf_php.log &
Source: https://habr.com/ru/post/282528/
All Articles