This file is indexed.

/usr/share/perl5/Net/SNPP.pm is in libnet-snpp-perl 1.17-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
# Net::SNPP.pm
#
# Copyright (c) 1995-2001 Graham Barr. 
# Copyright (c) 2001 Derek J. Balling <dredd@megacity.org>. 
# All rights reserved. This program is free software; you can 
# redistribute it and/or modify it under the same terms as Perl itself.
#

package Net::SNPP;

require 5.001;

use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
use Socket 1.3;
use Carp;
use IO::Socket;
use Net::Cmd;
use Net::Config;

$VERSION = "1.17"; # $Id: SNPP.pm,v 1.9 2004/01/27 22:18:32 tobeya Exp $
@ISA     = qw(Net::Cmd IO::Socket::INET);
@EXPORT  = (qw(CMD_2WAYERROR CMD_2WAYOK CMD_2WAYQUEUED), @Net::Cmd::EXPORT);

sub CMD_2WAYERROR  () { 7 }
sub CMD_2WAYOK     () { 8 }
sub CMD_2WAYQUEUED () { 9 }

sub new
{
 my $self = shift;
 my $type = ref($self) || $self;
 my $host = shift if @_ % 2;
 my %arg  = @_; 
 my $hosts = defined $host ? [ $host ] : $NetConfig{snpp_hosts};
 my $obj;

 my $h;
 foreach $h (@{$hosts})
  {
   $obj = $type->SUPER::new(PeerAddr => ($host = $h), 
			    PeerPort => $arg{Port} || 'snpp(444)',
			    Proto    => 'tcp',
			    Timeout  => defined $arg{Timeout}
						? $arg{Timeout}
						: 120
			    ) and last;
  }

 return undef
	unless defined $obj;

 ${*$obj}{'net_snpp_host'} = $host;

 $obj->autoflush(1);

 $obj->debug(exists $arg{Debug} ? $arg{Debug} : undef);

 unless ($obj->response() == CMD_OK)
  {
   $obj->close();
   return undef;
  }

 $obj;
}

##
## User interface methods
##

sub pager_id
{
 @_ == 2 or croak 'usage: $snpp->pager_id( PAGER_ID )';
 shift->_PAGE(@_);
}

sub content
{
 @_ == 2 or croak 'usage: $snpp->content( MESSAGE )';
 shift->_MESS(@_);
}

sub send
{
 my $me = shift;

 if(@_)
  {
   my %arg = @_;

   if(exists $arg{Pager})
    {
     my $pagers = ref($arg{Pager}) ? $arg{Pager} : [ $arg{Pager} ];
     my $pager;
     foreach $pager (@$pagers)
      {
       $me->_PAGE($pager) || return 0
      }
    }
   $me->_MESS($arg{Message}) || return 0
    if(exists $arg{Message});

   $me->hold($arg{Hold}) || return 0
	if(exists $arg{Hold});

   $me->hold($arg{HoldLocal},1) || return 0
	if(exists $arg{HoldLocal});

   $me->_COVE($arg{Coverage}) || return 0
	if(exists $arg{Coverage});

   $me->_ALER($arg{Alert} ? 1 : 0) || return 0
	if(exists $arg{Alert});

   $me->service_level($arg{ServiceLevel}) || return 0
	if(exists $arg{ServiceLevel});
  }

 $me->_SEND();
}

sub data
{
 my $me = shift;

 my $ok = $me->_DATA() && $me->datasend(@_);

 return $ok
	unless($ok && @_);

 $me->dataend;
}

sub login
{
 @_ == 2 || @_ == 3 or croak 'usage: $snpp->login( USER [, PASSWORD ])';
 shift->_LOGI(@_);
}

sub help
{
 @_ == 1 or croak 'usage: $snpp->help()';
 my $me = shift;

 return $me->_HELP() ? $me->message
		     : undef;
}

sub xwho
{
 @_ == 1 or croak 'usage: $snpp->xwho()';
 my $me = shift;

 $me->_XWHO or return undef;

 my(%hash,$line);
 my @msg = $me->message;
 pop @msg; # Remove command complete line

 foreach $line (@msg) {
   $line =~ /^\s*(\S+)\s*(.*)/ and $hash{$1} = $2;
 }

 \%hash;
}

sub service_level
{
 @_ == 2 or croak 'usage: $snpp->service_level( LEVEL )';
 my $me = shift;
 my $level = int(shift);

 if($level < 0 || $level > 11)
  {
   $me->set_status(550,"Invalid Service Level");
   return 0;
  }

 $me->_LEVE($level);
}

sub alert
{
 @_ == 1 || @_ == 2 or croak 'usage: $snpp->alert( VALUE )';
 my $me = shift;
 my $value  = (@_ == 1 || shift) ? 1 : 0;

 $me->_ALER($value);
}

sub coverage
{
 @_ == 1 or croak 'usage: $snpp->coverage( AREA )';
 shift->_COVE(@_);
}

sub hold
{
 @_ == 2 || @_ == 3 or croak 'usage: $snpp->hold( TIME [, LOCAL ] )';
 my $me = shift;
 my $time = shift;
 my $local = (shift) ? "" : " +0000";

 my @g = reverse((gmtime($time))[0..5]);
 $g[1] += 1;
 $g[0] %= 100;

 $me->_HOLD( sprintf("%02d%02d%02d%02d%02d%02d%s",@g,$local));
}

sub caller_id
{
 @_ == 2 or croak 'usage: $snpp->caller_id( CALLER_ID )';
 shift->_CALL(@_);
}

sub subject
{
 @_ == 2 or croak 'usage: $snpp->subject( SUBJECT )';
 shift->_SUBJ(@_);
}

sub site
{
 @_ == 2 or croak 'usage: $snpp->site( CMD )';
 shift->_SITE(@_);
}

sub two_way
{
 @_ == 1 or croak 'usage: $snpp->two_way()';
 shift->_2WAY();
}

sub ping
{
 @_ == 2 or croak 'usage: $snpp->ping( PAGER_ID )';
 shift->_PING(@_);
}

sub noqueue
{
 @_ == 1 or croak 'usage: $snpp->noqueue()';
 shift->_NOQU();
}

sub expire_time
{
 @_ == 2 or croak 'usage: $snpp->expire_time( HOURS )';
 shift->_EXPT(@_);
}

sub read_ack
{
 @_ == 2 or croak 'usage: $snpp->read_ack( TRUEFALSE )';
 shift->_ACKR(@_);
}

# 4.6.7 MCREsponse <2-byte_Code> Response_Text
sub message_response
{
 @_ == 3 or croak 'usage: $snpp->message_response( INT, RESPONSE )';
 shift->_MCRE(@_);
}

# 4.6.10 MSTAtus <Message_Tag> <Pass_Code>
sub message_status
{
 @_ == 3 or croak 'usage: $snpp->message_status( Message_Tag, Pass_Code )';
 my $me = shift;
 my @out = ();
 my $resp = $me->command("MSTA", @_)->response();
 $out[4] = $me->code();
 if ($resp == CMD_2WAYQUEUED || $resp == CMD_2WAYOK || $resp == CMD_2WAYERROR)
  {
   # 860 <Sequence> <Date&Time> Delivered, Awaiting Read Confirmation
   # this regex doesn't count on every server putting the +/-GMT tag
   # on the timestamp
   my $msg = $me->message(); chomp( $msg );
   #if ($msg =~ /^(\d+)\s+(\d+)(.*)\s+(.*)$/)
   if ($msg =~ /^\s*(\d+)\s+(\d+)([+-]?\d*)\s+(.*)$/)
    {
     splice(@out, 0, 4, ($1,$2,$3,$4));
    }
    else
    {
     $me->debug_print( undef, "server reply for MCRE '$msg' did not match regex" );
    }
  }
 return wantarray ? @out : \@out;
}

# 4.6.9 SEND (Level 3) 
sub send_two_way
{
 @_ == 1 or croak 'usage: $snpp->send_two_way()';
 my $me = shift;
 my @out = ();
 $out[3] = $me->command("SEND")->response();
 # rfc1861 specifies that a 2way SEND can return 8xx or 9xx when successful
 # i.e.
 # 860 <Message_Tag> <Pass_Code> Delivered, Awaiting Read Ack
 # 960 <Message_Tag> <Pass_Code> OK, Message QUEUED for Delivery
 if ($out[3] == CMD_2WAYQUEUED || $out[3] == CMD_2WAYOK)
  {
   $me->message() =~ m/^(\d+)\s+(\d+)\s*(.*)$/;
   splice(@out, 0, 3, ($1,$2,$3));
  }
 return wantarray ? @out : \@out;
}

sub reset
{
 @_ == 1 or croak 'usage: $snpp->reset()';
 shift->_RESE();
}

sub reply_type
{
 @_ == 2 or croak 'usage: $snpp->reply_type( TYPE_CODE )';
 shift->_RTYP(uc (@_));
}

sub quit
{
 @_ == 1 or croak 'usage: $snpp->quit()';
 my $snpp = shift;

 $snpp->_QUIT;
 $snpp->close;
}



