Event socket bug fix and more docs (#6823)

* Add documentation to methods. Use is_resource for added type detection

* Allow connect to specify timeout in microseconds with default 30,000

* Update calling mechanism for event sockets

* Update project for new singleton event sockets

* remove unused variable

* catch errors on closing the socket
This commit is contained in:
frytimo 2023-12-02 20:16:18 -04:00 committed by GitHub
parent 44567f7a05
commit 3a4c2f72e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
74 changed files with 1620 additions and 1533 deletions

View File

@ -118,10 +118,7 @@
$cache->delete("configuration:acl.conf"); $cache->delete("configuration:acl.conf");
//create the event socket connection //create the event socket connection
$fp = event_socket_create(); event_socket::api("reloadacl");
if ($fp) {
event_socket_request($fp, "api reloadacl");
}
//redirect the user //redirect the user
header('Location: access_control_edit.php?id='.$id); header('Location: access_control_edit.php?id='.$id);
@ -204,10 +201,7 @@
$cache->delete("configuration:acl.conf"); $cache->delete("configuration:acl.conf");
//create the event socket connection //create the event socket connection
$fp = event_socket_create(); event_socket::async("reloadacl");
if ($fp) {
event_socket_request($fp, "api reloadacl");
}
//redirect the user //redirect the user
if (isset($action)) { if (isset($action)) {

View File

@ -40,18 +40,11 @@
//set the variables //set the variables
$search = $_REQUEST['search'] ?? ''; $search = $_REQUEST['search'] ?? '';
//create event socket connection //run the command
$fp = event_socket_create(); $result = rtrim(event_socket::api('reloadacl'));
if ($fp) {
//run the command
$result = rtrim(event_socket_request($fp, 'api reloadacl'));
//add message //add message
message::add($result, 'alert'); message::add($result, 'alert');
//close the connection
fclose($fp);
}
//redirect //redirect
$search = preg_replace('#[^a-zA-Z0-9_\-\.]# ', '', $search); $search = preg_replace('#[^a-zA-Z0-9_\-\.]# ', '', $search);

View File

@ -157,12 +157,10 @@
$cache->delete("configuration:sofia.conf:".gethostname()); $cache->delete("configuration:sofia.conf:".gethostname());
//create the event socket connection //create the event socket connection
if (!$fp) { $esl = event_socket::create();
$fp = event_socket_create();
}
//reload the acl //reload the acl
event_socket_request($fp, "api reloadacl"); event_socket::async("reloadacl");
//rescan each sip profile //rescan each sip profile
$sql = "select sip_profile_name from v_sip_profiles "; $sql = "select sip_profile_name from v_sip_profiles ";
@ -171,10 +169,10 @@
$sip_profiles = $database->select($sql, null, 'all'); $sip_profiles = $database->select($sql, null, 'all');
if (is_array($sip_profiles)) { if (is_array($sip_profiles)) {
foreach ($sip_profiles as $row) { foreach ($sip_profiles as $row) {
if ($fp) { if ($esl->is_connected()) {
$command = "sofia profile '".$row['sip_profile_name']."' rescan"; $command = "sofia profile '".$row['sip_profile_name']."' rescan";
//echo $command."\n"; //echo $command."\n";
$result = event_socket_request($fp, "api ".$command); $result = event_socket::api($command);
//echo $result."\n"; //echo $result."\n";
} }
} }

View File

@ -87,10 +87,7 @@ if (!class_exists('access_controls')) {
$cache->delete("configuration:acl.conf"); $cache->delete("configuration:acl.conf");
//create the event socket connection //create the event socket connection
$fp = event_socket_create(); event_socket::async("reloadacl");
if ($fp) {
event_socket_request($fp, "api reloadacl");
}
//set message //set message
message::add($text['message-delete']); message::add($text['message-delete']);
@ -146,10 +143,7 @@ if (!class_exists('access_controls')) {
$cache->delete("configuration:acl.conf"); $cache->delete("configuration:acl.conf");
//create the event socket connection //create the event socket connection
$fp = event_socket_create(); event_socket::async("reloadacl");
if ($fp) {
event_socket_request($fp, "api reloadacl");
}
//set message //set message
message::add($text['message-delete']); message::add($text['message-delete']);
@ -261,10 +255,7 @@ if (!class_exists('access_controls')) {
$cache->delete("configuration:acl.conf"); $cache->delete("configuration:acl.conf");
//create the event socket connection //create the event socket connection
$fp = event_socket_create(); event_socket::async("reloadacl");
if ($fp) {
event_socket_request($fp, "api reloadacl");
}
//set message //set message
message::add($text['message-copy']); message::add($text['message-copy']);

View File

@ -57,7 +57,7 @@ if (count($_GET) > 0) {
$direction = trim($_GET["direction"] ?? ''); $direction = trim($_GET["direction"] ?? '');
//setup the event socket connection //setup the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
//allow specific commands //allow specific commands
if (!empty($switch_cmd)) { if (!empty($switch_cmd)) {
@ -99,7 +99,7 @@ if (count($_GET) > 0) {
} }
//run the command //run the command
$switch_result = event_socket_request($fp, 'api '.$api_cmd); $switch_result = event_socket::api($api_cmd);
/* /*
//record stop //record stop

View File

@ -97,15 +97,15 @@
//update the user_status //update the user_status
if (is_uuid($call_center_agent_uuid)) { if (is_uuid($call_center_agent_uuid)) {
$fp = event_socket_create(); $esl = event_socket::create();
$switch_cmd .= "callcenter_config agent set status ".$call_center_agent_uuid." '".$user_status."'"; $switch_cmd .= "callcenter_config agent set status ".$call_center_agent_uuid." '".$user_status."'";
$switch_result = event_socket_request($fp, 'api '.$switch_cmd); $switch_result = event_socket::api($switch_cmd);
} }
//update the user state //update the user state
if (is_uuid($call_center_agent_uuid)) { if (is_uuid($call_center_agent_uuid)) {
$cmd = "api callcenter_config agent set state ".$call_center_agent_uuid." Waiting"; $cmd = "api callcenter_config agent set state ".$call_center_agent_uuid." Waiting";
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
} }
//update do not disturb //update do not disturb

View File

@ -86,10 +86,12 @@ if (!class_exists('basic_operator_panel')) {
} }
//send the command //send the command
$fp = event_socket_create(); $switch_result = event_socket::api('show channels as json');
if ($fp) { if ($switch_result !== false) {
$switch_result = event_socket_request($fp, 'api show channels as json'); $fp = true;
$json_array = json_decode($switch_result, true); $json_array = json_decode($switch_result, true);
} else {
$fp = false;
} }
//build the response //build the response
@ -205,8 +207,10 @@ if (!class_exists('basic_operator_panel')) {
if ($fp) { if ($fp) {
if (is_uuid($field['uuid'])) { if (is_uuid($field['uuid'])) {
$switch_cmd = 'uuid_dump '.$field['uuid'].' json'; $switch_cmd = 'uuid_dump '.$field['uuid'].' json';
$dump_result = event_socket_request($fp, 'api '.$switch_cmd); $dump_result = event_socket::api($switch_cmd);
$dump_array = json_decode($dump_result, true); if ($dump_result !== false) {
$dump_array = json_decode($dump_result, true);
}
if (is_array($dump_array)) { if (is_array($dump_array)) {
foreach ($dump_array as $dump_var_name => $dump_var_value) { foreach ($dump_array as $dump_var_name => $dump_var_value) {
$array[$x][$dump_var_name] = $dump_var_value; $array[$x][$dump_var_name] = $dump_var_value;

View File

@ -64,9 +64,8 @@ if (!empty($groups)) {
} }
//get the valet info //get the valet info
$fp = event_socket_create(); $valet_info = event_socket::api('valet_info park@'.$_SESSION['domain_name']);
if ($fp) { if ($valet_info !== false) {
$valet_info = event_socket_request($fp, 'api valet_info park@'.$_SESSION['domain_name']);
//get an array of the valet call uuid and park numbers //get an array of the valet call uuid and park numbers
if (isset($valet_info)) { if (isset($valet_info)) {
@ -78,10 +77,10 @@ if ($fp) {
//unset($_SESSION['valet']); //unset($_SESSION['valet']);
foreach($valet_matches as $row) { foreach($valet_matches as $row) {
if (!isset($_SESSION['valet']['uuid']['caller_id_name'])) { if (!isset($_SESSION['valet']['uuid']['caller_id_name'])) {
$_SESSION['valet'][$row[1]]['caller_id_name'] = event_socket_request($fp, 'api uuid_getvar '.$row[1].' caller_id_name'); $_SESSION['valet'][$row[1]]['caller_id_name'] = event_socket::api('uuid_getvar '.$row[1].' caller_id_name');
} }
if (!isset($_SESSION['valet']['uuid']['caller_id_number'])) { if (!isset($_SESSION['valet']['uuid']['caller_id_number'])) {
$_SESSION['valet'][$row[1]]['caller_id_number'] = event_socket_request($fp, 'api uuid_getvar '.$row[1].' caller_id_number'); $_SESSION['valet'][$row[1]]['caller_id_number'] = event_socket::api('uuid_getvar '.$row[1].' caller_id_number');
} }
} }

View File

@ -130,7 +130,7 @@
$broadcast_name = str_replace("'", "", $broadcast_name); $broadcast_name = str_replace("'", "", $broadcast_name);
//create the event socket connection //create the event socket connection
$fp = event_socket_create(); $fp = event_socket::create();
//get information over event socket //get information over event socket
if (!$fp) { if (!$fp) {
@ -196,11 +196,11 @@
//if the event socket connection is lost then re-connect //if the event socket connection is lost then re-connect
if (!$fp) { if (!$fp) {
$fp = event_socket_create(); $fp = event_socket::create();
} }
//method 1 //method 1
$response = trim(event_socket_request($fp, 'api '.$cmd)); $response = trim(event_socket::command($cmd));
//method 2 //method 2
//cmd_async($_SESSION['switch']['bin']['dir']."/fs_cli -x \"".$cmd."\";"); //cmd_async($_SESSION['switch']['bin']['dir']."/fs_cli -x \"".$cmd."\";");
@ -216,8 +216,7 @@
$count++; $count++;
} }
} }
fclose($fp);
echo "<div align='center'>\n"; echo "<div align='center'>\n";
echo "<table width='50%'>\n"; echo "<table width='50%'>\n";
echo "<tr>\n"; echo "<tr>\n";

View File

@ -45,10 +45,10 @@ else {
if (is_uuid($uuid)) { if (is_uuid($uuid)) {
//show the result //show the result
if (count($_GET) > 0) { if (count($_GET) > 0) {
$fp = event_socket_create(); $fp = event_socket::create();
if ($fp) { if ($fp !== false) {
$cmd = "sched_del ".$uuid; $cmd = "sched_del ".$uuid;
$result = event_socket_request($fp, 'api '.$cmd); $result = event_socket::api($cmd);
message::add(htmlentities($result)); message::add(htmlentities($result));
} }
} }

View File

@ -90,10 +90,10 @@
} }
//create an event socket connection //create an event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
//get the call center queue, agent and tiers list //get the call center queue, agent and tiers list
if (!$fp) { if (!$esl->is_connected()) {
$msg = "<div align='center'>Connection to Event Socket failed.<br /></div>"; $msg = "<div align='center'>Connection to Event Socket failed.<br /></div>";
echo "<div align='center'>\n"; echo "<div align='center'>\n";
echo "<table width='40%'>\n"; echo "<table width='40%'>\n";
@ -117,7 +117,7 @@
//send the event socket command and get the response //send the event socket command and get the response
//callcenter_config queue list tiers [queue_name] | //callcenter_config queue list tiers [queue_name] |
$switch_command = 'callcenter_config queue list tiers '.$queue_extension."@".$_SESSION["domain_name"]; $switch_command = 'callcenter_config queue list tiers '.$queue_extension."@".$_SESSION["domain_name"];
$event_socket_str = trim(event_socket_request($fp, 'api '.$switch_command)); $event_socket_str = trim(event_socket::api($switch_command));
$result = str_to_named_array($event_socket_str, '|'); $result = str_to_named_array($event_socket_str, '|');
//prepare the result for array_multisort //prepare the result for array_multisort
@ -139,7 +139,7 @@
//send the event socket command and get the response //send the event socket command and get the response
//callcenter_config queue list agents [queue_name] [status] | //callcenter_config queue list agents [queue_name] [status] |
$switch_command = 'callcenter_config queue list agents '.$queue_extension."@".$_SESSION["domain_name"]; $switch_command = 'callcenter_config queue list agents '.$queue_extension."@".$_SESSION["domain_name"];
$event_socket_str = trim(event_socket_request($fp, 'api '.$switch_command)); $event_socket_str = trim(event_socket::api($switch_command));
$agent_result = str_to_named_array($event_socket_str, '|'); $agent_result = str_to_named_array($event_socket_str, '|');
//get the agents from the database //get the agents from the database
@ -280,7 +280,7 @@
//callcenter_config queue list members [queue_name] //callcenter_config queue list members [queue_name]
if (is_uuid($queue_uuid)) { if (is_uuid($queue_uuid)) {
$switch_command = 'callcenter_config queue list members '.$queue_extension."@".$_SESSION["domain_name"]; $switch_command = 'callcenter_config queue list members '.$queue_extension."@".$_SESSION["domain_name"];
$event_socket_str = trim(event_socket_request($fp, 'api '.$switch_command)); $event_socket_str = trim(event_socket::api($switch_command));
$result = str_to_named_array($event_socket_str, '|'); $result = str_to_named_array($event_socket_str, '|');
if (!is_array($result)) { unset($result); } if (!is_array($result)) { unset($result); }
} }

View File

@ -90,8 +90,7 @@
//run the command //run the command
if (isset($switch_command)) { if (isset($switch_command)) {
$fp = event_socket_create(); $response = event_socket::api($switch_command);
$response = event_socket_request($fp, 'api '.$switch_command);
} }
/* /*
@ -134,14 +133,14 @@
//fs cmd //fs cmd
if (!empty($switch_cmd)) { if (!empty($switch_cmd)) {
//setup the event socket connection //setup the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
//ensure the connection exists //ensure the connection exists
if ($fp) { if ($esl) {
//send the command //send the command
$switch_result = event_socket_request($fp, 'api '.$switch_cmd); $switch_result = event_socket::api($switch_cmd);
//set the user state //set the user state
$cmd = "api callcenter_config agent set state ".$username."@".$_SESSION['domain_name']." Waiting"; $cmd = "api callcenter_config agent set state ".$username."@".$_SESSION['domain_name']." Waiting";
$response = event_socket_request($fp, $cmd); $response = event_socket::command($cmd);
} }
} }
} }

View File

@ -238,37 +238,37 @@
//add the agent //add the agent
//setup the event socket connection //setup the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
//add the agent using event socket //add the agent using event socket
if ($fp) { if ($esl->connected()) {
//add the agent //add the agent
$cmd = "api callcenter_config agent add ".$call_center_agent_uuid." ".$agent_type; $cmd = "callcenter_config agent add ".$call_center_agent_uuid." '".$agent_type."'";
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
usleep(200); usleep(200);
//agent set contact //agent set contact
$cmd = "api callcenter_config agent set contact ".$call_center_agent_uuid." ".$agent_contact; $cmd = "callcenter_config agent set contact ".$call_center_agent_uuid." '".$agent_contact."'";
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
usleep(200); usleep(200);
//agent set status //agent set status
$cmd = "api callcenter_config agent set status ".$call_center_agent_uuid." '".$agent_status."'"; $cmd = "callcenter_config agent set status ".$call_center_agent_uuid." '".$agent_status."'";
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
usleep(200); usleep(200);
//agent set reject_delay_time //agent set reject_delay_time
$cmd = "api callcenter_config agent set reject_delay_time ".$call_center_agent_uuid." ".$agent_reject_delay_time; $cmd = 'callcenter_config agent set reject_delay_time '.$call_center_agent_uuid.' '. $agent_reject_delay_time;
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
usleep(200); usleep(200);
//agent set busy_delay_time //agent set busy_delay_time
$cmd = "api callcenter_config agent set busy_delay_time ".$call_center_agent_uuid." ".$agent_busy_delay_time; $cmd = 'callcenter_config agent set busy_delay_time '.$call_center_agent_uuid.' '.$agent_busy_delay_time;
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
//agent set no_answer_delay_time //agent set no_answer_delay_time
$cmd = "api callcenter_config agent set no_answer_delay_time ".$call_center_agent_uuid." ".$agent_no_answer_delay_time; $cmd = 'callcenter_config agent set no_answer_delay_time '.$call_center_agent_uuid.' '.$agent_no_answer_delay_time;
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
//agent set max_no_answer //agent set max_no_answer
$cmd = "api callcenter_config agent set max_no_answer ".$call_center_agent_uuid." ".$agent_max_no_answer; $cmd = 'callcenter_config agent set max_no_answer '.$call_center_agent_uuid.' '.$agent_max_no_answer;
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
//agent set wrap_up_time //agent set wrap_up_time
$cmd = "api callcenter_config agent set wrap_up_time ".$call_center_agent_uuid." ".$agent_wrap_up_time; $cmd = 'callcenter_config agent set wrap_up_time '.$call_center_agent_uuid.' '.$agent_wrap_up_time;
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
} }
//redirect the user //redirect the user

View File

@ -57,7 +57,7 @@
unset($sql, $parameters); unset($sql, $parameters);
//setup the event socket connection //setup the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
//get the agents from the database //get the agents from the database
$sql = "select * from v_call_center_agents "; $sql = "select * from v_call_center_agents ";
@ -70,12 +70,12 @@
//get the agent list from event socket //get the agent list from event socket
$switch_cmd = 'callcenter_config agent list'; $switch_cmd = 'callcenter_config agent list';
$event_socket_str = trim(event_socket_request($fp, 'api '.$switch_cmd)); $event_socket_str = trim(event_socket::api($switch_cmd));
$agent_list = csv_to_named_array($event_socket_str, '|'); $agent_list = csv_to_named_array($event_socket_str, '|');
//get the agent list from event socket //get the agent list from event socket
$switch_cmd = 'callcenter_config tier list'; $switch_cmd = 'callcenter_config tier list';
$event_socket_str = trim(event_socket_request($fp, 'api '.$switch_cmd)); $event_socket_str = trim(event_socket::api($switch_cmd));
$call_center_tiers = csv_to_named_array($event_socket_str, '|'); $call_center_tiers = csv_to_named_array($event_socket_str, '|');
//get the call center queues from the database //get the call center queues from the database
@ -100,7 +100,7 @@
//get the queue list from event socket //get the queue list from event socket
$switch_cmd = "callcenter_config queue list agents ".$queue_id; $switch_cmd = "callcenter_config queue list agents ".$queue_id;
$event_socket_str = trim(event_socket_request($fp, 'api '.$switch_cmd)); $event_socket_str = trim(event_socket::api($switch_cmd));
$queue_list = csv_to_named_array($event_socket_str, '|'); $queue_list = csv_to_named_array($event_socket_str, '|');
$call_center_queues[$x]['queue_list'] = $queue_list; $call_center_queues[$x]['queue_list'] = $queue_list;
$x++; $x++;
@ -165,7 +165,7 @@
foreach($_POST['agents'] as $row) { foreach($_POST['agents'] as $row) {
if (!empty($row['agent_status'])) { if (!empty($row['agent_status'])) {
//agent set status //agent set status
if ($fp) { if ($esl->is_connected()) {
//set the user_status //set the user_status
if (!isset($row['queue_name'])) { if (!isset($row['queue_name'])) {
$array['users'][0]['user_uuid'] = $row['user_uuid'] ?? null; $array['users'][0]['user_uuid'] = $row['user_uuid'] ?? null;
@ -211,20 +211,20 @@
//set the call center status to Logged Out //set the call center status to Logged Out
if (is_uuid($row['agent_uuid'])) { if (is_uuid($row['agent_uuid'])) {
$command = "api callcenter_config agent set status ".$row['agent_uuid']." 'Logged Out' "; $command = "callcenter_config agent set status ".$row['agent_uuid']." 'Logged Out' ";
$response = event_socket_request($fp, $command); $response = event_socket::api($command);
} }
} }
else { else {
if (is_uuid($row['agent_uuid'])) { if (is_uuid($row['agent_uuid'])) {
//set the agent status //set the agent status
$command = "api callcenter_config agent set status ".$row['agent_uuid']." '".$agent_status."'"; $command = "callcenter_config agent set status ".$row['agent_uuid']." '".$agent_status."'";
$response = event_socket_request($fp, $command); $response = event_socket::api($command);
//set the agent state //set the agent state
if ($agent_status == 'Available' || $agent_status == 'Logged Out') { if ($agent_status == 'Available' || $agent_status == 'Logged Out') {
$command = "api callcenter_config agent set state ".$row['agent_uuid']." 'Waiting'"; $command = "callcenter_config agent set state ".$row['agent_uuid']." 'Waiting'";
$response = event_socket_request($fp, $command); $response = event_socket::api($command);
} }
} }
} }
@ -247,22 +247,21 @@
if (isset($row['queue_uuid']) && $row['agent_status'] == 'Available') { if (isset($row['queue_uuid']) && $row['agent_status'] == 'Available') {
//set the call center status //set the call center status
//$command = "api callcenter_config agent set status ".$row['agent_name']."@".$_SESSION['domain_name']." '".$row['agent_status']."'"; //$command = "api callcenter_config agent set status ".$row['agent_name']."@".$_SESSION['domain_name']." '".$row['agent_status']."'";
//$response = event_socket_request($fp, $command); //$response = event_socket::command($command);
//assign the agent to the queue //assign the agent to the queue
if (is_uuid($row['queue_uuid']) && is_uuid($row['agent_uuid'])) { if (is_uuid($row['queue_uuid']) && is_uuid($row['agent_uuid'])) {
$command = "api callcenter_config tier add ".$queue_id." ".$row['agent_uuid']." 1 1"; $command = "callcenter_config tier add ".$queue_id." ".$row['agent_uuid']." 1 1";
//echo $command."<br />\n"; $response = event_socket::api($command);
$response = event_socket_request($fp, $command);
} }
} }
//un-assign the agent from the queue //un-assign the agent from the queue
if (isset($row['queue_uuid']) && $row['agent_status'] == 'Logged Out') { if (isset($row['queue_uuid']) && $row['agent_status'] == 'Logged Out') {
if (is_uuid($row['queue_uuid']) && is_uuid($row['agent_uuid'])) { if (is_uuid($row['queue_uuid']) && is_uuid($row['agent_uuid'])) {
$command = "api callcenter_config tier del ".$queue_id." ".$row['agent_uuid']; $command = "callcenter_config tier del ".$queue_id." ".$row['agent_uuid'];
//echo $command."<br />\n"; //echo $command."<br />\n";
$response = event_socket_request($fp, $command); $response = event_socket::api($command);
} }
} }
usleep(200); usleep(200);

View File

@ -160,13 +160,13 @@
//delete the agent from freeswitch //delete the agent from freeswitch
//setup the event socket connection //setup the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
//delete the agent over event socket //delete the agent over event socket
if ($fp) { if ($esl->is_connected()) {
//callcenter_config tier del [queue_name] [agent_name] //callcenter_config tier del [queue_name] [agent_name]
if (is_numeric($queue_extension) && is_uuid($call_center_agent_uuid)) { if (is_numeric($queue_extension) && is_uuid($call_center_agent_uuid)) {
$cmd = "api callcenter_config tier del ".$queue_extension."@".$_SESSION['domain_name']." ".$call_center_agent_uuid; $cmd = "callcenter_config tier del ".$queue_extension."@".$_SESSION['domain_name']." ".$call_center_agent_uuid;
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
} }
} }
@ -468,9 +468,9 @@
if (!empty($agent_name)) { if (!empty($agent_name)) {
//setup the event socket connection //setup the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
//add the agent using event socket //add the agent using event socket
if ($fp) { if ($esl->is_connected()) {
/* syntax: /* syntax:
callcenter_config tier add [queue_name] [agent_name] [level] [position] callcenter_config tier add [queue_name] [agent_name] [level] [position]
callcenter_config tier set state [queue_name] [agent_name] [state] callcenter_config tier set state [queue_name] [agent_name] [state]
@ -479,20 +479,20 @@
*/ */
//add the agent //add the agent
if (is_numeric($queue_extension) && is_uuid($call_center_agent_uuid) && is_numeric($tier_level) && is_numeric($tier_position)) { if (is_numeric($queue_extension) && is_uuid($call_center_agent_uuid) && is_numeric($tier_level) && is_numeric($tier_position)) {
$cmd = "api callcenter_config tier add ".$queue_extension."@".$_SESSION["domain_name"]." ".$call_center_agent_uuid." ".$tier_level." ".$tier_position; $cmd = "callcenter_config tier add ".$queue_extension."@".$_SESSION["domain_name"]." ".$call_center_agent_uuid." ".$tier_level." ".$tier_position;
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
} }
usleep(200); usleep(200);
//agent set level //agent set level
if (is_numeric($queue_extension) && is_numeric($tier_level)) { if (is_numeric($queue_extension) && is_numeric($tier_level)) {
$cmd = "api callcenter_config tier set level ".$queue_extension."@".$_SESSION["domain_name"]." ".$call_center_agent_uuid." ".$tier_level; $cmd = "callcenter_config tier set level ".$queue_extension."@".$_SESSION["domain_name"]." ".$call_center_agent_uuid." ".$tier_level;
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
} }
usleep(200); usleep(200);
//agent set position //agent set position
if (is_numeric($queue_extension) && is_numeric($tier_position)) { if (is_numeric($queue_extension) && is_numeric($tier_position)) {
$cmd = "api callcenter_config tier set position ".$queue_extension."@".$_SESSION["domain_name"]." ".$tier_position; $cmd = "callcenter_config tier set position ".$queue_extension."@".$_SESSION["domain_name"]." ".$tier_position;
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
} }
usleep(200); usleep(200);
} }

View File

@ -70,11 +70,10 @@
//connect to event socket //connect to event socket
if (isset($queue_extension) && isset($cmd)) { if (isset($queue_extension) && isset($cmd)) {
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
$response = event_socket_request($fp, 'api reloadxml'); $response = event_socket::api('reloadxml');
$response = event_socket_request($fp, 'api callcenter_config queue '.$cmd. ' '.$queue_extension."@".$_SESSION["domain_name"]); $response = event_socket::api('callcenter_config queue '.$cmd.' '.$queue_extension.'@'.$_SESSION['domain_name']);
fclose($fp);
} }
else { else {
$response = ''; $response = '';
@ -85,4 +84,4 @@
$_SESSION["message"] = $response; $_SESSION["message"] = $response;
header("Location: call_center_queues.php?savemsg=".urlencode($response)); header("Location: call_center_queues.php?savemsg=".urlencode($response));
?> ?>

View File

@ -338,13 +338,13 @@
if (is_array($array) && @sizeof($array) != 0) { if (is_array($array) && @sizeof($array) != 0) {
//setup the event socket connection //setup the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
//delete the queue in the switch //delete the queue in the switch
if ($fp) { if ($esl->is_connected()) {
foreach ($uuids as $uuid) { foreach ($uuids as $uuid) {
$cmd = "api callcenter_config queue unload ".$call_center_queues[$uuid]['queue_extension']."@".$_SESSION["domain_name"]; $cmd = "callcenter_config queue unload ".$call_center_queues[$uuid]['queue_extension']."@".$_SESSION['domain_name'];
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
} }
} }
@ -436,13 +436,12 @@
if (is_array($array) && @sizeof($array) != 0) { if (is_array($array) && @sizeof($array) != 0) {
//setup the event socket connection //setup the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
//delete the agent in the switch //delete the agent in the switch
if ($fp) { if ($esl->is_connected()) {
foreach ($uuids as $uuid) { foreach ($uuids as $uuid) {
$cmd = "api callcenter_config agent del ".$uuid; event_socket::async("callcenter_config agent del $uuid");
$response = event_socket_request($fp, $cmd);
} }
} }
@ -627,4 +626,4 @@ $c->queue_cc_exit_keys = "";
$c->dialplan(); $c->dialplan();
*/ */
?> ?>

View File

@ -51,7 +51,7 @@
} }
//setup the event socket connection //setup the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
//get the http post values and set them as php variables //get the http post values and set them as php variables
if (!empty($_POST['agents'])) { if (!empty($_POST['agents'])) {
@ -91,8 +91,8 @@
$result = $database->save($array); $result = $database->save($array);
//send the agent status status to mod_call_center //send the agent status status to mod_call_center
$cmd = "api callcenter_config agent set status ".$agent_uuid." '".$agent_status."'"; $cmd = "callcenter_config agent set status ".$agent_uuid." '".$agent_status."'";
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
//add or delete agents from the queue assigned by the tier //add or delete agents from the queue assigned by the tier
foreach ($_POST['agents'] as $row) { foreach ($_POST['agents'] as $row) {
@ -103,21 +103,21 @@
//set the agent status to available and assign the agent to the queue with the tier //set the agent status to available and assign the agent to the queue with the tier
if ($row['agent_status'] == 'Available') { if ($row['agent_status'] == 'Available') {
//assign the agent to the queue //assign the agent to the queue
$cmd = "api callcenter_config tier add ".$row['queue_extension']."@".$_SESSION['domain_name']." ".$row['id']." 1 1"; $cmd = "callcenter_config tier add ".$row['queue_extension']."@".$_SESSION['domain_name']." ".$row['id']." 1 1";
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
} }
//set the agent status to available and assign the agent to the queue with the tier //set the agent status to available and assign the agent to the queue with the tier
if ($row['agent_status'] == 'On Break') { if ($row['agent_status'] == 'On Break') {
//assign the agent to the queue //assign the agent to the queue
$cmd = "api callcenter_config tier add ".$row['queue_extension']."@".$_SESSION['domain_name']." ".$row['id']." 1 1"; $cmd = "callcenter_config tier add ".$row['queue_extension']."@".$_SESSION['domain_name']." ".$row['id']." 1 1";
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
} }
//un-assign the agent from the queue //un-assign the agent from the queue
if ($row['agent_status'] == 'Logged Out') { if ($row['agent_status'] == 'Logged Out') {
$cmd = "api callcenter_config tier del ".$row['queue_extension']."@".$_SESSION['domain_name']." ".$row['id']; $cmd = "callcenter_config tier del ".$row['queue_extension']."@".$_SESSION['domain_name']." ".$row['id'];
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
} }
//small sleep //small sleep
@ -132,7 +132,7 @@
//get the agent list from event socket //get the agent list from event socket
$switch_cmd = 'callcenter_config tier list'; $switch_cmd = 'callcenter_config tier list';
$event_socket_str = trim(event_socket_request($fp, 'api '.$switch_cmd)); $event_socket_str = trim(event_socket::api($switch_cmd));
$call_center_tiers = csv_to_named_array($event_socket_str, '|'); $call_center_tiers = csv_to_named_array($event_socket_str, '|');
//get the agents from the database //get the agents from the database

View File

@ -31,11 +31,11 @@
} }
//connect to event socket //connect to event socket
$fp = event_socket_create(); $esl = event_socket::create();
//get the agent list from event socket //get the agent list from event socket
$switch_cmd = 'callcenter_config agent list'; $switch_cmd = 'callcenter_config agent list';
$event_socket_str = trim(event_socket_request($fp, 'api '.$switch_cmd)); $event_socket_str = trim(event_socket::api($switch_cmd));
$agent_list = csv_to_named_array($event_socket_str, '|'); $agent_list = csv_to_named_array($event_socket_str, '|');
//get the agents from the database //get the agents from the database
@ -69,7 +69,7 @@
} }
//build the event //build the event
if ($fp) { if ($esl->is_connected()) {
$event = "sendevent PRESENCE_IN\n"; $event = "sendevent PRESENCE_IN\n";
$event .= "proto: agent\n"; $event .= "proto: agent\n";
$event .= "from: ".$row['agent_name']."@".$row['domain_name']."\n"; $event .= "from: ".$row['agent_name']."@".$row['domain_name']."\n";
@ -104,16 +104,13 @@
} }
//send the event //send the event
$result = event_socket_request($fp, $event); $result = event_socket::command($event);
if (isset($debug)) { if (isset($debug)) {
print_r($result, false); print_r($result, false);
} }
} }
//close event socket connection
fclose($fp);
/* /*
* * * * * cd /var/www/fusionpbx && php /var/www/fusionpbx/app/call_centers/resources/jobs/call_center_agents.php * * * * * cd /var/www/fusionpbx && php /var/www/fusionpbx/app/call_centers/resources/jobs/call_center_agents.php
*/ */

View File

@ -257,8 +257,8 @@
// Update subscribed endpoints // Update subscribed endpoints
if (!empty($call_flow_feature_code)) { if (!empty($call_flow_feature_code)) {
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
//send the event //send the event
$event = "sendevent PRESENCE_IN\n"; $event = "sendevent PRESENCE_IN\n";
$event .= "proto: flow\n"; $event .= "proto: flow\n";
@ -274,8 +274,7 @@
} else { } else {
$event .= "answer-state: terminated\n"; $event .= "answer-state: terminated\n";
} }
event_socket_request($fp, $event); event_socket::command($event);
fclose($fp);
} }
} }

View File

@ -281,8 +281,7 @@ if (!class_exists('call_flows')) {
} }
//send the event //send the event
$fp = event_socket_create(); $switch_result = event_socket::command($cmd);
$switch_result = event_socket_request($fp, $cmd);
} }
} }
unset($call_flows); unset($call_flows);

View File

@ -399,9 +399,7 @@
$cmd .= "answer-state: confirmed\n"; $cmd .= "answer-state: confirmed\n";
//send the event //send the event
$fp = event_socket_create(); $switch_result = event_socket::command($cmd);
$switch_result = event_socket_request($fp, $cmd);
unset($fp);
} }
else { else {
$presence = new presence; $presence = new presence;
@ -421,9 +419,7 @@
$cmd .= "answer-state: terminated\n"; $cmd .= "answer-state: terminated\n";
//send the event //send the event
$fp = event_socket_create(); $switch_result = event_socket::command($cmd);
$switch_result = event_socket_request($fp, $cmd);
unset($fp);
} }
} }
} }

View File

@ -39,10 +39,10 @@
if ($this->enabled == "true") { if ($this->enabled == "true") {
//update the call center status //update the call center status
$user_status = "Logged Out"; $user_status = "Logged Out";
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
$switch_cmd .= "callcenter_config agent set status ".$_SESSION['username']."@".$this->domain_name." '".$user_status."'"; $switch_cmd .= "callcenter_config agent set status ".$_SESSION['username']."@".$this->domain_name." '".$user_status."'";
$switch_result = event_socket_request($fp, 'api '.$switch_cmd); $switch_result = event_socket::api($switch_cmd);
} }
//update the database user_status //update the database user_status

View File

@ -42,11 +42,11 @@
//feature_event method //feature_event method
public function send_notify() { public function send_notify() {
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
// Get the SIP profiles for the extension // Get the SIP profiles for the extension
$command = "sofia_contact */{$this->extension}@{$this->domain_name}"; $command = "sofia_contact */{$this->extension}@{$this->domain_name}";
$contact_string = event_socket_request($fp, "api ".$command); $contact_string = event_socket::api($command);
// The first value in the array will be full matching text, the second one will be the array of profile matches // The first value in the array will be full matching text, the second one will be the array of profile matches
preg_match_all('/sofia\/([^,]+)\/(?:[^,]+)/', $contact_string, $matches); preg_match_all('/sofia\/([^,]+)\/(?:[^,]+)/', $contact_string, $matches);
if (sizeof($matches) != 2 || sizeof($matches[1]) < 1) { if (sizeof($matches) != 2 || sizeof($matches[1]) < 1) {
@ -72,12 +72,11 @@
$event .= "forward_no_answer: " . $this->forward_no_answer_destination . "\n"; $event .= "forward_no_answer: " . $this->forward_no_answer_destination . "\n";
$event .= "doNotDisturbOn: " . $this->do_not_disturb . "\n"; $event .= "doNotDisturbOn: " . $this->do_not_disturb . "\n";
$event .= "ringCount: " . $this->ring_count . "\n"; $event .= "ringCount: " . $this->ring_count . "\n";
event_socket_request($fp, $event); event_socket::command($event);
} }
fclose($fp);
} }
} //function } //function
} //class } //class
?> ?>

