From 9b0448a09103e96b13964e52d9f9c0b9ee0ed273 Mon Sep 17 00:00:00 2001 From: James Rose Date: Fri, 16 Nov 2012 22:25:49 +0000 Subject: [PATCH] Add sip_uri dialing, and a patch so that you can dial with thunderbird addressbook. see http://wiki.fusionpbx.com/index.php?title=Click_to_Call#Integrating_with_Thunderbird.27s_Address_book --- app/click_to_call/click_to_call.php | 729 ++++++++++++++-------------- 1 file changed, 367 insertions(+), 362 deletions(-) diff --git a/app/click_to_call/click_to_call.php b/app/click_to_call/click_to_call.php index 13591374c5..c4715ed99e 100644 --- a/app/click_to_call/click_to_call.php +++ b/app/click_to_call/click_to_call.php @@ -1,362 +1,367 @@ - 0) { - $context = $_SESSION['context']; - } - else { - $context = 'default'; - } - - //translate ringback - switch ($ringback) { - case "us-ring": - $ringback_value = "\'%(2000,4000,440.0,480.0)\'"; - break; - case "uk-ring": - $ringback_value = "\'%(400,200,400,450);%(400,2200,400,450)\'"; - break; - case "fr-ring": - $ringback_value = "\'%(1500,3500,440.0,0.0)\'"; - break; - case "rs-ring": - $ringback_value = "\'%(1000,4000,425.0,0.0)\'"; - break; - case "music": - $ringback_value = "\'local_stream://moh\'"; - break; - default: - $ringback = 'us-ring'; - $ringback_value = "\'%(2000,4000,440.0,480.0)\'"; - } - - //source should see the destination caller id - if (strlen($src) < 7) { - $source = "{".$sip_auto_answer."origination_caller_id_name='$src_cid_name',origination_caller_id_number=$src_cid_number,instant_ringback=true,ringback=$ringback_value,presence_id=$src@".$_SESSION['domains'][$domain_uuid]['domain_name'].",call_direction=outbound}sofia/internal/$src%".$_SESSION['domains'][$domain_uuid]['domain_name']; - } - else { - $bridge_array = outbound_route_to_bridge ($_SESSION['domain_uuid'], $src); - $source = "{origination_caller_id_name='$src_cid_name',origination_caller_id_number=$src_cid_number,instant_ringback=true,ringback=$ringback_value,presence_id=$src@".$_SESSION['domains'][$domain_uuid]['domain_name'].",call_direction=outbound}".$bridge_array[0]; - } - - //destination needs to see the source caller id - if (strlen($dest) < 7) { - $switch_cmd = "api originate $source &transfer('".$dest." XML ".$context."')"; - } - else { - if (strlen($src) < 7) { - if (strlen($dest_cid_number) == 0) { - //get the caller id from the extension caller id comes from the extension (the source number) - $sql = "select * from v_extensions "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and extension = '$src' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - 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 - } - unset ($prep_statement); - } - } - $bridge_array = outbound_route_to_bridge ($_SESSION['domain_uuid'], $dest); - $destination = "{origination_caller_id_name='$dest_cid_name',origination_caller_id_number=$dest_cid_number}".$bridge_array[0]; - if (permission_exists('click_to_call_call')) { - $switch_cmd = "api originate $source &bridge($destination)"; - } - } - - //display the last command - echo "
\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "
Message
$switch_cmd $src has called $dest
\n"; - echo "
\n"; - - //create the even socket connection and send the event socket command - $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); - if (!$fp) { - //show the error message - $msg = "
Connection to Event Socket failed.
"; - echo "
\n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - echo "
Message
$msg
\n"; - echo "
\n"; - } - else { - //show the command result - $result = trim(event_socket_request($fp, $switch_cmd)); - if (substr($result, 0,3) == "+OK") { - $uuid = substr($result, 4); - if ($rec == "true") { - //use the server's time zone to ensure it matches the time zone used by freeswitch - date_default_timezone_set($_SESSION['time_zone']['system']); - //create the api record command and send it over event socket - $switch_cmd = "api uuid_record ".$uuid." start ".$_SESSION['switch']['recordings']['dir']."/archive/".date("Y")."/".date("M")."/".date("d")."/".$uuid.".wav"; - $result2 = trim(event_socket_request($fp, $switch_cmd)); - } - } - echo "
\n"; - echo "
\n"; - echo $result; - echo "
\n"; - echo "
\n"; - echo "
\n"; - } -} - -//show html form - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo " \n"; - echo " Click to Call\n"; - echo " \n"; - echo " \n"; - echo "  \n"; - echo "
\n"; - echo " \n"; - echo " Provide the following information to make a call from the source number to the destination number.\n"; - echo " \n"; - echo "
"; - - echo "
"; - - echo "
\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - - echo" \n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo " \n"; - echo "\n"; - echo "
Source Caller ID Name:\n"; - echo " \n"; - echo "
\n"; - echo " Enter the name to show to the source caller.\n"; - echo "
Source Caller ID Number:\n"; - echo " \n"; - echo "
\n"; - echo " Enter the number to show to the source caller.\n"; - echo "
Destination Caller ID Name:\n"; - echo " \n"; - echo "
\n"; - echo " Enter the name to send to the destination callee.\n"; - echo "
Destination Caller ID Number:\n"; - echo " \n"; - echo "
\n"; - echo " Enter the number to show to the destination callee.\n"; - echo "
Source Number:\n"; - echo " \n"; - echo "
\n"; - echo " Enter the number to call from.\n"; - echo "
Destination Number:\n"; - echo " \n"; - echo "
\n"; - echo " Enter the number to call.\n"; - echo "
\n"; - echo " Auto Answer:\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo "Select whether to enable auto answer.\n"; - echo "
\n"; - echo " Record:\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo "Select whether to record the call.\n"; - echo "
\n"; - echo " Ring Back:\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo "Defines what the caller will hear while destination is being called. The choices are music (music on hold) ring (ring tone.)\n"; - echo "
\n"; - echo " \n"; - echo "
\n"; - echo "
"; - -//show the footer - require_once "includes/footer.php"; -?> \ No newline at end of file + + James Rose + +*/ +include "root.php"; +require_once "includes/require.php"; +require_once "includes/checkauth.php"; +//require_once "includes/checkauth.php"; +if (permission_exists('click_to_call_view')) { + //access granted +} +else { + + echo "access denied"; + exit; +} + +require_once "includes/header.php"; + +if (is_array($_REQUEST) && !empty($_REQUEST['src']) && !empty($_REQUEST['dest'])) { + //get the http variables and set them as variables + $src = check_str($_REQUEST['src']); + $dest = check_str($_REQUEST['dest']); + $ringback = check_str($_REQUEST['ringback']); + $src = str_replace(array('.', '(', ')', '-', ' '), '', $src); + if (strpbrk($dest, '@') != FALSE) { + $dest = str_replace(array('(', ')', ' '), '', $dest); //don't strip periods or dashes in sip-uri calls + } + else { + $dest = str_replace(array('.', '(', ')', '-', ' '), '', $dest); //strip the periods for phone numbers. + } + $src_cid_name = check_str($_REQUEST['src_cid_name']); + $src_cid_number = check_str($_REQUEST['src_cid_number']); + $dest_cid_name = check_str($_REQUEST['dest_cid_name']); + $dest_cid_number = check_str($_REQUEST['dest_cid_number']); + $rec = check_str($_REQUEST['rec']); //true,false + if (strlen($cid_number) == 0) { $cid_number = $src;} + if (strlen($_SESSION['context']) > 0) { + $context = $_SESSION['context']; + } + else { + $context = 'default'; + } + + //woraround for TBDialout on Thunderbird + //seems it can only handle the first %NUM% + if ($dest == "%NUM%"){ + //echo "Thnuderbird fix, dest now = $src_cid_number
"; + $dest = $src_cid_number; + } + + //translate ringback + switch ($ringback) { + case "us-ring": + $ringback_value = "\'%(2000,4000,440.0,480.0)\'"; + break; + case "uk-ring": + $ringback_value = "\'%(400,200,400,450);%(400,2200,400,450)\'"; + break; + case "fr-ring": + $ringback_value = "\'%(1500,3500,440.0,0.0)\'"; + break; + case "rs-ring": + $ringback_value = "\'%(1000,4000,425.0,0.0)\'"; + break; + case "music": + $ringback_value = "\'local_stream://moh\'"; + break; + default: + $ringback = 'us-ring'; + $ringback_value = "\'%(2000,4000,440.0,480.0)\'"; + } + + //source should see the destination caller id + if (strlen($src) < 7) { + $source = "{origination_caller_id_name='$src_cid_name',origination_caller_id_number=$src_cid_number,instant_ringback=true,ringback=$ringback_value,presence_id=$src@".$_SESSION['domains'][$domain_uuid]['domain_name'].",call_direction=outbound}sofia/internal/$src%".$_SESSION['domains'][$domain_uuid]['domain_name']; + } + else { + $bridge_array = outbound_route_to_bridge ($_SESSION['domain_uuid'], $src); + $source = "{origination_caller_id_name='$src_cid_name',origination_caller_id_number=$src_cid_number,instant_ringback=true,ringback=$ringback_value,presence_id=$src@".$_SESSION['domains'][$domain_uuid]['domain_name'].",call_direction=outbound}".$bridge_array[0]; + } + + //destination needs to see the source caller id + if (strlen($dest) < 7) { + if (strpbrk($dest, '@') != FALSE) { + echo "Found an @ 2

"; + $switch_cmd = "api originate $source &bridge({origination_caller_id_name='$src_cid_name',origination_caller_id_number=$src_cid_number,call_direction=outbound}sofia/external/$dest)"; + echo "$switch_cmd"; + } + else { + $switch_cmd = "api originate $source &transfer('".$dest." XML ".$context."')"; + } + } + else { + + if (strlen($src) < 7) { + if (strlen($dest_cid_number) == 0) { + //get the caller id from the extension caller id comes from the extension (the source number) + $sql = ""; + $sql .= "select * from v_extensions "; + $sql .= "where domain_uuid = '$domain_uuid' "; + $sql .= "and extension = '$src' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + 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 + } + unset ($prep_statement); + } + } + $bridge_array = outbound_route_to_bridge ($_SESSION['domain_uuid'], $dest); + $destination = "{origination_caller_id_name='$dest_cid_name',origination_caller_id_number=$dest_cid_number}".$bridge_array[0]; + if (permission_exists('click_to_call_call')) { + if (strpbrk($dest, '@') != FALSE) { + //call a sip uri + //echo "Found an @ 4, do nothing for now

"; + $switch_cmd = "api originate $source &bridge({origination_caller_id_name='$src_cid_name',origination_caller_id_number=$src_cid_number,call_direction=outbound}sofia/external/$dest)"; + //echo "
SWITCH-CMD: $switch_cmd
"; + + } + else { + //regular call + $switch_cmd = "api originate $source &bridge($destination)"; + } + } + } + + //display the last command + echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
Message
$switch_cmd $src has called $dest
\n"; + echo "
\n"; + + //create the even socket connection and send the event socket command + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + if (!$fp) { + //show the error message + $msg = "
Connection to Event Socket failed.
"; + echo "
\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + echo "
Message
$msg
\n"; + echo "
\n"; + } + else { + //show the command result + $result = trim(event_socket_request($fp, $switch_cmd)); + if (substr($result, 0,3) == "+OK") { + $uuid = substr($result, 4); + if ($rec == "true") { + //use the server's time zone to ensure it matches the time zone used by freeswitch + date_default_timezone_set($_SESSION['time_zone']['system']); + //create the api record command and send it over event socket + $switch_cmd = "api uuid_record ".$uuid." start ".$_SESSION['switch']['recordings']['dir']."/archive/".date("Y")."/".date("M")."/".date("d")."/".$uuid.".wav"; + $result2 = trim(event_socket_request($fp, $switch_cmd)); + } + } + echo "
\n"; + echo "
\n"; + echo $result; + echo "
\n"; + echo "
\n"; + echo "
\n"; + } +} + +//show html form + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo " \n"; + echo " Click to Call\n"; + echo " \n"; + echo " \n"; + echo "  \n"; + echo "
\n"; + echo " \n"; + echo " Provide the following information to make a call from the source number to the destination number.\n"; + echo " \n"; + echo "
"; + + echo "
"; + + echo "
\n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo " \n"; + echo "\n"; + echo "
Source Caller ID Name:\n"; + echo " \n"; + echo "
\n"; + echo " Enter the Caller ID name to send to your phone.\n"; + echo "
Source Caller ID Number:\n"; + echo " \n"; + echo "
\n"; + echo " Enter the Caller ID number to send to your phone (you probably want this to be the same as the destination number).\n"; + echo "
Destination Caller ID Name:\n"; + echo " \n"; + echo "
\n"; + echo " Enter the Caller ID name to send to the destination number.\n"; + echo "
Destination Caller ID Number:\n"; + echo " \n"; + echo "
\n"; + echo " Enter the Caller ID number to send to the destination number (you probably want this to be your phone number).\n"; + echo "
Source Number:\n"; + echo " \n"; + echo "
\n"; + echo " Enter your phone number. This can be an extension on the system, or another number (eg: mobile phone).\n"; + echo "
Destination Number:\n"; + echo " \n"; + echo "
\n"; + echo " Enter the number to call. This can be an extension on the system, another number, or a sip uri. Sip URI's are of the form 5551234567@voip.example.com:5080 (5080 for freeswitch, or 5060 for other systems).\n"; + echo "
\n"; + echo " Record:\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo "Select whether to record the call.\n"; + echo "
\n"; + echo " Ring Back:\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo "Defines what the you will hear while destination is being called. The choices are music (music on hold) ring (ring tone.)\n"; + echo "
\n"; + echo " \n"; + echo "
\n"; + echo "
"; + +//show the footer + require_once "includes/footer.php"; +?>