##
## IO/perl methods
##

sub DESTROY
{
 my $snpp = shift;
 defined(fileno($snpp)) && $snpp->quit;
 delete ${*$snpp}{'net_snpp_host'};
}

##
## Over-ride methods (Net::Cmd)
##

sub debug_text
{
 $_[2] =~ s/^((logi|page)\s+\S+\s+)\S+/$1 xxxx/io;
 $_[2];
}

sub parse_response
{
 return ()
    unless $_[1] =~ s/^(\d\d\d)(.?)//o;
 my($code,$more) = ($1, $2 eq "-");

 $more ||= $code == 214;

 ($code,$more);
}

##
## RFC1861 commands
##

# Level 1

sub _PAGE { shift->command("PAGE", @_)->response()  == CMD_OK }   
sub _MESS { shift->command("MESS", @_)->response()  == CMD_OK }   
sub _RESE { shift->command("RESE")->response()  == CMD_OK }
# level 3 SEND returns 8xx or 9xx for successful responses
sub _SEND { shift->command("SEND")->response()  == CMD_OK }
sub _QUIT { shift->command("QUIT")->response()  == CMD_OK }   
sub _HELP { shift->command("HELP")->response()  == CMD_OK }   
sub _DATA { shift->command("DATA")->response()  == CMD_MORE }   
sub _SITE { shift->command("SITE",@_)->response() == CMD_OK }   

# Level 2

sub _LOGI { shift->command("LOGI", @_)->response()  == CMD_OK }   
sub _LEVE { shift->command("LEVE", @_)->response()  == CMD_OK }   
sub _ALER { shift->command("ALER", @_)->response()  == CMD_OK }   
sub _COVE { shift->command("COVE", @_)->response()  == CMD_OK }   
sub _HOLD { shift->command("HOLD", @_)->response()  == CMD_OK }   
sub _CALL { shift->command("CALL", @_)->response()  == CMD_OK }   
sub _SUBJ { shift->command("SUBJ", @_)->response()  == CMD_OK }   

# Level 3
 sub _2WAY { shift->command("2WAY")->response()  == CMD_OK }   
 sub _PING { shift->command("PING", @_)->response()  == CMD_OK }   
 sub _ACKR { shift->command("ACKR", @_)->response()  == CMD_OK }   
 sub _EXPT { shift->command("EXPT", @_)->response()  == CMD_OK }   
 sub _KTAG { shift->command("KTAG", @_)->response()  == CMD_OK }   
 sub _MCRE { shift->command("MCRE", @_)->response()  == CMD_OK }   
# MSTA here is not RFC compliant (returns 8xx or 9xx on success)
 sub _MSTA { shift->command("MSTA", @_)->response()  == CMD_OK }   
 sub _NOQU { shift->command("NOQU")->response()  == CMD_OK }   
 sub _RTYP { shift->command("RTYP", @_)->response()  == CMD_OK }   

# NonStandard

sub _XWHO { shift->command("XWHO")->response()  == CMD_OK }   

1;
__END__

=head1 NAME

Net::SNPP - Simple Network Pager Protocol Client

=head1 SYNOPSIS

    use Net::SNPP;

    # Constructors
    $snpp = Net::SNPP->new('snpphost');
    $snpp = Net::SNPP->new('snpphost', Timeout => 60);

=head1 NOTE

This module is in a maintenance mode, as I no longer have significant
access to SNPP servers to test with. However, to the best of the
present maintainer's knowledge, the module works just fine and has been
used in many a production environment.

=head1 DESCRIPTION

This module implements a client interface to the SNPP protocol, enabling
a perl5 application to talk to SNPP servers. This documentation assumes
that you are familiar with the SNPP protocol described in RFC1861.

A new Net::SNPP object must be created with the I<new> method. Once
this has been done, all SNPP commands are accessed through this object.

=head1 EXAMPLES

This example will send a pager message in one hour saying "Your lunch is ready"

    #!/usr/local/bin/perl -w

    use Net::SNPP;

    $snpp = Net::SNPP->new('snpphost');

    $snpp->send( Pager   => $some_pager_number,
	         Message => "Your lunch is ready",
	         Alert   => 1,
	         Hold    => time + 3600, # lunch ready in 1 hour :-)
	       ) || die $snpp->message;

    $snpp->quit;

=head1 CONSTRUCTOR

=over 4

=item new ( [ HOST, ] [ OPTIONS ] )

This is the constructor for a new Net::SNPP object. C<HOST> is the
name of the remote host to which a SNPP connection is required.

