Browse Source

Add more bandwidth stuff and add debug to the hook files. (#33)

Chris Black 8 years ago
parent
commit
c4c65a0170

+ 34 - 2
sms/app_defaults.php

@@ -59,6 +59,14 @@ if ($domains_processed == 1) {
 	$array[$x]['default_setting_enabled'] = 'true';
 	$array[$x]['default_setting_description'] = '';
 	$x++;
+	$array[$x]['default_setting_uuid'] = 'deda7f98-f627-49bb-8a1b-899e4512e7ff';
+	$array[$x]['default_setting_category'] = 'sms';
+	$array[$x]['default_setting_subcategory'] = 'carriers';
+	$array[$x]['default_setting_name'] = 'array';
+	$array[$x]['default_setting_value'] = 'bandwidth';
+	$array[$x]['default_setting_enabled'] = 'true';
+	$array[$x]['default_setting_description'] = '';
+	$x++;
 	$array[$x]['default_setting_uuid'] = 'e997203c-ca48-45b4-828d-e347ff66fa7c';
 	$array[$x]['default_setting_category'] = 'sms';
 	$array[$x]['default_setting_subcategory'] = 'twilio_api_url';
@@ -91,6 +99,15 @@ if ($domains_processed == 1) {
 	$array[$x]['default_setting_enabled'] = 'false';
 	$array[$x]['default_setting_description'] = '';
 	$x++;
+	$array[$x]['default_setting_uuid'] = '5c8a66d1-f8ae-4adc-9056-443cc53bac16';
+	$array[$x]['default_setting_category'] = 'sms';
+	$array[$x]['default_setting_subcategory'] = 'bandwidth_api_url';
+	$array[$x]['default_setting_name'] = 'text';
+	$array[$x]['default_setting_value'] = 'https://api.catapult.inetwork.com/v1/users/{userId}/messages';
+	$array[$x]['default_setting_enabled'] = 'false';
+	$array[$x]['default_setting_description'] = '';
+	$x++;
+
 
 	$array[$x]['default_setting_uuid'] = '14101c26-c3f9-46aa-a67a-3642752e56f4';
 	$array[$x]['default_setting_category'] = 'sms';
@@ -117,7 +134,6 @@ if ($domains_processed == 1) {
 	$array[$x]['default_setting_enabled'] = 'false';
 	$array[$x]['default_setting_description'] = '';
 	$x++;
-	
 	$array[$x]['default_setting_uuid'] = 'c7607430-1b55-41ff-934e-7f9142b29df0';
 	$array[$x]['default_setting_category'] = 'sms';
 	$array[$x]['default_setting_subcategory'] = 'teli_secret_key';
@@ -135,7 +151,6 @@ if ($domains_processed == 1) {
 	$array[$x]['default_setting_enabled'] = 'false';
 	$array[$x]['default_setting_description'] = '';
 	$x++;
-	
 	$array[$x]['default_setting_uuid'] = '784196cb-d012-4a74-8183-4fc0b738c06a';
 	$array[$x]['default_setting_category'] = 'sms';
 	$array[$x]['default_setting_subcategory'] = 'twilio_secret_key';
@@ -145,6 +160,23 @@ if ($domains_processed == 1) {
 	$array[$x]['default_setting_description'] = '';
 	$x++;
 
+	$array[$x]['default_setting_uuid'] = '4a86c939-9d80-4da7-bbda-49d6bf1c3882';
+	$array[$x]['default_setting_category'] = 'sms';
+	$array[$x]['default_setting_subcategory'] = 'bandwidth_access_key';
+	$array[$x]['default_setting_name'] = 'text';
+	$array[$x]['default_setting_value'] = '';
+	$array[$x]['default_setting_enabled'] = 'false';
+	$array[$x]['default_setting_description'] = '';
+	$x++;
+	$array[$x]['default_setting_uuid'] = '0af3ff85-b325-4b67-b838-e8a85a8cbc0d';
+	$array[$x]['default_setting_category'] = 'sms';
+	$array[$x]['default_setting_subcategory'] = 'bandwidth_secret_key';
+	$array[$x]['default_setting_name'] = 'text';
+	$array[$x]['default_setting_value'] = '';
+	$array[$x]['default_setting_enabled'] = 'false';
+	$array[$x]['default_setting_description'] = '';
+	$x++;
+
 	//get an array of the default settings
 		$sql = "select * from v_default_settings where default_setting_category = 'sms'";
 		$prep_statement = $db->prepare($sql);

+ 12 - 4
sms/hook/sms_hook_bandwidth.php

@@ -5,15 +5,23 @@ include "../root.php";
 require_once "resources/require.php";
 require_once "../sms_hook_common.php";
 
+if ($debug) {
+	error_log('[SMS] REQUEST: ' .  print_r($_SERVER, true));
+}
+
 if (check_acl()) {
-	if  ($_SERVER['CONTENT_TYPE'] == 'application/json') {
+	if  ($_SERVER['CONTENT_TYPE'] == 'application/json; charset=utf-8') {
 		$data = json_decode(file_get_contents("php://input"));
-		route_and_send_sms($data->from, $data->to, $data->body);	
+		if ($debug) {
+			error_log('[SMS] REQUEST: ' .  print_r($data, true));
+		}
+		route_and_send_sms($data->from, $data->to, $data->text);
 	} else {
-	  die("no");
+		error_log('[SMS] REQUEST: No SMS Data Received');
+		die("no");
 	}
 } else {
 	error_log('ACCESS DENIED [SMS]: ' .  print_r($_SERVER['REMOTE_ADDR'], true));
 	die("access denied");
 }
-?>
+?>

+ 4 - 1
sms/hook/sms_hook_flowroute.php

@@ -8,6 +8,9 @@ require_once "../sms_hook_common.php";
 if (check_acl()) {
 	if  ($_SERVER['CONTENT_TYPE'] == 'application/json') {
 		$data = json_decode(file_get_contents("php://input"));
+		if ($debug) {
+			error_log('[SMS] REQUEST: ' .  print_r($data, true));
+		}
 		route_and_send_sms($data->from, $data->to, $data->body);	
 	} else {
 	  die("no");
@@ -16,4 +19,4 @@ if (check_acl()) {
 	error_log('ACCESS DENIED [SMS]: ' .  print_r($_SERVER['REMOTE_ADDR'], true));
 	die("access denied");
 }
-?>
+?>

+ 4 - 2
sms/hook/sms_hook_plivo.php

@@ -7,7 +7,9 @@ require_once "../sms_hook_common.php";
 
 if (check_acl()) {
 	if  ($_SERVER['REQUEST_METHOD'] == 'POST') {
-		//error_log('REQUEST: ' .  print_r($_REQUEST, true));
+		if ($debug) {
+			error_log('[SMS] REQUEST: ' .  print_r($_REQUEST, true));
+		}
 		route_and_send_sms($_REQUEST['From'], str_replace("+","",$_REQUEST['To']), $_REQUEST['Text']);
 	} else {
 	  die("no");
@@ -16,4 +18,4 @@ if (check_acl()) {
 	error_log('ACCESS DENIED [SMS]: ' .  print_r($_SERVER['REMOTE_ADDR'], true));
 	die("access denied");
 }
-?>
+?>

+ 5 - 1
sms/hook/sms_hook_teli.php

@@ -5,9 +5,13 @@ include "../root.php";
 require_once "resources/require.php";
 require_once "../sms_hook_common.php";
 
-if(check_acl()) { // IP whitelisting sucks, we should get proper auth like tokens or something
+if(check_acl()) {
+		if ($debug) {
+			error_log('[SMS] REQUEST: ' .  print_r($_REQUEST, true));
+		}
 		route_and_send_sms($_POST['source'], $_POST['destination'], $_POST['message']);
 } else {
 	error_log('ACCESS DENIED [SMS]: ' .  print_r($_SERVER['REMOTE_ADDR'], true));
 	die("access denied");
 }
+?>

+ 4 - 2
sms/hook/sms_hook_twilio.php

@@ -7,7 +7,9 @@ require_once "../sms_hook_common.php";
 
 if (check_acl()) {
 	if  ($_SERVER['REQUEST_METHOD'] == 'POST') {
-		//error_log('REQUEST: ' .  print_r($_REQUEST, true));
+		if ($debug) {
+			error_log('[SMS] REQUEST: ' .  print_r($_REQUEST, true));
+		}
 		route_and_send_sms($_REQUEST['From'], str_replace("+","",$_REQUEST['To']), $_REQUEST['Body']);
 	} else {
 	  die("no");
@@ -16,4 +18,4 @@ if (check_acl()) {
 	error_log('ACCESS DENIED [SMS]: ' .  print_r($_SERVER['REMOTE_ADDR'], true));
 	die("access denied");
 }
-?>
+?>

+ 3 - 3
sms/resources/install/scripts/app/sms/index.lua

@@ -29,8 +29,8 @@
 	dbh = database_handle('system');
 
 --debug
-	debug["info"] = false;
-	debug["sql"] = false;
+	debug["info"] = true;
+	debug["sql"] = true;
 
 --set the api
 	api = freeswitch.API();
@@ -228,7 +228,7 @@
 			if outbound_caller_id_number:len() < 11 then
 				outbound_caller_id_number = "1" .. outbound_caller_id_number;
 			end
-			cmd="curl -v -X POST " .. api_url .." -u " .. access_key .. ":" .. secret_key .. " -H \"Content-type: application/json\" -d '{\"from\": \"+" .. outbound_caller_id_number .. "\", \"to\": \"+" .. to .."\", \"text\": " .. body .."}'"		
+			cmd="curl -v -X POST " .. api_url .." -u " .. access_key .. ":" .. secret_key .. " -H \"Content-type: application/json\" -d '{\"from\": \"+" .. outbound_caller_id_number .. "\", \"to\": \"+" .. to .."\", \"text\": \"" .. body .."\"}'"		
 		
 		end
 		if (debug["info"]) then

+ 1 - 1
sms/sms_hook_common.php

@@ -34,7 +34,7 @@ include "root.php";
 
 //luarun /var/www/fusionpbx/app/sms/sms.lua TO FROM 'BODY'
 
-$debug = false;
+$debug = true;
 
 require_once "resources/require.php";