source: trunk/scripts/example_sms.pl@ 27

Last change on this file since 27 was 1, checked in by katerina, 19 years ago

Initial import

File size: 5.3 KB
Line 
1#!/usr/bin/perl -w
2
3use strict;
4use IO::Socket; # Socket work
5
6###############################################################################
7##
8## example_sms.pl -- simple example script to send
9## an SMS message via a web cgi
10## Works with German pitcom powered free SMS sites
11## - find one and look at the page source to set the
12## pitcom variables (see below)
13## - note that pitcom checks the referer, thus you should
14## take care to set the proper value
15##
16## NOTE: while the 'big names' have implemented measures to prevent
17## the use of automated scripts, and disallow such scripts
18## explicitely in their TOS (Terms of Service), this is not
19## neccesarily true for smaller websites.
20##
21## An example for the latter are German websites providing free
22## SMS (to German nets only) powered by pitcom.
23## With a suitable query, you may find such sites on (e.g.) Google.
24## At the time of the writing of this script, the sites I found did not
25## disallow the use of scripts, but check for yourself if you are
26## using this.
27##
28## usage: example_sms.pl [NR]
29## <NR> destination phone number
30## message is read from STDIN
31##
32## (c) R. Wichmann <support@la-samhna.de> Tue Jul 17 CEST 2001
33## Released under the Gnu Public License version 2.0 or later
34## adapted from archpage ( (c) Rob Muhlestein )
35## and mpage.pl ( (c) David Allen <s2mdalle@titan.vcu.edu> )
36##
37
38########################## -- BEGIN CONFIGURATION --
39
40## set to default phone number
41 my $NR = '<default phone number>';
42
43## set to sender
44 #my $VON = '<default sender>';
45 my $VON = 'stupsel';
46
47## set to URL of form page
48 my $REFERER = '<default referer>';
49
50## set to cgi script URL without 'http://domain';
51 my $PAGE = '<default cgi URL>';
52
53## set to domain where cgi script lives;
54 my $DOMAIN = '<default domain>';
55
56## set to 1 if you want to save response
57 my $save_response = 1;
58
59## set to 1 for verbose output
60 my $verbose = 1;
61
62## set to 1 to enable sending
63 my $really_send = 0;
64
65
66## The PITCOM variables
67
68#my $ID = '<id>'; # gateway-ID
69#my $WERBUNG = '<advertisement>'; # advertisement
70#my $QUITTUNG = '<return page>'; # return page
71#my $USER = '<customer>'; # customer
72#my $LIST = '0'; # message type
73
74########################## -- END CONFIGURATION --
75
76$NR = $ARGV[0] if $ARGV[0];
77
78my $message='';
79undef $/;
80$message=<STDIN>;
81
82$message =~ s/\[EOF\]//g;
83
84## URL encode and remove line breaks
85$message =~ s/\n/ /g;
86$message =~ s/\r//g;
87$message =~s/\s+/ /g; # Multiple whitespace -> one space
88
89$message =~ s/([^a-zA-Z0-9-_\.\/])/uc sprintf("%%%02x",ord($1))/eg;
90$message =~ s/%20/+/g;
91
92$WERBUNG =~ s/([^a-zA-Z0-9-_\.\/])/uc sprintf("%%%02x",ord($1))/eg;
93$WERBUNG =~ s/%20/+/g;
94$QUITTUNG =~ s/([^a-zA-Z0-9-_\.\/])/uc sprintf("%%%02x",ord($1))/eg;
95$QUITTUNG =~ s/%20/+/g;
96$USER =~ s/([^a-zA-Z0-9-_\.\/])/uc sprintf("%%%02x",ord($1))/eg;
97$USER =~ s/%20/+/g;
98
99## truncate
100my $maxChars = 153 - length($WERBUNG) - length($VON);
101
102if(length($message) >= $maxChars)
103{
104 $message = substr($message, 0, $maxChars);
105}
106
107
108my $NR1 = substr($NR, 0, 4);
109my $NR2 = substr($NR, 4, length($NR)-4);
110
111my $msglen = length($message);
112
113my $overhead = "ID=$ID&";
114$overhead .= "WERBUNG=$WERBUNG&";
115$overhead .= "QUITTUNG=$QUITTUNG&";
116$overhead .= "USER=$USER&";
117$overhead .= "LIST=$LIST&";
118$overhead .= "NR1=$NR1&";
119$overhead .= "NR2=$NR2&";
120$overhead .= "VON=$VON&";
121$overhead .= "MESSAGE=$message&";
122$overhead .= "CNT=$msglen";
123
124my $smslen = length($overhead);
125
126my $llim = "\r\n"; # At the end of each line.
127
128my $SMS = "POST $PAGE HTTP/1.0$llim";
129$SMS .= "User-Agent: EvilGenius/1.0$llim";
130$SMS .= "Referer: $REFERER$llim";
131$SMS .= "Accept: */*$llim";
132$SMS .= "Content-length: $smslen$llim";
133$SMS .= "Content-type: application/x-www-form-urlencoded$llim";
134$SMS .= "$llim";
135$SMS .= "$overhead";
136
137if ($verbose)
138{
139 print STDERR " Sending message...\n\n";
140 print STDERR "$SMS\n\n";
141}
142
143my $document='';
144
145if ($really_send)
146{
147 my $sock = IO::Socket::INET->new(PeerAddr => $DOMAIN,
148 PeerPort => 'http(80)',
149 Proto => 'tcp');
150
151
152 if ($verbose)
153 {
154 die "Cannot create socket : $!" unless $sock;
155 }
156 else
157 {
158 exit (1) unless $sock;
159 }
160
161 $sock->autoflush();
162 $sock->print("$SMS");
163
164 $document = join('', $sock->getlines());
165}
166else
167{
168 $document = " really_send was set to 0, SMS not sent";
169}
170
171if ($save_response)
172{
173 if ($verbose)
174 {
175 print STDERR "Saving response to tmp.html...\n\n";
176 }
177 my $status = 0;
178 open(TMP,">tmp.html") or $status=1;
179 print TMP "$document\n" unless $status;
180 close TMP unless $status;
181}
182
183if ($document =~ m/SMS wird versendet/g)
184{
185 if ($verbose)
186 {
187 print STDERR " SMS successfully sent to $NR.\n";
188 }
189 exit (0);
190}
191else
192{
193 if ($verbose)
194 {
195 print STDERR " SMS not sent. There was an error.\n";
196 print STDERR " Use save_response = 1 to save the response to\n";
197 print STDERR " tmp.html in order to see what the server sent back.\n";
198 }
199 exit (1);
200}
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
Note: See TracBrowser for help on using the repository browser.