My favorites | Sign in
Project Home Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
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
225
226
227
228
229
230
#!/usr/bin/perl -w
#
# Skrypt wysyłający wiadomości SMS do wszystkich polskich sieci
# poprzez bramkę SMS zarejestrowanych użytkowników Orange (mBox)
#
# Wymaga: perl + LWP + SSL (perl-libwww/libwwwperl, perl-crypt-SSLeay).
# Wymagana autoryzacja użytkownika
#
# (c) 2003-2009 Jacek Fiok <jfiok@jfiok.org>; http://sms.jfiok.org
#
# Treść wiadomości: do 640 znaków; wszystkie polskie sieci.
#
# Podziękowania dla:
# - Spley <sms@spley.home.pl>
# - Maciej Krzyżanowski <spider@popnet.pl>
# - Łukasz Górowski <lukasz@gorowski.com>
#
# Przeróbka po przekształceniu sieci Idea w Orange:
# - Rafał 'RaV.' Matczak <matczak.rafal.orangutan.gmail.com>

my $VERSION = "2012041901";

use strict;
use HTTP::Request::Common;
use HTTP::Cookies;
use LWP::UserAgent;
use Crypt::SSLeay;

# --- DEBUG ---
my $debug = 0; # 0:no, 1:yes
# use LWP::Debug qw(+ -conns);
# LWP::Debug::trace('send()');
sub debug { if ($debug) { print "[", shift, "]\n"; } }

# --- COOKIES ---

##
my $ckey = "";
my $cval = "";
my $cookie_jar = HTTP::Cookies->new;

sub cookieScanner {
# my $i; for ($i=0; $i<5; $i++) { print $i, " : ", $_[$i], "\n"; }
($ckey eq $_[1]) and $cval = $_[2];
}

sub getCookie {
$cval = "";
$ckey = shift;
$cookie_jar->scan (\&cookieScanner);
return $cval;
}

# --- User Agent ---

my $ua = new LWP::UserAgent;
$ua->timeout(30);
$ua->agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.5 Safari/534.55.3");
#$ua->env_proxy();
$ua->cookie_jar($cookie_jar);

# --- functions() ---

## zero set
my $res; my $req; # response; request

sub error {
my ($text, $return) = @_;
print "[ERROR] $text (#$return)\n";
exit $return;
}

sub visit {
$res = $ua->request (GET $_[0]);
if (!($res->is_success)) { error ($_[1], $_[2]); }
}

# --- main() ---

select(STDERR); $| = 1; # make unbuffered
select(STDOUT); $| = 1; # make unbuffered

if ($#ARGV != 3 ) { error ("Zła ilość parametrów - podaj numer i treść wiadomości", 6); }

my $number = $ARGV[0];
my $text = $ARGV[1];
my $username = $ARGV[2];
my $password = $ARGV[3];

$number =~ s/^\+48//;
$number =~ s/^00//;

# allow redirect (POST)
push @{ $ua->requests_redirectable }, 'POST';

# --- DO IT! ---

visit ("https://www.orange.pl/zaloguj.phtml",
"Błąd podczas otwierania formularza [1]", 1);

my $action = 'https://www.orange.pl/zaloguj.phtml?_DARGS=/ocp/gear/infoportal/portlets/login/login-box.jsp';

debug ("Wysyłanie formularza logowania: ".$action);
$req = POST $action, [
"_dyncharset"=>"UTF-8",
"_dynSessConf"=>"-7322242883615328119",
"/tp/core/profile/login/ProfileLoginFormHandler.loginErrorURL"=>"https://www.orange.pl/zaloguj.phtml",
"_D:/tp/core/profile/login/ProfileLoginFormHandler.loginErrorURL"=>"",
"/tp/core/profile/login/ProfileLoginFormHandler.loginSuccessURL"=>"",
"_D:/tp/core/profile/login/ProfileLoginFormHandler.loginSuccessURL"=>"",
"/tp/core/profile/login/ProfileLoginFormHandler.firstEnter"=>"true",
"_D:/tp/core/profile/login/ProfileLoginFormHandler.firstEnter"=>"",
"/tp/core/profile/login/ProfileLoginFormHandler.value.login"=>$username,
"_D:/tp/core/profile/login/ProfileLoginFormHandler.value.login"=>"",
"/tp/core/profile/login/ProfileLoginFormHandler.value.password"=>$password,
"_D:/tp/core/profile/login/ProfileLoginFormHandler.value.password"=>"",
"/tp/core/profile/login/ProfileLoginFormHandler.rememberMe"=>"false",
"_D:/tp/core/profile/login/ProfileLoginFormHandler.rememberMe"=>"",
"/tp/core/profile/login/ProfileLoginFormHandler.login.x"=>"1",
"/tp/core/profile/login/ProfileLoginFormHandler.login.y"=>"1",
"_D:/tp/core/profile/login/ProfileLoginFormHandler.login"=>"",
"_DARGS" => "/ocp/gear/infoportal/portlets/login/login-box.jsp"
];

$req->referer ("https://www.orange.pl/zaloguj.phtml");
$res = $ua->request($req);
if (! ($res->is_success)) { error ("Błąd podczas logowania [2]", 1); }

if (! ($res->content =~ /witaj/) ) { error ("Błąd podczas logowania - sprawdź poprawność wprowadzonego hasła", 5); }

debug ("Logowanie zakończone powodzeniem");

$req = GET 'http://www.orange.pl/portal/map/map/message_box?mbox_view=newsms&mbox_edit=new';
$res = $ua->request($req);

debug ("Sprawdzam ilość pozostałych do wykorzystania wiadomości");
my $left = -1;

if ($res->content =~ /<span class="label">bezpłatne :<\/span><span class="value">([0-9]+).*<\/span><span class="label">z doładowa.*:<\/span><span class="value">([0-9]+)<\/span>/sm) {
$left = eval ($1) + eval ($2);
} elsif ($res->content =~ /<span class=\"label\">bezpłatne :<\/span><span class=\"value\">([0-9]+)<\/span>/sm) {
$left = eval ($1);
}

if ($left == -1) { error ("Nie mogę odczytać ilości dostępnych wiadomości SMS", 7); }
if ($left == 0) { error ("Wykorzystano limit wiadomości w tym miesiącu", 3); }

debug ("Pobieram token");
##
my $token;

if ($res->content =~ /<input name="\/amg\/ptk\/map\/messagebox\/formhandlers\/MessageFormHandler.token" value="([a-zA-Z0-9]{1,15})" type="hidden"\/>/sm) { $token=$1; };
if (!$token) { error ("Token nie został pobrany prawidłowo",1);}
debug ("Token " . $token);

debug ("Rozpoczynam wysyłanie formularza wiadomości SMS");
$req = POST 'http://www.orange.pl/portal/map/map/message_box?_DARGS=/gear/mapmessagebox/smsform.jsp', [
'_dyncharset' => "UTF-8",
'/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.type' => "sms",
'_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.type' => " ",
'/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.errorURL' => '/portal/map/map/message_box?mbox_view=newsms',
'_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.errorURL' => " ",
'/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.successURL' => '/portal/map/map/message_box?mbox_view=sentmessageslist',
'_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.successURL' => " ",
'/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.to' => $number,
'_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.to' => " ",
'_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.body' => " ",
'/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.body' => $text,
'/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.token' => $token,
'_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.token' => ' ',
'enabled' => "true",
'counter' => (640 - length($text)),
'/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.create.x' => 0,
'/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.create.y' => 0,
'_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.create' => " ",
'_DARGS' => '/gear/mapmessagebox/smsform.jsp'
];
$req->referer('http://www.orange.pl/portal/map/map/message_box?mbox_edit=new&mbox_view=newsms');
# Where the magic happens!
$res = $ua->request($req);
if (!($res->is_success)) { error ("Błąd podczas wysyłania wiadomości SMS", 1);}

debug ("Sprawdzam ilość pozostałych wiadomości SMS po przesłaniu formularza wysyłania wiadomości");
##
my $right = -1;

if ($res->content =~ /<span class="label">bezp.*atne :<\/span>\n[ \t]*<span class="value">([0-9]+).*<span class="label">z do.*adowa.*:<\/span>\n[ \t]*<span class="value">([0-9]+)/sm) {
$right = eval ($1) + eval ($2);
} elsif ($res->content =~ /<span class=\"label\">bezp..atne.*<\/span>.*<span class=\"value\">([0-9]+)<\/span>/sm) {
$right = eval ($1);
}

if ($right == -1) { error ("Nie mogę odczytać ilości pozostałych po wysłaniu wiadomości SMS", 7); }

# --- report() ---

if ($res->content =~ /Niepoprawny numer telefonu/) { error ("Podano niepoprawny numer telefonu", 2); }

if ($left > $right) {
print "[OK] Wszystko w porządku; pozostały limit wiadomości: ".$right."\n";
exit 0;
} else {
error ("Możliwy błąd podczas wysyłania (raportowane limity - przed wysłaniem: ".$left.", po wysłaniu: ".$right.").", 8);
}


### DEPRECATED ###
#my $mode = 0; # raport doręczenia 0:nie 1:tak
#my $seconds = 0; # sprawdź raport po X sekundach

my %answers = (
"Skrzynka wiadomości" => ["Wszystko OK", 0],
"Zły numer" => ["Zły numer!", 2],
"został wyczerpany" => ["Limit wiadomości na dziś przekroczony!", 3]
);

sub analizeResults {
my $res = $_[0];
my $searchString;
my @val;
while ( ($searchString, @val) = each (%answers) ) {
if ($res =~ /$searchString/ ) {
print $answers{$searchString}[0], "\n";
exit $answers{$searchString}[1];
}
}
print "Nieoczekiwany błąd:\n$res\n";
exit 127;
}
### end DEPRACATED ###

Change log

r69 by jacek.fiok on Apr 19, 2012   Diff
Update bramki sms.orange.pl po zmianach na
stronie www orange (rebranding tp ->
orange...)

Go to: 
Project members, sign in to write a code review

Older revisions

r65 by jacek.fiok on May 27, 2011   Diff
sms.orange.pl authors
r64 by matczak.rafal on Nov 28, 2010   Diff
I corrected token matching. After some
changes on Orange's web pages, script
stopped working.
r60 by jacek.fiok on Dec 20, 2009   Diff
Porządki w kodzie skryptu nadesłane
przez: Krzysztof Zembrowski

All revisions of this file

File info

Size: 8570 bytes, 230 lines
Powered by Google Project Hosting