line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package SMS::Send::CZ::Smseagle; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: SMS::Send driver for SMSEagle - Czech Republic |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
107311
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
65
|
|
8
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
35
|
|
9
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
152
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = "1.001"; |
12
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
1450
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
104339
|
|
|
2
|
|
|
|
|
68
|
|
15
|
2
|
|
|
2
|
|
17
|
use URI::Escape; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
110
|
|
16
|
2
|
|
|
2
|
|
1974
|
use DateTime qw(); |
|
2
|
|
|
|
|
1115203
|
|
|
2
|
|
|
|
|
142
|
|
17
|
2
|
|
|
2
|
|
25
|
use base 'SMS::Send::Driver'; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
769
|
|
18
|
2
|
|
|
2
|
|
1492
|
use Log::LogLite; |
|
2
|
|
|
|
|
27976
|
|
|
2
|
|
|
|
|
75
|
|
19
|
2
|
|
|
2
|
|
1263
|
use Data::Dumper; |
|
2
|
|
|
|
|
13876
|
|
|
2
|
|
|
|
|
130
|
|
20
|
2
|
|
|
2
|
|
1171
|
use Text::Unidecode; |
|
2
|
|
|
|
|
2958
|
|
|
2
|
|
|
|
|
145
|
|
21
|
2
|
|
|
2
|
|
1731
|
use XML::Simple; |
|
2
|
|
|
|
|
18816
|
|
|
2
|
|
|
|
|
12
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
24
|
1
|
|
|
1
|
1
|
94
|
my $class = shift; |
25
|
1
|
|
|
|
|
26
|
my %params = @_; |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
2
|
my $LOG_FILE = "/var/log/smseagle.log"; |
28
|
1
|
|
|
|
|
4
|
my $ERROR_LOG_LEVEL = 6; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
352
|
open HANDLE, ">>$LOG_FILE"; |
31
|
1
|
|
|
|
|
21
|
close HANDLE; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Create our LWP::UserAgent object |
34
|
1
|
|
|
|
|
20
|
my $ua = LWP::UserAgent->new; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Create the object, saving any private params for later |
37
|
|
|
|
|
|
|
my $self = bless { |
38
|
|
|
|
|
|
|
ua => $ua, |
39
|
|
|
|
|
|
|
login => $params{_login}, |
40
|
|
|
|
|
|
|
password => $params{_password}, |
41
|
|
|
|
|
|
|
api_url => $params{_api_url}, |
42
|
1
|
50
|
|
|
|
3095
|
private => \%params, |
43
|
|
|
|
|
|
|
log => (-w $LOG_FILE) ? new Log::LogLite($LOG_FILE, $ERROR_LOG_LEVEL) : 0 |
44
|
|
|
|
|
|
|
}, $class; |
45
|
1
|
|
|
|
|
252
|
$self->log("Driver Smseagle created", 4); |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
377
|
$self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub log { |
51
|
1
|
|
|
1
|
1
|
3
|
my ($self, $msg, $level) = @_; |
52
|
|
|
|
|
|
|
|
53
|
1
|
50
|
|
|
|
10
|
if ($self->{'log'}) { |
54
|
1
|
|
|
|
|
4
|
$self->{'log'}->write($msg, $level); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub send_sms { |
59
|
0
|
|
|
0
|
1
|
|
my ($self, %args) = @_; |
60
|
0
|
|
|
|
|
|
my $url = $self->{'api_url'}; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
$args{'text'} = unidecode($args{'text'}); |
63
|
0
|
|
|
|
|
|
$self->log("TEXT: " . $args{'text'} . ", TO: " . $args{'to'}, 4); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my %params = ( |
66
|
|
|
|
|
|
|
'to' => $args{'to'} || '', |
67
|
|
|
|
|
|
|
'message' => $args{'text'} || '', |
68
|
|
|
|
|
|
|
'login' => $self->{'login'}, |
69
|
0
|
|
0
|
|
|
|
'pass' => $self->{'password'}, |
|
|
|
0
|
|
|
|
|
70
|
|
|
|
|
|
|
'responsetype' => 'xml' |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# cleanup |
74
|
0
|
|
|
|
|
|
$params{'to'} =~ s{\D}{}g; # remove non-digits |
75
|
0
|
0
|
|
|
|
|
if (length($params{'to'}) == 9) { |
76
|
0
|
|
|
|
|
|
$params{'to'} = '00420' . $params{'to'}; |
77
|
0
|
|
|
|
|
|
$self->log("Auto-prefix: " . $args{'to'} . " => " . $params{'to'}, 4); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# send away |
81
|
0
|
|
|
|
|
|
my $uri = join( '&', map { $_ . '=' . uri_escape_utf8( $params{ $_ } ) } keys %params ); |
|
0
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 }); |
84
|
0
|
|
|
|
|
|
$ua->protocols_allowed( ['https'] ); |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $res = $ua->get($url . "?" . $uri); |
87
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
if( $res->{'_rc'} == 200 ) { |
89
|
0
|
|
|
|
|
|
$params{'password'} = "------"; # hide password in logs |
90
|
0
|
|
|
|
|
|
my $successLog = $url . "?" . join( '&', map { $_ . '=' . uri_escape_utf8( $params{ $_ } ) } keys %params ); |
|
0
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
$self->log("HTTP SUCCESS: " . $successLog, 4); |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my $parser = new XML::Simple; |
94
|
0
|
|
|
|
|
|
my $data = $parser->XMLin($res->decoded_content); |
95
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
if ($data) { |
97
|
0
|
|
|
|
|
|
my $logMsg; |
98
|
0
|
|
|
|
|
|
my $result = 0; |
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
if ($data->{'status'} eq 'ok' ) { |
|
|
0
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
$logMsg = "SMS #" . $data->{'message_id'} . " sent"; |
102
|
0
|
|
|
|
|
|
$result = 1; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
elsif ($data->{'status'} eq 'error') { |
105
|
0
|
|
|
|
|
|
$logMsg = "SMS processing error: " . $data->{'error_text'}; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
$self->log($logMsg, 4); |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
return $result; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
else { |
114
|
0
|
|
|
|
|
|
return 0; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
__END__ |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=pod |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=encoding UTF-8 |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 NAME |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
SMS::Send::CZ::Smseagle - SMS::Send driver for SMSEagle - Czech Republic |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 VERSION |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
version 1.001 |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 SYNOPSIS |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
use SMS::Send; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
my $sender = SMS::Send->new('CZ::Smseagle', |
137
|
|
|
|
|
|
|
_login => 'who', |
138
|
|
|
|
|
|
|
_password => 'secret', |
139
|
|
|
|
|
|
|
_api_url => 'https://.../index.php/http_api/send_sms |
140
|
|
|
|
|
|
|
); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
my $sent = $sender->send_sms( |
143
|
|
|
|
|
|
|
text => 'Test SMS', |
144
|
|
|
|
|
|
|
to => '604111111', |
145
|
|
|
|
|
|
|
); |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# Did it send? |
148
|
|
|
|
|
|
|
if ( $sent ) { |
149
|
|
|
|
|
|
|
print "Sent test message\n"; |
150
|
|
|
|
|
|
|
} else { |
151
|
|
|
|
|
|
|
print "Test message failed\n"; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 METHODS |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 log |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Logs message to /var/log/smseagle.log if this file is accessible and writable |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 send_sms |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Sends the message using SMSEagle API, see https://www.smseagle.eu |
163
|
|
|
|
|
|
|
Parameter 'text' contains the message itself and 'to' provides recipient's number. |
164
|
|
|
|
|
|
|
API URL is passed to the constructor as '_api_url'. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Processing information is automatically logged to /var/log/smseagle.log to allow tracking of possible problems. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Returns true if the msssage was successfully sent |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Returns false if an error occured |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=cut |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 AUTHOR |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Radek Šiman <rbit@rbit.cz> |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
This software is copyright (c) 2023 by R-Bit Technology, s.r.o. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
183
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut |