Advertisement
xaker1

asterisk transfer

Oct 28th, 2020 (edited)
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. /* Перевод звонка
  2. * phone - номер оператора, от которого нужно "забрать" звонок
  3. * exten - куда перевести звонок
  4. *
  5. */
  6. $action_id = 1;
  7. stream_set_blocking($fp, TRUE);
  8. stream_set_timeout($fp, 30);
  9. if(!isset($_REQUEST['phone'])){
  10. $_REQUEST['phone'] = $_SESSION['agent_telephone'];
  11. }
  12.  
  13. $info = stream_get_meta_data($fp);
  14.  
  15. fprintf($fp, "Action: Login\r\n");
  16. fprintf($fp, "ActionID: " . $action_id++ . "\r\n");
  17. fprintf($fp, "Username: %s\r\n", $login);
  18. fprintf($fp, "Secret: %s\r\n", $password);
  19. fprintf($fp, "\r\n");
  20.  
  21. fprintf($fp, "Action: CoreShowChannels\r\n");
  22. fprintf($fp, "ActionID: " . $action_id++ . "\r\n");
  23. fprintf($fp, "\r\n");
  24.  
  25. $request = array();
  26.  
  27. $channels = array();
  28.  
  29. while (!feof($fp) && (!$info['timed_out']))
  30. {
  31. $s = trim(fgets($fp));
  32.  
  33. if (strlen($s) == 0 && (!$info['timed_out']))
  34. {
  35. if (!isset($request['Event']))
  36. $request['Event'] = 'None';
  37.  
  38.  
  39. switch($request['Event']){
  40. case 'None':
  41.  
  42. break;
  43. case 'CoreShowChannel':
  44. if($request['ConnectedLineNum']==""||strlen($request['ConnectedLineNum'])!=3) break;
  45. $channels[$request['ConnectedLineNum']][] = $request;
  46. break;
  47. case 'CoreShowChannelsComplete':
  48. break 2;
  49. }
  50. $request = array();
  51. }
  52. else
  53. {
  54. $se = explode(':', $s, 2);
  55. if (count($se) == 2)
  56. $request[trim($se[0])] = trim($se[1]);
  57. }
  58. }
  59. if(isset($channels[$_REQUEST['phone']][0]['Channel'])){
  60. fprintf($fp, "Action: Redirect\r\n");
  61. fprintf($fp, "ActionID: " . $action_id++ . "\r\n");
  62. fprintf($fp, "Channel: %s\r\n",$channels[$_REQUEST['phone']][0]['Channel']);
  63. fprintf($fp, "Context: from-internal\r\n");
  64. fprintf($fp, "Priority: 1\r\n");
  65. fprintf($fp, "Exten: %s\r\n",$_REQUEST['exten']);
  66. fprintf($fp, "\r\n");
  67. }
  68. sleep(2);
  69. fclose($fp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement