#!/bin/sh -u # $0 SMSnumber|alias SMS text message quoted or not # This script defines several short aliases for common people. # -Ian! D. Allen - idallen@idallen.ca - www.idallen.com CMD=${0##*/} if [ $# -lt 2 ] ; then echo 1>&2 "$CMD: expecting 10-digit number and text message found $# ($*)" exit 1 fi # Remove all non-alphanumeric from the number|alias. # Everything after the number is part of the message. # arg1=$1 num=$( echo "$1" | sed -e 's/[^[:alnum:]]//g' ) shift msg="$*" case "$num" in Alana | alana | ala | aod | a ) arg1="Alana" num=613-315-6712 ;; Amy | amy ) arg1="Amy" num=613-297-3420 ;; Betsy | betsy | bet | b ) arg1="Betsy" num=647-380-1387 ;; Brendan | brendan | bre ) arg1="Brendan" num=613-263-3966 ;; Carolina | carolina | caro ) arg1="Carolina" num=613-286-6732 ;; Charlie | charlie | cha | c ) arg1="Charlie" num=416-427-2177 ;; Cheryl | cheryl | che | cbg ) arg1="Cheryl" num=416-993-3418 ;; Chiara | chiara | chi | c ) arg1="Chiara" num=613-222-1647 ;; Fran | fran ) arg1="Fran" num=613-914-5383 ;; Ian | ian | i ) arg1="Ian" num=613-235-6216 ;; tnow | iant ) arg1="Ian Textnow" num=343-304-0648 ;; Jan | jan | j ) arg1="Jan" num=613-293-4423 ;; janhome | jh ) arg1="Jan" num=613-567-6262 ;; Katie | katie | kat ) arg1="Katie" num=514-993-2283 ;; Kia | kia ) arg1="Kia" num=613-852-3540 ;; Kieran | kie ) arg1="Keiran" num=780-965-4589 ;; Laurinda | laurinda | lau ) arg1="Laurinda" num=343-571-4615 ;; Louis | lou ) arg1="Louis" num=613-501-8615 ;; Michael | maa ) arg1="Michael" num=613-322-9996 ;; Mike | mph ) arg1="Mike Phaneuf" num=613-293-5369 ;; Natalie | natalie | nat | n ) arg1="Natalie" num=613-293-1900 ;; paypal ) arg1="PayPal" num=702-500-3695 ;; Rachel | rachel ) arg1="Rachel" num=408-833-0063 ;; Savannah | savannah | sav ) arg1="Savannah" num=416-731-5016 ;; Sierra | sierra| sie | smb ) arg1="Sierra" num=613-265-3266 ;; Sue | sue ) arg1="Sue" num=613-407-2626 ;; Vaalea | vaalea | val | v ) arg1="Vaalea" num=613-903-3040 ;; [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] ) ;; * ) echo 1>&2 "$CMD: number '$num' invalid: must have 10-digit number" exit 1 ;; esac # Once again remove all non-alphanumeric from the number. num=$( echo "$num" | sed -e 's/[^[:alnum:]]//g' ) exec php -q -- "$CMD" "$arg1" "$num" "$msg" <<'EOF' 5 ) { $i = $argc - 1; echo "$CMD: ERROR: Expecting four PHP script arguments found $i.\n"; exit(1); } $SMSnumber = $argv[3]; $SMSmessage = $argv[4]; $SMSsender="6132356216"; # Class VoIPms taken from voip.ms API web site; unneeded functions removed. # Calling script comes from http://incrediblepbx.com/voipms-SMS.tar.gz # with lots of modifications by me, including the storing of the password # in a different file. -Ian! class VoIPms { var $api_username = 'idallen@idallen.ca'; # Customize me var $api_password = ''; # will be set below var $soap_client; function soapClient(){ $this->soap_client = new SoapClient(null, array( 'location' => "https://voip.ms/api/v1/server.php", 'uri' => "urn://voip.ms", 'soap_version' => SOAP_1_2, 'trace' => 1 ) ); } function soapCall($function, $params){ if(!$this->soap_client){$this->soapClient();} try { return $this->soap_client->__soapCall($function, $params);} catch (SoapFault $e) { trigger_error("SOAP Fault: [{$e->faultcode}] {$e->faultstring}", E_USER_ERROR); } } function sendSMS($did,$dst,$message){ $function = "sendSMS"; $params = array( "params" => array( "api_username" => $this->api_username, "api_password" => $this->api_password, "did" => $did, "dst" => $dst, "message" => $message ) ); return $this->soapCall($function,$params); } } ob_implicit_flush(false); set_time_limit(300); $errorflag = false; if ( strlen($SMSsender)<>10 ) { echo "$CMD: ERROR '$SMSsender': SMS sender number must be 10 digits.\n"; $errorflag = true; } if ( strlen($SMSnumber)<>10 ) { echo "$CMD: ERROR '$SMSnumber': recipient SMS number must be 10 digits.\n"; $errorflag = true; } if ( strlen($SMSmessage)<2 ) { echo "$CMD: ERROR '$SMSmessage': SMS message must be at least 2 characters long.\n"; $errorflag = true; } if ( strlen($SMSmessage)>160 ) { echo "$CMD: ERROR SMS message must be less than 160 characters long.\n"; $errorflag = true; } if ($errorflag) { echo "$CMD: SYNTAX: Usage: $CMD SMSnumber 'sms message'\n"; exit(1); } $voipms = new VoIPms(); /* Get the password from a file and put it into the class */ $fmc = "/home/idallen/.fetchmailrc"; $fh = fopen($fmc,"r"); if ( $fh == false ) { echo "$CMD: '$fmc': cannot open for reading\n"; exit(1); } $passwd = array(); while( $line=fgets($fh) ) { if ( preg_match("/^# voipms password sms (\S+)/",$line,$passwd) ) { $voipms->api_password = $passwd[1]; break; } } fclose($fh); if ( strlen($voipms->api_password) < 8 ) { echo "$CMD: ERROR: missing or too short voipms sms password in $fmc\n"; exit(1); } /* Send SMS and check for errors */ $response = $voipms->sendSMS($SMSsender,$SMSnumber,$SMSmessage); if ( $response['status'] != 'success' ) { echo "$CMD: FAILED to $SMSnumber: $response[status]\n"; exit(1); } echo "$CMD: SMS message sent from $SMSsender to $arg1 $SMSnumber.\n"; ?> EOF