Re: Входящий номер при поступление звонка, способы получения
Добавлено: 07 янв 2016, 12:26
Я когда-то тожеписал софтинку.
Версия не последняя, к сожалению исходники утеряны
Версия не последняя, к сожалению исходники утеряны
Русский форум Asterisk сообщества
https://forum.asterisk.ru/
Код: Выделить всё
<?php
//settings
$ajam_url = "http://127.0.0.1:8088/asterisk/";
$ajam_username = 'admin';
$ajam_secret = "amipasswd";
$basic_auth_users = array(
//user admin
'admin' => array(
'password' => "adminpasswd",
'access' => "all",
),
//user don
'don' => array(
'password' => "userpasswd",
'access' => array('donglesendsms', 'donglesendussd', 'dongleshowdevices'),
'dongle_access' => array('dongle0'),
),
);
//basic auth protection
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
die(json_encode(array('response' => "Error", 'message' => "Basic authentication failed")));
} else {
//check username
if(!array_key_exists($_SERVER['PHP_AUTH_USER'], $basic_auth_users)) die(json_encode(array('response' => "Error", 'message' => "Basic authentication failed")));
//check password
if($basic_auth_users[$_SERVER['PHP_AUTH_USER']]['password'] <> $_SERVER['PHP_AUTH_PW']) die(json_encode(array('response' => "Error", 'message' => "Basic authentication failed")));
//check access
if($basic_auth_users[$_SERVER['PHP_AUTH_USER']]['access'] <> "all")
if(!in_array($_GET['action'], $basic_auth_users[$_SERVER['PHP_AUTH_USER']]['access']))
die(json_encode(array('response' => "Error", 'message' => "No access to action: {$_GET['action']}")));
//check dongle access
if(is_array($basic_auth_users[$_SERVER['PHP_AUTH_USER']]['dongle_access']))
if(isset($_GET['device']))
if(!in_array($_GET['device'], $basic_auth_users[$_SERVER['PHP_AUTH_USER']]['dongle_access']))
die(json_encode(array('response' => "Error", 'message' => "No access to device: {$_GET['device']}")));
}
//auth
list($result, $coo) = ajam("action=Login&username=$ajam_username&secret=$ajam_secret", $coo);
if($result['response'] <> "Success") die(json_encode($result));
//
list($result, $coo) = ajam(http_build_query($_GET), $coo);
if(is_array($basic_auth_users[$_SERVER['PHP_AUTH_USER']]['dongle_access']))
foreach($result as $key => $val)
if($val['event'] == "DongleDeviceEntry")
if(!in_array($val['device'], $basic_auth_users[$_SERVER['PHP_AUTH_USER']]['dongle_access']))
unset($result[$key]);
//die(base64_encode(json_encode($result)));
//die(json_encode($result));
print "<pre>"; print_r($result); die();
function ajam($params, $cookie){
global $ajam_url;
$url = "{$ajam_url}mxml?{$params}";
if(!empty($cookie)) {
$opts = stream_context_create(array(
'http'=>array(
'method'=>"GET",
'header'=>"User-Agent : Opera/9.80 (X11; Linux i686; U; ru) Presto/2.7.62 Version/11.00 \r\n".
"Cookie: ".$cookie."\r\n",
'verify_peer'=>false,
'verify_peer_name'=>false,
),
'ssl'=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
));
} else {
$opts = stream_context_create(array(
'http'=>array(
'method'=>"GET",
'header'=>"User-Agent : Opera/9.80 (X11; Linux i686; U; ru) Presto/2.7.62 Version/11.00 \r\n",
'verify_peer'=>false,
'verify_peer_name'=>false,
),
'ssl'=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
));
}
$response = json_decode(json_encode(simplexml_load_string(file_get_contents($url, false, $opts), "SimpleXMLElement", LIBXML_NOCDATA)), true);
$return_array = array();
if(isset($response['response']['generic']['@attributes'])){
$return_array = $response['response']['generic']['@attributes'];
}
else {
foreach ($response['response'] as $key => $val)
$return_array[] = $val['generic']['@attributes'];
}
if(empty($cookie)) {
$cookie = Array();
foreach( $http_response_header as $head){
if(stristr($head, 'Set-Cookie:' )) $cookie[] = (str_ireplace('Set-Cookie:', '', $head ));
}
$cookie = implode('; ',$cookie);
}
return array($return_array, $cookie); //['response']['generic']['@attributes']
}
?>