Advertisement
antonrd

cli2sms.php

Jul 30th, 2015
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. #!/usr/bin/php -q
  2. <?php
  3.  
  4. /**
  5.  * cli2sms.php by Anton Raharja (antonrd@gmail.com)
  6.  *
  7.  * Example script to get data from shell script and send it as SMS via playSMS
  8.  * You need to have a configured and working playSMS
  9.  * In this example playSMS is accessible from http://localhost/playsms
  10.  * Don't forget to chmod +x cli2sms.php to use it from Linux shell
  11.  *
  12.  * You may modify this script to suit your needs
  13.  *
  14.  * Example usage:
  15.  * - get stat data (eg: uptime) and send it periodically (using cron) to admin's mobile phones
  16.  * - https://aacable.wordpress.com/2015/07/30/playsms-send-sms-via-scriptcli-using-webservices-token/
  17.  */
  18.  
  19. // suppress error message
  20. error_reporting(0);
  21.  
  22. // playSMS username/account for sending SMS
  23. $username = 'admin';
  24.  
  25. // Webservices token for above username
  26. $token = '1194df9e20d06c3790f0c6fef49f174a';
  27.  
  28. // playSMS Webservices URL
  29. $playsms_ws = 'http://localhost/playsms/index.php?app=ws';
  30.  
  31. // destination numbers, comma seperated or use #groupcode for sending to group
  32. // $destinations = '#devteam,+6200123123123,+6200456456456';
  33. $destinations = '+6200123123123,+6200456456456';
  34.  
  35. // get message to send from another shell script or Linux command, for example 'uptime'
  36. // $message = trim(shell_exec('/path/to/your/stat/shell/script/dot/sh'));
  37. $message = trim(shell_exec('uptime'));
  38.  
  39. // send via playSMS HTTP API
  40. if ($message) {
  41.     $ws = $playsms_ws . '&u=' . $username . '&h=' . $token . '&op=pv';
  42.     $ws .= '&to=' . urlencode($destinations) . '&msg='.urlencode($message) . '&nofooter=1';
  43.     $ret = @file_get_contents($ws);
  44.  
  45.     // echo $ret;
  46.     echo "OK: message sent" . PHP_EOL;
  47. } else {
  48.     echo "ERROR: message is empty" . PHP_EOL;
  49. }
  50.  
  51. // end of script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement