line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package SMS::Send::CZ::Axima; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: SMS::Send driver for Axima - Czech Republic |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
65761
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
69
|
|
8
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
35
|
|
9
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
167
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = "1.000"; |
12
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
1334
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
95602
|
|
|
2
|
|
|
|
|
82
|
|
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
19
|
use base 'SMS::Send::Driver'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
624
|
|
17
|
2
|
|
|
2
|
|
1426
|
use Text::Unidecode; |
|
2
|
|
|
|
|
4800
|
|
|
2
|
|
|
|
|
138
|
|
18
|
2
|
|
|
2
|
|
18
|
use Digest::MD5 qw(md5 md5_hex); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
104
|
|
19
|
2
|
|
|
2
|
|
1682
|
use XML::Simple; |
|
2
|
|
|
|
|
18112
|
|
|
2
|
|
|
|
|
18
|
|
20
|
2
|
|
|
2
|
|
1096
|
use Log::LogLite qw(logpath); |
|
2
|
|
|
|
|
25925
|
|
|
2
|
|
|
|
|
904
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
1
|
|
|
1
|
1
|
77
|
my $class = shift; |
24
|
1
|
|
|
|
|
4
|
my %params = @_; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# prepare logging |
27
|
1
|
|
|
|
|
3
|
my $LOG_FILE = "/tmp/axima.log"; |
28
|
1
|
|
|
|
|
2
|
my $ERROR_LOG_LEVEL = 6; |
29
|
1
|
|
|
|
|
189
|
open(my $fh, ">", $LOG_FILE); |
30
|
1
|
|
|
|
|
14
|
close $fh; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Create our LWP::UserAgent object |
33
|
1
|
|
|
|
|
26
|
my $ua = LWP::UserAgent->new; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Create the object, saving any private params for later |
36
|
|
|
|
|
|
|
my $self = bless { |
37
|
|
|
|
|
|
|
ua => $ua, |
38
|
|
|
|
|
|
|
login => $params{_login}, |
39
|
|
|
|
|
|
|
password => $params{_password}, |
40
|
1
|
50
|
|
|
|
2853
|
private => \%params, |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# State variables |
43
|
|
|
|
|
|
|
logged_in => '', |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# logging |
46
|
|
|
|
|
|
|
log => (-w $LOG_FILE) ? new Log::LogLite($LOG_FILE, $ERROR_LOG_LEVEL) : 0 |
47
|
|
|
|
|
|
|
}, $class; |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
227
|
$self->log("Driver Axima created", 4); |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
379
|
$self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub log { |
55
|
2
|
|
|
2
|
0
|
6
|
my ($self, $msg, $level) = @_; |
56
|
|
|
|
|
|
|
|
57
|
2
|
50
|
|
|
|
13
|
if ($self->{'log'}) { |
58
|
2
|
|
|
|
|
7
|
$self->{'log'}->write($msg, $level); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub send_sms { |
63
|
1
|
|
|
1
|
1
|
1199
|
my ($self, %args) = @_; |
64
|
1
|
|
|
|
|
2
|
my $url = 'https://smsgateapi.sms-sluzba.cz/apipost30/sms'; |
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
6
|
$args{'text'} = unidecode($args{'text'}); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my %params = ( |
69
|
|
|
|
|
|
|
'msisdn' => $args{'to'} || '', |
70
|
|
|
|
|
|
|
'msg' => $args{'text'} || '', |
71
|
|
|
|
|
|
|
'act' => 'send', |
72
|
|
|
|
|
|
|
'login' => $self->{'login'}, |
73
|
1
|
|
50
|
|
|
38
|
'auth' => md5_hex(md5_hex($self->{'password'}) . $self->{'login'} . 'send' . substr($args{'text'}, 0, 31)) |
|
|
|
50
|
|
|
|
|
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# cleanup |
77
|
1
|
|
|
|
|
4
|
$params{'msisdn'} =~ s{\D}{}g; # remove non-digits |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
7
|
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 }); |
80
|
1
|
|
|
|
|
226
|
$ua->protocols_allowed( ['https'] ); |
81
|
1
|
|
|
|
|
21
|
my $res = $ua->post($url, \%params ); |
82
|
|
|
|
|
|
|
|
83
|
1
|
50
|
|
|
|
13115
|
if( $res->is_success ) { |
84
|
0
|
0
|
|
|
|
0
|
if ( $res->decoded_content ) { |
85
|
0
|
|
|
|
|
0
|
my $parser = new XML::Simple; |
86
|
0
|
|
|
|
|
0
|
my $data = $parser->XMLin($res->decoded_content); |
87
|
0
|
0
|
|
|
|
0
|
if ($data->{'id'} == 200) { |
88
|
0
|
|
|
|
|
0
|
return 1; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else { |
91
|
0
|
|
|
|
|
0
|
$self->log("SMS processing error: " . $data->{'message'}, 4); |
92
|
0
|
|
|
|
|
0
|
return 0; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
0
|
|
|
|
|
0
|
$self->log("Unexpected response from SMS provider: " . res->decoded_content, 4); |
96
|
0
|
|
|
|
|
0
|
return 0; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
else { |
99
|
1
|
|
|
|
|
14
|
$self->log("Communication error", 4); |
100
|
1
|
|
|
|
|
311
|
return 0; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |