#!/usr/bin/perl # #------------------------------------------------------------------------------------------- # PERL CODE FOR SERVER TO SERVER CONNECTION WITH SMSWebAd # Version 2.1.0 # # ============ YOU MUST SET YOUR ACCOUNT DATA AT ROWS 67 and 68 ============== # # With this part of code it is possible to send the variables to the SMSWebAd gateway and obtain an outcome through the code with the following values: # result = 01 (The message has been sent without errors) # result = 02 (The message has queued for post sending) # result = 76 (DeliveryRequest not valid) # result = 77 (Udh not valid) # result = 78 (Network code not valid) # result = 79 (Permission denied) # result = 80 (Tcp/Ip not allowed) # result = 81 (Gateway not valid) # result = 82 (ID SMS not found) # result = 83 (Bad request) # result = 84 (Sender not valid) # result = 85 (IP address non enabled by the account) # result = 86 (Destination number blocked by the account) # result = 87 (IP address blocked by the account) # result = 88 (SMS type not recognized) # result = 89 (Account non valid or not active) # result = 90 (GSM operator blocked) # result = 91 (International prefix or operator not enabled) # result = 92 (Date and time of sending of message irregular) # result = 93 (The text of the message has not been inserted) # result = 94 (The GSM number or characters are not valid) # result = 95 (The GSM prefix or characters are not valid) # result = 96 (The international prefix or characters are not valid) # result = 97 (The message has not been sent due to a connection error with the gateway) # result = 98 (Reached maximum amount of SMS per single session) # result = 99 (The message has not been sent because the account has no SMS available) #------------------------------------------------------------------------------------------- #------------------------------------------------------------------------------------------- # VARIABLES TO GIVE TO THE GATEWAY: # # CountryCode (Max 4 Characters) = International Prefix (es.Italia = 39) # GsmCode (Max 5 Characters) = GSM phone prefix that will receive the SMS (es.Tim = 335,338 etc) # PhoneNumber (Max 9 Characters) = phone number that will receive the SMS # TextMessage (Max 160 Car. per Sms sonly text) = Text of the message that will be sent # Sender (Max 11 car. alphanumeric or 16 numeric) = The Sender of the SMS message # Language (3 Characters) = Language used ("ita" or "eng") # SmsHour (2 Characters) = Time the message has been sent (from 01 to 12) # SmsMinute (2 Characters) = Minutes (from 00 to 59) # SmsAmPm (2 Characters) = Anti Post Meridian (AM o PM) # SmsDay (2 Characters) = Day (from 01 to 31) # SmsMonth (2 Characters) = Month (from 01 to 12) # SmsYear (2 Characters) = Year (from 01 to 99 Es. 01=2001, 02=2002, 03=2003 etc) # SmsType (Max 3 Character) = Type of message (empty=Sms, RT=RingTone, LG=Logo, FL=Flash, GIF=File Gif, BMP=File Bmp, # RTX=File RTTTL or RTX, MID= File MIDI, UCS=Unicode UCS-2, PIC=Picture SCR=Screen Saver, # UDH=Sms with User Data Header, CLI=Group Logo, WPS=WAP Push Message, WBK=WAP Bookmark) # # The variables SmsHour, SmsMinute, SmsAmPm, SmsDay, SmsMonth and SmsYear if left blank (zero value) # will take the current system values, also singularly # #------------------------------------------------------------------------------------------- # # Reads the value of the variables from the FORM of the web page # #------------------------------------------------------------------------------------------- $Language = "eng"; # Select language ("ita" = Italiano "eng" = English) $Account = "XXXXX"; # Insert your registed account for SMSWebAd $Password = "YYYYY"; # Insert your Password for SMSWebAd $Test = 0; # "1" if enable the Test (the message will not be sent) $Gateway = ""; # EMPTY automatic routing $NetworkCode = ""; # EMPTY automatic network code $Udh = ""; # Assign User Data Header $DeliveryRequest = "0"; # DeliveryRequest = "1" delivery confirmation request $Notification = ""; # Delivery notification via email or via Http $MainServer = "www.evangelo.org"; $BackupServer = "www.evangelo.org"; use CGI; use IO::Socket; $cgi = new CGI; $CountryCode = $cgi->param("CountryCode"); $GsmCode = $cgi->param("GsmCode"); $PhoneNumber = $cgi->param("PhoneNumber"); $Sender = $cgi->param("Sender"); $TextMessage = $cgi->param("TextMessage"); $SmsDay = $cgi->param("SmsDay"); $SmsMonth = $cgi->param("SmsMonth"); $SmsYear = $cgi->param("SmsYear"); $SmsHour = $cgi->param("SmsHour"); $SmsMinute = $cgi->param("SmsMinute"); $SmsAmPm = $cgi->param("SmsAmPm"); $SmsType = $cgi->param("SmsType"); #--------------------------------------------------------------- # SENDER AND MESSAGE WILL BE CLEANED BY CERTAIN CHARACTERS #--------------------------------------------------------------- $TextMessage =~ s{([&\+%# =])}{hx($1)}ge; $Sender =~ s{([&\+%# =])}{hx($1)}ge; #--------------------------------------------------------------- # CONNECTION VIA HTTP (NO PROXY) #--------------------------------------------------------------- $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 "$result\n"; #------------------------------------------------------------------------------------------------------------------------------ # IF REDIRECT THE RESULT #------------------------------------------------------------------------------------------------------------------------------ #$Url="http://www.domain.com/page.xxx?result=$result\n\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 #--------------------------------------------------------------- $Stringa = "Language=$Language&Account=$Account&Password=$Password&Test=$Test&Gateway=$Gateway&CountryCode=$CountryCode&GsmCode=$GsmCode&PhoneNumber=$PhoneNumber&Sender=$Sender&TextMessage=$TextMessage"; $Stringa = "$Stringa&SmsDay=$SmsDay&SmsMonth=$SmsMonth&SmsYear=$SmsYear&SmsHour=$SmsHour&SmsMinute=$SmsMinute&SmsAmPm=$SmsAmPm&SmsType=$SmsType"; $Len = length($Stringa); #--------------------------------------------------------------- # YOU WILL CONNECT TO THE SERVER FOR SENDING THE SMS MESSAGE #--------------------------------------------------------------- # Use this Row to SIMULATE SENDING # $sock->print("POST /smswebad/test.asp HTTP/1.0\n"); # Use this Row to REALLY SEND $sock->print("POST /smswebad/send.asp HTTP/1.0\n"); $sock->print("Host: $ServerName\n"); $sock->print("Content-type: application/x-www-form-urlencoded\n"); $sock->print("Content-length: $Len\n\n"); $sock->print("$Stringa\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); }