// php script written by Simon Moore 19th July 2003< // this script is for 'It's Arrived' or csoft.co.uk employees or customers // and users must have an account with csoft.co.uk or 'It's Arrived' // This script will send either SMS or MMS messages, and deal with all encoding // // IMPORTANT NOTE // there is no warranty, implied or otherwise with this software. // // LICENCE // This code has been placed in the Public Domain for all to enjoy. // // The variables set at the end of this comment must be modified as follows: // // $uname = USERNAME eg: $uname = "USERNAME.12345"; // $pw = PASSWORD eg: $pw = "QWERTYU.POIUYT"; // $pin = PIN number eg: $pin = "12345678"; // // $path = UPLOAD DIRECTORY FOR MMS images eg $path = "uploads/"; // ***NOTE - this path must be set world writable in your server directory (ie, chmod 777) // // $max_size = MAXIMUM SIZE OF MMS IMAGE IN BYTES // eg: $max_size = 10240; (max size is set to 10kb) // // This script should be saved as 'index.php' in a directory of your choice // A subdirectory should also exist for MMS uploads (see note above) // // MMS content has been limited to JPEG or GIF files, // but this could be changed by altering the $userfile_type // conditions in the 'sendmms' action below $uname = "USERNAME.12345"; $pw = "QWERTYU.POIUYT"; $pin = "12345678"; $path = "uploads/"; $max_size = 10240; function http_post($server, $port, $url, $vars) { $user_agent = "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)"; $urlencoded = ""; while (list($key, $value) = each($vars)) { $urlencoded.= urlencode($key)."=".$value."&"; } $urlencoded = substr($urlencoded, 0, -1); $content_length = strlen($urlencoded); $headers = "POST $url HTTP/1.1\nAccept: */*\nAccept-Langauge: en-au\nContent-Type: application/x-www-form-urlencoded\n"; $headers.= "User-Agent: $user_agent\nHost: $server\nConnection: Keep-Alive\nCache-Contrrol: no-cache\n"; $headers.= "Content-Length: $content_length\n\n"; $fp = fsockopen($server, $port, $errno, $errstr); if (!$fp) { return false; } fputs($fp, $headers); fputs($fp, $urlencoded); $ret = ""; while (!feof($fp)) { $ret.=fgets($fp, 1024); } fclose($fp); return $ret; } function ascii_convert($text) { $text = str_replace(' ', '___SPACE___', $text); $text = urlencode($text); $text = str_replace('___SPACE___', '%20', $text); return $text; } echo "SMS / MMS"; echo ""; if ($action == "") { echo "Please choose an option from the list below:

"; echo "
  • Send SMS message"; echo "
  • Send MMS message"; echo "

    "; } elseif ($action == "sms") { echo "Please fill in the form below to send your message:

    "; echo "
    "; echo ""; echo "Number: (ie, 447788778877)
    "; echo ""; echo "

    Message:
    "; echo ""; echo "

    "; echo "  |   "; echo "
    "; } elseif ($action == "sendsms") { $message = stripslashes($message); $message = ascii_convert($message); $sending = http_post("www.csoft.co.uk", 80, "/sendsms", array("Username" => $uname, "PIN" => $pin, "SendTo" => $phone, Message" => $message)); } elseif ($action == "mms") { echo "Please fill in the form below to send your message:

    "; echo "
    "; echo ""; echo "Number: (ie, 447788778877)
    ";< echo ""; echo "

    Image: "; echo "

    Message:
    "; echo ""; echo "


    "; echo "   |  "; } elseif ($action == "sendmms") { if (is_uploaded_file($userfile)) { if ($userfile_size > $max_size) { echo "The file is too big. Please click back to try again with a smaller image.

    "; exit; } if (($userfile_type == "image/gif") || ($userfile_type == "image/jpeg") || ($userfile_type == "image/jpg") || ($userfile_type == "image/pjpeg")) { if (file_exists($path.$userfile_name)) { echo "Sorry. An image with that name already exists. Please rename the image and click back to try again.

    "; exit; } $res = copy($userfile, $path.$userfile_name); if (!$res) { echo "Sorry. The upload failed. Please click back to try again.

    "; exit; } else { echo "File $userfile_name uploaded successfully. Thank you.

    "; $success = "yes"; } } else { echo "Sorry. Your file needs to be either a .gif or .jpg file. Please click back to try again.
    \n"; exit; } } if ($success == "yes") { $filetoattach = $path.$userfile_name; $filehandle = fopen("$filetoattach", "r"); $data = fread($filehandle, filesize($filetoattach)); fclose ($filehandle); $data = bin2hex($data); $message = stripslashes($message); $message = ascii_convert($message); $sending = http_post("www.csoft.co.uk", 80, "/sendmms", array("Username" => $uname, "PIN" => $pin, "SendTo" => $phone, "Message" => $message, "WAPPushFileName1" => $userfile_name, "WAPPushFileData1" => $data)); $delete = @unlink($filetoattach); echo "

    Result: $sending

    "; } } -------------------------------------------------------------------------------- Visual BASIC code to convert a string to hex Contributed by Kenric Mckenzie. This script may be useful when sending ringtones or graphics. Function HexConvert(ByVal strFileName As String) As String Dim s As String Dim hx As String Open strFileName For Binary Access Read As 1 hx = "" While (Not EOF(1)) c = Input$(1, 1) If (c <> "") Then s = Hex(Asc(c)) If (Len(s) = 1) Then hx = hx + "0" + s Else hx = hx + s End If End if Wend HexConvert = hx End Function -------------------------------------------------------------------------------- Perl script to convert a file to hex Contributed by Kenric Mckenzie. This script may be useful when sending ringtones or graphics. open(F, "image.gif") || die $!; $s = $hx = ""; while (read(F, $s, 1) > 0) { $hx .= sprintf("%02X", ord($s)); } close F; print "The hex-encoded GIF file is: $hx\n"; -------------------------------------------------------------------------------- Unix shell script to convert a stream to hex Contributed by Kenric Mckenzie. This script may be useful when sending ringtones or graphics. od -v -t x1 image.gif | \ sed -e 's/^........//' | \ tr 'a-f' 'A-F' | \ tr -dc '0-9A-F' -------------------------------------------------------------------------------- C# wrapper class for HTTP POST Contributed by Jon Gianni of J D Wetherspoon plc /// /// This class is responsible for sending to the SMS gateway. /// public class SMSProxy { private string[] Gateways = new string[2]; private static string AccountName = "ABcdefg.123456"; private static string AccountPIN = "12345678"; public enum DeliveryServiceOption { [Description("Economy")] Economy, [Description("Premier")] Premier, [Description("LeastCost")] LeastCost } public static string GetDescription(Enum value) { FieldInfo fi= value.GetType().GetField(value.ToString()); DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes( typeof(DescriptionAttribute), false); return (attributes.Length>0)?attributes[0].Description:value.ToString(); } public SMSProxy() { // // TODO: Add constructor logic here // // list of SMS gateways to use (code will try each in turn if failure encountered.) Gateways[0] = "www.csoft.co.uk/sendsms"; Gateways[1] = "www2.csoft.co.uk/sendsms"; } public void sendSMS(string msg, string sendTo, DeliveryServiceOption deliveryServiceOption, bool sendForReal) { string Query = ""; string decodedMsg = decodeMessage(msg); // Construct the HTTP query string Query = "Username=" + AccountName + "&PIN=" + AccountPIN + "&SendTo=" + sendTo + "&Message=" + decodedMsg + "&DeliveryServiceOption=" + GetDescription(deliveryServiceOption); // Only send the message if sending for real (otherwise, if set to zero don't send the message.) if (sendForReal == true) { int qLen; qLen = Query.Length; // Request and Response objects System.Net.WebResponse objRes; System.IO.StreamReader sr; System.IO.StreamWriter sw; foreach (string gw in Gateways) { System.Net.HttpWebRequest objReq = (System.Net.HttpWebRequest) System.Net.WebRequest.Create("http://" + gw); objReq.KeepAlive= false; objReq.Method = "POST"; objReq.ContentType = @"application/x-www-form-urlencoded; charset=""utf-8"""; objReq.ContentLength = qLen; objReq.Timeout = 10000; // set up access via the proxy server System.Net.WebProxy prx = new System.Net.WebProxy("servername", 80); prx.BypassProxyOnLocal = true; prx.Credentials = new System.Net.NetworkCredential ("username", "password", "domain"); objReq.Proxy = prx; sw = new System.IO.StreamWriter(objReq.GetRequestStream()); sw.Write(Query); sw.Close(); // get server response objRes = objReq.GetResponse(); sr = new System.IO.StreamReader(objRes.GetResponseStream()); if (Convert.ToString(sr.ReadToEnd().Substring(0, 2)) == "01") { // success, exit loop sr.Close(); objRes.Close(); break; } } } } private string decodeMessage(string msg) { // Convert characters in the message text string c; string str = ""; for (int i = 0; i < msg.Length; i++) { c = msg.Substring(i, 1); switch (c) { case " " : c = "%20"; break; case "+" : c = "%2B"; break; case "#" : c = "%23"; break; case "%" : c = "%25"; break; case "&" : c = "%26"; break; case "," : c = "%2C"; break; case "." : c = "%2E"; break; case "/" : c = "%2F"; break; case ":" : c = "%3A"; break; case ";" : c = "%3B"; break; case "<" : c = "%3C"; break; case "=" : c = "%3D"; break; case ">" : c = "%3E"; break; case "?" : c = "%3F"; break; case "!" : c = "%A1"; break; case "óG" : c = "%A3"; break; } str = str + c; } return str; } }