From a78d09cfd511c884b1315955cb97cc7edd8d0518 Mon Sep 17 00:00:00 2001 From: Chris Black Date: Tue, 24 May 2016 01:02:36 -0700 Subject: [PATCH] Add support for twilio (#1610) added support for twilio and made it a bit easier to add support for other carriers as well. --- app/sms/app_config.php | 52 ++++ app/sms/app_defaults.php | 20 +- app/sms/app_languages.php | 39 +++ app/sms/sms.php | 270 +++++++++++++------- app/sms/sms_api.php | 11 +- app/sms/sms_edit.php | 242 ++++++++++++++++++ app/sms/sms_mdr.php | 141 ++++++++++ resources/install/scripts/app/sms/index.lua | 37 ++- 8 files changed, 712 insertions(+), 100 deletions(-) create mode 100644 app/sms/sms_edit.php create mode 100644 app/sms/sms_mdr.php diff --git a/app/sms/app_config.php b/app/sms/app_config.php index 0e3d2117a8..f9c1ded9fd 100644 --- a/app/sms/app_config.php +++ b/app/sms/app_config.php @@ -27,6 +27,18 @@ $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; $apps[$x]['permissions'][$y]['groups'][] = "admin"; $y++; + $apps[$x]['permissions'][$y]['name'] = "sms_edit"; + $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; + $y++; + $apps[$x]['permissions'][$y]['name'] = "sms_add"; + $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; + $y++; + $apps[$x]['permissions'][$y]['name'] = "sms_delete"; + $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; + $y++; + $apps[$x]['permissions'][$y]['name'] = "sms_enabled"; + $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; + $y++; //schema details @@ -81,6 +93,46 @@ $apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ""; $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = "carrier"; + $apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ""; + $z++; + $y = 1; //table array index + $z = 0; //field array index + $apps[$x]['db'][$y]['table'] = "v_sms_destinations"; + $apps[$x]['db'][$y]['fields'][$z]['name']['text'] = "sms_destination_uuid"; + $apps[$x]['db'][$y]['fields'][$z]['name']['deprecated'] = "sms_destination_uuid"; + $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "uuid"; + $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text"; + $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(36)"; + $apps[$x]['db'][$y]['fields'][$z]['key']['type'] = "primary"; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = "domain_uuid"; + $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "uuid"; + $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text"; + $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(36)"; + $apps[$x]['db'][$y]['fields'][$z]['key']['type'] = "foreign"; + $apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = "v_domains"; + $apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = "domain_uuid"; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ""; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = "destination"; + $apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ""; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = "carrier"; + $apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ""; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = "enabled"; + $apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ""; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = "description"; + $apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ""; + $z++; + ?> diff --git a/app/sms/app_defaults.php b/app/sms/app_defaults.php index 380be27d4a..7618a3c6ee 100644 --- a/app/sms/app_defaults.php +++ b/app/sms/app_defaults.php @@ -24,6 +24,24 @@ Mark J Crane */ -//if the extensions dir doesn't exist then create it +if ($domains_processed == 1) { + + $x = 0; + $array[$x]['default_setting_category'] = 'sms'; + $array[$x]['default_setting_subcategory'] = 'carriers'; + $array[$x]['default_setting_name'] = 'array'; + $array[$x]['default_setting_value'] = 'flowroute'; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = ''; + $x++; + $array[$x]['default_setting_category'] = 'sms'; + $array[$x]['default_setting_subcategory'] = 'carriers'; + $array[$x]['default_setting_name'] = 'array'; + $array[$x]['default_setting_value'] = 'twilio'; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = ''; + $x++; + +} ?> \ No newline at end of file diff --git a/app/sms/app_languages.php b/app/sms/app_languages.php index b2c537fbd2..93cf2efb89 100644 --- a/app/sms/app_languages.php +++ b/app/sms/app_languages.php @@ -13,6 +13,19 @@ $text['title-sms']['de-at'] = ""; $text['title-sms']['ar-eg'] = ""; $text['title-sms']['he'] = ""; +$text['header-sms']['en-us'] = "SMS"; +$text['header-sms']['es-cl'] = ""; +$text['header-sms']['pt-pt'] = ""; +$text['header-sms']['fr-fr'] = ""; +$text['header-sms']['pt-br'] = ""; +$text['header-sms']['pl'] = ""; +$text['header-sms']['uk'] = ""; +$text['header-sms']['sv-se'] = ""; +$text['header-sms']['ro'] = ""; +$text['header-sms']['de-at'] = ""; +$text['header-sms']['ar-eg'] = ""; +$text['header-sms']['he'] = ""; + $text['title-sms-edit']['en-us'] = "SMS"; $text['title-sms-edit']['es-cl'] = ""; $text['title-sms-edit']['pt-pt'] = ""; @@ -91,6 +104,19 @@ $text['label-start']['de-at'] = ""; $text['label-start']['ar-eg'] = ""; $text['label-start']['he'] = ""; +$text['label-carrier']['en-us'] = "Carrier"; +$text['label-carrier']['es-cl'] = ""; +$text['label-carrier']['pt-pt'] = ""; +$text['label-carrier']['fr-fr'] = ""; +$text['label-carrier']['pt-br'] = ""; +$text['label-carrier']['pl'] = " "; +$text['label-carrier']['uk'] = ""; +$text['label-carrier']['sv-se'] = ""; +$text['label-carrier']['ro'] = ""; +$text['label-carrier']['de-at'] = ""; +$text['label-carrier']['ar-eg'] = ""; +$text['label-carrier']['he'] = ""; + $text['label-message']['en-us'] = "Message"; $text['label-message']['es-cl'] = ""; $text['label-message']['pt-pt'] = ""; @@ -104,4 +130,17 @@ $text['label-message']['de-at'] = ""; $text['label-message']['ar-eg'] = ""; $text['label-message']['he'] = ""; +$text['button-mdr']['en-us'] = "MDRs"; +$text['button-mdr']['es-cl'] = ""; +$text['button-mdr']['pt-pt'] = ""; +$text['button-mdr']['fr-fr'] = ""; +$text['button-mdr']['pt-br'] = ""; +$text['button-mdr']['pl'] = " "; +$text['button-mdr']['uk'] = ""; +$text['button-mdr']['sv-se'] = ""; +$text['button-mdr']['ro'] = ""; +$text['button-mdr']['de-at'] = ""; +$text['button-mdr']['ar-eg'] = ""; +$text['button-mdr']['he'] = ""; + ?> \ No newline at end of file diff --git a/app/sms/sms.php b/app/sms/sms.php index a753a12b46..9da7d3819a 100644 --- a/app/sms/sms.php +++ b/app/sms/sms.php @@ -1,36 +1,28 @@ + Portions created by the Initial Developer are Copyright (C) 2008-2016 + the Initial Developer. All Rights Reserved. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. Contributor(s): Mark J Crane - James Rose - */ - include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; @@ -46,92 +38,192 @@ else { $language = new text; $text = $language->get(); -//include the header - require_once "resources/header.php"; - require_once "resources/paging.php"; +//get the http values and set them as variables + $search = check_str($_GET["search"]); + $order_by = check_str($_GET["order_by"]); + $order = check_str($_GET["order"]); +require_once "resources/header.php"; +$document['title'] = $text['title-sms']; + +require_once "resources/paging.php"; + +//get total extension count from the database + $sql = "select "; + $sql .= "(select count(*) from v_sms_destinations where domain_uuid = '".$_SESSION['domain_uuid']."' ".$sql_mod.") as num_rows "; + if ($db_type == "pgsql") { + $sql .= ",(select count(*) as count from v_sms_destinations "; + $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; + $sql .= ") as numeric_sms "; + } + $prep_statement = $db->prepare($sql); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + $total_sms_destinations = $row['num_rows']; + if (($db_type == "pgsql") or ($db_type == "mysql")) { + $numeric_sms = $row['numeric_sms']; + } + } + unset($prep_statement, $row); + +//prepare to page the results $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; + $param = "&search=".$search; + if (!isset($_GET['page'])) { $_GET['page'] = 0; } + $_GET['page'] = check_str($_GET['page']); + list($paging_controls_mini, $rows_per_page, $var_3) = paging($total_sms_destinations, $param, $rows_per_page, true); //top + list($paging_controls, $rows_per_page, $var_3) = paging($total_sms_destinations, $param, $rows_per_page); //bottom + $offset = $rows_per_page * $_GET['page']; - $sql = "select domain_name, extension, sms_message_uuid,start_stamp,from_numer,to_number,message,direction from v_sms_messages, v_domains, v_extensions where v_sms_messages.domain_uuid = v_domains.domain_uuid and v_sms_messages.extension_uuid = v_extensions.extension_uuid and v_domains.domain_uuid = '" . $domain_uuid . "' order by start_stamp"; - error_log("SQL: " . print_r($sql,true)); +//to cast or not to cast + if ($db_type == "pgsql") { + $order_text = ($total_sms_destinations == $numeric_sms) ? "cast(destination as bigint)" : "destination asc"; + } + else { + $order_text = "extension asc"; + } + +//get the extensions + $sql = "select * from v_sms_destinations "; + $sql .= "where domain_uuid = '$domain_uuid' "; + $sql .= $sql_mod; //add search mod from above + if (strlen($order_by) > 0) { + $sql .= ($order_by == 'destination') ? "order by $order_text ".$order." " : "order by ".$order_by." ".$order." "; + } + else { + $sql .= "order by $order_text "; + } + $sql .= "limit $rows_per_page offset $offset "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); - $result_count = count($result); + $sms_destinations = $prep_statement->fetchAll(PDO::FETCH_NAMED); unset ($prep_statement, $sql); +//show the content + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
".$text['header-sms']." (".$total_sms_destinations.")
\n"; + echo " ".$text['description-sms']."\n"; + echo "
\n"; + if (if_group("superadmin")) { + echo " \n"; + } + echo " "; + echo " "; + if ($paging_controls_mini != '') { + echo "".$paging_controls_mini."\n"; + } + echo "
\n"; + echo "
"; + $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; -//mod paging parameters for inclusion in column sort heading links - $param = substr($param, 1); //remove leading '&' - $param = substr($param, 0, strrpos($param, '&order_by=')); //remove trailing order by - -//show the results - $col_count = 6; - echo "
\n"; - echo "\n"; + echo "\n"; + echo "
\n"; echo "\n"; - echo "\n"; - if ($_REQUEST['showall'] && permission_exists('xml_cdr_all')) { - echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, null, null, $param); - $col_count++; + if (permission_exists('sms_delete') && is_array($sms_destinations)) { + echo ""; } - echo th_order_by('extension', $text['label-extension'], $order_by, $order, null, null, $param); - echo th_order_by('start_stamp', $text['label-start'], $order_by, $order, null, "style='text-align: center;'", $param); - echo th_order_by('caller_id_number', $text['label-source'], $order_by, $order, null, null, $param); - echo th_order_by('destination_number', $text['label-destination'], $order_by, $order, null, null, $param); - echo th_order_by('message', $text['label-message'], $order_by, $order, null, null, $param); + echo th_order_by('destination', $text['label-destination'], $order_by, $order); + echo th_order_by('carrier', $text['label-carrier'], $order_by, $order); + echo th_order_by('enabled', $text['label-enabled'], $order_by, $order); + echo th_order_by('description', $text['label-description'], $order_by, $order); + echo "\n"; echo "\n"; - if ($result_count > 0) { - echo "\n"; + if (is_array($sms_destinations)) { - //determine if theme images exist - $theme_image_path = $_SERVER["DOCUMENT_ROOT"]."/themes/".$_SESSION['domain']['template']['name']."/images/"; - $theme_cdr_images_exist = ( - file_exists($theme_image_path."icon_cdr_inbound_answered.png") && - file_exists($theme_image_path."icon_cdr_inbound_voicemail.png") && - file_exists($theme_image_path."icon_cdr_inbound_cancelled.png") && - file_exists($theme_image_path."icon_cdr_inbound_failed.png") && - file_exists($theme_image_path."icon_cdr_outbound_answered.png") && - file_exists($theme_image_path."icon_cdr_outbound_cancelled.png") && - file_exists($theme_image_path."icon_cdr_outbound_failed.png") && - file_exists($theme_image_path."icon_cdr_local_answered.png") && - file_exists($theme_image_path."icon_cdr_local_voicemail.png") && - file_exists($theme_image_path."icon_cdr_local_cancelled.png") && - file_exists($theme_image_path."icon_cdr_local_failed.png") - ) ? true : false; - - foreach($result as $index => $row) { - - $tmp_start_epoch = ($_SESSION['domain']['time_format']['text'] == '12h') ? date("j M Y g:i:sa", $row['start_stamp']) : date("j M Y H:i:s", $row['start_epoch']); - - //determine call result and appropriate icon - echo "\n"; + if (permission_exists('sms_delete')) { + echo " "; + $ext_ids[] = 'checkbox_'.$row['sms_destination_uuid']; + } + echo " \n"; - //domain name - if ($_REQUEST['showall'] && permission_exists('xml_cdr_all')) { - echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; + if (permission_exists('sms_delete')) { + echo "$v_link_label_delete"; + } + echo "\n"; echo "\n"; $c = ($c) ? 0 : 1; - } // end foreach - unset($sql, $result, $row_count); - } // end if + } + unset($sms_destinations, $row); + } + + if (is_array($sms_destinations)) { + echo "\n"; + echo " \n"; + echo "\n"; + } + + echo "
 \n"; + if (permission_exists('sms_add')) { + echo "".$v_link_label_add.""; + } + if (permission_exists('sms_delete') && is_array($sms_destinations)) { + echo "".$v_link_label_delete.""; + } + echo "
\n"; - if ($theme_cdr_images_exist) { - $call_result = 'answered'; - echo "\n"; + foreach($sms_destinations as $row) { + $tr_link = (permission_exists('sms_edit')) ? " href='sms_edit.php?id=".$row['sms_destination_uuid']."'" : null; + echo "
"; + if (permission_exists('sms_edit')) { + echo "".$row['destination'].""; + } + else { + echo $row['destination']; } - else { echo " "; } echo ""; - echo $row['domain_name'].' '; - echo " ".$row['carrier']."".ucwords($row['enabled'])."".$row['description']." "; + if (permission_exists('sms_edit')) { + echo "$v_link_label_edit"; } - echo " ".$row['extension']." ".$row['start_stamp']." ".$row['from_numer']." ".$row['to_number']." ".$row['message']." 
\n"; + if (permission_exists('sms_add')) { + echo "".$v_link_label_add.""; + } + if (permission_exists('sms_delete')) { + echo "".$v_link_label_delete.""; + } + echo "
"; + echo "
"; + + if (strlen($paging_controls) > 0) { + echo "
".$paging_controls."
\n"; + } + + echo "

".((is_array($sms_destinations)) ? "

" : null); + + // check or uncheck all checkboxes + if (sizeof($ext_ids) > 0) { + echo "\n"; + } + + if (is_array($sms_destinations)) { + // check all checkboxes + key_press('ctrl+a', 'down', 'document', null, null, "check('all');", true); + + // delete checked + key_press('delete', 'up', 'document', array('#search'), $text['confirm-delete'], 'document.forms.frm.submit();', true); + } + //show the footer require_once "resources/footer.php"; ?> \ No newline at end of file diff --git a/app/sms/sms_api.php b/app/sms/sms_api.php index 2d0d8c07e4..346b86046e 100644 --- a/app/sms/sms_api.php +++ b/app/sms/sms_api.php @@ -39,11 +39,20 @@ $debug = false; require_once "resources/require.php"; if ($_SERVER['REQUEST_METHOD'] == 'POST') { - $data = json_decode(file_get_contents("php://input")); + if ($_SERVER['CONTENT_TYPE'] == 'application/json') { + $data = json_decode(file_get_contents("php://input")); + } else { + error_log('REQUEST: ' . print_r($_REQUEST, true)); + $data = (object) ['body' => $_REQUEST['Body'], + 'to' => str_replace("+", "", $_REQUEST['To']), + 'from' => str_replace("+", "", $_REQUEST['From']) + ]; + } if ($debug) { error_log('DATA: ' . print_r($data, true)); } + //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) { diff --git a/app/sms/sms_edit.php b/app/sms/sms_edit.php new file mode 100644 index 0000000000..ac0493e2d8 --- /dev/null +++ b/app/sms/sms_edit.php @@ -0,0 +1,242 @@ + + James Rose + +*/ + +include "root.php"; +require_once "resources/require.php"; +require_once "resources/check_auth.php"; +if (permission_exists('sms_add') || permission_exists('sms_edit')) { + //access granted +} +else { + echo "access denied"; + exit; +} + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//set the action as an add or an update + if (isset($_REQUEST["id"])) { + $action = "update"; + $sms_uuid = check_str($_REQUEST["id"]); + $sql = "select * from v_sms_destinations "; + $sql .= "where sms_destination_uuid = '" . $_REQUEST["id"] . "' "; + $sql .= "and domain_uuid = '" . $_SESSION['domain_uuid'] . "' LIMIT 1"; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $sms_destinations = $prep_statement->fetchAll(PDO::FETCH_NAMED); + foreach ($sms_destinations as $row) { + $destination = check_str($row["destination"]); + $carrier = check_str($row["carrier"]); + $description = check_str($row["description"]); + $enabled = check_str($row["enabled"]); + $sms_destination_uuid = $row['sms_destination_uuid']; + } + } + else { + $action = "add"; + } + +//get the http values and set them as php variables + if (count($_POST) > 0 && $action != "update") { + //get the values from the HTTP POST and save them as PHP variables + $destination = str_replace(' ','-',check_str($_POST["destination"])); + $carrier = check_str($_POST["carrier"]); + $description = check_str($_POST["description"]); + $enabled = check_str($_POST["enabled"]); + $sms_destination_uuid = uuid(); + if ($action == "add") { + $sql_insert = "insert into v_sms_destinations "; + $sql_insert .= "("; + $sql_insert .= "sms_destination_uuid, "; + $sql_insert .= "carrier, "; + $sql_insert .= "domain_uuid, "; + $sql_insert .= "destination, "; + $sql_insert .= "enabled, "; + $sql_insert .= "description "; + $sql_insert .= ")"; + $sql_insert .= "values "; + $sql_insert .= "("; + $sql_insert .= "'".$sms_destination_uuid."', "; + $sql_insert .= "'".$carrier."', "; + $sql_insert .= "'".$_SESSION['domain_uuid']."', "; + $sql_insert .= "'".$destination."', "; + $sql_insert .= "'".$enabled."', "; + $sql_insert .= "'".$description."' "; + $sql_insert .= ")"; + $db->exec($sql_insert); + header( 'Location: sms.php') ; + + } + } elseif (count($_POST) > 0 && $action == "update") { + $destination = str_replace(' ','-',check_str($_POST["destination"])); + $carrier = check_str($_POST["carrier"]); + $description = check_str($_POST["description"]); + $enabled = check_str($_POST["enabled"]); + + $sql_insert = "update v_sms_destinations set"; + $sql_insert .= "("; + $sql_insert .= "carrier, "; + $sql_insert .= "destination, "; + $sql_insert .= "enabled, "; + $sql_insert .= "description "; + $sql_insert .= ")"; + $sql_insert .= "= "; + $sql_insert .= "("; + $sql_insert .= "'".$carrier."', "; + $sql_insert .= "'".$destination."', "; + $sql_insert .= "'".$enabled."', "; + $sql_insert .= "'".$description."' "; + $sql_insert .= ")"; + $sql_insert .= "where sms_destination_uuid = '" . $sms_destination_uuid . "' and domain_uuid = '" . $_SESSION['domain_uuid'] . "'"; + $db->exec($sql_insert); + header( 'Location: sms.php') ; + } + +//include the header + require_once "resources/header.php"; + require_once "resources/paging.php"; + + echo "
\n"; + echo "\n"; + echo "\n"; + if ($action == "add") { + echo "\n"; + } + if ($action == "update") { + echo "\n"; + } + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + + if (permission_exists('sms_enabled')) { + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + if ($action == "update") { + echo " \n"; + echo " "; + } + + echo "
".$text['header-sms-add']."".$text['header-sms-edit']."\n"; + echo " \n"; + echo " \n"; + echo "

\n"; + echo "
\n"; + echo " ".$text['label-destination']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-destination']."\n"; + echo "
\n"; + echo " ".$text['label-carrier']."\n"; + echo "\n"; + if (count($_SESSION['sms']['carriers']) > 0) { + echo "
\n"; + } + echo $text['description-carrier']."\n"; + echo "
\n"; + echo " ".$text['label-enabled']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-enabled']."\n"; + echo "
\n"; + echo " ".$text['label-description']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-description']."\n"; + echo "
\n"; + echo "
\n"; + + + echo "\n"; + +//show the footer + require_once "resources/footer.php"; +?> \ No newline at end of file diff --git a/app/sms/sms_mdr.php b/app/sms/sms_mdr.php new file mode 100644 index 0000000000..2f96a63210 --- /dev/null +++ b/app/sms/sms_mdr.php @@ -0,0 +1,141 @@ + + James Rose + +*/ + +include "root.php"; +require_once "resources/require.php"; +require_once "resources/check_auth.php"; +if (permission_exists('sms_view')) { + //access granted +} +else { + echo "access denied"; + exit; +} + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//include the header + require_once "resources/header.php"; + require_once "resources/paging.php"; + + $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; + + $sql = "select domain_name, extension, sms_message_uuid,start_stamp,from_numer,to_number,message,direction from v_sms_messages, v_domains, v_extensions where v_sms_messages.domain_uuid = v_domains.domain_uuid and v_sms_messages.extension_uuid = v_extensions.extension_uuid and v_domains.domain_uuid = '" . $domain_uuid . "' order by start_stamp"; + error_log("SQL: " . print_r($sql,true)); + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); + $result_count = count($result); + unset ($prep_statement, $sql); + + $c = 0; + $row_style["0"] = "row_style0"; + $row_style["1"] = "row_style1"; + +//mod paging parameters for inclusion in column sort heading links + $param = substr($param, 1); //remove leading '&' + $param = substr($param, 0, strrpos($param, '&order_by=')); //remove trailing order by + +//show the results + $col_count = 6; + echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + if ($_REQUEST['showall'] && permission_exists('xml_cdr_all')) { + echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, null, null, $param); + $col_count++; + } + echo th_order_by('extension', $text['label-extension'], $order_by, $order, null, null, $param); + echo th_order_by('start_stamp', $text['label-start'], $order_by, $order, null, "style='text-align: center;'", $param); + echo th_order_by('caller_id_number', $text['label-source'], $order_by, $order, null, null, $param); + echo th_order_by('destination_number', $text['label-destination'], $order_by, $order, null, null, $param); + echo th_order_by('message', $text['label-message'], $order_by, $order, null, null, $param); + echo "\n"; + + if ($result_count > 0) { + echo "\n"; + + //determine if theme images exist + $theme_image_path = $_SERVER["DOCUMENT_ROOT"]."/themes/".$_SESSION['domain']['template']['name']."/images/"; + $theme_cdr_images_exist = ( + file_exists($theme_image_path."icon_cdr_inbound_answered.png") && + file_exists($theme_image_path."icon_cdr_inbound_voicemail.png") && + file_exists($theme_image_path."icon_cdr_inbound_cancelled.png") && + file_exists($theme_image_path."icon_cdr_inbound_failed.png") && + file_exists($theme_image_path."icon_cdr_outbound_answered.png") && + file_exists($theme_image_path."icon_cdr_outbound_cancelled.png") && + file_exists($theme_image_path."icon_cdr_outbound_failed.png") && + file_exists($theme_image_path."icon_cdr_local_answered.png") && + file_exists($theme_image_path."icon_cdr_local_voicemail.png") && + file_exists($theme_image_path."icon_cdr_local_cancelled.png") && + file_exists($theme_image_path."icon_cdr_local_failed.png") + ) ? true : false; + + foreach($result as $index => $row) { + + $tmp_start_epoch = ($_SESSION['domain']['time_format']['text'] == '12h') ? date("j M Y g:i:sa", $row['start_stamp']) : date("j M Y H:i:s", $row['start_epoch']); + + //determine call result and appropriate icon + echo "\n"; + //domain name + if ($_REQUEST['showall'] && permission_exists('xml_cdr_all')) { + echo " \n"; + } + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "\n"; + $c = ($c) ? 0 : 1; + } // end foreach + unset($sql, $result, $row_count); + } // end if + + echo "
 
\n"; + if ($theme_cdr_images_exist) { + $call_result = 'answered'; + echo "\n"; + } + else { echo " "; } + echo ""; + echo $row['domain_name'].' '; + echo " ".$row['extension']." ".$row['start_stamp']." ".$row['from_numer']." ".$row['to_number']." ".$row['message']." 
\n"; + echo "
\n"; + +//show the footer + require_once "resources/footer.php"; +?> \ No newline at end of file diff --git a/resources/install/scripts/app/sms/index.lua b/resources/install/scripts/app/sms/index.lua index 04f0dd2610..fce32a8918 100644 --- a/resources/install/scripts/app/sms/index.lua +++ b/resources/install/scripts/app/sms/index.lua @@ -118,37 +118,56 @@ if (outbound_caller_id_number == nil) then --get the outbound_caller_id_number using the domain_uuid and the extension number if (domain_uuid ~= nil) then - sql = "SELECT outbound_caller_id_number, extension_uuid FROM v_extensions "; - sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .. "' and extension = '" .. from .."' "; + sql = "SELECT outbound_caller_id_number, extension_uuid, carrier FROM v_extensions "; + sql = sql .. ", v_sms_destinations "; + sql = sql .. "WHERE outbound_caller_id_number = destination and "; + sql = sql .. "v_extensions.domain_uuid = '" .. domain_uuid .. "' and extension = '" .. from .."' "; if (debug["sql"]) then freeswitch.consoleLog("notice", "[sms] SQL: " .. sql .. "\n"); end status = dbh:query(sql, function(rows) outbound_caller_id_number = rows["outbound_caller_id_number"]; extension_uuid = rows["extension_uuid"]; + carrier = rows["carrier"]; end); end end sql = "SELECT default_setting_value FROM v_default_settings "; - sql = sql .. "where default_setting_category = 'sms' and default_setting_subcategory = 'flowroute_access_key'"; + sql = sql .. "where default_setting_category = 'sms' and default_setting_subcategory = '" .. carrier .. "_access_key'"; if (debug["sql"]) then freeswitch.consoleLog("notice", "[sms] SQL: " .. sql .. "\n"); end status = dbh:query(sql, function(rows) - flowroute_access_key = rows["default_setting_value"]; + access_key = rows["default_setting_value"]; end); sql = "SELECT default_setting_value FROM v_default_settings "; - sql = sql .. "where default_setting_category = 'sms' and default_setting_subcategory = 'flowroute_secret_key'"; + sql = sql .. "where default_setting_category = 'sms' and default_setting_subcategory = '" .. carrier .. "_secret_key'"; if (debug["sql"]) then freeswitch.consoleLog("notice", "[sms] SQL: " .. sql .. "\n"); end status = dbh:query(sql, function(rows) - flowroute_secret_key = rows["default_setting_value"]; + secret_key = rows["default_setting_value"]; end); - cmd = "curl -u ".. flowroute_access_key ..":" .. flowroute_secret_key .. " -H \"Content-Type: application/json\" -X POST -d '{\"to\":\"" .. to .. "\",\"from\":\"" .. outbound_caller_id_number .."\",\"body\":\"" .. body .. "\"}' https://api.flowroute.com/v2/messages" + sql = "SELECT default_setting_value FROM v_default_settings "; + sql = sql .. "where default_setting_category = 'sms' and default_setting_subcategory = '" .. carrier .. "_api_url'"; + if (debug["sql"]) then + freeswitch.consoleLog("notice", "[sms] SQL: " .. sql .. "\n"); + end + status = dbh:query(sql, function(rows) + api_url = rows["default_setting_value"]; + end); + + if (carrier == "flowroute") then + cmd = "curl -u ".. access_key ..":" .. secret_key .. " -H \"Content-Type: application/json\" -X POST -d '{\"to\":\"" .. to .. "\",\"from\":\"" .. outbound_caller_id_number .."\",\"body\":\"" .. body .. "\"}' " .. api_url; + elseif (carrier == "twilio") then + cmd ="curl -X POST '" .. api_url .."' --data-urlencode 'To=+" .. to .."' --data-urlencode 'From=+" .. outbound_caller_id_number .. "' --data-urlencode 'Body=" .. body .. "' -u ".. access_key ..":" .. secret_key .. " --insecure"; + end + if (debug["info"]) then + freeswitch.consoleLog("notice", "[sms] CMD: " .. cmd .. "\n"); + end os.execute(cmd) end @@ -181,8 +200,8 @@ end end sql = "insert into v_sms_messages"; - sql = sql .. "(sms_message_uuid,extension_uuid,domain_uuid,start_stamp,from_numer,to_number,message,direction,response)"; - sql = sql .. " values ('" .. uuid() .. "','" .. extension_uuid .. "','" .. domain_uuid .."',now(),'" .. from .. "','" .. to .. "','" .. body .. "','" .. direction .. "','')"; + sql = sql .. "(sms_message_uuid,extension_uuid,domain_uuid,start_stamp,from_numer,to_number,message,direction,response,carrier)"; + sql = sql .. " values ('" .. uuid() .. "','" .. extension_uuid .. "','" .. domain_uuid .."',now(),'" .. from .. "','" .. to .. "','" .. body .. "','" .. direction .. "','','" .. carrier .."')"; if (debug["sql"]) then freeswitch.consoleLog("notice", "[sms] "..sql.."\n"); end