sms_hook_bulkvs.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. //set the include path
  3. $conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE);
  4. set_include_path(parse_ini_file($conf[0])['document.root']);
  5. //includes files
  6. require_once "resources/require.php";
  7. require_once "../sms_hook_common.php";
  8. //if (check_acl()) {
  9. //Make sure that it is a POST request.
  10. if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){
  11. throw new Exception('Request method must be POST!');
  12. }
  13. //Make sure that the content type of the POST request has been set to application/json
  14. $contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
  15. if(strcasecmp($contentType, 'application/json') != 0){
  16. throw new Exception('Content type must be: application/json');
  17. }
  18. //Receive the RAW post data.
  19. $content = trim(file_get_contents("php://input"));
  20. //$mail_body.="RAW post data: ".$content."\n";
  21. //Attempt to decode the incoming RAW post data from JSON.
  22. $decoded = json_decode($content, true);
  23. $mail_body.="decoded data: \n";
  24. $sms_from=$decoded['From'];
  25. $sms_text=$decoded['Message'];
  26. //$sms_media_url=print_r($decoded['MediaURLs'], TRUE);
  27. foreach($decoded['To'] as $key=>$value){
  28. $sms_to_did_no=$value;
  29. }
  30. foreach($decoded['MediaURLs'] as $media_url){
  31. $sms_media_url=$media_url." ".$sms_media_url;
  32. }
  33. route_and_send_sms($sms_from, $sms_to_did_no,$sms_text.$sms_media_url);
  34. // } else {
  35. die("no");
  36. // }
  37. //} else {
  38. error_log('ACCESS DENIED [SMS]: ' . print_r($_SERVER['REMOTE_ADDR'], true));
  39. die("access denied");
  40. //}
  41. ?>