| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::MonM::Channel::Command; |
|
2
|
1
|
|
|
1
|
|
421
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
26
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use utf8; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=encoding utf-8 |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
App::MonM::Channel::Command - MonM command channel |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 1.00 |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Type Command |
|
20
|
|
|
|
|
|
|
Enable on |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Real To id/address/name |
|
23
|
|
|
|
|
|
|
# To 14242545300 |
|
24
|
|
|
|
|
|
|
# To +1-424-254-5300 |
|
25
|
|
|
|
|
|
|
To testusername |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Schedule |
|
28
|
|
|
|
|
|
|
#At Sun-Sat[00:00-23:59] |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# MIME options |
|
31
|
|
|
|
|
|
|
#Encoding 8bit |
|
32
|
|
|
|
|
|
|
# 8bit, quoted-printable, 7bit, base64 |
|
33
|
|
|
|
|
|
|
#ContentType text/plain |
|
34
|
|
|
|
|
|
|
#Charset utf-8 |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Command mask |
|
37
|
|
|
|
|
|
|
#Command curl -d "[MESSAGE]" "https://sms.com/?[MSISDN]" |
|
38
|
|
|
|
|
|
|
Command "echo "[NUMBER]; [SUBJECT]; [MESSAGE]" >> /tmp/fakesms.txt" |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Schedule |
|
41
|
|
|
|
|
|
|
#At Sun-Sat[00:00-23:59] |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Command Options |
|
44
|
|
|
|
|
|
|
Content body |
|
45
|
|
|
|
|
|
|
Timeout 20s |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
This module provides command method that send the content |
|
52
|
|
|
|
|
|
|
of the message to an external program |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=over 4 |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item B |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
For internal use only! |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=back |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 CONFIGURATION DIRECTIVES |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
The basic Channel configuration options (directives) detailed describes in L |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=over 4 |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item B |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Defines full path to external program or mask of command |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Default: none |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Available variables: |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
[ID] -- Internal ID of the message |
|
77
|
|
|
|
|
|
|
[TO] -- The real "to" field of message |
|
78
|
|
|
|
|
|
|
[RCPT], [RECIPIENT] -- Recipient (name, account, id, number and etc.) |
|
79
|
|
|
|
|
|
|
[PHONE], [NUM], [TEL], [NUMBER], [MSISDN] -- Recipient too |
|
80
|
|
|
|
|
|
|
[TIME] -- Current time (in unix time format) |
|
81
|
|
|
|
|
|
|
[DATETIME] -- date and time in short-format (YYYMMDDHHMMSS) |
|
82
|
|
|
|
|
|
|
[DATE] -- Date in short-format (YYYMMDD) |
|
83
|
|
|
|
|
|
|
[SUBJECT], [SUBJ], [SBJ] -- Subject of message |
|
84
|
|
|
|
|
|
|
[MESSAGE], [MSG] -- The Subject too (! no real message content) |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Note! The real message content body sends to STDIN of command |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item B |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Sender address email (optional) |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item B |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Content email |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Sets the whole MIME message as content for command STDIN |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Content body |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Sets the body of message as content for command STDIN |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Content none |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Suppress sending content to command STDIN (no content - no problems) |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Default: body |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item B |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Recipient address (email) or name |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item B |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Timeout 20s |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Sets timeout for command running |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Timeout off |
|
119
|
|
|
|
|
|
|
Timeout 0 |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Disable timeout |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Default: 20 sec |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
See also description of format for the timeout values L |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item B |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Type Command |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Required directive! |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Defines type of channel. MUST BE set to "Command" value |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=back |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
About common directives see L |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 HISTORY |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
See C file |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 TO DO |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
See C file |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 AUTHOR |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Serż Minus (Sergey Lepenkov) L Eabalama@cpan.orgE |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Copyright (C) 1998-2022 D&D Corporation. All Rights Reserved |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 LICENSE |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
|
158
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
See C file and L |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
|
163
|
|
|
|
|
|
|
|
|
164
|
1
|
|
|
1
|
|
42
|
use vars qw/$VERSION/; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
51
|
|
|
165
|
|
|
|
|
|
|
$VERSION = '1.00'; |
|
166
|
|
|
|
|
|
|
|
|
167
|
1
|
|
|
1
|
|
5
|
use CTK::Util qw/ execute dformat date_time2dig date2dig /; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
134
|
|
|
168
|
1
|
|
|
1
|
|
6
|
use CTK::ConfGenUtil; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
78
|
|
|
169
|
1
|
|
|
1
|
|
6
|
use App::MonM::Util qw/ set2attr getTimeOffset run_cmd /; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
56
|
|
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
use constant { |
|
172
|
1
|
|
|
|
|
382
|
TIMEOUT => 20, # 20 sec timeout |
|
173
|
1
|
|
|
1
|
|
6
|
}; |
|
|
1
|
|
|
|
|
1
|
|
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub sendmsg { |
|
176
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
177
|
0
|
0
|
|
|
|
|
return $self->maybe::next::method() unless $self->type eq 'command'; |
|
178
|
0
|
|
|
|
|
|
my $message = $self->message; |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
# Options |
|
181
|
0
|
|
0
|
|
|
|
my $options = set2attr($self->chconf) || {}; |
|
182
|
|
|
|
|
|
|
#print App::MonM::Util::explain($options); |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# Get command string |
|
185
|
0
|
|
0
|
|
|
|
my $command = lvalue($self->chconf, "command") || lvalue($self->chconf, "script"); |
|
186
|
0
|
0
|
|
|
|
|
unless ($command) { |
|
187
|
0
|
|
|
|
|
|
$self->error("Command string incorrect"); |
|
188
|
0
|
|
|
|
|
|
return 0; |
|
189
|
|
|
|
|
|
|
} |
|
190
|
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
my $phone = $self->message->recipient; |
|
192
|
0
|
|
|
|
|
|
my $command_res = dformat($command, { |
|
193
|
|
|
|
|
|
|
ID => $self->message->msgid, |
|
194
|
|
|
|
|
|
|
TO => $self->message->to, |
|
195
|
|
|
|
|
|
|
RCPT => $phone, RECIPIENT => $phone, |
|
196
|
|
|
|
|
|
|
PHONE => $phone, NUM => $phone, TEL => $phone, NUMBER => $phone, MSISDN => $phone, |
|
197
|
|
|
|
|
|
|
TIME => time(), DATETIME => date_time2dig(), DATE => date2dig(), |
|
198
|
|
|
|
|
|
|
SUBJECT => $self->message->subject, SUBJ => $self->message->subject, SBJ => $self->message->subject, |
|
199
|
|
|
|
|
|
|
MESSAGE => $self->message->subject, MSG => $self->message->subject, |
|
200
|
|
|
|
|
|
|
}); |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
# Get content body |
|
203
|
0
|
|
0
|
|
|
|
my $ct_type = lc(lvalue($self->chconf, "content") || "body"); |
|
204
|
0
|
|
|
|
|
|
my $content = undef; |
|
205
|
0
|
0
|
0
|
|
|
|
if ($ct_type eq 'body') { |
|
|
|
0
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
|
$content = $message->email->body; |
|
207
|
|
|
|
|
|
|
} elsif ($ct_type eq 'email' or $ct_type eq 'mail') { |
|
208
|
0
|
|
|
|
|
|
$content = $message->email->as_string; |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
#print App::MonM::Util::explain($self->chconf); |
|
212
|
|
|
|
|
|
|
#print App::MonM::Util::explain(\$body); |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
# Get timeout |
|
215
|
0
|
|
0
|
|
|
|
my $timeout = getTimeOffset(lvalue($self->chconf, "timeout") // TIMEOUT); |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
# Run command |
|
218
|
0
|
|
|
|
|
|
my $r = run_cmd($command_res, $timeout, $content); |
|
219
|
0
|
|
|
|
|
|
$self->{exitval} = $r->{code}; |
|
220
|
0
|
|
|
|
|
|
$self->{content} = $r->{stdout}; |
|
221
|
0
|
|
|
|
|
|
$self->error($r->{stderr}); |
|
222
|
|
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
return $r->{status}; |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
1; |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
__END__ |