Advertisement
akai

page_stop.php

Nov 15th, 2011
1,048
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.10 KB | None | 0 0
  1. <?php
  2. $mdb = "paging";
  3. $mhost = "localhost";
  4. $mlog = "pageuser";
  5. $mpass = "123456";
  6. $thisIP = $_SERVER['REMOTE_ADDR'];
  7. @mysql_connect($mhost, $mlog, $mpass) or die("Could not connect to MySQL server");
  8. @mysql_select_db($mdb) or die("Could not select DB mysql");
  9.  
  10. //читаем из бд адреса телефонов в массив $ip. флагом ex отмечены телефоны, участвующие в пейджинге
  11. $query = "SELECT * FROM phoneip WHERE ex=1";
  12. $res = mysql_query($query) or die(mysql_error());
  13. $i = 0;
  14. $ip = array();
  15. while ($row=mysql_fetch_array($res)) {
  16.   $ip[$i++] = $row['ip'];
  17.   }
  18.  
  19. //читаем из бд $log, $pass, $mcastIP
  20. $query = "SELECT * FROM conf";
  21. $res = mysql_query($query) or die(mysql_error());
  22. $log = mysql_result($res, 0, 'login');
  23. $pass = mysql_result($res, 0, 'pass');
  24. $mcastIP = mysql_result($res, 0, 'mcastip');
  25.  
  26. function phonepush($ip,$uri, $uid, $pwd)
  27. {
  28. $auth = base64_encode($uid.":".$pwd);
  29. $uri = "<CiscoIPPhoneExecute><ExecuteItem Priority=\"0\" URL=\"".$uri."\"/></CiscoIPPhoneExecute>";
  30. $uri  = "XML=".urlencode($uri);
  31.  
  32. $post  = "POST /CGI/Execute HTTP/1.0\r\n";
  33. $post .= "Host: $ip\r\n";
  34. $post .= "Authorization: Basic $auth\r\n";
  35. $post .= "Connection: close\r\n";
  36. $post .= "Content-Type: application/x-www-form-urlencoded\r\n";
  37. $post .= "Content-Length: ".strlen($uri)."\r\n\r\n";
  38. $fp = fsockopen ( $ip, 80, $errno, $errstr, 3);
  39. if(!$fp){ echo "$errstr ($errno)<br>\n"; }
  40. else
  41. {
  42.  fputs($fp, $post.$uri);
  43.  flush();
  44.  while (!feof($fp))
  45.  {
  46.   $response .= fgets($fp, 128);
  47.   flush();
  48.  }
  49. }
  50. return $response;
  51. }
  52.  
  53.  
  54. $auth = base64_encode($log.":".$pass);
  55. //URI для остановки приема multicast RTP потока
  56. $uri = "RTPMRx:Stop";
  57. $uri = "<CiscoIPPhoneExecute><ExecuteItem Priority=\"0\" URL=\"".$uri."\"/></CiscoIPPhoneExecute>";
  58. $uri  = "XML=".urlencode($uri);
  59.  
  60. //заголовки POST запроса
  61. $post  = "POST /CGI/Execute HTTP/1.0\r\n";
  62. $post .= "Host: $ip\r\n";
  63. $post .= "Authorization: Basic $auth\r\n";
  64. $post .= "Connection: close\r\n";
  65. $post .= "Content-Type: application/x-www-form-urlencoded\r\n";
  66. $post .= "Content-Length: ".strlen($uri)."\r\n\r\n";
  67.  
  68. $timeout = 1;
  69. $sockets = array();
  70. foreach ($ip as $id => $host) {
  71.     $s = stream_socket_client("$host:80", $errno, $errstr, $timeout,
  72.         STREAM_CLIENT_ASYNC_CONNECT|STREAM_CLIENT_CONNECT);
  73.     if ($s) {
  74.         $sockets[$id] = $s;
  75.     } else {
  76.         $res = mysql_query($query) or die(mysql_error());
  77.     }
  78. }
  79. while (count($sockets)) {
  80.     $read = $write = $sockets;
  81.  
  82.     $n = stream_select($read, $write, $e = null, $timeout);
  83.     if ($n > 0) {
  84.          foreach ($read as $r) {
  85.             $id = array_search($r, $sockets);
  86.             $data = fread($r, 8192);
  87.             if (strlen($data) == 0) {
  88.                 fclose($r);
  89.                 unset($sockets[$id]);
  90.             }
  91.         }
  92.          foreach ($write as $w) {
  93.             $id = array_search($w, $sockets);
  94.             fwrite($w, $post.$uri);
  95.         }
  96.     } else {
  97.         break;
  98.     }
  99. }
  100. mysql_close();
  101. phonePush($thisIP,"Init:Services",$log,$pass);
  102.  
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement