line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SMS::Send::DE::Sipgate; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: SMS::Send driver to send via sipgate.de |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
29175
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
7
|
1
|
|
|
1
|
|
3386
|
use HTTP::Cookies; |
|
1
|
|
|
|
|
26306
|
|
|
1
|
|
|
|
|
31
|
|
8
|
1
|
|
|
1
|
|
378
|
use XMLRPC::Lite; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use parent qw(SMS::Send::Driver); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
SMS::Send::DE::Sipgate - An SMS::Send driver for the sipgate.de service. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 VERSION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Version 0.02 |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# create the sender object |
28
|
|
|
|
|
|
|
my $sender = SMS::Send::->new('DE::Sipgate', |
29
|
|
|
|
|
|
|
_login => '123', |
30
|
|
|
|
|
|
|
_password => '456', |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
# send a message |
33
|
|
|
|
|
|
|
my $sent = $sender->send_sms( |
34
|
|
|
|
|
|
|
text => 'You message may use up to 160 chars', |
35
|
|
|
|
|
|
|
to' => '0555 4444', # only german numbers allowed for this driver |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
if ( $sent ) { |
39
|
|
|
|
|
|
|
print "Sent message\n"; |
40
|
|
|
|
|
|
|
} else { |
41
|
|
|
|
|
|
|
print "Failed to send test message\n"; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
L is an regional L driver for |
47
|
|
|
|
|
|
|
the Sipgate.de service. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 Preparing to use this driver |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
You need to sign-up on L and get an Account as well |
52
|
|
|
|
|
|
|
as a local number. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 Disclaimer |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
The authors of this driver take no responibility for any cost accured on your bill |
57
|
|
|
|
|
|
|
by using this module. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Using this driver will cost you money. B |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 METHODS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 new |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Create new sender using this driver. |
66
|
|
|
|
|
|
|
my $sender = SMS::Send::->new( |
67
|
|
|
|
|
|
|
'DE::Sipgate', |
68
|
|
|
|
|
|
|
_login => '123', |
69
|
|
|
|
|
|
|
_password => '456', |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
The C constructor takes two parameter, which should be passed |
73
|
|
|
|
|
|
|
throuh from the L constructor. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=over |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item _login |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
The C<_login> param is your sipgate.de username. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item _password |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
The C<_password> param is your sipgate.de password. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Returns a new C object, or dies on error. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=back |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub new { |
92
|
|
|
|
|
|
|
my $class = shift; |
93
|
|
|
|
|
|
|
my %params = @_; |
94
|
|
|
|
|
|
|
exists $params{_login} |
95
|
|
|
|
|
|
|
or die $class."->new requires _login parameter\n"; |
96
|
|
|
|
|
|
|
exists $params{_password} |
97
|
|
|
|
|
|
|
or die $class."->new requires _password parameter\n"; |
98
|
|
|
|
|
|
|
exists $params{_verbose} |
99
|
|
|
|
|
|
|
or $params{_verbose} = 1; |
100
|
|
|
|
|
|
|
my $self = \%params; |
101
|
|
|
|
|
|
|
bless $self, $class; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$self->{_url} = 'https://'.$self->{_login}.':'.$self->{_password}.'@samurai.sipgate.net/RPC2'; |
104
|
|
|
|
|
|
|
$self->{_cookies} = HTTP::Cookies::->new( ignore_discard => 1, ); |
105
|
|
|
|
|
|
|
return $self; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 client |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Lazy initialization of the XMLRPC client. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub client { |
115
|
|
|
|
|
|
|
my $self = shift; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
if(!$self->{_client}) { |
118
|
|
|
|
|
|
|
$self->{_client} = $self->_init_client(); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
return $self->{_client}; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub _init_client { |
125
|
|
|
|
|
|
|
my $self = shift; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
my $Client = XMLRPC::Lite::->proxy( $self->{_url} ); |
128
|
|
|
|
|
|
|
$Client->transport()->cookie_jar( $self->{_cookies} ); |
129
|
|
|
|
|
|
|
if ( $Client->transport()->can('ssl_opts') ) { |
130
|
|
|
|
|
|
|
$Client->transport()->ssl_opts( verify_hostname => 0, ); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
my $resp = $Client->call( |
134
|
|
|
|
|
|
|
'samurai.ClientIdenfity', |
135
|
|
|
|
|
|
|
{ |
136
|
|
|
|
|
|
|
'ClientName' => 'SMS::Send::DE::Sipgate', |
137
|
|
|
|
|
|
|
'ClientVersion' => '0.1', |
138
|
|
|
|
|
|
|
'ClientVendor' => 'CPAN', |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
); |
141
|
|
|
|
|
|
|
# ignore the result of this call since it seems not to be essential |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
return $Client; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 responses |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
List all known response codes with their explaination. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub responses { |
153
|
|
|
|
|
|
|
my $self = shift; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
if(!$self->{_responses}) { |
156
|
|
|
|
|
|
|
$self->{_responses} = $self->_init_responses(); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
return $self->{_responses}; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub _init_responses { |
163
|
|
|
|
|
|
|
my $self = shift; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# see http://www.sipgate.de/beta/public/static/downloads/basic/api/sipgate_api_documentation.pdf, page 30ff. |
166
|
|
|
|
|
|
|
my $resp_ref = { |
167
|
|
|
|
|
|
|
'200' => 'Method success', |
168
|
|
|
|
|
|
|
'400' => 'Method not supported', |
169
|
|
|
|
|
|
|
'401' => 'Request denied (no reason specified)', |
170
|
|
|
|
|
|
|
'402' => 'Internal error', |
171
|
|
|
|
|
|
|
'403' => 'Invalid arguments', |
172
|
|
|
|
|
|
|
'404' => 'Resources exceeded', |
173
|
|
|
|
|
|
|
'405' => 'Invalid parameter name', |
174
|
|
|
|
|
|
|
'406' => 'Invalid parameter type', |
175
|
|
|
|
|
|
|
'407' => 'Invalid parameter value', |
176
|
|
|
|
|
|
|
'408' => 'Attempt to set a non-writable parameter', |
177
|
|
|
|
|
|
|
'409' => 'Notification request denied', |
178
|
|
|
|
|
|
|
'410' => 'Parameter exceeds maximum size', |
179
|
|
|
|
|
|
|
'411' => 'Missig parameter', |
180
|
|
|
|
|
|
|
'412' => 'Too many requests', |
181
|
|
|
|
|
|
|
'500' => 'Date out of range', |
182
|
|
|
|
|
|
|
'501' => 'URI does not belong to user', |
183
|
|
|
|
|
|
|
'502' => 'Unknown type of service', |
184
|
|
|
|
|
|
|
'503' => 'Selected payment method failed', |
185
|
|
|
|
|
|
|
'504' => 'Selected currecy not supported', |
186
|
|
|
|
|
|
|
'505' => 'Amount exceeds limit', |
187
|
|
|
|
|
|
|
'506' => 'Malformed SIP URI', |
188
|
|
|
|
|
|
|
'507' => 'URI not in list', |
189
|
|
|
|
|
|
|
'508' => 'Format is not valid E.164', |
190
|
|
|
|
|
|
|
'509' => 'Unknown status', |
191
|
|
|
|
|
|
|
'510' => 'Unknown ID', |
192
|
|
|
|
|
|
|
'511' => 'Invalid timevalue', |
193
|
|
|
|
|
|
|
'512' => 'Referenced session not found', |
194
|
|
|
|
|
|
|
'513' => 'Only single value per TOS allowed', |
195
|
|
|
|
|
|
|
'514' => 'Malformed VCARD format', |
196
|
|
|
|
|
|
|
'515' => 'Malformed PID format', |
197
|
|
|
|
|
|
|
'516' => 'Presence information not available', |
198
|
|
|
|
|
|
|
'517' => 'Invalid label name', |
199
|
|
|
|
|
|
|
'518' => 'Label not assigned', |
200
|
|
|
|
|
|
|
'519' => "Label doesn't exist", |
201
|
|
|
|
|
|
|
'520' => 'Parameter includes invalid characters', |
202
|
|
|
|
|
|
|
'521' => 'Bad password. (Rejected due to security concerns)', |
203
|
|
|
|
|
|
|
'522' => 'Malformed timezone format', |
204
|
|
|
|
|
|
|
'523' => 'Delay exceeds limit', |
205
|
|
|
|
|
|
|
'524' => 'Requested VPN type not available', |
206
|
|
|
|
|
|
|
'525' => 'Requested TOS not available', |
207
|
|
|
|
|
|
|
'526' => 'Unified messaging not available', |
208
|
|
|
|
|
|
|
'527' => 'URI not available for registration', |
209
|
|
|
|
|
|
|
}; |
210
|
|
|
|
|
|
|
for my $i (900 .. 999) { |
211
|
|
|
|
|
|
|
$resp_ref->{$i} = 'Vendor defined status code'; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
return $resp_ref; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head2 send_sms |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Send an SMS. See L for the details. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=cut |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub send_sms { |
224
|
|
|
|
|
|
|
my $self = shift; |
225
|
|
|
|
|
|
|
my %params = @_; |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
my $destination = $self->_clean_number($params{'to'}); |
228
|
|
|
|
|
|
|
my $message = substr($params{'text'},0,159); |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
my $resp = $self->client()->call( |
231
|
|
|
|
|
|
|
'samurai.SessionInitiate', |
232
|
|
|
|
|
|
|
{ |
233
|
|
|
|
|
|
|
'RemoteUri' => 'sip:'.$destination.'@sipgate.net', |
234
|
|
|
|
|
|
|
'TOS' => 'text', |
235
|
|
|
|
|
|
|
'Content' => $message, |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
); |
238
|
|
|
|
|
|
|
my $result = $resp->result(); |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
if($result && $result->{'StatusCode'} == 200) { |
241
|
|
|
|
|
|
|
print 'Sent '.$message.' to '.$destination."\n" if $self->{_verbose}; |
242
|
|
|
|
|
|
|
return 1; |
243
|
|
|
|
|
|
|
} else { |
244
|
|
|
|
|
|
|
my $errstr = $result->{'StatusCode'}; |
245
|
|
|
|
|
|
|
if($self->responses()->{$result->{'StatusCode'}}) { |
246
|
|
|
|
|
|
|
$errstr .= ' ('.$result->responses()->{$result->{'StatusCode'}}.')'; |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
$errstr .= ' - '.$result->{'StatusString'}; |
249
|
|
|
|
|
|
|
warn 'Failed to send '.$message.' to '.$destination.'. Error: '.$errstr if $self->{_verbose}; |
250
|
|
|
|
|
|
|
return; |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
sub _clean_number { |
255
|
|
|
|
|
|
|
my $self = shift; |
256
|
|
|
|
|
|
|
my $number = shift; |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
# strip all non-number chars |
259
|
|
|
|
|
|
|
$number =~ s/\D//g; |
260
|
|
|
|
|
|
|
# make sure to use the country prefix for germany |
261
|
|
|
|
|
|
|
$number =~ s/^01/491/; |
262
|
|
|
|
|
|
|
# never prefix country with 00 |
263
|
|
|
|
|
|
|
$number =~ s/^00491/491/; |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
return $number; |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=head1 AUTHOR |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
Dominik Schulz, C<< >> |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=head1 BUGS |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
275
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
276
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=head1 SUPPORT |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
perldoc SMS::Send::DE::Sipgate |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
You can also look for information at: |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=over 4 |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
L |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
L |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=item * CPAN Ratings |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
L |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
=item * Search CPAN |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
L |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
=back |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
Copyright 2012 Dominik Schulz. |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
319
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
320
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=cut |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
1; # End of SMS::Send::DE::Sipgate |