晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
Server : Apache System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64 User : rainic ( 1014) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /proc/thread-self/root/home/akaindir/public_html/crm/modules/PBXManager/connectors/ |
Upload File : |
<?php
/* +***********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
* *********************************************************************************** */
require_once 'include/utils/utils.php';
require_once 'vtlib/Vtiger/Net/Client.php';
class PBXManager_PBXManager_Connector {
private static $SETTINGS_REQUIRED_PARAMETERS = array('webappurl' => 'text','outboundcontext' => 'text', 'outboundtrunk' => 'text' , 'vtigersecretkey' => 'text');
private static $RINGING_CALL_PARAMETERS = array('From' => 'callerIdNumber', 'SourceUUID' => 'callUUID', 'Direction' => 'Direction');
private static $NUMBERS = array();
private $webappurl;
private $outboundcontext, $outboundtrunk;
private $vtigersecretkey;
const RINGING_TYPE = 'ringing';
const ANSWERED_TYPE = 'answered';
const HANGUP_TYPE = 'hangup';
const RECORD_TYPE = 'record';
const INCOMING_TYPE = 'inbound';
const OUTGOING_TYPE = 'outbound';
const USER_PHONE_FIELD = 'phone_crm_extension';
function __construct() {
$serverModel = PBXManager_Server_Model::getInstance();
$this->setServerParameters($serverModel);
}
/**
* Function to get provider name
* returns <string>
*/
public function getGatewayName() {
return 'PBXManager';
}
public function getPicklistValues($field) {
}
public function getServer() {
return $this->webappurl;
}
public function getOutboundContext() {
return $this->outboundcontext;
}
public function getOutboundTrunk() {
return $this->outboundtrunk;
}
public function getVtigerSecretKey() {
return $this->vtigersecretkey;
}
public function getXmlResponse() {
header("Content-type: text/xml; charset=utf-8");
$response = '<?xml version="1.0" encoding="utf-8"?>';
$response .= '<Response><Authentication>';
$response .= 'Failure';
$response .= '</Authentication></Response>';
return $response;
}
/**
* Function to set server parameters
* @param <array> authdetails
*/
public function setServerParameters($serverModel) {
$this->webappurl = $serverModel->get('webappurl');
$this->outboundcontext = $serverModel->get('outboundcontext');
$this->outboundtrunk = $serverModel->get('outboundtrunk');
$this->vtigersecretkey = $serverModel->get('vtigersecretkey');
}
/**
* Function to get Settings edit view params
* returns <array>
*/
public function getSettingsParameters() {
return self::$SETTINGS_REQUIRED_PARAMETERS;
}
protected function prepareParameters($details, $type) {
switch ($type) {
case 'ringing':
foreach (self::$RINGING_CALL_PARAMETERS as $key => $value) {
$params[$key] = $details->get($value);
}
$params['GateWay'] = $this->getGatewayName();
break;
}
return $params;
}
/**
* Function to handle the dial call event
* @param <Vtiger_Request> $details
*/
public function handleDialCall($details) {
$callid = $details->get('callUUID');
$answeredby = $details->get('callerid2');
$caller = $details->get('callerid1');
// For Inbound call, answered by will be the user, we should fill the user field
$recordModel = PBXManager_Record_Model::getInstanceBySourceUUID($callid);
$direction = $recordModel->get('direction');
if ($direction == self::INCOMING_TYPE) {
// For Incoming call, we should fill the user field if he answered that call
$user = PBXManager_Record_Model::getUserInfoWithNumber($answeredby);
$params['user'] = $user['id'];
$recordModel->updateAssignedUser($user['id']);
} else {
$user = PBXManager_Record_Model::getUserInfoWithNumber($caller);
if ($user) {
$params['user'] = $user['id'];
$recordModel->updateAssignedUser($user['id']);
}
}
$params['callstatus'] = "in-progress";
$recordModel->updateCallDetails($params);
}
/**
* Function to handle the EndCall event
* @param <Vtiger_Request> $details
*/
public function handleEndCall($details) {
$callid = $details->get('callUUID');
$recordModel = PBXManager_Record_Model::getInstanceBySourceUUID($callid);
$params['starttime'] = $details->get('starttime');
$params['endtime'] = $details->get('endtime');
$params['totalduration'] = $details->get('duration');
$params['billduration'] = $details->get('billableseconds');
$recordModel->updateCallDetails($params);
}
/**
* Function to handle the hangup call event
* @param <Vtiger_Request> $details
*/
public function handleHangupCall($details) {
$callid = $details->get('callUUID');
$recordModel = PBXManager_Record_Model::getInstanceBySourceUUID($callid);
$hangupcause = $details->get('causetxt');
switch ($hangupcause) {
// If call is successfull
case 'Normal Clearing':
$params['callstatus'] = 'completed';
if($details->get('HangupCause') == 'NO ANSWER') {
$params['callstatus'] = 'no-answer';
}
break;
case 'User busy' :
$params['callstatus'] = 'busy';
break;
case 'Call Rejected':
$params['callstatus'] = 'busy';
break;
default :
$params['callstatus'] = $hangupcause;
break;
}
if($details->get('EndTime') && $details->get('Duration')) {
$params['endtime'] = $details->get('EndTime');
$params['totalduration'] = $details->get('Duration');
}
$recordModel->updateCallDetails($params);
}
/**
* Function to handle record event
* @param <Vtiger_Request> $details
*/
public function handleRecording($details) {
$callid = $details->get('callUUID');
$recordModel = PBXManager_Record_Model::getInstanceBySourceUUID($callid);
$params['recordingurl'] = $details->get('recordinglink');
$recordModel->updateCallDetails($params);
}
/**
* Function to handle AGI event
* @param <Vtiger_Request> $details
*/
public function handleStartupCall($details, $userInfo, $customerInfo) {
global $current_user;
$params = $this->prepareParameters($details, self::RINGING_TYPE);
$direction = $details->get('Direction');
// To add customer and user information in params
$params['Customer'] = $customerInfo['id'];
$params['CustomerType'] = $customerInfo['setype'];
$params['User'] = $userInfo['id'];
if ($details->get('from')) {
$params['CustomerNumber'] = $details->get('from');
} else if ($details->get('to')) {
$params['CustomerNumber'] = $details->get('to');
}
$params['starttime'] = $details->get('StartTime');
$params['callstatus'] = "ringing";
$user = CRMEntity::getInstance('Users');
$current_user = $user->getActiveAdminUser();
$recordModel = PBXManager_Record_Model::getCleanInstance();
$recordModel->saveRecordWithArrray($params);
if ($direction == self::INCOMING_TYPE)
$this->respondToIncomingCall($details);
else
$this->respondToOutgoingCall($params['CustomerNumber']);
}
/**
* Function to respond for incoming calls
* @param <Vtiger_Request> $details
*/
public function respondToIncomingCall($details) {
global $current_user;
self::$NUMBERS = PBXManager_Record_Model::getUserNumbers();
header("Content-type: text/xml; charset=utf-8");
$response = '<?xml version="1.0" encoding="utf-8"?>';
$response .= '<Response><Dial><Authentication>';
$response .= 'Success</Authentication>';
if (self::$NUMBERS) {
foreach (self::$NUMBERS as $userId => $number) {
$userInstance = Users_Privileges_Model::getInstanceById($userId);
$current_user = $userInstance;
$callPermission = Users_Privileges_Model::isPermitted('PBXManager', 'ReceiveIncomingCalls');
if ($number != $details->get('callerIdNumber') && $callPermission) {
if(preg_match("/sip/", $number) || preg_match("/@/", $number)) {
$number = trim($number, "/sip:/");
$response .= '<Number>SIP/';
$response .= $number;
$response .= '</Number>';
}else {
$response .= '<Number>SIP/';
$response .= $number;
$response .= '</Number>';
}
}
}
}else {
$response .= '<ConfiguredNumber>empty</ConfiguredNumber>';
$date = date('Y/m/d H:i:s');
$params['callstatus'] = 'no-answer';
$params['starttime'] = $date;
$params['endtime'] = $date;
$recordModel = PBXManager_Record_Model::getInstanceBySourceUUID($details->get('callUUID'));
$recordModel->updateCallDetails($params);
}
$response .= '</Dial></Response>';
echo $response;
}
/**
* Function to respond for outgoing calls
* @param <Vtiger_Request> $details
*/
public function respondToOutgoingCall($to) {
header("Content-type: text/xml; charset=utf-8");
$response = '<?xml version="1.0" encoding="utf-8"?>';
$response .= '<Response><Dial><Authentication>';
$response .= 'Success</Authentication>';
$numberLength = strlen($to);
if(preg_match("/sip/", $to) || preg_match("/@/", $to)) {
$to = trim($to, "/sip:/");
$response .= '<Number>SIP/';
$response .= $to;
$response .= '</Number>';
}else {
$response .= '<Number>SIP/';
$response .= $to;
if($numberLength > 5) $response .= '@'. $this->getOutboundTrunk();
$response .= '</Number>';
}
$response .= '</Dial></Response>';
echo $response;
}
/**
* Function to make outbound call
* @param <string> $number (Customer)
* @param <string> $recordid
*/
function call($number, $record) {
$user = Users_Record_Model::getCurrentUserModel();
$extension = $user->phone_crm_extension;
$webappurl = $this->getServer();
$context = $this->getOutboundContext();
$vtigerSecretKey = $this->getVtigerSecretKey();
$serviceURL = $webappurl;
$serviceURL .= '/makecall?event=OutgoingCall&';
$serviceURL .= 'secret=' . urlencode($vtigerSecretKey) . '&';
$serviceURL .= 'from=' . urlencode($extension) . '&';
$serviceURL .= 'to=' . urlencode($number) . '&';
$serviceURL .= 'context='. urlencode($context);
$httpClient = new Vtiger_Net_Client($serviceURL);
$response = $httpClient->doPost(array());
$response = trim($response);
if ($response == "Error" || $response == "" || $response == null
|| $response == "Authentication Failure" ) {
return false;
}
return true;
}
}