2 600 !

7

CRM 24 Asterisk? , . 24 :)


?

( ). , php - Asterisk , , , . .


AMI (Asterisk Manager Interface) , . :

vim /etc/asterisk/manager.conf

[general] - enabled yes:

[general]
enabled = yes //    :)
port = 5038
bindaddr = 0.0.0.0

, manager.conf ( , ):

#include manager_custom.conf

. /etc/asterisk/manager_custom.conf ( ) :

[]
secret = 
deny=0.0.0.0/0.0.0.0
permit=127.0.0.1/255.255.255.0
permit=ip__Asterisk/
read = all,system,call,log,verbose,command,agent,user,config,originate
write = all,system,call,log,verbose,command,agent,user,config,originate
  • - ;
  • - , , ;
  • ip__Asterisk/ - . IP , AMI. - 192.168.1.0/255.255.255.0;

24 .


. . . :

  • - , ;
  • - , ;
  • - (user);

. :

  Asterisk 24

: , URL URL REST. /profile/. , :

https://merionet.bitrix24.ru/rest/2/1a2b3c4d5e6f7g8h

URL :) , , URL . , 3 , . : , :

http://ilovemerionet.ru/

. 3 , :

  1. IpVy7ul85sz1Doi
  2. C49BNGJW3Yf30eo
  3. qBN0NBC56lj07yh

, /var/www/html/ , :

/var/www/html/IpVy7ul85sz1Doi/C49BNGJW3Yf30eo/qBN0NBC56lj07yh/

, , index.php, , 24 URL:

http://ilovemerionet.ru/IpVy7ul85sz1Doi/C49BNGJW3Yf30eo/qBN0NBC56lj07yh/

, :) . . :

  • - , ;
  • - , http://ilovemerionet.ru/IpVy7ul85sz1Doi/C49BNGJW3Yf30eo/qBN0NBC56lj07yh/ - , , URL :);
  • - , . Asterisk Calls, ?;
  • - , ;
  • - (ONEXTERNALCALLSTART);
  Asterisk 24

. .


Asterisk

, 24. , , :

<?php
$check_token = "_"; //       .     ,   ,   ;
$user_hook_url = "__"; // ,      ,   ;
$ami_login = "ami_"; //   AMI,    ;
$ami_password = ""; //   AMI,    ;
$strhost = "IP_"; // IP -   Asterisk;
if (strcmp($_POST['auth']['application_token'], $check_token) === 0) {
function writeToLog($data, $title = '') { 
$log = "\n------------------------\n"; 
$log .= date("Y.m.d G:i:s") . "\n"; 
$log .= (strlen($title) > 0 ? 
$title : 'DEBUG') . "\n"; 
$log .= print_r($data, 1); 
$log .= "\n------------------------\n"; 
file_put_contents(getcwd() . '/hook.log', $log, FILE_APPEND); 
return true; }
writeToLog($_REQUEST, 'incoming');
$UID = $_POST['data']['USER_ID'];
$bitrix_contact_url = "$user_hook_url/user.get.json?ID=$UID";
$btc = curl_init();
curl_setopt ($btc, CURLOPT_URL,$bitrix_contact_url);
curl_setopt ($btc, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($btc, CURLOPT_TIMEOUT, 60);
curl_setopt ($btc, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($btc, CURLOPT_RETURNTRANSFER, 1);
$bitrix_contact = curl_exec ($btc);
curl_close($btc);
$bitrix_contact_o = json_decode($bitrix_contact, true);
$cid = $bitrix_contact_o['result'][0]['UF_PHONE_INNER'];
$strport = "5038";
$timeout = "5";
$num = str_replace("+","",$_POST['data']['PHONE_NUMBER_INTERNATIONAL']);
$callid = $_POST['data']['CALL_ID'];
$c="from-internal";
$p="1";
$errno=0 ;
$errstr=0 ;
$sconn = fsockopen($strhost, $strport, &$errno, &$errstr, $timeout) or die("Connection to $strhost:$strport failed");
if (!$sconn) { echo "$errstr ($errno)
\n"; } else { $sconn1 = fsockopen($strhost, $strport, &$errno, &$errstr, $timeout) or die("Connection to $strhost:$strport failed"); if (!$sconn1) { echo "$errstr ($errno)
\n"; } else { fputs($sconn1, "Action: login\r\n"); fputs($sconn1, "Username: $ami_login\r\n"); fputs($sconn1, "Secret: $ami_password\r\n"); fputs($sconn1, "Events: off\r\n\r\n"); usleep(500); fputs($sconn1, "Action: Setvar\r\n"); fputs($sconn1, "Variable: B24ID\r\n"); fputs($sconn1, "Value: $callid/$cid\r\n"); fputs($sconn1, "Action: Logoff\r\n\r\n"); usleep(500); $wrets1=fgets($sconn1,128); fclose($sconn1);} fputs($sconn, "Action: login\r\n"); fputs($sconn, "Username: $ami_login\r\n"); fputs($sconn, "Secret: $ami_password\r\n"); fputs($sconn, "Events: off\r\n\r\n"); usleep(500); fputs($sconn, "Action: Originate\r\n"); fputs($sconn, "Channel: SIP/$cid\r\n"); fputs($sconn, "Callerid: $cid\r\n"); fputs($sconn, "Timeout: 20000\r\n"); fputs($sconn, "Context: $c\r\n"); fputs($sconn, "Exten: $num\r\n"); fputs($sconn, "Priority: $p\r\n"); fputs($sconn, "Async: yes\r\n\r\n" ); usleep(500); $wrets=fgets($sconn,128); fclose($sconn); exit; }} else { exit; }; ?>
, .php

5 :

  • $check_token - , ;
  • $user_hook_url - , /profile/;
  • $ami_login - AMI, ;
  • $ami_password - AMI;
  • $strhost - IP - Asterisk;

, , , /var/www/html/IpVy7ul85sz1Doi/C49BNGJW3Yf30eo/qBN0NBC56lj07yh/ ( !) :

dos2unix /var/www/html/IpVy7ul85sz1Doi/C49BNGJW3Yf30eo/qBN0NBC56lj07yh/index.php
chown asterisk:asterisk /var/www/html/IpVy7ul85sz1Doi/C49BNGJW3Yf30eo/qBN0NBC56lj07yh/index.php
chmod 775 /var/www/html/IpVy7ul85sz1Doi/C49BNGJW3Yf30eo/qBN0NBC56lj07yh/index.php

, , hook.log, . , :)

. . CRM 24, - ( : Asterisk Calls:

    24

.

   24

:) ! CRM ( ). AMI , , Setvar ( ) B24ID = $callid. , .

, , , telephony.externalcall.finish , ( ), , .

, , . :)


?


: