#!/usr/bin/perl #------------------------------------------------------------------------------------------- # PERL SCRIPT FOR SMS GATEWAY # (c) 2001-2009 Digitel Mobile Srl # all rights reserved # last update: 20 May 2009 #------------------------------------------------------------------------------------------- # +OK Credit SMS is accepted by SMS Server # -ERR 100 Syntax/System Error # -ERR 99 Credit Not Available # -ERR 98 Login Failure # -ERR 97 Gateway Error # -ERR 96 Country Code Not Valid # -ERR 95 Gsm Code Not Valid # -ERR 94 Phone Number/Recipients Not Valid # -ERR 93 SMS Data Not Valid # -ERR 92 Data/Time Not Valid # -ERR 91 Country Code or/and Gsm Code Not Available # -ERR 90 Network Barred # -ERR 89 Account Blocked # -ERR 88 SMS Not Recognized # -ERR 87 IP Address Blocked By Account # -ERR 86 Recipient Blocked By Account # -ERR 85 IP Address Not Authorized # -ERR 84 Sender Not Valid # -ERR 83 Bad Request $Account = "xxxxxx" # Mandatory, Max 20 Bytes, String, Username of customer account $Password = "yyyyyyy" # Mandatory, Max 20 Bytes, String, Password of customer account $Sender = "testSMS" # Mandatory, Max 14 Digits or 11 characters alpahnumeric Originator $Recipients = 2 # Mandatory, Max 2 Digits, Integer: 1 to 99 Number of recipients $PhoneNumbers = "+39123456789,+44123456789" # Mandatory, Max 1584 Bytes, String, List of one or several recipient phone number to receive the SMS (separated by commas) $SMSData = "This is a test message" # Mandatory, Max 4096 Bytes, String, SMS Message $SMSType = "" # Optional, Max 3 Bytes, String Type of message $SMSDateTime = "25-Dec-2009 02:00:00 PM" # Optional, Max 30 Bytes, Date and Time for deferred delivery $SMSTest = 1 # Optional, Boolean (1=True, 0=False), Indicates "test" mode $UDH = "" # Optional, Max 400 Bytes, String, User Data Header $DCS = "" # Optional, Max 2 Bytes, Hex, Data Coding Scheme $DeliveryRequest = 1 # Optional, Max 1 Digit, Integer, Request for Delivery Report $Notification = "mailto:youremail@yourdomain.xxx" # Optional, Max 98 Bytes, String, Allow to send notification to email address or to a script via Http $SmsValidity = "" # Optional, Max 4 Digits, Numeric, Validity Period $SmsRef = "1000012345" # Optional, Max 20 Bytes, String, Reference ID $MainServer = "gateway.smsitaly.com"; $BackupServer = "backup.smsitaly.com"; use CGI; use IO::Socket; $cgi = new CGI; $SMSData =~ s{([&\+%# =])}{hx($1)}ge; $Sender =~ s{([&\+%# =])}{hx($1)}ge; $SMSDateTime =~ s{([&\+%# =])}{hx($1)}ge; $Notification =~ s{([&\+%# =])}{hx($1)}ge; $SmsRef =~ s{([&\+%# =])}{hx($1)}ge; $PhoneNumbers =~ s{([&\+%# =])}{hx($1)}ge; $ServerName = $MainServer; while (true) { $sock = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $ServerName, PeerPort => 80 ); if (defined($sock)) { $result = &sendToServer; #--------------------------------------------------------------- # WRITE RESPONSE #--------------------------------------------------------------- print $cgi->header.""; print "The response of the sent message is: $result\r\n"; #------------------------------------------------------------------------------------------------------------------------------ # IF REDIRECT THE RESULT #------------------------------------------------------------------------------------------------------------------------------ #$Url="http://www.domain.com/page.xxx?result=$result\r\n\r\n"; #print "Location: $Url"." "; exit; } else { #--------------------------------------------------------------- # CHANGE SERVER #--------------------------------------------------------------- if ($ServerName eq $MainSERVER) { $ServerName = $BackupSERVER; } else { $ServerName = $MainSERVER; } } } sub sendToServer { #--------------------------------------------------------------- # CONNECTION OK #--------------------------------------------------------------- $sock->autoflush(1); #--------------------------------------------------------------- # BUILDS THE STRING TO SEND TO THE SERVER #--------------------------------------------------------------- $StringHttpPost="Account=$Account&Password=$Password&SMSTest=$SMSTest&SMSGateway=$SMSGateway&Recipients=$Recipients&PhoneNumbers=$PhoneNumbers&Sender=$Sender&SMSData=$SMSData"; $StringHttpPost="$StringHttpPost&SMSDateTime=$SMSDateTime&SMSType=$SMSType&NetworkCode=$NetworkCode&Udh=$Udh"; $StringHttpPost="$StringHttpPost&DeliveryRequest=$DeliveryRequest&Notification=$Notification"; $StringHttpPost="$StringHttpPost&SmsValidity=$SmsValidity&SmsRef=$SmsRef&DCS=$DCS"; $Len = length($StringHttpPost); #--------------------------------------------------------------- # YOU WILL CONNECT TO THE SERVER FOR SENDING THE SMS MESSAGE #--------------------------------------------------------------- $sock->print("POST /bulk/send.asp HTTP/1.0\r\n"); $sock->print("Host: $ServerName\r\n"); $sock->print("Content-type: application/x-www-form-urlencoded\r\n"); $sock->print("Content-length: $Len\r\n\r\n"); $sock->print("$StringHttpPost\r\n"); #--------------------------------------------------------------- # GIVES THE RESPONSE FOR THE SENT MESSAGE #--------------------------------------------------------------- while ($_ = <$sock>) { if (/^(\d+)/) { $result = $1; last; } } $sock->close; return $result; } #--------------------------------------------------------------- # ROUTINE CLEAR STRING #--------------------------------------------------------------- sub hx { my($char) = @_; return sprintf "%%%X", ord($char); }