View File

@ -3,7 +3,7 @@
//check the permission //check the permission
if (defined('STDIN')) { if (defined('STDIN')) {
//includes files //includes files
require_once dirname(__DIR__, 4) . "/resources/require.php"; require_once dirname(__DIR__, 4) . "/resources/require.php";
} }
else { else {
exit; exit;
@ -31,54 +31,63 @@
exit; exit;
} }
//connect to event socket //use global conf created from require.php
$fp = event_socket_create(); global $conf;
//get the list //set the event socket connection settings
$sql = "select domain_name, extension, user_context, do_not_disturb, description "; $host = $conf['switch.event_socket.host'] ?? $conf['event_socket.ip_address'] ?? '127.0.0.1';
$sql .= "from v_extensions as e, v_domains as d "; $port = $conf['switch.event_socket.port'] ?? $conf['event_socket.port'] ?? '8021';
$sql .= "where do_not_disturb = 'true' "; $pass = $conf['switch.event_socket.password'] ?? $conf['event_socket.password'] ?? 'ClueCon';
$sql .= "and e.domain_uuid = d.domain_uuid ";
$sql .= "and enabled = 'true' ";
$database = new database;
$results = $database->select($sql, $parameters, 'all');
unset($parameters);
//view_array($results); //connect to event socket using a lower timeout because we are on cli
foreach($results as $row) { $esl = event_socket::create($host, $port, $pass, 10000);
//build the event //ensure we are connected
$cmd = "sendevent PRESENCE_IN\n"; if ($esl->is_connected()) {
$cmd .= "proto: sip\n";
$cmd .= "login: ".$row['extension']."@".$row['domain_name']."\n";
$cmd .= "from: ".$row['extension']."@".$row['domain_name']."\n";
$cmd .= "status: Active (1 waiting)\n";
$cmd .= "rpid: unknown\n";
$cmd .= "event_type: presence\n";
$cmd .= "alt_event_type: dialog\n";
$cmd .= "event_count: 1\n";
$cmd .= "unique-id: ".uuid()."\n";
$cmd .= "Presence-Call-Direction: outbound\n";
$cmd .= "answer-state: confirmed\n";
//$cmd .= "answer-state: early\n";
//$cmd .= "answer-state: terminated\n";
//send message to the console //get the list
if (isset($debug)) { $sql = "select domain_name, extension, user_context, do_not_disturb, description ";
echo "\n"; $sql .= "from v_extensions as e, v_domains as d ";
echo "[presence] dnd ".$row['extension']."@".$row['domain_name']."\n"; $sql .= "where do_not_disturb = 'true' ";
$sql .= "and e.domain_uuid = d.domain_uuid ";
$sql .= "and enabled = 'true' ";
$database = new database;
$results = $database->select($sql, $parameters, 'all');
unset($parameters);
foreach ($results as $row) {
//build the event
$cmd = "sendevent PRESENCE_IN\n";
$cmd .= "proto: sip\n";
$cmd .= "login: " . $row['extension'] . "@" . $row['domain_name'] . "\n";
$cmd .= "from: " . $row['extension'] . "@" . $row['domain_name'] . "\n";
$cmd .= "status: Active (1 waiting)\n";
$cmd .= "rpid: unknown\n";
$cmd .= "event_type: presence\n";
$cmd .= "alt_event_type: dialog\n";
$cmd .= "event_count: 1\n";
$cmd .= "unique-id: " . uuid() . "\n";
$cmd .= "Presence-Call-Direction: outbound\n";
$cmd .= "answer-state: confirmed\n";
//$cmd .= "answer-state: early\n";
//$cmd .= "answer-state: terminated\n";
//send message to the console
if (isset($debug)) {
echo "\n";
echo "[presence] dnd " . $row['extension'] . "@" . $row['domain_name'] . "\n";
}
//send the event
$result = event_socket::command($cmd);
if (isset($debug)) {
print_r($result, false);
}
} }
}
//send the event else {
$result = event_socket_request($fp, $cmd); trigger_error("Unable to connect to FreeSWITCH using $host, $port, $password", E_USER_ERROR);
if (isset($debug)) {
print_r($result, false);
}
} }
/* /*
* * * * * cd /var/www/fusionpbx && php /var/www/fusionpbx/app/call_forward/resources/jobs/dnd.php * * * * * cd /var/www/fusionpbx && php /var/www/fusionpbx/app/call_forward/resources/jobs/dnd.php
*/ */
?>

View File

@ -52,11 +52,11 @@
$switch_cmd = 'show channels as json'; $switch_cmd = 'show channels as json';
//create the event socket connection //create the event socket connection
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); $esl = event_socket::create();
//send the event socket command and get the array //send the event socket command and get the array
if ($fp) { if ($esl->is_connected()) {
$json = trim(event_socket_request($fp, 'api '.$switch_cmd)); $json = trim(event_socket::api($switch_cmd));
$results = json_decode($json, "true"); $results = json_decode($json, "true");
} }
@ -90,7 +90,7 @@
//if the connnection is available then run it and return the results //if the connnection is available then run it and return the results
if (!$fp) { if (!$esl) {
$msg = "<div align='center'>".$text['confirm-socket']."<br /></div>"; $msg = "<div align='center'>".$text['confirm-socket']."<br /></div>";
echo "<div align='center'>\n"; echo "<div align='center'>\n";

View File

@ -58,6 +58,7 @@
exit; exit;
} }
$calls = [];
//verify submitted call uuids //verify submitted call uuids
if (is_array($_POST['calls']) && @sizeof($_POST['calls']) != 0) { if (is_array($_POST['calls']) && @sizeof($_POST['calls']) != 0) {
foreach ($_POST['calls'] as $call) { foreach ($_POST['calls'] as $call) {
@ -71,18 +72,18 @@
} }
//iterate through calls //iterate through calls
if (is_array($calls) && @sizeof($calls) != 0) { if (count($calls) > 0) {
//setup the event socket connection //setup the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
//execute hangup command //execute hangup command
foreach ($calls as $call_uuid) { if ($esl->is_connected()) foreach ($calls as $call_uuid) {
$switch_result = event_socket_request($fp, 'api uuid_kill '.$call_uuid); event_socket::async("uuid_kill $call_uuid");
} }
//set message //set message
message::add($text['message-calls_ended'].': '.@sizeof($calls),'positive'); message::add($text['message-calls_ended'].': '.count($calls),'positive');
} }

View File

@ -93,124 +93,120 @@
} }
//create the even socket connection and send the event socket command //create the even socket connection and send the event socket command
$fp = event_socket_create(); $esl = event_socket::create();
if (!$fp) { if ($esl->is_connected()) {
//error message
echo "<div align='center'><strong>Connection to Event Socket failed.</strong></div>";
}
//set call uuid //set call uuid
$origination_uuid = trim(event_socket_request($fp, "api create_uuid")); $origination_uuid = trim(event_socket::api("create_uuid"));
//add record path and name //add record path and name
if ($rec == "true") { if ($rec == "true") {
$record_path = $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/archive/".date("Y")."/".date("M")."/".date("d"); $record_path = $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/archive/".date("Y")."/".date("M")."/".date("d");
if (isset($_SESSION['recordings']['extension']['text'])) { if (isset($_SESSION['recordings']['extension']['text'])) {
$record_extension = $_SESSION['recordings']['extension']['text']; $record_extension = $_SESSION['recordings']['extension']['text'];
} }
else { else {
$record_extension = 'wav'; $record_extension = 'wav';
} }
if (isset($_SESSION['recordings']['template']['text'])) { if (isset($_SESSION['recordings']['template']['text'])) {
//${year}${month}${day}-${caller_id_number}-${caller_destination}-${uuid}.${record_extension} //${year}${month}${day}-${caller_id_number}-${caller_destination}-${uuid}.${record_extension}
$record_name = $_SESSION['recordings']['template']['text']; $record_name = $_SESSION['recordings']['template']['text'];
$record_name = str_replace('${year}', date("Y"), $record_name); $record_name = str_replace('${year}', date("Y"), $record_name);
$record_name = str_replace('${month}', date("M"), $record_name); $record_name = str_replace('${month}', date("M"), $record_name);
$record_name = str_replace('${day}', date("d"), $record_name); $record_name = str_replace('${day}', date("d"), $record_name);
$record_name = str_replace('${source}', $src, $record_name); $record_name = str_replace('${source}', $src, $record_name);
$record_name = str_replace('${caller_id_name}', $src_cid_name, $record_name); $record_name = str_replace('${caller_id_name}', $src_cid_name, $record_name);
$record_name = str_replace('${caller_id_number}', $src_cid_number, $record_name); $record_name = str_replace('${caller_id_number}', $src_cid_number, $record_name);
$record_name = str_replace('${caller_destination}', $dest, $record_name); $record_name = str_replace('${caller_destination}', $dest, $record_name);
$record_name = str_replace('${destination}', $dest, $record_name); $record_name = str_replace('${destination}', $dest, $record_name);
$record_name = str_replace('${uuid}', $origination_uuid, $record_name); $record_name = str_replace('${uuid}', $origination_uuid, $record_name);
$record_name = str_replace('${record_extension}', $record_extension, $record_name); $record_name = str_replace('${record_extension}', $record_extension, $record_name);
} }
else { else {
$record_name = $origination_uuid.'.'.$record_extension; $record_name = $origination_uuid.'.'.$record_extension;
}
}
//determine call direction
$dir = (user_exists($dest)) ? 'local' : 'outbound';
//define a leg - set source to display the defined caller id name and number
$source_common = "{";
$source_common .= "click_to_call=true";
$source_common .= ",origination_caller_id_name='".$src_cid_name."'";
$source_common .= ",origination_caller_id_number=".$src_cid_number;
$source_common .= ",instant_ringback=true";
$source_common .= ",ringback=".$ringback_value;
$source_common .= ",presence_id=".$src."@".$_SESSION['domains'][$domain_uuid]['domain_name'];
$source_common .= ",call_direction=".$dir;
if ($rec == "true") {
$source_common .= ",record_path='".$record_path."'";
$source_common .= ",record_name='".$record_name."'";
}
if (user_exists($src)) {
//source is a local extension
$source = $source_common.$sip_auto_answer.
",domain_uuid=".$domain_uuid.
",domain_name=".$_SESSION['domains'][$domain_uuid]['domain_name']."}user/".$src."@".$_SESSION['domains'][$domain_uuid]['domain_name'];
}
else {
//source is an external number
$bridge_array = outbound_route_to_bridge($_SESSION['domain_uuid'], $src);
$source = $source_common."}".$bridge_array[0];
}
unset($source_common);
//define b leg - set destination to display the defined caller id name and number
$destination_common = " &bridge({origination_caller_id_name='".$dest_cid_name."',origination_caller_id_number=".$dest_cid_number;
if (user_exists($dest)) {
//destination is a local extension
if (strpbrk($dest, '@') != FALSE) { //sip-uri
$switch_cmd = $destination_common.",call_direction=outbound}sofia/external/".$dest.")";
}
else { //not sip-uri
$switch_cmd = " &transfer('".$dest." XML ".$context."')";
}
}
else {
//local extension (source) > external number (destination)
if (user_exists($src) && empty($dest_cid_number)) {
//retrieve outbound caller id from the (source) extension
$sql = "select outbound_caller_id_name, outbound_caller_id_number from v_extensions where domain_uuid = :domain_uuid and extension = :src ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$parameters['src'] = $src;
$database = new database;
$result = $database->select($sql, $parameters, 'all');
foreach ($result as &$row) {
$dest_cid_name = $row["outbound_caller_id_name"];
$dest_cid_number = $row["outbound_caller_id_number"];
break; //limit to 1 row
} }
} }
if (permission_exists('click_to_call_call')) {
//determine call direction
$dir = (user_exists($dest)) ? 'local' : 'outbound';
//define a leg - set source to display the defined caller id name and number
$source_common = "{";
$source_common .= "click_to_call=true";
$source_common .= ",origination_caller_id_name='".$src_cid_name."'";
$source_common .= ",origination_caller_id_number=".$src_cid_number;
$source_common .= ",instant_ringback=true";
$source_common .= ",ringback=".$ringback_value;
$source_common .= ",presence_id=".$src."@".$_SESSION['domains'][$domain_uuid]['domain_name'];
$source_common .= ",call_direction=".$dir;
if ($rec == "true") {
$source_common .= ",record_path='".$record_path."'";
$source_common .= ",record_name='".$record_name."'";
}
if (user_exists($src)) {
//source is a local extension
$source = $source_common.$sip_auto_answer.
",domain_uuid=".$domain_uuid.
",domain_name=".$_SESSION['domains'][$domain_uuid]['domain_name']."}user/".$src."@".$_SESSION['domains'][$domain_uuid]['domain_name'];
}
else {
//source is an external number
$bridge_array = outbound_route_to_bridge($_SESSION['domain_uuid'], $src);
$source = $source_common."}".$bridge_array[0];
}
unset($source_common);
//define b leg - set destination to display the defined caller id name and number
$destination_common = " &bridge({origination_caller_id_name='".$dest_cid_name."',origination_caller_id_number=".$dest_cid_number;
if (user_exists($dest)) {
//destination is a local extension
if (strpbrk($dest, '@') != FALSE) { //sip-uri if (strpbrk($dest, '@') != FALSE) { //sip-uri
$switch_cmd = $destination_common.",call_direction=outbound}sofia/external/".$dest.")"; $switch_cmd = $destination_common.",call_direction=outbound}sofia/external/".$dest.")";
} }
else { //not sip-uri else { //not sip-uri
$bridge_array = outbound_route_to_bridge($_SESSION['domain_uuid'], $dest);
//$switch_cmd = $destination_common."}".$bridge_array[0].")"; // wouldn't set cdr destination correctly, so below used instead
$switch_cmd = " &transfer('".$dest." XML ".$context."')"; $switch_cmd = " &transfer('".$dest." XML ".$context."')";
} }
} }
} else {
unset($destination_common); //local extension (source) > external number (destination)
if (user_exists($src) && empty($dest_cid_number)) {
//create the even socket connection and send the event socket command //retrieve outbound caller id from the (source) extension
$fp = event_socket_create(); $sql = "select outbound_caller_id_name, outbound_caller_id_number from v_extensions where domain_uuid = :domain_uuid and extension = :src ";
if (!$fp) { $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$parameters['src'] = $src;
$database = new database;
$result = $database->select($sql, $parameters, 'all');
foreach ($result as &$row) {
$dest_cid_name = $row["outbound_caller_id_name"];
$dest_cid_number = $row["outbound_caller_id_number"];
break; //limit to 1 row
}
}
if (permission_exists('click_to_call_call')) {
if (strpbrk($dest, '@') != FALSE) { //sip-uri
$switch_cmd = $destination_common.",call_direction=outbound}sofia/external/".$dest.")";
}
else { //not sip-uri
$bridge_array = outbound_route_to_bridge($_SESSION['domain_uuid'], $dest);
//$switch_cmd = $destination_common."}".$bridge_array[0].")"; // wouldn't set cdr destination correctly, so below used instead
$switch_cmd = " &transfer('".$dest." XML ".$context."')";
}
}
}
unset($destination_common);
} else {
//error message //error message
echo "<div align='center'><strong>Connection to Event Socket failed.</strong></div>"; echo "<div align='center'><strong>Connection to Event Socket failed.</strong></div>";
} }
else {
//ensure we are still connected and send the event socket command
if ($esl->is_connected()) {
//display the last command //display the last command
$switch_cmd = "api originate ".$source.$switch_cmd; $switch_cmd = "originate ".$source.$switch_cmd;
echo "<div align='center'><strong>".escape($src)." has called ".escape($dest)."</strong></div>\n"; echo "<div align='center'><strong>".escape($src)." has called ".escape($dest)."</strong></div>\n";
//show the command result //show the command result
$result = trim(event_socket_request($fp, $switch_cmd)); $result = trim(event_socket::api($switch_cmd));
if (substr($result, 0,3) == "+OK") { if (substr($result, 0,3) == "+OK") {
//$uuid = substr($result, 4); //$uuid = substr($result, 4);
if ($rec == "true") { if ($rec == "true") {
@ -218,12 +214,15 @@
date_default_timezone_set($_SESSION['time_zone']['system']); date_default_timezone_set($_SESSION['time_zone']['system']);
//create the api record command and send it over event socket //create the api record command and send it over event socket
if (is_uuid($origination_uuid) && file_exists($record_path)) { if (is_uuid($origination_uuid) && file_exists($record_path)) {
$switch_cmd = "api uuid_record ".$origination_uuid." start ".$record_path."/".$record_name; $switch_cmd = "uuid_record $origination_uuid start $record_path/$record_name";
} }
$result2 = trim(event_socket_request($fp, $switch_cmd)); $result2 = trim(event_socket::api($switch_cmd));
} }
} }
echo "<div align='center'><br />".escape($result)."<br /><br /></div>\n"; echo "<div align='center'><br />".escape($result)."<br /><br /></div>\n";
} else {
//error message
echo "<div align='center'><strong>Connection to Event Socket failed.</strong></div>";
} }
} }

