Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $mdb = "paging";
- $mhost = "localhost";
- $mlog = "pageuser";
- $mpass = "123456";
- $thisIP = $_SERVER['REMOTE_ADDR'];
- @mysql_connect($mhost, $mlog, $mpass) or die("Could not connect to MySQL server");
- @mysql_select_db($mdb) or die("Could not select DB mysql");
- //читаем из бд адреса телефонов в массив $ip. флагом ex отмечены телефоны, участвующие в пейджинге
- $query = "SELECT * FROM phoneip WHERE ex=1";
- $res = mysql_query($query) or die(mysql_error());
- $i = 0;
- $ip = array();
- while ($row=mysql_fetch_array($res)) {
- $ip[$i++] = $row['ip'];
- }
- //читаем из бд $log, $pass, $mcastIP
- $query = "SELECT * FROM conf";
- $res = mysql_query($query) or die(mysql_error());
- $log = mysql_result($res, 0, 'login');
- $pass = mysql_result($res, 0, 'pass');
- $mcastIP = mysql_result($res, 0, 'mcastip');
- function phonepush($ip,$uri, $uid, $pwd)
- {
- $auth = base64_encode($uid.":".$pwd);
- $uri = "<CiscoIPPhoneExecute><ExecuteItem Priority=\"0\" URL=\"".$uri."\"/></CiscoIPPhoneExecute>";
- $uri = "XML=".urlencode($uri);
- $post = "POST /CGI/Execute HTTP/1.0\r\n";
- $post .= "Host: $ip\r\n";
- $post .= "Authorization: Basic $auth\r\n";
- $post .= "Connection: close\r\n";
- $post .= "Content-Type: application/x-www-form-urlencoded\r\n";
- $post .= "Content-Length: ".strlen($uri)."\r\n\r\n";
- $fp = fsockopen ( $ip, 80, $errno, $errstr, 3);
- if(!$fp){ echo "$errstr ($errno)<br>\n"; }
- else
- {
- fputs($fp, $post.$uri);
- flush();
- while (!feof($fp))
- {
- $response .= fgets($fp, 128);
- flush();
- }
- }
- return $response;
- }
- $auth = base64_encode($log.":".$pass);
- //URI для остановки приема multicast RTP потока
- $uri = "RTPMRx:Stop";
- $uri = "<CiscoIPPhoneExecute><ExecuteItem Priority=\"0\" URL=\"".$uri."\"/></CiscoIPPhoneExecute>";
- $uri = "XML=".urlencode($uri);
- //заголовки POST запроса
- $post = "POST /CGI/Execute HTTP/1.0\r\n";
- $post .= "Host: $ip\r\n";
- $post .= "Authorization: Basic $auth\r\n";
- $post .= "Connection: close\r\n";
- $post .= "Content-Type: application/x-www-form-urlencoded\r\n";
- $post .= "Content-Length: ".strlen($uri)."\r\n\r\n";
- $timeout = 1;
- $sockets = array();
- foreach ($ip as $id => $host) {
- $s = stream_socket_client("$host:80", $errno, $errstr, $timeout,
- STREAM_CLIENT_ASYNC_CONNECT|STREAM_CLIENT_CONNECT);
- if ($s) {
- $sockets[$id] = $s;
- } else {
- $res = mysql_query($query) or die(mysql_error());
- }
- }
- while (count($sockets)) {
- $read = $write = $sockets;
- $n = stream_select($read, $write, $e = null, $timeout);
- if ($n > 0) {
- foreach ($read as $r) {
- $id = array_search($r, $sockets);
- $data = fread($r, 8192);
- if (strlen($data) == 0) {
- fclose($r);
- unset($sockets[$id]);
- }
- }
- foreach ($write as $w) {
- $id = array_search($w, $sockets);
- fwrite($w, $post.$uri);
- }
- } else {
- break;
- }
- }
- mysql_close();
- phonePush($thisIP,"Init:Services",$log,$pass);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement