-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpingpong.pm
296 lines (248 loc) · 10.2 KB
/
pingpong.pm
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#!/usr/bin/perl
#
=head1 NAME
pingpong.pm - Ping robot for HPT perl. (c) Stas Mishchenkov 2:460/58.
=head1 SYNOPSIS
use pingpong;
sub filter{
ping_pong( $fromname, $fromaddr, $toname, $toaddr, $subject, $text );
}
$fromname - sender name
$fromaddr - sender address
$toname - recipient's name
$toaddr - recipient address for netmail or undef
$area - area for echomail, otherwise undef
$secure - current message received via SecureInbound
$subject - subject of message
$text - text message (with kludges)
=head1 DESCRIPTION
This program is a Ping robot designed according to FTS-5001.006.
This is an extended implementation that allows the Ping response to be
redirected via any password-protected link.
Insert into HPT configuration file:
hptperlfile /home/fido/perl/filter.pl
Make sure that the Origin variable is defined in the HPT config. Something like
Origin "Origin of the message"
(see section B<BUGS>)
Put pingpong.pm somewhere in the @INC path. It's strongly recommended for Windows
users to put it in the same directory with filter.pl.
place to filter.pl something like this:
use pingpong;
sub filter{
if ( !defined( $area ) ) {
ping_pong( $fromname, $fromaddr, $toname, $toaddr, $subject, $text );
}
}
$fromname - sender name
$fromaddr - sender address
$toname - recipient's name
$toaddr - recipient address for netmail or undef
$area - area for echomail, otherwise undef
$secure - current message received via SecureInbound
$subject - subject of message
$text - text message (with kludges)
Also, you can use two optional additional parameters "message attributes"
and "link level".
"message attributes" - Sets additional attributes of the Ping Robot
response message. $PVT - for PVT attribute, $K_S - for K/S attribute,
undef or 0 to add nothing. See HPT doc for more details on message
attributes.
B<Be completely sure of what you are doing by adding message attributes.>
"link level" - A Number. Used when building a list of password-protected
links. Only those links will be added to the list, the level of which
in the HPT configuration file is equal to or higher than the specified
one. For trusted links, you can set the level above the rest in the HPT
configuration. Thus, in the Ping Robot response to the %Links command,
you can show a list of only trusted links.
This parameter also affects, in the same manner, the execution of the
command "%RouteTo:".
ping_pong( $fromname, $fromaddr, $toname, $toaddr, $subject,
$text, $PVT+$K_S );
adds PVT and K/S attributes.
ping_pong( $fromname, $fromaddr, $toname, $toaddr, $subject,
$text, undef, 100 );
Only nodes with level 100 and higher will be added to the list of links
by command %Links.
To use the "%RouteTo:" command you should place in the filter.pl
sub route{
return route_to();
}
=head1 RETURN VALUE
ping_pong() return 1 if a message to Ping was detected, 0 - otherwise.
=head1 BUGS
ping_pong uses the $config{origin} variable. If the Origin variable
is not defined in the HPT configuration file, then this leads to
the crash of the whole Perl hook. It was fixed in the hpt version 1.9.0 2021-04-18.
=head1 AUTHOR
Stas Mishchenkov 2:460/58.
=head1 COPYRIGHT AND LICENSE
This library is free software; you may redistribute it and/or
modify it under the same terms as Perl itself.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
=head1 SEE ALSO
B<FTS-5001.006> http://ftsc.org/docs/fts-5001.006
=cut
sub ping_pong($$$$$$;$$)
{
my ( $from_name, $from_addr, $to_name, $to_addr, $subj, $mtext,
$m_attr, $m_level ) = @_;
my ( $links_mask );
my $ori_gin = 'Upgrade your HPT to version 1.9.0 2021-04-18 or higher.';
$hpt_version =~ /(\d{4})\-(\d{2})\-(\d{2})$/;
my $subver = $1.$2.$3;
if ( $subver >= 20210418 ) {
if ( defined $config{origin} ) {
$ori_gin = $config{origin};
} else {
$ori_gin = 'Ping-Pong Robot by Stas Mishchenkov';
}
}
my $addline = '';
my $replykludge = '';
my $msgdirection = 'passed through';
my $time = localtime;
my $my_aka = @{$config{addr}}[0];
$m_attr = 0 unless defined $m_attr;
$m_level = 0 unless defined $m_level;
my $tz = gmtoff();
my $tzs = '';
my $tze = '0';
$tz =~ /(\-?)(\d+)[\.\,]?(\d?)/;
$tzs = $1 if defined $1;
$tze = $3 . $tze if defined $3;
$tz = sprintf("$tzs%02d%02d\r",$2,$tze);
if ($to_name =~ /^Ping$/i){
w_log("Ping message detected." );
if ($from_name =~ /^Ping$/i){
w_log("From name \'$from_name\' not allowed." );
$from_name = "Mr. $from_name";
}
if ( istous($to_addr) == 1 ) {
$my_aka = $to_addr;
if ( $subj =~ /\%RouteTo\: (\d\:\d+\/\d+)/i) {
w_log( "\'\%RouteTo\:\' command found." );
if ( defined $links{$1}{password} &&
$links{$1}{level} >= $m_level ) {
$addline = "\r\%RouteTo\: $1\r" if $secure == 1;
} else {
$addline = "\r$1 isn't my password protecded link. '%RouteTo\: $1' command was ignored.\r";
w_log("$1 isn't protecded link. \'\%RouteTo\: $1\' command was not accepted.");
}
}
if ( $subj =~ /\%Links\s?\(?([^\(\)]*)\)?/i) {
$links_mask = $1 if defined $1;
$addline .= "My links are:\r~~~~~~~~~~~~~\r";
foreach my $key( sort keys %links) {
next if defined( $links_mask ) && $key !~ /$links_mask/ &&
$links_mask ne '';
$addline .= sprintf("%-20s", $key) .
"$links{$key}{name}\r" if defined $links{$key}{password} &&
$key =~ /^\d+\:\d+\/\d+$/ &&
$links{$key}{name} !~ /Our virtual lin/i &&
$links{$key}{level} >= $m_level;
}
}
$msgdirection = "was received by";
}
if ( $mtext =~ /\x01MSGID: ([^\r]+)\r/i ) {
$replykludge = "\x01REPLY: $1\r";
}
$mtext =~ s/\r\x01/\r\@/g;
$mtext =~ s/^\x01/\@/;
$mtext =~ s/\r--- /\r-+- /g;
$mtext =~ s/\r \* Origin\:/\r \+ Origin\:/g;
$mtext =~ s/\r\%RouteTo\:/\r\@RouteTo\:/gi;
putMsgInArea("", "Ping Robot", $from_name, $my_aka, $from_addr,
"Pong", "", $LOC+$m_attr, "${replykludge}${tz}Hi $from_name.\r\r".
" Your ping-message $msgdirection my system at $time\r\r".
"$addline".
"---------- Help ------------------------------------------------------------\r".
" Also, You may use the following commands in the Subject line:\r".
" \%RouteTo\: \<3D_address\> \- The Ping robot reply will be routed via\r".
" this node. It MUST be my password-protected link.\r".
" \%Links \- Get the list of my password protected-links.\r".
" -------- Example ---------------------------------------------\r".
" From: ".sprintf("%-32s", $from_name)."$from_addr\r".
" To : Ping $my_aka\r".
" Subj: %RouteTo: 2:292/854\r".
" --------------------------------------------------------------\r".
" - The answer to this message will be routed via 2:292/854.\r".
"----------------------------------------------------------------------------\r".
"\rOrignal message:\r".
"============================================================================\r".
"From: ".sprintf("%-32s",$from_name).sprintf("%-20s",$from_addr)."$date\r".
"To : ".sprintf("%-32s",$to_name)."$to_addr\r".
"Subj: $subj\r".
"============================================================================\r".
"$mtext".
"============================================================================\r".
"--- perl on $hpt_version\r * Origin: $ori_gin \($my_aka\)", 1);
return 1;
}
return 0;
}
sub istous($)
{
my ( $addrr ) = @_;
for my $cfg_addr ( @{$config{addr}} ) {
if( $addrr eq $cfg_addr ) {
return 1;
}
}
return 0;
}
sub route_to()
{
if ( $text =~ /\r\%RouteDir\:\s+(\d+\:\d+\/\d+\.?\d*)\s*(\d+\:\d+\/\d+){0,1}/i){
return '' if defined( $2 ) && istous( $2 ) == 0;
$route = $1;
$route =~ /\d+\:\d+\/\d+(\.?\d*)/;
$route .= '.0' unless defined( $1 );
$flavour = 'direct';
w_log("\%RouteDir to $route");
$text =~ s/\r\%RouteDir\:\s+(\d+\:\d+\/\d+\.?\d*)\s*(\d+\:\d+\/\d+){0,1}/\r\x01Routed_Direct\: $1 at @{$config{addr}}[0]/i;
$change=1;
}
if ( $text =~ /\r\%RouteHold\:\s+(\d+\:\d+\/\d+\.?\d*)\s*(\d+\:\d+\/\d+){0,1}/i){
return '' if defined( $2 ) && istous( $2 ) == 0;
$route = $1;
$route =~ /\d+\:\d+\/\d+(\.?\d*)/;
$route .= '.0' unless defined( $1 );
$flavour = 'hold';
w_log("\%RouteHold to $route");
$text =~ s/\r\%RouteHold\:\s+(\d+\:\d+\/\d+\.?\d*)\s*(\d+\:\d+\/\d+){0,1}/\r\x01Routed_Hold\: $1 at @{$config{addr}}[0]/i;
$change=1;
}
if ( $text =~ /\r\%RouteTo\:\s+(\d+\:\d+\/\d+\.?\d*)\s*(\d+\:\d+\/\d+){0,1}/i){
return '' if defined( $2 ) && istous( $2 ) == 0;
if ( defined( $links{$1}{password} ) ) {
w_log("\%Route to $1");
$route = $1;
$route =~ /\d+\:\d+\/\d+(\.?\d*)/;
$route .= '.0' unless defined( $1 );
$text =~ s/\r\%RouteTo\:\s+(\d+\:\d+\/\d+\.?\d*)\s*(\d+\:\d+\/\d+){0,1}//i;
$text = "\x01Routed_To\: $1 at @{$config{addr}}[0]\r$text";
$change=1;
} else {
$addline = "\rMy links are:\r~~~~~~~~~~~~~\r\r";
foreach $key( sort keys %links) {
$addline = $addline . sprintf("%-20s", $key) .
"$links{$key}{name}\r" if defined $links{$key}{password} &&
$key =~ /^\d+\:\d+\/\d+$/ &&
$links{$key}{name} !~ /Our virtual lin/i;
}
putMsgInArea("", "Evil Robot", $fromname, "", $fromaddr,
"Routing", "", $LOC, "Hi $fromname.\r\r".
" You use the command \"\%RouteTo:\" and wish to change ".
"the routing of your message from default via \"$route\" to \"$1\"".
", but it is not my passworded link. Your message is routed by ".
"default.\r\r$addline\r\r".
"--- perl on $hpt_version\r * Origin: $config{origin} \(@{$config{addr}}[0]\)", 1);
$newmail = 1;
}
}
return $route;
}
1;