View File

@ -141,9 +141,9 @@
$default_voice = 'callie'; $default_voice = 'callie';
$switch_cmd = "conference ".$conference_room_uuid."@".$_SESSION['domain_name']." play ".$_SESSION['switch']['sounds']['dir']."/".$default_language."/".$default_dialect."/".$default_voice."/ivr/ivr-recording_started.wav"; $switch_cmd = "conference ".$conference_room_uuid."@".$_SESSION['domain_name']." play ".$_SESSION['switch']['sounds']['dir']."/".$default_language."/".$default_dialect."/".$default_voice."/ivr/ivr-recording_started.wav";
//connect to event socket //connect to event socket
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
$switch_result = event_socket_request($fp, 'api '.$switch_cmd); $switch_result = event_socket::api($switch_cmd);
} }
} }

View File

@ -98,9 +98,9 @@
$default_voice = 'callie'; $default_voice = 'callie';
$switch_cmd = "conference ".$meeting_uuid."@".$_SESSION['domain_name']." play ".$_SESSION['switch']['sounds']['dir']."/".$default_language."/".$default_dialect."/".$default_voice."/ivr/ivr-recording_started.wav"; $switch_cmd = "conference ".$meeting_uuid."@".$_SESSION['domain_name']." play ".$_SESSION['switch']['sounds']['dir']."/".$default_language."/".$default_dialect."/".$default_voice."/ivr/ivr-recording_started.wav";
//connect to event socket //connect to event socket
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl) {
$switch_result = event_socket_request($fp, 'api '.$switch_cmd); $switch_result = event_socket::api($switch_cmd);
} }
} }
@ -137,12 +137,12 @@
//get conference array //get conference array
$switch_cmd = "conference xml_list"; $switch_cmd = "conference xml_list";
$fp = event_socket_create(); $esl = event_socket::create();
if (!$fp) { if (!$esl->is_connected()) {
//connection to even socket failed trigger_error('Unable to connect to FreeSWITCH', E_USER_WARNING);
} }
else { else {
$xml_str = trim(event_socket_request($fp, 'api '.$switch_cmd)); $xml_str = trim(event_socket::api($switch_cmd));
try { try {
$xml = new SimpleXMLElement($xml_str, true); $xml = new SimpleXMLElement($xml_str, true);
} }

View File

@ -37,8 +37,8 @@
//feature_event method //feature_event method
public function send_call_center_notify() { public function send_call_center_notify() {
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
//send the event //send the event
$event = "sendevent PRESENCE_IN\n"; $event = "sendevent PRESENCE_IN\n";
$event .= "proto: agent\n"; $event .= "proto: agent\n";
@ -50,9 +50,8 @@
$event .= "login: agent+".$this->agent_name."@".$this->domain_name."\n"; $event .= "login: agent+".$this->agent_name."@".$this->domain_name."\n";
$event .= "unique-id: ".$this->agent_uuid."\n"; $event .= "unique-id: ".$this->agent_uuid."\n";
$event .= "answer-state: ".$this->answer_state."\n"; $event .= "answer-state: ".$this->answer_state."\n";
event_socket_request($fp, $event); event_socket::command($event);
//echo $event."<br />"; //echo $event."<br />";
fclose($fp);
} }
} //function } //function

View File

@ -687,10 +687,10 @@ if (!class_exists('conference_centers')) {
$switch_cmd_notice = "conference ".$meeting_uuid[$uuid]."@".$_SESSION['domain_name']." play ".$_SESSION['switch']['sounds']['dir']."/".$default_language."/".$default_dialect."/".$default_voice."/ivr/ivr-recording_started.wav"; $switch_cmd_notice = "conference ".$meeting_uuid[$uuid]."@".$_SESSION['domain_name']." play ".$_SESSION['switch']['sounds']['dir']."/".$default_language."/".$default_dialect."/".$default_voice."/ivr/ivr-recording_started.wav";
//execute api commands //execute api commands
// if (!file_exists($recording_dir.'/'.$meeting_uuid[$uuid].'.wav')) { // if (!file_exists($recording_dir.'/'.$meeting_uuid[$uuid].'.wav')) {
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
// $switch_result = event_socket_request($fp, 'api '.$switch_cmd_record); // $switch_result = event_socket::api($switch_cmd_record);
$switch_result = event_socket_request($fp, 'api '.$switch_cmd_notice); $switch_result = event_socket::api($switch_cmd_notice);
} }
// } // }
} }

View File

@ -147,9 +147,9 @@
} }
//define an alternative kick all //define an alternative kick all
function conference_end($fp, $name) { function conference_end($name) {
$switch_cmd = "conference '".$name."' xml_list"; $switch_cmd = "conference '".$name."' xml_list";
$xml_str = trim(event_socket_request($fp, 'api '.$switch_cmd)); $xml_str = trim(event_socket::api($switch_cmd));
try { try {
$xml = new SimpleXMLElement($xml_str); $xml = new SimpleXMLElement($xml_str);
} }
@ -161,7 +161,7 @@
foreach ($xml->conference->members->member as $row) { foreach ($xml->conference->members->member as $row) {
$uuid = (string)$row->uuid; $uuid = (string)$row->uuid;
if (is_uuid($uuid)) { if (is_uuid($uuid)) {
$switch_result = event_socket_request($fp, 'api uuid_kill '.$uuid); $switch_result = event_socket::api("uuid_kill $uuid");
} }
if ($x < 1) { if ($x < 1) {
usleep(500000); //500000 = 0.5 seconds usleep(500000); //500000 = 0.5 seconds
@ -188,66 +188,66 @@
} }
//connect to event socket //connect to event socket
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
if ($data == "energy") { if ($data == "energy") {
//conference 3001-example-domain.org energy 103 //conference 3001-example-domain.org energy 103
$switch_result = event_socket_request($fp, 'api '.$switch_cmd); $switch_result = event_socket::api($switch_cmd);
$result_array = explode("=",$switch_result); $result_array = explode("=",$switch_result);
$tmp_value = $result_array[1]; $tmp_value = $result_array[1];
if ($direction == "up") { $tmp_value = $tmp_value + 100; } if ($direction == "up") { $tmp_value = $tmp_value + 100; }
if ($direction == "down") { $tmp_value = $tmp_value - 100; } if ($direction == "down") { $tmp_value = $tmp_value - 100; }
//echo "energy $tmp_value<br />\n"; //echo "energy $tmp_value<br />\n";
$switch_result = event_socket_request($fp, 'api '.$switch_cmd.' '.$tmp_value); $switch_result = event_socket::api("$switch_cmd $tmp_value");
} }
elseif ($data == "volume_in") { elseif ($data == "volume_in") {
$switch_result = event_socket_request($fp, 'api '.$switch_cmd); $switch_result = event_socket::api($switch_cmd);
$result_array = explode("=",$switch_result); $result_array = explode("=",$switch_result);
$tmp_value = $result_array[1]; $tmp_value = $result_array[1];
if ($direction == "up") { $tmp_value = $tmp_value + 1; } if ($direction == "up") { $tmp_value = $tmp_value + 1; }
if ($direction == "down") { $tmp_value = $tmp_value - 1; } if ($direction == "down") { $tmp_value = $tmp_value - 1; }
//echo "volume $tmp_value<br />\n"; //echo "volume $tmp_value<br />\n";
$switch_result = event_socket_request($fp, 'api '.$switch_cmd.' '.$tmp_value); $switch_result = event_socket::api($switch_cmd.' '.$tmp_value);
} }
elseif ($data == "volume_out") { elseif ($data == "volume_out") {
$switch_result = event_socket_request($fp, 'api '.$switch_cmd); $switch_result = event_socket::api($switch_cmd);
$result_array = explode("=",$switch_result); $result_array = explode("=",$switch_result);
$tmp_value = $result_array[1]; $tmp_value = $result_array[1];
if ($direction == "up") { $tmp_value = $tmp_value + 1; } if ($direction == "up") { $tmp_value = $tmp_value + 1; }
if ($direction == "down") { $tmp_value = $tmp_value - 1; } if ($direction == "down") { $tmp_value = $tmp_value - 1; }
//echo "volume $tmp_value<br />\n"; //echo "volume $tmp_value<br />\n";
$switch_result = event_socket_request($fp, 'api '.$switch_cmd.' '.$tmp_value); $switch_result = event_socket::api($switch_cmd.' '.$tmp_value);
} }
elseif ($data == "record") { elseif ($data == "record") {
$recording_dir = $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.date("Y").'/'.date("M").'/'.date("d"); $recording_dir = $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.date("Y").'/'.date("M").'/'.date("d");
$switch_cmd .= $recording_dir."/".$uuid.".wav"; $switch_cmd .= $recording_dir."/{$uuid}.wav";
if (!file_exists($recording_dir."/".$uuid.".wav")) { if (!file_exists($switch_cmd)) {
$switch_result = event_socket_request($fp, "api ".$switch_cmd); $switch_result = event_socket::api($switch_cmd);
} }
} }
elseif ($data == "norecord") { elseif ($data == "norecord") {
//stop recording and rename the file //stop recording and rename the file
$recording_dir = $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.date("Y").'/'.date("M").'/'.date("d"); $recording_dir = $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.date("Y").'/'.date("M").'/'.date("d");
$switch_cmd .= $recording_dir."/".$uuid.".wav"; $switch_cmd .= $recording_dir."/".$uuid.".wav";
$switch_result = event_socket_request($fp, 'api '.$switch_cmd); $switch_result = event_socket::api($switch_cmd);
} }
elseif ($data == "kick") { elseif ($data == "kick") {
$switch_result = event_socket_request($fp, 'api uuid_kill '.$uuid); $switch_result = event_socket::api("uuid_kill $uuid");
} }
elseif ($data == "kick all") { elseif ($data == "kick all") {
//$switch_result = event_socket_request($fp, 'api '.$switch_cmd); //$switch_result = event_socket::api($switch_cmd);
conference_end($fp, $name); conference_end($name);
} }
elseif ($data == "mute" || $data == "unmute" || $data == "mute non_moderator" || $data == "unmute non_moderator") { elseif ($data == "mute" || $data == "unmute" || $data == "mute non_moderator" || $data == "unmute non_moderator") {
$switch_result = event_socket_request($fp, 'api '.$switch_cmd); $switch_result = event_socket::api($switch_cmd);
$switch_cmd = "uuid_setvar ".$uuid. " hand_raised false"; $switch_cmd = "uuid_setvar ".$uuid. " hand_raised false";
event_socket_request($fp, 'api '.$switch_cmd); event_socket::api($switch_cmd);
} }
elseif ($data == "deaf" || $data == "undeaf" ) { elseif ($data == "deaf" || $data == "undeaf" ) {
$switch_result = event_socket_request($fp, 'api '.$switch_cmd); $switch_result = event_socket::api($switch_cmd);
} }
elseif ($data == "lock" || $data == "unlock" ) { elseif ($data == "lock" || $data == "unlock" ) {
$switch_result = event_socket_request($fp, 'api '.$switch_cmd); $switch_result = event_socket::api($switch_cmd);
} }
//echo "command: ".$switch_cmd." result: ".$switch_result."<br\n>"; //echo "command: ".$switch_cmd." result: ".$switch_result."<br\n>";
} }

View File

@ -61,8 +61,8 @@
$switch_cmd = "conference '".$conference_name."' xml_list"; $switch_cmd = "conference '".$conference_name."' xml_list";
//connect to event socket, send the command and process the results //connect to event socket, send the command and process the results
$fp = event_socket_create(); $esl = event_socket::create();
if (!$fp) { if (!$esl->is_connected()) {
$msg = "<div align='center'>".$text['message-connection']."<br /></div>"; $msg = "<div align='center'>".$text['message-connection']."<br /></div>";
echo "<div align='center'>\n"; echo "<div align='center'>\n";
echo "<table width='40%'>\n"; echo "<table width='40%'>\n";
@ -77,7 +77,7 @@
} }
else { else {
//show the content //show the content
$xml_str = trim(event_socket_request($fp, 'api '.$switch_cmd)); $xml_str = trim(event_socket::api($switch_cmd));
if (substr($xml_str, -9) == "not found") { if (substr($xml_str, -9) == "not found") {
$valid_xml = false; $valid_xml = false;
} }
@ -188,7 +188,7 @@
$caller_id_name = urldecode($caller_id_name); $caller_id_name = urldecode($caller_id_name);
$caller_id_number = $row->caller_id_number; $caller_id_number = $row->caller_id_number;
$switch_cmd = "uuid_getvar ".$uuid. " hand_raised"; $switch_cmd = "uuid_getvar ".$uuid. " hand_raised";
$hand_raised = (trim(event_socket_request($fp, 'api '.$switch_cmd)) == "true") ? "true" : "false"; $hand_raised = (trim(event_socket::api($switch_cmd)) == "true") ? "true" : "false";
//format secondsfloor(floor($fifo_duration / 60) % 60) //format secondsfloor(floor($fifo_duration / 60) % 60)
$join_time_formatted = sprintf('%02d:%02d:%02d', floor($join_time / 3600), floor(floor($join_time / 60) % 60), $join_time % 60); $join_time_formatted = sprintf('%02d:%02d:%02d', floor($join_time / 3600), floor(floor($join_time / 60) % 60), $join_time % 60);
$last_talking_formatted = sprintf('%02d:%02d:%02d', floor($last_talking / 3600), floor(floor($last_talking / 60) % 60), $last_talking % 60); $last_talking_formatted = sprintf('%02d:%02d:%02d', floor($last_talking / 3600), floor(floor($last_talking / 60) % 60), $last_talking % 60);

View File

@ -43,8 +43,8 @@
$text = $language->get(); $text = $language->get();
//show content //show content
$fp = event_socket_create(); $fp = event_socket::create();
if (!$fp) { if (!$fp->is_connected()) {
$msg = "<div align='center'>".$text['message-connection']."<br /></div>"; $msg = "<div align='center'>".$text['message-connection']."<br /></div>";
echo "<div align='center'>\n"; echo "<div align='center'>\n";
echo "<table width='40%'>\n"; echo "<table width='40%'>\n";
@ -58,7 +58,7 @@
echo "</div>\n"; echo "</div>\n";
} }
else { else {
$xml_string = trim(event_socket_request($fp, 'api conference xml_list')); $xml_string = trim(event_socket::api('conference xml_list'));
try { try {
$xml = new SimpleXMLElement($xml_string); $xml = new SimpleXMLElement($xml_string);
} }

View File

@ -65,11 +65,11 @@
} }
//create the event socket connection //create the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
// Get the SIP profiles for the user // Get the SIP profiles for the user
$command = "sofia_contact */{$user}@{$domain_name}"; $command = "sofia_contact */{$user}@{$domain_name}";
$contact_string = event_socket_request($fp, "api ".$command); $contact_string = event_socket::api($command);
// The first value in the array will be full matching text, the second one will be the array of profile matches // The first value in the array will be full matching text, the second one will be the array of profile matches
preg_match_all('/sofia\/([^,]+)\/(?:[^,]+)/', $contact_string, $matches); preg_match_all('/sofia\/([^,]+)\/(?:[^,]+)/', $contact_string, $matches);
@ -93,8 +93,8 @@
} }
//send the command //send the command
$response = event_socket_request($fp, "api {$command}"); $response = event_socket::api("{$command}");
event_socket_request($fp, "api log notice {$command}"); event_socket::api("log notice {$command}");
//prepare the response //prepare the response
$message = $text['message-command_sent']; $message = $text['message-command_sent'];
@ -105,9 +105,6 @@
//show the response //show the response
message::add($text['label-event']." ".$message, 'positive', 3500); message::add($text['label-event']." ".$message, 'positive', 3500);
} }
//close the connection
fclose($fp);
} }
//redirect the user //redirect the user