If C<HOST> is not given, then the C<SNPP_Host> specified in C<Net::Config>
will be used.

C<OPTIONS> are passed in a hash like fashion, using key and value pairs.
Possible options are:

B<Timeout> - Maximum time, in seconds, to wait for a response from the
SNPP server (default: 120)

B<Debug> - Enable debugging information


Example:


    $snpp = Net::SNPP->new('snpphost', 
                           Debug => 1,	  
                           );

=back

=head1 METHODS

Unless otherwise stated all methods return either a I<true> or I<false>
value, with I<true> meaning that the operation was a success. When a method
states that it returns a value, failure will be returned as I<undef> or an
empty list.

=over 4

=item reset ()

=item help ()

Request help text from the server. Returns the text or undef upon failure

=item quit ()

Send the QUIT command to the remote SNPP server and close the socket connection.

=item site ( CMD )

Send a SITE command to the remote SNPP server. site() take a single argument 
which is the command string to send to the SNPP server. 

=item ping ( PAGER_ID )

Determine if the remote SNPP server is able to contact a given pager ID. 
(Level 3 command)

=item noqueue ()

Instruct the SNPP server not to queue the two-way request.
(Level 3 command)

=item expire_time ( HOURS )

Cause the paging request to be canceled if it has not been sent in the 
specified number of hours. (Level 3 command)

=item read_ack ( TRUEFALSE )

Enable and disable the read acknowledgement notification sent by the pager. 
(Level 3 command)

=item reply_type ( TYPE_CODE )

Change the type of reply that the page will send back. Valid options are:
NONE, YESNO, SIMREPLY, MULTICHOICE, and TEXT. (Level 3 command)

=item message_response ( INT TEXT ) (Level 3)

Create message responses to deliver with the message.  INT is a 2-byte number.
The total number of definable responses may be limited by your server.  Some
server may need you to call reply_type() before specifying responses.

=item message_status ( MSGID MSGID ) (Level 3)

Get the message status from the remote server.  Use the Message_Tag and
Pass_Code from send_two_way() as the arguments to this method, and if
your server supports it, you should be able to retrieve the status of
a 2-way message.  An array/arraref is returned with the following 5 elements:
 [0] Sequence
 [1] Date&Time
 [2] +/- GMT (if provided by server)
 [3] server-specific response text
 [4] numeric response code from server (i.e. 860 or 960)

=item send_two_way () (Level 3)

Use this method instead of send() when working in Level 3 of the SNPP protocol.
Before using this method, you have to build up your page using the other
methods in the module, then use this at the very end to "submit" your page.
An array/arrayref will be returned with the following 4 elements:
 [0] Message_Tag
 [1] Pass_Code
 [2] server-specific response text
 [3] numeric response code from server (i.e. 860 or 960)

NOTE: This is only the SEND command - you have to build the page using various
methods from this module before calling this method.

=back

=head1 2WAY EXAMPLES

 use Net::SNPP;

 my $snpp = Net::SNPP->new( "snpp.provider.com" );
 $snpp->two_way();
 $snpp->pager_id( 5555555555 );
 $snpp->data( "The sky is falling!\nThe sky is falling!" );
 $snpp->message_response( 1, "Don't Panic" );
 $snpp->message_response( 2, "Panic!" );
 my @result = $snpp->send_two_way();
 $snpp->quit();
 printf "Use these two numbers: \"%s %s\" to check message status.\n",
        $result[0], $result[1];

 __END__

 use Net::SNPP;

 my $snpp = Net::SNPP->new( "snpp.provider.com" );
 my @status = $snpp->message_status( $ARGV[0], $ARGV[1] );
 $snpp->quit;

 printf "User responded with: %s\n", $status[3];

=head1 EXPORTS

C<Net::SNPP> exports all that C<Net::CMD> exports, plus three more subroutines
that can bu used to compare against the result of C<status>. These are :-
C<CMD_2WAYERROR>, C<CMD_2WAYOK>, and C<CMD_2WAYQUEUED>.

=head1 SEE ALSO

L<Net::Cmd>
RFC1861

=head1 AUTHOR

Derek J. Balling <dredd@megacity.org> ( original version by Graham Barr )
Al Tobey <tobeya@tobert.org> (since Oct 2003)

=head1 COPYRIGHT

Copyright (c) 1995-2001 Graham Barr. (c) 2001-2003 Derek J. Balling. All 
rights reserved. This program is free software; you can redistribute it 
and/or modify it under the same terms as Perl itself.

=for html <hr>

I<$Id: SNPP.pm,v 1.9 2004/01/27 22:18:32 tobeya Exp $>

=cut