View File

@ -89,14 +89,14 @@
//get the list of applications //get the list of applications
if (empty($_SESSION['switch']['applications']) || !is_array($_SESSION['switch']['applications'])) { if (empty($_SESSION['switch']['applications']) || !is_array($_SESSION['switch']['applications'])) {
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
$result = event_socket_request($fp, 'api show application'); $result = event_socket::api('show application');
$show_applications = explode("\n\n", $result); $show_applications = explode("\n\n", $result);
$raw_applications = explode("\n", $show_applications[0]); $raw_applications = explode("\n", $show_applications[0]);
unset($result); unset($result);
unset($fp); unset($esl);
$previous_application = null; $previous_application = null;
foreach($raw_applications as $row) { foreach($raw_applications as $row) {

View File

@ -383,11 +383,11 @@
$domain_name = $database->select($sql, $parameters, 'column'); $domain_name = $database->select($sql, $parameters, 'column');
//send the message waiting status //send the message waiting status
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
//$switch_cmd .= "luarun app.lua voicemail mwi ".$voicemail_id."@".$domain_name; //$switch_cmd .= "luarun app.lua voicemail mwi ".$voicemail_id."@".$domain_name;
$switch_cmd .= "luarun app/voicemail/resources/scripts/mwi_notify.lua ".$voicemail_id." ".$domain_name." 0 0"; $switch_cmd .= "luarun app/voicemail/resources/scripts/mwi_notify.lua $voicemail_id $domain_name 0 0";
$switch_result = event_socket_request($fp, 'api '.$switch_cmd); $switch_result = event_socket::api($switch_cmd);
echo $switch_cmd."\n"; echo $switch_cmd."\n";
} }
else { else {
@ -517,7 +517,7 @@
unset($mail); unset($mail);
//save output to //save output to
//$fp = fopen(sys_get_temp_dir()."/mailer-app.log", "a"); //$esl = fopen(sys_get_temp_dir()."/mailer-app.log", "a");
//prepare the output buffers //prepare the output buffers
//ob_end_clean(); //ob_end_clean();
@ -532,7 +532,7 @@
//ob_end_clean(); //clean the buffer //ob_end_clean(); //clean the buffer
//fwrite($fp, $content); //fwrite($esl, $content);
//fclose($fp); //fclose($esl);
?> ?>

View File

@ -157,8 +157,8 @@ if (!class_exists('event_guard')) {
$cmd = "sendevent CUSTOM\n"; $cmd = "sendevent CUSTOM\n";
$cmd .= "Event-Name: CUSTOM\n"; $cmd .= "Event-Name: CUSTOM\n";
$cmd .= "Event-Subclass: event_guard:unblock\n"; $cmd .= "Event-Subclass: event_guard:unblock\n";
$fp = event_socket_create(); $esl = event_socket::create();
$switch_result = event_socket_request($fp, $cmd); $switch_result = event_socket::command($cmd);
//set message //set message
message::add($text['message-delete']); message::add($text['message-delete']);

View File

@ -780,8 +780,8 @@
//reload acl if allowed //reload acl if allowed
if (permission_exists("extension_cidr")) { if (permission_exists("extension_cidr")) {
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { event_socket_request($fp, "api reloadacl"); } if ($esl->is_connected()) { event_socket::api("reloadacl"); }
} }
//check the permissions //check the permissions

View File

@ -98,11 +98,11 @@
$switch_cmd = 'show channels as json'; $switch_cmd = 'show channels as json';
//create the event socket connection //create the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
//send the event socket command and get the array //send the event socket command and get the array
if ($fp) { if ($esl->is_connected()) {
$json = trim(event_socket_request($fp, 'api '.$switch_cmd)); $json = trim($esl->api($switch_cmd));
$results = json_decode($json, "true"); $results = json_decode($json, "true");
} }

View File

@ -212,8 +212,8 @@
if ($fax_status == 'waiting' || $fax_status == 'trying' || $fax_status == 'busy') { if ($fax_status == 'waiting' || $fax_status == 'trying' || $fax_status == 'busy') {
//create event socket handle //create event socket handle
$fp = event_socket_create(); $esl = event_socket::create();
if (!$fp) { if (!$esl->is_connected()) {
echo "Could not connect to event socket.\n"; echo "Could not connect to event socket.\n";
exit; exit;
} }
@ -297,7 +297,7 @@
//send the fax and try another route if the fax fails //send the fax and try another route if the fax fails
foreach($route_array as $route) { foreach($route_array as $route) {
$fax_command = "originate {" . $dial_string . ",fax_uri=".$route."}" . $route." &txfax('".$fax_file."')"; $fax_command = "originate {" . $dial_string . ",fax_uri=".$route."}" . $route." &txfax('".$fax_file."')";
$fax_response = event_socket_request($fp, "api " . $fax_command); $fax_response = event_socket::api($fax_command);
$response = str_replace("\n", "", $fax_response); $response = str_replace("\n", "", $fax_response);
$response = trim(str_replace("+OK", "", $response)); $response = trim(str_replace("+OK", "", $response));
if (is_uuid($response)) { if (is_uuid($response)) {
@ -311,8 +311,7 @@
echo "response: ".$response."\n"; echo "response: ".$response."\n";
} }
} }
fclose($fp);
//set the fax file name without the extension //set the fax file name without the extension
$fax_instance_id = pathinfo($fax_file, PATHINFO_FILENAME); $fax_instance_id = pathinfo($fax_file, PATHINFO_FILENAME);

View File

@ -51,38 +51,38 @@
/* /*
if ($action == "energy") { if ($action == "energy") {
//conference 3001-example.dyndns.org energy 103 //conference 3001-example.dyndns.org energy 103
$switch_result = event_socket_request($fp, 'api '.$switch_cmd); $switch_result = event_socket::api($switch_cmd);
$result_array = explode("=",$switch_result); $result_array = explode("=",$switch_result);
$tmp_value = $result_array[1]; $tmp_value = $result_array[1];
if ($direction == "up") { $tmp_value = $tmp_value + 100; } if ($direction == "up") { $tmp_value = $tmp_value + 100; }
if ($direction == "down") { $tmp_value = $tmp_value - 100; } if ($direction == "down") { $tmp_value = $tmp_value - 100; }
//echo "energy $tmp_value<br />\n"; //echo "energy $tmp_value<br />\n";
$switch_result = event_socket_request($fp, 'api '.$switch_cmd.' '.$tmp_value); $switch_result = event_socket::api($switch_cmd.' '.$tmp_value);
} }
if ($action == "volume_in") { if ($action == "volume_in") {
$switch_result = event_socket_request($fp, 'api '.$switch_cmd); $switch_result = event_socket::api($switch_cmd);
$result_array = explode("=",$switch_result); $result_array = explode("=",$switch_result);
$tmp_value = $result_array[1]; $tmp_value = $result_array[1];
if ($direction == "up") { $tmp_value = $tmp_value + 1; } if ($direction == "up") { $tmp_value = $tmp_value + 1; }
if ($direction == "down") { $tmp_value = $tmp_value - 1; } if ($direction == "down") { $tmp_value = $tmp_value - 1; }
//echo "volume $tmp_value<br />\n"; //echo "volume $tmp_value<br />\n";
$switch_result = event_socket_request($fp, 'api '.$switch_cmd.' '.$tmp_value); $switch_result = event_socket::api($switch_cmd.' '.$tmp_value);
} }
if ($action == "volume_out") { if ($action == "volume_out") {
$switch_result = event_socket_request($fp, 'api '.$switch_cmd); $switch_result = event_socket::api($switch_cmd);
$result_array = explode("=",$switch_result); $result_array = explode("=",$switch_result);
$tmp_value = $result_array[1]; $tmp_value = $result_array[1];
if ($direction == "up") { $tmp_value = $tmp_value + 1; } if ($direction == "up") { $tmp_value = $tmp_value + 1; }
if ($direction == "down") { $tmp_value = $tmp_value - 1; } if ($direction == "down") { $tmp_value = $tmp_value - 1; }
//echo "volume $tmp_value<br />\n"; //echo "volume $tmp_value<br />\n";
$switch_result = event_socket_request($fp, 'api '.$switch_cmd.' '.$tmp_value); $switch_result = event_socket::api($switch_cmd.' '.$tmp_value);
} }
*/ */
//connect to the event socket //connect to the event socket
//$fp = event_socket_create(); //$esl = event_socket::create();
//send the command over event socket //send the command over event socket
//if ($fp) { //if ($esl->is_connected()) {
// $switch_result = event_socket_request($fp, 'api '.$switch_cmd); // $switch_result = event_socket::api($switch_cmd);
//} //}
} }

View File

@ -57,8 +57,8 @@
$switch_cmd = 'fifo list_verbose '.$fifo_name.''; $switch_cmd = 'fifo list_verbose '.$fifo_name.'';
$fp = event_socket_create(); $esl = event_socket::create();
if (!$fp) { if (!$esl->is_connected()) {
$msg = "<div align='center'>Connection to Event Socket failed.<br /></div>"; $msg = "<div align='center'>Connection to Event Socket failed.<br /></div>";
echo "<div align='center'>\n"; echo "<div align='center'>\n";
echo "<table width='40%'>\n"; echo "<table width='40%'>\n";
@ -73,7 +73,7 @@
} }
else { else {
//send the api command over event socket //send the api command over event socket
$xml_str = trim(event_socket_request($fp, 'api '.$switch_cmd)); $xml_str = trim(event_socket::api($switch_cmd));
//parse the response as xml //parse the response as xml
try { try {

View File

@ -46,9 +46,9 @@
//show the list //show the list
$switch_cmd = 'fifo list'; $switch_cmd = 'fifo list';
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
$xml_str = trim(event_socket_request($fp, 'api '.$switch_cmd)); $xml_str = trim(event_socket::api($switch_cmd));
try { try {
$xml = new SimpleXMLElement($xml_str); $xml = new SimpleXMLElement($xml_str);
} }

View File

@ -143,8 +143,8 @@
save_gateway_xml(); save_gateway_xml();
//clear the cache //clear the cache
$fp = event_socket_create(); $esl = event_socket::create();
$hostname = trim(event_socket_request($fp, 'api switchname')); $hostname = trim(event_socket::api('switchname'));
$cache = new cache; $cache = new cache;
$cache->delete("configuration:sofia.conf:".$hostname); $cache->delete("configuration:sofia.conf:".$hostname);

View File

@ -227,20 +227,16 @@
save_gateway_xml(); save_gateway_xml();
//clear the cache //clear the cache
$fp = event_socket_create(); $esl = event_socket::create();
$hostname = trim(event_socket_request($fp, 'api switchname')); $hostname = trim(event_socket::api('switchname'));
$cache = new cache; $cache = new cache;
$cache->delete("configuration:sofia.conf:".$hostname); $cache->delete("configuration:sofia.conf:".$hostname);
//rescan the external profile to look for new or stopped gateways //rescan the external profile to look for new or stopped gateways
//create the event socket connection //create the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
$tmp_cmd = 'api sofia profile external rescan'; $response = event_socket::api('sofia profile external rescan');
$response = event_socket_request($fp, $tmp_cmd);
unset($tmp_cmd);
usleep(1000); usleep(1000);
//close the connection
fclose($fp);
//clear the apply settings reminder //clear the apply settings reminder
$_SESSION["reload_xml"] = false; $_SESSION["reload_xml"] = false;

View File

@ -70,15 +70,15 @@
$obj->delete($gateways); $obj->delete($gateways);
} }
case 'start': case 'start':
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp && permission_exists('gateway_edit')) { if ($esl && permission_exists('gateway_edit')) {
$obj = new gateways; $obj = new gateways;
$obj->start($gateways); $obj->start($gateways);
} }
break; break;
case 'stop': case 'stop':
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp && permission_exists('gateway_edit')) { if ($esl && permission_exists('gateway_edit')) {
$obj = new gateways; $obj = new gateways;
$obj->stop($gateways); $obj->stop($gateways);
} }
@ -90,19 +90,19 @@
} }
//connect to event socket //connect to event socket
$fp = event_socket_create(); $esl = event_socket::create();
//gateway status function //gateway status function
if (!function_exists('switch_gateway_status')) { if (!function_exists('switch_gateway_status')) {
function switch_gateway_status($gateway_uuid, $result_type = 'xml') { function switch_gateway_status($gateway_uuid, $result_type = 'xml') {
global $fp; global $esl;
if ($fp) { if ($esl->is_connected()) {
$fp = event_socket_create(); $esl = event_socket::create();
$cmd = 'api sofia xmlstatus gateway '.$gateway_uuid; $cmd = 'sofia xmlstatus gateway '.$gateway_uuid;
$response = trim(event_socket_request($fp, $cmd)); $response = trim(event_socket::api($cmd));
if ($response == "Invalid Gateway!") { if ($response == "Invalid Gateway!") {
$cmd = 'api sofia xmlstatus gateway '.strtoupper($gateway_uuid); $cmd = 'sofia xmlstatus gateway '.strtoupper($gateway_uuid);
$response = trim(event_socket_request($fp, $cmd)); $response = trim(event_socket::api($cmd));
} }
return $response; return $response;
} }
@ -267,7 +267,7 @@
echo "<th class='hide-sm-dn'>".$text['label-proxy']."</th>\n"; echo "<th class='hide-sm-dn'>".$text['label-proxy']."</th>\n";
echo th_order_by('context', $text['label-context'], $order_by, $order); echo th_order_by('context', $text['label-context'], $order_by, $order);
echo th_order_by('register', $text['label-register'], $order_by, $order); echo th_order_by('register', $text['label-register'], $order_by, $order);
if ($fp) { if ($esl->is_connected()) {
echo "<th class='hide-sm-dn'>".$text['label-status']."</th>\n"; echo "<th class='hide-sm-dn'>".$text['label-status']."</th>\n";
if (permission_exists('gateway_edit')) { if (permission_exists('gateway_edit')) {
echo "<th class='center'>".$text['label-action']."</th>\n"; echo "<th class='center'>".$text['label-action']."</th>\n";
@ -316,7 +316,7 @@
echo " <td>".escape($row["proxy"])."</td>\n"; echo " <td>".escape($row["proxy"])."</td>\n";
echo " <td>".escape($row["context"])."</td>\n"; echo " <td>".escape($row["context"])."</td>\n";
echo " <td>".ucwords(escape($row["register"]))."</td>\n"; echo " <td>".ucwords(escape($row["register"]))."</td>\n";
if ($fp) { if ($esl->is_connected()) {
if ($row["enabled"] == "true") { if ($row["enabled"] == "true") {
$response = switch_gateway_status($row["gateway_uuid"]); $response = switch_gateway_status($row["gateway_uuid"]);
if ($response == "Invalid Gateway!") { if ($response == "Invalid Gateway!") {

View File

@ -110,23 +110,23 @@ if (!class_exists('gateways')) {
if (!empty($gateways) && is_array($gateways) && @sizeof($gateways) != 0) { if (!empty($gateways) && is_array($gateways) && @sizeof($gateways) != 0) {
//create the event socket connection //create the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
//start gateways //start gateways
foreach ($gateways as $gateway_uuid => $gateway) { foreach ($gateways as $gateway_uuid => $gateway) {
if ($gateway['enabled'] == 'true') { if ($gateway['enabled'] == 'true') {
//start gateways //start gateways
foreach ($gateways as $gateway_uuid => $gateway) { foreach ($gateways as $gateway_uuid => $gateway) {
if ($gateway['enabled'] == 'true') { if ($gateway['enabled'] == 'true') {
$cmd = 'api sofia profile '.$gateway['profile'].' startgw '.$gateway_uuid; $cmd = 'sofia profile '.$gateway['profile'].' startgw '.$gateway_uuid;
$responses[$gateway_uuid]['gateway'] = $gateway['name']; $responses[$gateway_uuid]['gateway'] = $gateway['name'];
$responses[$gateway_uuid]['message'] = trim(event_socket_request($fp, $cmd)); $responses[$gateway_uuid]['message'] = trim(event_socket::api($cmd));
} }
} }
//old method used to start gateways //old method used to start gateways
//$cmd = 'api sofia profile '.$gateway['profile'].' rescan'; //$cmd = 'sofia profile '.$gateway['profile'].' rescan';
//$responses[$gateway_uuid]['gateway'] = $gateway['name']; //$responses[$gateway_uuid]['gateway'] = $gateway['name'];
//$responses[$gateway_uuid]['message'] = trim(event_socket_request($fp, $cmd)); //$responses[$gateway_uuid]['message'] = trim(event_socket::api($cmd));
} }
} }
@ -198,14 +198,14 @@ if (!class_exists('gateways')) {
if (!empty($gateways) && is_array($gateways) && @sizeof($gateways) != 0) { if (!empty($gateways) && is_array($gateways) && @sizeof($gateways) != 0) {
//create the event socket connection //create the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
//stop gateways //stop gateways
foreach ($gateways as $gateway_uuid => $gateway) { foreach ($gateways as $gateway_uuid => $gateway) {
if ($gateway['enabled'] == 'true') { if ($gateway['enabled'] == 'true') {
$cmd = 'api sofia profile '.$gateway['profile'].' killgw '.$gateway_uuid; $cmd = 'sofia profile '.$gateway['profile'].' killgw '.$gateway_uuid;
$responses[$gateway_uuid]['gateway'] = $gateway['name']; $responses[$gateway_uuid]['gateway'] = $gateway['name'];
$responses[$gateway_uuid]['message'] = trim(event_socket_request($fp, $cmd)); $responses[$gateway_uuid]['message'] = trim(event_socket::api($cmd));
} }
} }
//set message //set message
@ -274,9 +274,7 @@ if (!class_exists('gateways')) {
} }
//create the event socket connection //create the event socket connection
if (!isset($fp)) { $esl = event_socket::create();
$fp = event_socket_create();
}
//loop through gateways //loop through gateways
$x = 0; $x = 0;
@ -294,9 +292,9 @@ if (!class_exists('gateways')) {
} }
//send the api command to stop the gateway //send the api command to stop the gateway
if ($fp) { if ($esl->is_connected()) {
$cmd = 'api sofia profile '.$gateway['profile'].' killgw '.$gateway_uuid; $cmd = 'sofia profile '.$gateway['profile'].' killgw '.$gateway_uuid;
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
unset($cmd); unset($cmd);
} }
@ -320,20 +318,16 @@ if (!class_exists('gateways')) {
save_gateway_xml(); save_gateway_xml();
//clear the cache //clear the cache
if (!$fp) { $esl = event_socket::create();
$fp = event_socket_create(); if ($esl->is_connected()) {
} $hostname = trim(event_socket::api('switchname'));
if ($fp) {
$hostname = trim(event_socket_request($fp, 'api switchname'));
$cache = new cache; $cache = new cache;
$cache->delete("configuration:sofia.conf:".$hostname); $cache->delete("configuration:sofia.conf:".$hostname);
} }
//rescan the sip profile to look for new or stopped gateways //rescan the sip profile to look for new or stopped gateways
if (!$fp) { $esl = event_socket::create();
$fp = event_socket_create(); if ($esl->is_connected()) {
}
if ($fp) {
//get distinct profiles from gateways //get distinct profiles from gateways
foreach ($gateways as $gateway) { foreach ($gateways as $gateway) {
$array[] = $gateway['profile']; $array[] = $gateway['profile'];
@ -342,13 +336,8 @@ if (!class_exists('gateways')) {
//send the api command to rescan each profile //send the api command to rescan each profile
foreach ($profiles as $profile) { foreach ($profiles as $profile) {
$cmd = 'api sofia profile '.$profile.' rescan'; $response = event_socket::api("sofia profile $profile rescan");
$response = event_socket_request($fp, $cmd);
} }
unset($cmd);
//close the connection
fclose($fp);
} }
usleep(1000); usleep(1000);
@ -452,18 +441,16 @@ if (!class_exists('gateways')) {
save_gateway_xml(); save_gateway_xml();
//clear the cache //clear the cache
$fp = event_socket_create(); $esl = event_socket::create();
$hostname = trim(event_socket_request($fp, 'api switchname')); $hostname = trim(event_socket::api('switchname'));
$cache = new cache; $cache = new cache;
$cache->delete("configuration:sofia.conf:".$hostname); $cache->delete("configuration:sofia.conf:".$hostname);
//create the event socket connection //create the event socket connection
if (!$fp) { $esl = event_socket::create();
$fp = event_socket_create();
}
//rescan the sip profile to look for new or stopped gateways //rescan the sip profile to look for new or stopped gateways
if ($fp) { if ($esl->is_connected()) {
//get distinct profiles from gateways //get distinct profiles from gateways
foreach ($gateways as $gateway) { foreach ($gateways as $gateway) {
$array[] = $gateway['profile']; $array[] = $gateway['profile'];
@ -472,13 +459,8 @@ if (!class_exists('gateways')) {
//send the api command to rescan each profile //send the api command to rescan each profile
foreach ($profiles as $profile) { foreach ($profiles as $profile) {
$cmd = 'api sofia profile '.$profile.' rescan'; event_socket::api("sofia profile $profile rescan");
$response = event_socket_request($fp, $cmd);
} }
unset($cmd);
//close the connection
fclose($fp);
} }
usleep(1000); usleep(1000);
@ -585,8 +567,8 @@ if (!class_exists('gateways')) {
save_gateway_xml(); save_gateway_xml();
//clear the cache //clear the cache
$fp = event_socket_create(); $esl = event_socket::create();
$hostname = trim(event_socket_request($fp, 'api switchname')); $hostname = trim(event_socket::api('switchname'));
$cache = new cache; $cache = new cache;
$cache->delete("configuration:sofia.conf:".$hostname); $cache->delete("configuration:sofia.conf:".$hostname);

View File

@ -92,17 +92,10 @@
} }
//connect to event socket //connect to event socket
$fp = event_socket_create(); $esl = event_socket::create();
//check connection status
$esl_alive = false;
if ($fp) {
$esl_alive = true;
fclose($fp);
}
//warn if switch not running //warn if switch not running
if (!$fp) { if (!$esl->is_connected()) {
message::add($text['error-event-socket'], 'negative', 5000); message::add($text['error-event-socket'], 'negative', 5000);
} }
@ -133,7 +126,7 @@
echo "<div class='action_bar' id='action_bar'>\n"; echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['header-modules']." (".$module_count.")</b></div>\n"; echo " <div class='heading'><b>".$text['header-modules']." (".$module_count.")</b></div>\n";
echo " <div class='actions'>\n"; echo " <div class='actions'>\n";
if (permission_exists('module_edit') && $modules && $fp) { if (permission_exists('module_edit') && $modules && $esl->is_connected()) {
echo button::create(['type'=>'button','label'=>$text['button-stop'],'icon'=>$_SESSION['theme']['button_icon_stop'],'onclick'=>"modal_open('modal-stop','btn_stop');"]); echo button::create(['type'=>'button','label'=>$text['button-stop'],'icon'=>$_SESSION['theme']['button_icon_stop'],'onclick'=>"modal_open('modal-stop','btn_stop');"]);
echo button::create(['type'=>'button','label'=>$text['button-start'],'icon'=>$_SESSION['theme']['button_icon_start'],'onclick'=>"modal_open('modal-start','btn_start');"]); echo button::create(['type'=>'button','label'=>$text['button-start'],'icon'=>$_SESSION['theme']['button_icon_start'],'onclick'=>"modal_open('modal-start','btn_start');"]);
} }
@ -151,7 +144,7 @@
echo " <div style='clear: both;'></div>\n"; echo " <div style='clear: both;'></div>\n";
echo "</div>\n"; echo "</div>\n";
if (permission_exists('module_edit') && !empty($modules) && $fp) { if (permission_exists('module_edit') && !empty($modules) && $esl->is_connected()) {
echo modal::create(['id'=>'modal-stop','type'=>'general','message'=>$text['confirm-stop_modules'],'actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_stop','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('stop'); list_form_submit('form_list');"])]); echo modal::create(['id'=>'modal-stop','type'=>'general','message'=>$text['confirm-stop_modules'],'actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_stop','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('stop'); list_form_submit('form_list');"])]);
echo modal::create(['id'=>'modal-start','type'=>'general','message'=>$text['confirm-start_modules'],'actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_start','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('start'); list_form_submit('form_list');"])]); echo modal::create(['id'=>'modal-start','type'=>'general','message'=>$text['confirm-start_modules'],'actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_start','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('start'); list_form_submit('form_list');"])]);
} }
@ -171,7 +164,7 @@
echo "<table class='list'>\n"; echo "<table class='list'>\n";
function write_header($modifier) { function write_header($modifier) {
global $fp, $text, $modules, $list_row_edit_button; global $text, $modules, $list_row_edit_button;
$modifier = str_replace('/', '', $modifier); $modifier = str_replace('/', '', $modifier);
$modifier = str_replace(' ', ' ', $modifier); $modifier = str_replace(' ', ' ', $modifier);
$modifier = str_replace(' ', '_', $modifier); $modifier = str_replace(' ', '_', $modifier);
@ -185,7 +178,8 @@
} }
echo "<th>".$text['label-label']."</th>\n"; echo "<th>".$text['label-label']."</th>\n";
echo "<th class='hide-xs'>".$text['label-status']."</th>\n"; echo "<th class='hide-xs'>".$text['label-status']."</th>\n";
if ($fp) { $esl = event_socket::create();
if ($esl->is_connected()) {
echo "<th class='center'>".$text['label-action']."</th>\n"; echo "<th class='center'>".$text['label-action']."</th>\n";
} }
echo "<th class='center'>".$text['label-enabled']."</th>\n"; echo "<th class='center'>".$text['label-enabled']."</th>\n";
@ -229,7 +223,7 @@
echo escape($row['module_label']); echo escape($row['module_label']);
} }
echo " </td>\n"; echo " </td>\n";
if ($fp) { if ($esl->is_connected()) {
if ($module->active($row["module_name"])) { if ($module->active($row["module_name"])) {
echo " <td class='hide-xs'>".$text['label-running']."</td>\n"; echo " <td class='hide-xs'>".$text['label-running']."</td>\n";
if (permission_exists('module_edit')) { if (permission_exists('module_edit')) {

View File

@ -32,7 +32,7 @@ if (!class_exists('modules')) {
* declare public variables * declare public variables
*/ */
public $dir; public $dir;
public $fp; public $esl;
public $modules; public $modules;
public $msg; public $msg;
@ -65,9 +65,8 @@ if (!class_exists('modules')) {
$this->toggle_values = ['true','false']; $this->toggle_values = ['true','false'];
//get the list of active modules //get the list of active modules
$this->fp = event_socket_create(); $this->esl = event_socket::create();
$cmd = "api show modules as json"; $json = $this->esl->api("show modules as json");
$json = event_socket_request($this->fp, $cmd);
$this->active_modules = json_decode($json, true); $this->active_modules = json_decode($json, true);
} }
@ -884,15 +883,14 @@ if (!class_exists('modules')) {
if (is_array($modules) && @sizeof($modules) != 0) { if (is_array($modules) && @sizeof($modules) != 0) {
//create the event socket connection //create the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
//control modules //control modules
foreach ($modules as $module_uuid => $module) { foreach ($modules as $module_uuid => $module) {
if ($module['enabled'] == 'true') { if ($module['enabled'] == 'true') {
$cmd = 'api '.$action.' '.$module['name'];
$responses[$module_uuid]['module'] = $module['name']; $responses[$module_uuid]['module'] = $module['name'];
$responses[$module_uuid]['message'] = trim(event_socket_request($fp, $cmd)); $responses[$module_uuid]['message'] = trim(event_socket::api($action.' '.$module['name']));
} }
else { else {
$responses[$module_uuid]['module'] = $module['name']; $responses[$module_uuid]['module'] = $module['name'];
@ -970,15 +968,14 @@ if (!class_exists('modules')) {
if (is_array($array) && @sizeof($array) != 0) { if (is_array($array) && @sizeof($array) != 0) {
//create the event socket connection //create the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
//stop modules //stop modules
if ($fp) { if ($esl->is_connected()) {
foreach ($modules as $module_uuid => $module) { foreach ($modules as $module_uuid => $module) {
if ($this->active($module['name'])) { if ($this->active($module['name'])) {
$cmd = 'api unload '.$module['name'];
$responses[$module_uuid]['module'] = $module['name']; $responses[$module_uuid]['module'] = $module['name'];
$responses[$module_uuid]['message'] = trim(event_socket_request($fp, $cmd)); $responses[$module_uuid]['message'] = trim(event_socket::api('unload '.$module['name']));
} }
} }
} }
@ -1070,15 +1067,15 @@ if (!class_exists('modules')) {
unset($array); unset($array);
//create the event socket connection //create the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
//stop modules if active //stop modules if active
if ($fp) { if ($esl->is_connected()) {
foreach ($modules as $module_uuid => $module) { foreach ($modules as $module_uuid => $module) {
if ($this->active($module['name'])) { if ($this->active($module['name'])) {
$cmd = 'api unload '.$module['name']; $cmd = 'unload '.$module['name'];
$responses[$module_uuid]['module'] = $module['name']; $responses[$module_uuid]['module'] = $module['name'];
$responses[$module_uuid]['message'] = trim(event_socket_request($fp, $cmd)); $responses[$module_uuid]['message'] = trim(event_socket::api($cmd));
} }
} }
} }

View File

@ -147,15 +147,15 @@ if (!class_exists('switch_music_on_hold')) {
public function reload() { public function reload() {
//if the handle does not exist create it //if the handle does not exist create it
$fp = event_socket_create(); $esl = event_socket::create();
//if the handle still does not exist show an error message //if the handle still does not exist show an error message
if (!$fp) { if (!$esl->is_connected()) {
$msg = "<div align='center'>".$text['message-event-socket']."<br /></div>"; $msg = "<div align='center'>".$text['message-event-socket']."<br /></div>";
} }
//send the api command to check if the module exists //send the api command to check if the module exists
if ($fp) { if ($esl->is_connected()) {
$cmd = "reload mod_local_stream"; $cmd = "reload mod_local_stream";
$switch_result = event_socket_request($fp, 'api '.$cmd); $switch_result = event_socket::api($cmd);
unset($cmd); unset($cmd);
} }
} }

View File

@ -42,22 +42,20 @@
$rdr = $_GET['rdr']; $rdr = $_GET['rdr'];
//create the event socket connection //create the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
//reloadxml //reloadxml
if ($cmd == "api reloadxml") { if ($cmd == "api reloadxml") {
message::add(rtrim(event_socket_request($fp, $cmd)), 'alert'); message::add(rtrim(event_socket::command($cmd)), 'alert');
unset($cmd); unset($cmd);
} }
//reload mod_translate //reload mod_translate
if ($cmd == "api reload mod_translate") { if ($cmd == "api reload mod_translate") {
message::add(rtrim(event_socket_request($fp, $cmd)), 'alert'); message::add(rtrim(event_socket::command($cmd)), 'alert');
unset($cmd); unset($cmd);
} }
//close the connection
fclose($fp);
} }
//redirect the user //redirect the user

View File

@ -142,8 +142,8 @@ if ($domains_processed == 1) {
//save_phrases_xml(); //save_phrases_xml();
//delete the phrase from memcache //delete the phrase from memcache
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
//get phrase languages //get phrase languages
$sql = "select distinct phrase_language from v_phrases order by phrase_language asc "; $sql = "select distinct phrase_language from v_phrases order by phrase_language asc ";
$database = new database; $database = new database;
@ -158,7 +158,7 @@ if ($domains_processed == 1) {
} }
unset($sql, $result, $row); unset($sql, $result, $row);
} }
unset($fp); unset($esl);
} }

View File

@ -60,7 +60,7 @@ if (!class_exists('registrations')) {
$id = 0; $id = 0;
//create the event socket connection //create the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
//get the default settings //get the default settings
$sql = "select sip_profile_name from v_sip_profiles "; $sql = "select sip_profile_name from v_sip_profiles ";
@ -77,7 +77,7 @@ if (!class_exists('registrations')) {
//get sofia status profile information including registrations //get sofia status profile information including registrations
$cmd = "api sofia xmlstatus profile '".$field['sip_profile_name']."' reg"; $cmd = "api sofia xmlstatus profile '".$field['sip_profile_name']."' reg";
$xml_response = trim(event_socket_request($fp, $cmd)); $xml_response = trim(event_socket::command($cmd));
//show an error message //show an error message
if ($xml_response == "Invalid Profile!") { if ($xml_response == "Invalid Profile!") {
@ -269,10 +269,10 @@ if (!class_exists('registrations')) {
unset($sql); unset($sql);
//create the event socket connection //create the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
//loop through registrations //loop through registrations
if ($fp) { if ($esl->is_connected()) {
//check if registrations exist //check if registrations exist
if (is_array($registrations)) { if (is_array($registrations)) {
foreach ($registrations as $registration) { foreach ($registrations as $registration) {
@ -332,9 +332,9 @@ if (!class_exists('registrations')) {
} }
//send the api command //send the api command
if (!empty($command) && $fp) { if (!empty($command) && $esl->is_connected()) {
$response_api[$registration['user']]['command'] = event_socket_request($fp, "api ".$command); $response_api[$registration['user']]['command'] = event_socket::api($command);
$response_api[$registration['user']]['log'] = event_socket_request($fp, "api log notice ".$command); $response_api[$registration['user']]['log'] = event_socket::api("log notice $command");
} }
} }

View File

@ -154,9 +154,9 @@ if (!class_exists('sip_profiles')) {
} }
} }
if ($empty_hostname) { if ($empty_hostname) {
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
$hostnames[] = event_socket_request($fp, 'api switchname'); $hostnames[] = event_socket::api('switchname');
} }
} }
@ -237,9 +237,9 @@ if (!class_exists('sip_profiles')) {
//get system hostname if necessary //get system hostname if necessary
if (empty($sip_profile_hostname)) { if (empty($sip_profile_hostname)) {
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
$sip_profile_hostname = event_socket_request($fp, 'api switchname'); $sip_profile_hostname = event_socket::api('switchname');
} }
} }
@ -315,9 +315,9 @@ if (!class_exists('sip_profiles')) {
//get system hostname if necessary //get system hostname if necessary
if (empty($sip_profile_hostname)) { if (empty($sip_profile_hostname)) {
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
$sip_profile_hostname = event_socket_request($fp, 'api switchname'); $sip_profile_hostname = event_socket::api('switchname');
} }
} }
@ -403,9 +403,9 @@ if (!class_exists('sip_profiles')) {
} }
} }
if ($empty_hostname) { if ($empty_hostname) {
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
$hostnames[] = event_socket_request($fp, 'api switchname'); $hostnames[] = event_socket::api('switchname');
} }
} }

View File

@ -247,9 +247,9 @@
//get the hostname //get the hostname
if ($sip_profile_hostname == '') { if ($sip_profile_hostname == '') {
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
$sip_profile_hostname = event_socket_request($fp, 'api switchname'); $sip_profile_hostname = event_socket::api('switchname');
} }
} }

View File

@ -91,15 +91,15 @@
} }
//create the event socket connection //create the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
//if reloadxml then run reloadacl, reloadxml and rescan the external profile for new gateways //if reloadxml then run reloadacl, reloadxml and rescan the external profile for new gateways
if (isset($command)) { if (isset($command)) {
//clear the apply settings reminder //clear the apply settings reminder
$_SESSION["reload_xml"] = false; $_SESSION["reload_xml"] = false;
//run the command //run the command
$result = rtrim(event_socket_request($fp, 'api '.$command)); $result = rtrim(event_socket::api($command));
} }
//sofia profile //sofia profile
@ -109,9 +109,6 @@
else if (!empty($result)) { else if (!empty($result)) {
message::add($result, 'alert'); message::add($result, 'alert');
} }
//close the connection
fclose($fp);
} }
//redirect the user //redirect the user

View File

@ -43,8 +43,8 @@
$text = $language->get(); $text = $language->get();
//create event socket //create event socket
$fp = event_socket_create(); $esl = event_socket::create();
if (!$fp) { if (!$esl->is_connected()) {
message::add($text['error-event-socket'], 'negative', 5000); message::add($text['error-event-socket'], 'negative', 5000);
} }
@ -57,8 +57,8 @@
unset($sql); unset($sql);
//get the sip profiles //get the sip profiles
if ($fp) { if ($esl->is_connected()) {
$hostname = trim(event_socket_request($fp, 'api switchname')); $hostname = trim(event_socket::api('switchname'));
} }
$sql = "select sip_profile_uuid, sip_profile_name from v_sip_profiles "; $sql = "select sip_profile_uuid, sip_profile_name from v_sip_profiles ";
$sql .= "where sip_profile_enabled = 'true' "; $sql .= "where sip_profile_enabled = 'true' ";
@ -80,8 +80,8 @@
//get status //get status
try { try {
$cmd = "api sofia xmlstatus"; $cmd = "sofia xmlstatus";
$xml_response = trim(event_socket_request($fp, $cmd)); $xml_response = trim(event_socket::api($cmd));
if ($xml_response) { if ($xml_response) {
$xml = new SimpleXMLElement($xml_response); $xml = new SimpleXMLElement($xml_response);
} }
@ -91,8 +91,8 @@
message::add($message, 'negative', 5000); message::add($message, 'negative', 5000);
} }
try { try {
$cmd = "api sofia xmlstatus gateway"; $cmd = "sofia xmlstatus gateway";
$xml_response = trim(event_socket_request($fp, $cmd)); $xml_response = trim(event_socket::api($cmd));
if ($xml_response) { if ($xml_response) {
$xml_gateways = new SimpleXMLElement($xml_response); $xml_gateways = new SimpleXMLElement($xml_response);
} }
@ -221,10 +221,9 @@
} }
//sofia status profile //sofia status profile
if ($fp && permission_exists('system_status_sofia_status_profile')) { if ($esl && permission_exists('system_status_sofia_status_profile')) {
foreach ($sip_profiles as $sip_profile_name => $sip_profile_uuid) { foreach ($sip_profiles as $sip_profile_name => $sip_profile_uuid) {
$cmd = "api sofia xmlstatus profile ".$sip_profile_name.""; $xml_response = trim(event_socket::api("sofia xmlstatus profile $sip_profile_name"));
$xml_response = trim(event_socket_request($fp, $cmd));
if ($xml_response == "Invalid Profile!") { if ($xml_response == "Invalid Profile!") {
$xml_response = "<error_msg>Invalid Profile!</error_msg>"; $xml_response = "<error_msg>Invalid Profile!</error_msg>";
$profile_state = 'stopped'; $profile_state = 'stopped';
@ -309,16 +308,14 @@
} }
//status //status
if ($fp && permission_exists('sip_status_switch_status')) { if ($esl->is_connected() && permission_exists('sip_status_switch_status')) {
$cmd = "api status"; $response = event_socket::api("status");
$response = event_socket_request($fp, $cmd);
echo "<b><a href='javascript:void(0);' onclick=\"$('#status').slideToggle();\">".$text['title-status']."</a></b>\n"; echo "<b><a href='javascript:void(0);' onclick=\"$('#status').slideToggle();\">".$text['title-status']."</a></b>\n";
echo "<div id='status' style='margin-top: 20px; font-size: 9pt;'>"; echo "<div id='status' style='margin-top: 20px; font-size: 9pt;'>";
echo "<pre>"; echo "<pre>";
echo trim(escape($response)); echo trim(escape($response));
echo "</pre>\n"; echo "</pre>\n";
echo "</div>"; echo "</div>";
fclose($fp);
} }
//include the footer //include the footer

View File

@ -36,10 +36,7 @@ if (!class_exists('presence')) {
* @var string $presence_id * @var string $presence_id
*/ */
public function active($presence_id) { public function active($presence_id) {
$fp = event_socket_create(); $json = event_socket::api('show calls as json');
$cmd = 'show calls as json';
$json = event_socket_request($fp, 'api '.$cmd);
unset($fp);
$call_array = json_decode($json, true); $call_array = json_decode($json, true);
if (isset($call_array['rows'])) { if (isset($call_array['rows'])) {
$x = 0; $x = 0;
@ -65,10 +62,7 @@ if (!class_exists('presence')) {
* show presence * show presence
*/ */
public function show() { public function show() {
$fp = event_socket_create(); $json = event_socket::api('show calls as json');
$cmd = 'show calls as json';
$json = event_socket_request($fp, 'api '.$cmd);
unset($fp);
$call_array = json_decode($json, true); $call_array = json_decode($json, true);
if (isset($call_array['rows'])) { if (isset($call_array['rows'])) {
$x = 0; $x = 0;

View File

@ -1,7 +1,7 @@
<configuration name="event_socket.conf" description="Socket Client"> <configuration name="event_socket.conf" description="Socket Client">
<settings> <settings>
<param name="nat-map" value="false"/> <param name="nat-map" value="false"/>
<param name="listen-ip" value="127.0.0.1"/> <param name="listen-ip" value="0.0.0.0"/>
<param name="listen-port" value="8021"/> <param name="listen-port" value="8021"/>
<param name="password" value="ClueCon"/> <param name="password" value="ClueCon"/>
<!--<param name="apply-inbound-acl" value="lan"/>--> <!--<param name="apply-inbound-acl" value="lan"/>-->

View File

@ -26,19 +26,19 @@
$row_style["1"] = "row_style1"; $row_style["1"] = "row_style1";
//connect to event socket //connect to event socket
$fp = event_socket_create(); $esl = event_socket::create();
//switch version //switch version
if (permission_exists('switch_version') && $fp) { if (permission_exists('switch_version') && $esl->is_connected()) {
$switch_version = event_socket_request($fp, 'api version'); $switch_version = event_socket::api('version');
preg_match("/FreeSWITCH Version (\d+\.\d+\.\d+(?:\.\d+)?).*\(.*?(\d+\w+)\s*\)/", $switch_version, $matches); preg_match("/FreeSWITCH Version (\d+\.\d+\.\d+(?:\.\d+)?).*\(.*?(\d+\w+)\s*\)/", $switch_version, $matches);
$switch_version = $matches[1]; $switch_version = $matches[1];
$switch_bits = $matches[2]; $switch_bits = $matches[2];
} }
//switch uptime //switch uptime
if (permission_exists('switch_uptime') && $fp) { if (permission_exists('switch_uptime') && $esl->is_connected()) {
$tmp = event_socket_request($fp, 'api status'); $tmp = event_socket::api('status');
$tmp = explode("\n", $tmp); $tmp = explode("\n", $tmp);
$tmp = $tmp[0]; $tmp = $tmp[0];
$tmp = explode(' ', $tmp); $tmp = explode(' ', $tmp);
@ -55,8 +55,8 @@
//channel count //channel count
$channels = ''; $channels = '';
$tr_link_channels = ''; $tr_link_channels = '';
if (permission_exists('switch_channels') && $fp) { if (permission_exists('switch_channels') && $esl->is_connected()) {
$tmp = event_socket_request($fp, 'api status'); $tmp = event_socket::api('status');
$matches = Array(); $matches = Array();
preg_match("/(\d+)\s+session\(s\)\s+\-\speak/", $tmp, $matches); preg_match("/(\d+)\s+session\(s\)\s+\-\speak/", $tmp, $matches);
$channels = $matches[1] ? $matches[1] : 0; $channels = $matches[1] ? $matches[1] : 0;

View File

@ -38,7 +38,7 @@
$cpu_cores = trim($result); $cpu_cores = trim($result);
} }
if (stristr(PHP_OS, 'Linux')) { if (stristr(PHP_OS, 'Linux')) {
$result = trim(shell_exec("grep -P '^processor' /proc/cpuinfo")); $result = @trim(shell_exec("grep -P '^processor' /proc/cpuinfo"));
$cpu_cores = count(explode("\n", $result)); $cpu_cores = count(explode("\n", $result));
} }
if ($cpu_cores > 1) { $percent_cpu = $percent_cpu / $cpu_cores; } if ($cpu_cores > 1) { $percent_cpu = $percent_cpu / $cpu_cores; }

View File

@ -187,8 +187,9 @@
} }
//channel count //channel count
if (isset($fp)) { $esl = event_socket::create();
$tmp = event_socket_request($fp, 'api status'); if ($esl->is_connected()) {
$tmp = event_socket::api('status');
$matches = Array(); $matches = Array();
preg_match("/(\d+)\s+session\(s\)\s+\-\speak/", $tmp, $matches); preg_match("/(\d+)\s+session\(s\)\s+\-\speak/", $tmp, $matches);
$channels = !empty($matches[1]) ? $matches[1] : 0; $channels = !empty($matches[1]) ? $matches[1] : 0;
@ -201,7 +202,7 @@
} }
//registration count //registration count
if (isset($fp) && file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/registrations/")) { if ($esl->is_connected() && file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/registrations/")) {
$registration = new registrations; $registration = new registrations;
$registrations = $registration->count(); $registrations = $registration->count();
$tr_link = "href='".PROJECT_PATH."/app/registrations/registrations.php'"; $tr_link = "href='".PROJECT_PATH."/app/registrations/registrations.php'";

View File

@ -144,9 +144,9 @@
echo " </td>\n"; echo " </td>\n";
echo "</tr>\n"; echo "</tr>\n";
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
$switch_version = event_socket_request($fp, 'api version'); $switch_version = event_socket::api('version');
preg_match("/FreeSWITCH Version (\d+\.\d+\.\d+(?:\.\d+)?).*\(.*?(\d+\w+)\s*\)/", $switch_version, $matches); preg_match("/FreeSWITCH Version (\d+\.\d+\.\d+(?:\.\d+)?).*\(.*?(\d+\w+)\s*\)/", $switch_version, $matches);
$switch_version = $matches[1]; $switch_version = $matches[1];
$switch_bits = $matches[2]; $switch_bits = $matches[2];
@ -544,10 +544,10 @@
$memcache_fail = false; $memcache_fail = false;
$mod = new modules; $mod = new modules;
if ($mod -> active("mod_memcache")) { if ($mod -> active("mod_memcache")) {
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
$switch_cmd = "memcache status verbose"; $switch_cmd = "memcache status verbose";
$switch_result = event_socket_request($fp, 'api '.$switch_cmd); $switch_result = event_socket::api($switch_cmd);
$memcache_lines = preg_split('/\n/', $switch_result); $memcache_lines = preg_split('/\n/', $switch_result);
foreach($memcache_lines as $memcache_line) { foreach($memcache_lines as $memcache_line) {
if (!empty(trim($memcache_line)) > 0 && substr_count($memcache_line, ': ')) { if (!empty(trim($memcache_line)) > 0 && substr_count($memcache_line, ': ')) {

View File

@ -595,10 +595,10 @@
//send the message waiting status //send the message waiting status
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
$switch_cmd = "luarun app.lua voicemail mwi ".$this->voicemail_id."@".$_SESSION['domain_name']; $switch_cmd = "luarun app.lua voicemail mwi ".$this->voicemail_id."@".$_SESSION['domain_name'];
$switch_result = event_socket_request($fp, 'api '.$switch_cmd); $switch_result = event_socket::api($switch_cmd);
} }
} }
@ -843,7 +843,7 @@
* range download method (helps safari play audio sources) * range download method (helps safari play audio sources)
*/ */
private function range_download($file) { private function range_download($file) {
$fp = @fopen($file, 'rb'); $esl = @fopen($file, 'rb');
$size = filesize($file); // File size $size = filesize($file); // File size
$length = $size; // Content length $length = $size; // Content length
@ -909,7 +909,7 @@
$start = $c_start; $start = $c_start;
$end = $c_end; $end = $c_end;
$length = $end - $start + 1; // Calculate new content length $length = $end - $start + 1; // Calculate new content length
fseek($fp, $start); fseek($esl, $start);
header('HTTP/1.1 206 Partial Content'); header('HTTP/1.1 206 Partial Content');
} }
// Notify the client the byte range we'll be outputting // Notify the client the byte range we'll be outputting
@ -918,14 +918,14 @@
// Start buffered download // Start buffered download
$buffer = 1024 * 8; $buffer = 1024 * 8;
while(!feof($fp) && ($p = ftell($fp)) <= $end) { while(!feof($esl) && ($p = ftell($esl)) <= $end) {
if ($p + $buffer > $end) { if ($p + $buffer > $end) {
// In case we're only outputtin a chunk, make sure we don't // In case we're only outputtin a chunk, make sure we don't
// read past the length // read past the length
$buffer = $end - $p + 1; $buffer = $end - $p + 1;
} }
set_time_limit(0); // Reset time limit for big files set_time_limit(0); // Reset time limit for big files
echo fread($fp, $buffer); echo fread($esl, $buffer);
flush(); // Free up memory. Otherwise large files will trigger PHP's memory limit. flush(); // Free up memory. Otherwise large files will trigger PHP's memory limit.
} }

View File

@ -74,9 +74,9 @@ Mark J Crane <markjcrane@fusionpbx.com>
$web_server = $_SERVER['SERVER_SOFTWARE']; $web_server = $_SERVER['SERVER_SOFTWARE'];
// switch version // switch version
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp) { if ($esl->is_connected()) {
$switch_result = event_socket_request($fp, 'api version'); $switch_result = event_socket::api('version');
} }
$switch_ver = trim($switch_result); $switch_ver = trim($switch_result);

View File

@ -573,16 +573,16 @@
//update the user_status //update the user_status
if (isset($call_center_agent_uuid) && is_uuid($call_center_agent_uuid) && !empty($user_status)) { if (isset($call_center_agent_uuid) && is_uuid($call_center_agent_uuid) && !empty($user_status)) {
$fp = event_socket_create(); $esl = event_socket::create();
$switch_cmd = "callcenter_config agent set status ".$call_center_agent_uuid." '".$user_status."'"; $switch_cmd = "callcenter_config agent set status ".$call_center_agent_uuid." '".$user_status."'";
$switch_result = event_socket_request($fp, 'api '.$switch_cmd); $switch_result = event_socket::api($switch_cmd);
} }
//update the user state //update the user state
if (isset($call_center_agent_uuid) && is_uuid($call_center_agent_uuid)) { if (isset($call_center_agent_uuid) && is_uuid($call_center_agent_uuid)) {
$fp = event_socket_create(); $esl = event_socket::create();
$cmd = "api callcenter_config agent set state ".$call_center_agent_uuid." Waiting"; $cmd = "callcenter_config agent set state ".$call_center_agent_uuid." Waiting";
$response = event_socket_request($fp, $cmd); $response = event_socket::api($cmd);
} }
} }

View File

@ -30,17 +30,15 @@ class cache {
//save to memcache //save to memcache
if ($_SESSION['cache']['method']['text'] == "memcache") { if ($_SESSION['cache']['method']['text'] == "memcache") {
//connect to event socket //connect to event socket
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp === false) { if ($esl === false) {
return false; return false;
} }
//run the memcache //run the memcache
$command = "memcache set ".$key." ".$value; $command = "memcache set ".$key." ".$value;
$result = event_socket_request($fp, 'api '.$command); $result = event_socket::api($command);
//close event socket
fclose($fp);
} }
//save to the file cache //save to the file cache
@ -64,8 +62,8 @@ class cache {
//cache method memcache //cache method memcache
if ($_SESSION['cache']['method']['text'] == "memcache") { if ($_SESSION['cache']['method']['text'] == "memcache") {
// connect to event socket // connect to event socket
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp === false) { if (!$esl->is_connected()) {
return false; return false;
} }
@ -73,10 +71,8 @@ class cache {
//run the memcache //run the memcache
$command = "memcache get ".$key; $command = "memcache get ".$key;
$result = event_socket_request($fp, 'api '.$command); $result = event_socket::api($command);
//close event socket
fclose($fp);
} }
//get the file cache //get the file cache
@ -106,8 +102,8 @@ class cache {
//cache method memcache //cache method memcache
if (!empty($_SESSION['cache']['method']['text']) && $_SESSION['cache']['method']['text'] == "memcache") { if (!empty($_SESSION['cache']['method']['text']) && $_SESSION['cache']['method']['text'] == "memcache") {
//connect to event socket //connect to event socket
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp === false) { if ($esl === false) {
return false; return false;
} }
@ -117,14 +113,12 @@ class cache {
$event .= "Event-Subclass: fusion::memcache\n"; $event .= "Event-Subclass: fusion::memcache\n";
$event .= "API-Command: memcache\n"; $event .= "API-Command: memcache\n";
$event .= "API-Command-Argument: delete ".$key."\n"; $event .= "API-Command-Argument: delete ".$key."\n";
event_socket_request($fp, $event); event_socket::command($event);
//run the memcache //run the memcache
$command = "memcache delete ".$key; $command = "memcache delete ".$key;
$result = event_socket_request($fp, 'api '.$command); $result = event_socket::api($command);
//close event socket
fclose($fp);
} }
//cache method file //cache method file
@ -133,8 +127,8 @@ class cache {
$key = str_replace(":", ".", $key); $key = str_replace(":", ".", $key);
//connect to event socket //connect to event socket
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp === false) { if ($esl === false) {
return false; return false;
} }
@ -144,7 +138,7 @@ class cache {
$event .= "Event-Subclass: fusion::file\n"; $event .= "Event-Subclass: fusion::file\n";
$event .= "API-Command: cache\n"; $event .= "API-Command: cache\n";
$event .= "API-Command-Argument: delete ".$key."\n"; $event .= "API-Command-Argument: delete ".$key."\n";
event_socket_request($fp, $event); event_socket::command($event);
//remove the local files //remove the local files
foreach (glob($_SESSION['cache']['location']['text'] . "/" . $key) as $file) { foreach (glob($_SESSION['cache']['location']['text'] . "/" . $key) as $file) {
@ -174,8 +168,8 @@ class cache {
//cache method memcache //cache method memcache
if ($_SESSION['cache']['method']['text'] == "memcache") { if ($_SESSION['cache']['method']['text'] == "memcache") {
// connect to event socket // connect to event socket
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp === false) { if ($esl === false) {
return false; return false;
} }
@ -185,21 +179,19 @@ class cache {
$event .= "Event-Subclass: fusion::memcache\n"; $event .= "Event-Subclass: fusion::memcache\n";
$event .= "API-Command: memcache\n"; $event .= "API-Command: memcache\n";
$event .= "API-Command-Argument: flush\n"; $event .= "API-Command-Argument: flush\n";
event_socket_request($fp, $event); event_socket::command($event);
//run the memcache //run the memcache
$command = "memcache flush"; $command = "memcache flush";
$result = event_socket_request($fp, 'api '.$command); $result = event_socket::api($command);
//close event socket
fclose($fp);
} }
//cache method file //cache method file
if ($_SESSION['cache']['method']['text'] == "file") { if ($_SESSION['cache']['method']['text'] == "file") {
// connect to event socket // connect to event socket
$fp = event_socket_create(); $esl = event_socket::create();
if ($fp === false) { if ($esl === false) {
return false; return false;
} }
@ -209,7 +201,7 @@ class cache {
$event .= "Event-Subclass: fusion::file\n"; $event .= "Event-Subclass: fusion::file\n";
$event .= "API-Command: cache\n"; $event .= "API-Command: cache\n";
$event .= "API-Command-Argument: flush\n"; $event .= "API-Command-Argument: flush\n";
event_socket_request($fp, $event); event_socket::command($event);
//remove the cache //remove the cache
recursive_delete($_SESSION['cache']['location']['text']); recursive_delete($_SESSION['cache']['location']['text']);

View File

@ -42,26 +42,43 @@ class buffer {
//print($b->read_line()); //print($b->read_line());
//print($b->read_line()); //print($b->read_line());
/**
* Subscribes to the event socket of the FreeSWITCH (c) Event Socket Server
* @depends buffer::class
*/
class event_socket { class event_socket {
private $buffer; private $buffer;
public $fp; public $fp;
private static $socket = null;
/**
* Create a new connection to the socket
* @param resource|false $fp
*/
public function __construct($fp = false) { public function __construct($fp = false) {
$this->buffer = new buffer; $this->buffer = new buffer;
$this->fp = $fp; $this->fp = $fp;
} }
/**
* Ensures a closed connection on destruction of object
*/
public function __destructor() { public function __destructor() {
$this->close(); $this->close();
} }
/**
* Read the event body from the socket
* @return string|false Content body or false if not connected or empty message
* @depends buffer::class
*/
public function read_event() { public function read_event() {
if (!$this->fp) { if (!$this->connected()) {
return false; return false;
} }
$b = $this->buffer; $b = $this->buffer;
$content_length = 0;
$content = array(); $content = array();
while (true) { while (true) {
@ -87,7 +104,7 @@ class event_socket {
$str = $b->read_n($content['Content-Length']); $str = $b->read_n($content['Content-Length']);
if ($str === false) { if ($str === false) {
while (true) { while (true) {
if (feof($this->fp)) { if (!$this->connected()) {
break; break;
} }
@ -107,69 +124,67 @@ class event_socket {
return $content; return $content;
} }
public function connect($host = null, $port = null, $password = null) { /**
* Connect to the FreeSWITCH (c) event socket server
* <p>If the configuration is not loaded then the defaults of
* host 127.0.0.1, port of 8021, and default password of ClueCon will be used</p>
* @global array $conf Global configuration used in fusionpbx/config.conf
* @param string $host Host or IP address of FreeSWITCH event socket server. Defaults to 127.0.0.1
* @param string $port Port number of FreeSWITCH event socket server. Defaults to 8021
* @param string $password Password of FreeSWITCH event socket server. Defaults to ClueCon
* @param int $timeout_microseconds Number of microseconds before timeout is triggered on socket
* @return bool Returns true on success or false if not connected
*/
public function connect($host = null, $port = null, $password = null, $timeout_microseconds = 30000) {
global $conf; global $conf;
//get the database connection settings //set the event socket variables in the order of
if (empty($host) && empty($conf['event_socket.ip_address'])) { //param passed to func, conf setting, old conf setting, default
$host = '127.0.0.1'; $host = $host ?? $conf['switch.event_socket.host'] ?? $conf['event_socket.ip_address'] ?? '127.0.0.1';
} $port = $port ?? $conf['switch.event_socket.port'] ?? $conf['event_socket.port'] ?? '8021';
if (empty($port) && empty($conf['event_socket.port'])) { $password = $password ?? $conf['switch.event_socket.password'] ?? $conf['event_socket.password'] ?? 'ClueCon';
$port = '8021';
}
if (empty($password) && empty($conf['switch.event_socket.password'])) {
$password = 'ClueCon';
}
//set the event socket variables
if (!empty($conf['switch.event_socket.host'])) {
$host = $conf['switch.event_socket.host'];
}
if (!empty($conf['switch.event_socket.port'])) {
$port = $conf['switch.event_socket.port'];
}
if (!empty($conf['switch.event_socket.password'])) {
$password = $conf['switch.event_socket.password'];
}
//open the socket connection //open the socket connection
$fp = @fsockopen($host, $port, $errno, $errdesc, 3); $this->fp = @fsockopen($host, $port, $errno, $errdesc, 3);
if (!$fp) { if (!$this->connected()) {
return false; return false;
} }
socket_set_timeout($fp, 0, 30000);
socket_set_blocking($fp, true); socket_set_timeout($this->fp, 0, $timeout_microseconds);
$this->fp = $fp; socket_set_blocking($this->fp, true);
//wait auth request and send response //wait auth request and send response
while (!feof($fp)) { while ($this->connected()) {
$event = $this->read_event(); $event = $this->read_event();
if(@$event['Content-Type'] == 'auth/request'){ if(($event['Content-Type'] ?? '') === 'auth/request'){
fputs($fp, "auth $password\n\n"); fputs($this->fp, "auth $password\n\n");
break; break;
}
} }
}
//wait auth response //wait auth response
while (!feof($fp)) { while ($this->connected()) {
$event = $this->read_event(); $event = $this->read_event();
if (@$event['Content-Type'] == 'command/reply') { if (($event['Content-Type'] ?? '') === 'command/reply') {
if (@$event['Reply-Text'] == '+OK accepted') { if (($event['Reply-Text'] ?? '') === '+OK accepted') {
return $fp; break;
} } else {
$this->fp = false; $this->close();
fclose($fp);
return false;
} }
} }
}
return false; return $this->connected();
} }
public function connected() { /**
if (!$this->fp) { * Tests if connected to the FreeSWITCH Event Socket Server
* @return bool Returns true when connected or false when not connected
*/
public function connected(): bool {
if (!is_resource($this->fp)) {
//not connected to the socket //not connected to the socket
return false; return false;
} }
@ -177,14 +192,27 @@ class event_socket {
//not connected to the socket //not connected to the socket
return false; return false;
} }
else { //connected to the socket
//connected to the socket return true;
return true;
}
} }
/**
* alias of connected
* @return bool
*/
public function is_connected(): bool {
return $this->connected();
}
/**
* Send a command to the FreeSWITCH Event Socket Server
* <p>Multi-line commands can be sent when separated by '\n'</p>
* @param string $cmd Command to send through the socket
* @return mixed Returns the response from FreeSWITCH or false if not connected
* @depends read_event()
*/
public function request($cmd) { public function request($cmd) {
if (!$this->fp) { if (!$this->connected()) {
return false; return false;
} }
@ -202,42 +230,90 @@ class event_socket {
return $event; return $event;
} }
/**
* Sets the current socket resource returning the old
* @param resource|bool $fp Sets the current FreeSWITCH resource
* @return mixed Returns the original resource
* @deprecated since version 5.1
*/
public function reset_fp($fp = false){ public function reset_fp($fp = false){
$tmp = $this->fp; $tmp = $this->fp;
$this->fp = $fp; $this->fp = $fp;
return $tmp; return $tmp;
} }
/**
* Closes the socket
*/
public function close() { public function close() {
if ($this->fp) { //fp is public access so ensure it is a resource before closing it
fclose($this->fp); if (is_resource($this->fp)) {
$this->fp = false; try {
fclose($this->fp);
} catch (\Exception $t) {
//report it
trigger_error("event_socket failed to close socket", E_USER_WARNING);
}
} else {
//log an error if fp was set to something other than a resource
if ($this->fp !== false) {
trigger_error("event_socket not a resource", E_USER_ERROR);
}
} }
//force fp to be false
$this->fp = false;
}
/**
* Create uses a singleton design to return a connected socket to the FreeSWITCH Event Socket Layer
* @global array $conf Global configuration used in config.conf
* @param string $host Host or IP address of FreeSWITCH event socket server. Defaults to 127.0.0.1
* @param string $port Port number of FreeSWITCH event socket server. Defaults to 8021
* @param string $password Password of FreeSWITCH event socket server. Defaults to ClueCon
* @param int $timeout_microseconds Number of microseconds before timeout is triggered on socket
* @return self
*/
public static function create($host = null, $port = null, $password = null, $timeout_microseconds = 30000): self {
//create the event socket object
if (self::$socket === null) {
self::$socket = new event_socket();
}
//attempt to connect it
if(!self::$socket->connected()) {
self::$socket->connect($host, $port, $password, $timeout_microseconds);
}
return self::$socket;
}
/**
* Sends a command on the socket blocking for a response
* @param string $cmd
* @return string|false Response from server or false if failed
*/
public static function command(string $cmd) {
return self::create()->request($cmd);
}
/**
* Sends an API command on the socket
* @param string $api_cmd
* @return string|false Response from server or false if failed
*/
public static function api(string $api_cmd) {
return self::command('api '.$api_cmd);
}
/**
* Sends an API command to FreeSWITCH using asynchronous (non-blocking) mode
* @param string $cmd API command to send
* @returns string $job_id the Job ID for tracking completion status
*/
public static function async(string $cmd) {
return self::command('bgapi '.$cmd);
} }
} }
/* // $esl = event_socket::create('127.0.0.1', 8021, 'ClueCon');
function event_socket_create($host, $port, $password) {
$esl = new event_socket;
if ($esl->connect($host, $port, $password)) {
return $esl->reset_fp();
}
return false;
}
function event_socket_request($fp, $cmd) {
$esl = new event_socket($fp);
$result = $esl->request($cmd);
$esl->reset_fp();
return $result;
}
*/
// $esl = new event_socket;
// $esl->connect('127.0.0.1', 8021, 'ClueCon');
// print($esl->request('api sofia status')); // print($esl->request('api sofia status'));
// $fp = event_socket_create('127.0.0.1', 8021, 'ClueCon');
// print(event_socket_request($fp, 'api sofia status'));
?> ?>

View File

@ -51,9 +51,8 @@ if (!class_exists('switch_settings')) {
} }
//connect to event socket //connect to event socket
$esl = new event_socket; $esl = event_socket::create($this->event_socket_ip_address, $this->event_socket_port, $this->event_socket_password);
$esl->connect($this->event_socket_ip_address, $this->event_socket_port, $this->event_socket_password);
//run the api command //run the api command
$result = $esl->request('api global_getvar'); $result = $esl->request('api global_getvar');

File diff suppressed because it is too large Load Diff

View File

@ -35,9 +35,9 @@
} }
else { else {
//create the event socket connection //create the event socket connection
$fp = event_socket_create(); $esl = event_socket::create();
//reload the access control list this also runs reloadxml //reload the access control list this also runs reloadxml
$response = event_socket_request($fp, 'api reloadxml'); $response = event_socket::api('reloadxml');
$_SESSION["reload_xml"] = ''; $_SESSION["reload_xml"] = '';
unset($_SESSION["reload_xml"]); unset($_SESSION["reload_xml"]);
usleep(500); usleep(500);

View File

@ -29,29 +29,39 @@
//includes files //includes files
require_once __DIR__ . "/require.php"; require_once __DIR__ . "/require.php";
/**
* Returns an fp connector from an event socket.
* This has been replaced with event_socket::create() method and using the
* socket directly is preferred.
* @param string $host
* @param string $port
* @param string $password
* @return true Returns true if successful connection and false if there is a failure
* @deprecated since version 5.1.11
*/
function event_socket_create($host = null, $port = null, $password = null) { function event_socket_create($host = null, $port = null, $password = null) {
$esl = new event_socket; $esl = event_socket::create($host = null, $port = null, $password = null);
if ($esl->connect($host, $port, $password)) { return ($esl !== false);
return $esl->reset_fp();
}
return false;
} }
/**
* Makes a request on the event socket
* @param null $fp No longer used
* @param string $cmd Command to use
* @return string|false Response of the server or false if failed
*/
function event_socket_request($fp, $cmd) { function event_socket_request($fp, $cmd) {
$esl = new event_socket($fp); return event_socket::command($cmd);
$result = $esl->request($cmd);
$esl->reset_fp();
return $result;
} }
/**
* Makes a request on the event socket
* @param type $fp
* @param type $cmd
* @return type
*/
function event_socket_request_cmd($cmd) { function event_socket_request_cmd($cmd) {
$esl = new event_socket; return event_socket::command($cmd);
if (!$esl->connect()) {
return false;
}
$response = $esl->request($cmd);
$esl->close();
return $response;
} }
function remove_config_from_cache($name) { function remove_config_from_cache($name) {