EXTENSIVE user file and route cleanup, see Changes
[spider.git] / perl / DXUser.pm
1 #
2 # DX cluster user routines
3 #
4 # Copyright (c) 1998 - Dirk Koopman G1TLH
5 #
6 #
7 #
8
9 package DXUser;
10
11 use DXLog;
12 use DB_File;
13 use Data::Dumper;
14 use Fcntl;
15 use IO::File;
16 use DXDebug;
17 use DXUtil;
18 use LRU;
19 use File::Copy;
20 use Data::Structure::Util qw(unbless);
21 use Time::HiRes qw(gettimeofday tv_interval);
22 use IO::File;
23 use DXJSON;
24
25 use strict;
26
27 use vars qw(%u $dbm $filename %valid $lastoperinterval $lasttime $lru $lrusize $tooold $veryold $v3);
28
29 %u = ();
30 $dbm = undef;
31 $filename = undef;
32 $lastoperinterval = 60*24*60*60;
33 $lasttime = 0;
34 $lrusize = 5000;
35 $tooold = 86400 * 365 * 2;              # this marks an old user who hasn't given enough info to be useful
36 $veryold = $tooold * 6;         # Ancient default 12 years
37 $v3 = 0;
38 our $maxconnlist = 3;                   # remember this many connection time (duration) [start, end] pairs
39
40 my $json;
41
42 # hash of valid elements and a simple prompt
43 %valid = (
44                   call => '0,Callsign',
45                   alias => '0,Real Callsign',
46                   name => '0,Name',
47                   qth => '0,Home QTH',
48                   lat => '0,Latitude,slat',
49                   long => '0,Longitude,slong',
50                   qra => '0,Locator',
51                   email => '0,E-mail Address,parray',
52                   priv => '9,Privilege Level',
53                   lastin => '0,Last Time in,cldatetime',
54                   lastseen => '0,Last Seen,cldatetime',
55                   passwd => '9,Password,yesno',
56                   passphrase => '9,Pass Phrase,yesno',
57                   addr => '0,Full Address',
58                   'sort' => '0,Type of User', # A - ak1a, U - User, S - spider cluster, B - BBS
59                   xpert => '0,Expert Status,yesno',
60                   bbs => '0,Home BBS',
61                   node => '0,Last Node',
62                   homenode => '0,Home Node',
63                   lockout => '9,Locked out?,yesno',     # won't let them in at all
64                   dxok => '9,Accept DX Spots?,yesno', # accept his dx spots?
65                   annok => '9,Accept Announces?,yesno', # accept his announces?
66                   lang => '0,Language',
67                   hmsgno => '0,Highest Msgno',
68                   group => '0,Group,parray',    # used to create a group of users/nodes for some purpose or other
69                   buddies => '0,Buddies,parray',
70                   isolate => '9,Isolate network,yesno',
71                   wantbeep => '0,Req Beep,yesno',
72                   wantann => '0,Req Announce,yesno',
73                   wantwwv => '0,Req WWV,yesno',
74                   wantwcy => '0,Req WCY,yesno',
75                   wantecho => '0,Req Echo,yesno',
76                   wanttalk => '0,Req Talk,yesno',
77                   wantwx => '0,Req WX,yesno',
78                   wantdx => '0,Req DX Spots,yesno',
79                   wantemail => '0,Req Msgs as Email,yesno',
80                   pagelth => '0,Current Pagelth',
81                   pingint => '9,Node Ping interval',
82                   nopings => '9,Ping Obs Count',
83                   wantlogininfo => '0,Login Info Req,yesno',
84           wantgrid => '0,Show DX Grid,yesno',
85                   wantann_talk => '0,Talklike Anns,yesno',
86                   wantpc16 => '9,Want Users from node,yesno',
87                   wantsendpc16 => '9,Send PC16,yesno',
88                   wantroutepc19 => '9,Route PC19,yesno',
89                   wantusstate => '0,Show US State,yesno',
90                   wantdxcq => '0,Show CQ Zone,yesno',
91                   wantdxitu => '0,Show ITU Zone,yesno',
92                   wantgtk => '0,Want GTK interface,yesno',
93                   wantpc9x => '0,Want PC9X interface,yesno',
94                   wantrbn => '0,Want RBN spots,yesno',
95                   wantft => '0,Want RBN FT4/8,yesno',
96                   wantcw => '0,Want RBN CW,yesno',
97                   wantrtty => '0,Want RBN RTTY,yesno',
98                   wantpsk => '0,Want RBN PSK,yesno',
99                   wantbeacon => '0,Want RBN Beacon,yesno',
100                   lastoper => '9,Last for/oper,cldatetime',
101                   nothere => '0,Not Here Text',
102                   registered => '9,Registered?,yesno',
103                   prompt => '0,Required Prompt',
104                   version => '1,Version',
105                   build => '1,Build',
106                   believe => '1,Believable nodes,parray',
107                   lastping => '1,Last Ping at,ptimelist',
108                   maxconnect => '1,Max Connections',
109                   startt => '0,Start Time,cldatetime',
110                   connlist => '1,Connections,parraydifft',
111                   width => '0,Preferred Width',
112                   rbnseeme => '0,RBN See Me',
113                  );
114
115 #no strict;
116 sub AUTOLOAD
117 {
118         no strict;
119         my $name = $AUTOLOAD;
120   
121         return if $name =~ /::DESTROY$/;
122         $name =~ s/^.*:://o;
123   
124         confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
125         # this clever line of code creates a subroutine which takes over from autoload
126         # from OO Perl - Conway
127         *$AUTOLOAD = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}};
128        goto &$AUTOLOAD;
129 }
130
131 #use strict;
132
133 #
134 # initialise the system
135 #
136 sub init
137 {
138         my $mode = shift;
139   
140         $json = DXJSON->new->canonical(1);
141         my $fn = "users";
142         $filename = localdata("$fn.v3j");
143         unless (-e $filename || $mode == 2 ) {
144                 if (-e localdata("$fn.v3") || -e localdata("$fn.v2")) {
145                         LogDbg('DXUser', "New User File version $filename does not exist, running conversion from users.v3 or v2, please wait");
146                         system('/spider/perl/convert-users-v3-to-v3j.pl');
147                         init(1);
148                         export();
149                         return;
150                 }
151         }
152         if (-e $filename || $mode) {
153                 $lru = LRU->newbase("DXUser", $lrusize);
154                 if ($mode) {
155                         $dbm = tie (%u, 'DB_File', $filename, O_CREAT|O_RDWR, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!) [rebuild it from user_json?]";
156                 } else {
157                         $dbm = tie (%u, 'DB_File', $filename, O_RDONLY, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!) [rebuild it from user_json?]";
158                 }
159         }
160         die "Cannot open $filename ($!)\n" unless $dbm || $mode == 2;
161         return;
162 }
163
164 # delete files with extreme prejudice
165 sub del_file
166 {
167         # with extreme prejudice
168         unlink "$main::data/users.v3j";
169         unlink "$main::local_data/users.v3j";
170 }
171
172 #
173 # periodic processing
174 #
175 sub process
176 {
177         if ($main::systime > $lasttime + 15) {
178                 $dbm->sync if $dbm;
179                 $lasttime = $main::systime;
180         }
181 }
182
183 #
184 # close the system
185 #
186
187 sub finish
188 {
189         $dbm->sync;
190         undef $dbm;
191         untie %u;
192 }
193
194 #
195 # new - create a new user
196 #
197
198 sub alloc
199 {
200         my $pkg = shift;
201         my $call = uc shift;
202         my $self = bless {call => $call, 'sort'=>'U'}, $pkg;
203         return $self;
204 }
205
206 sub new
207 {
208         my $pkg = shift;
209         my $call = shift;
210         #  $call =~ s/-\d+$//o;
211   
212 #       confess "can't create existing call $call in User\n!" if $u{$call};
213
214         my $self = $pkg->alloc($call);
215         $self->put;
216         return $self;
217 }
218
219 #
220 # get - get an existing user - this seems to return a different reference everytime it is
221 #       called - see below
222 #
223
224 sub get
225 {
226         my $call = uc shift;
227         my $data;
228         
229         # is it in the LRU cache?
230         my $ref = $lru->get($call);
231         if ($ref && ref $ref eq 'DXUser') {
232                 return $ref;
233         }
234         
235         # search for it
236         unless ($dbm->get($call, $data)) {
237                 eval { $ref = decode($data); };
238                 
239                 if ($ref) {
240                         if (!UNIVERSAL::isa($ref, 'DXUser')) {
241                                 dbg("DXUser::get: got strange answer from decode of $call". ref $ref. " ignoring");
242                                 return undef;
243                         }
244                         # we have a reference and it *is* a DXUser
245                 } else {
246                         if ($@) {
247                                 LogDbg('err', "DXUser::get decode error on $call '$@'");
248                         } else {
249                                 dbg("DXUser::get: no reference returned from decode of $call $!");
250                         }
251                         return undef;
252                 }
253                 $lru->put($call, $ref);
254                 return $ref;
255         }
256         return undef;
257 }
258
259 #
260 # get an existing either from the channel (if there is one) or from the database
261 #
262 # It is important to note that if you have done a get (for the channel say) and you
263 # want access or modify that you must use this call (and you must NOT use get's all
264 # over the place willy nilly!)
265 #
266
267 sub get_current
268 {
269         my $call = uc shift;
270   
271         my $dxchan = DXChannel::get($call);
272         if ($dxchan) {
273                 my $ref = $dxchan->user;
274                 return $ref if $ref && UNIVERSAL::isa($ref, 'DXUser');
275
276                 dbg("DXUser::get_current: got invalid user ref for $call from dxchan $dxchan->{call} ". ref $ref. " ignoring");
277         }
278         return get($call);
279 }
280
281 #
282 # get all callsigns in the database 
283 #
284
285 sub get_all_calls
286 {
287         return (sort keys %u);
288 }
289
290 #
291 # put - put a user
292 #
293
294 sub put
295 {
296         my $self = shift;
297         confess "Trying to put nothing!" unless $self && ref $self;
298         my $call = $self->{call};
299
300         $dbm->del($call);
301         delete $self->{annok};
302         delete $self->{dxok};
303         $self->{lastseen} = $main::systime;
304         $lru->put($call, $self);
305         my $ref = $self->encode;
306         $dbm->put($call, $ref);
307 }
308
309
310 # thaw the user
311 sub decode
312 {
313         return $json->decode(shift, __PACKAGE__);
314 }
315
316 # freeze the user
317 sub encode
318 {
319         return $json->encode(shift);
320 }
321
322
323 #
324 # del - delete a user
325 #
326
327 sub del
328 {
329         my $self = shift;
330         my $call = $self->{call};
331         $lru->remove($call);
332         $dbm->del($call);
333 }
334
335 #
336 # close - close down a user
337 #
338
339 sub close
340 {
341         my $self = shift;
342         my $startt = shift;
343         my $ip = shift;
344         # add a record to the connect list
345         $self->{lastin} = $main::systime;
346         my $ref = [$startt || $self->{startt}, $main::systime];
347         push @$ref, $ip if $ip;
348         push @{$self->{connlist}}, $ref;
349         shift @{$self->{connlist}} if @{$self->{connlist}} > $maxconnlist;
350         $self->put();
351 }
352
353 #
354 # sync the database
355 #
356
357 sub sync
358 {
359         $dbm->sync;
360 }
361
362 #
363 # return a list of valid elements 
364
365
366 sub fields
367 {
368         return keys(%valid);
369 }
370
371
372 #
373 # export the database to an ascii file
374 #
375
376 sub export
377 {
378         my $name = shift || 'user_json';
379         my $basic_info_only = shift;
380
381         my $fn = $name ne 'user_json' ? $name : "$main::local_data/$name";                       # force use of local
382         
383         # save old ones
384         copy $fn, "$fn.keep" unless -e "$fn.keep";
385         copy "$fn.ooooo", "$fn.backstop" unless -e "$fn,backstop";
386
387         move "$fn.oooo", "$fn.ooooo" if -e "$fn.oooo";
388         move "$fn.ooo", "$fn.oooo" if -e "$fn.ooo";
389         move "$fn.oo", "$fn.ooo" if -e "$fn.oo";
390         move "$fn.o", "$fn.oo" if -e "$fn.o";
391         move "$fn", "$fn.o" if -e "$fn";
392
393         
394         my $ta = [gettimeofday];
395         my $count = 0;
396         my $err = 0;
397         my $del = 0;
398         my $spurious = 0;
399         my $unlocked = 0;
400         my $old =  0;
401         my $ancient =  0;
402         my $nodes = 0;
403         my $renamed = 0;
404                 
405         my $fh = new IO::File ">$fn" or return "cannot open $fn ($!)";
406         if ($fh) {
407                 my $key = 0;
408                 my $val = undef;
409                 my $action;
410                 my $t = scalar localtime;
411                 print $fh q{#!/usr/bin/perl
412 #
413 # The exported userfile for a DXSpider System
414 #
415 # Input file: $filename
416 #       Time: $t
417 #
418                         
419 package main;
420                         
421 # search local then perl directories
422 BEGIN {
423         umask 002;
424                                 
425         # root of directory tree for this system
426         $root = "/spider"; 
427         $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
428         
429         unshift @INC, "$root/perl";     # this IS the right way round!
430         unshift @INC, "$root/local";
431         
432         # try to detect a lockfile (this isn't atomic but 
433         # should do for now
434         $lockfn = "$root/local_data/cluster.lck";       # lock file name
435         if (-e $lockfn) {
436                 open(CLLOCK, "$lockfn") or die "Can't open Lockfile ($lockfn) $!";
437                 my $pid = <CLLOCK>;
438                 chomp $pid;
439                 die "Lockfile ($lockfn) and process $pid exists - cluster must be stopped first\n" if kill 0, $pid;
440                 close CLLOCK;
441         }
442 }
443
444 use SysVar;
445 use DXUtil;
446 use DXUser;
447 use JSON;
448 use Time::HiRes qw(gettimeofday tv_interval);
449 package DXUser;
450
451 our $json = JSON->new->canonical(1);
452
453 my $ta = [gettimeofday];
454 our $filename = "$main::local_data/users.v3j";
455 my $exists = -e $filename ? "OVERWRITING" : "CREATING"; 
456 print "perl user_json $exists $filename\n";
457
458 del_file();
459 init(2);
460 %u = ();
461 my $count = 0;
462 my $err = 0;
463 while (<DATA>) {
464         chomp;
465         my @f = split /\t/;
466         my $ref = decode($f[1]);
467         if ($ref) {
468                 $ref->put();
469                 $count++;
470         } else {
471                 print "# Error: $f[0]\t$f[1]\n";
472                 $err++
473         }
474 }
475 DXUser::sync(); DXUser::finish();
476 my $diff = _diffms($ta);
477 print "There are $count user records and $err errors in $diff mS\n";
478 };
479                 print $fh "__DATA__\n";
480
481         for ($action = R_FIRST; !$dbm->seq($key, $val, $action); $action = R_NEXT) {
482                         if (!is_callsign($key) || $key =~ /^0/) {
483                                 my $eval = $val;
484                                 my $ekey = $key;
485                                 $eval =~ s/([\%\x00-\x1f\x7f-\xff])/sprintf("%%%02X", ord($1))/eg; 
486                                 $ekey =~ s/([\%\x00-\x1f\x7f-\xff])/sprintf("%%%02X", ord($1))/eg;
487                                 LogDbg('DXCommand', "Export Error1: invalid call '$key' => '$val'");
488                                 eval {$dbm->del($key)};
489                             dbg(carp("Export Error1: delete $key => '$val' $@")) if $@;
490                                 ++$err;
491                                 next;
492                         }
493                         my $ref;
494                         eval {$ref = decode($val); };
495                         if ($ref) {
496                                 my $t = $ref->{lastseen} if exists $ref->{lastseen};
497                                 $t ||= $ref->{lastin} if exists $ref->{lastin};
498                                 $t ||= $ref->{lastoper} if exists $ref->{lastoper};
499                                 $t //= 0;
500                                 
501                                 if ($ref->is_user) {
502                                         if ($ref->{priv} == 0 && $main::systime > $t + $tooold) {
503                                                 unless (($ref->{lat} && $ref->{long}) || $ref->{qth} || $ref->{name} || $ref->{qra}) {
504                                                         LogDbg('DXCommand', sprintf("$ref->{call} deleted, empty and too Old at %s", difft($t, ' ')));
505                                                         ++$del;
506                                                         ++$old;
507                                                         eval {$dbm->del($key)};
508                                                         dbg(carp("Export Error2: delete '$key' => '$val' $@")) if $@;
509                                                         next;
510                                                 }
511                                         }
512                                         if ($main::systime > $t + $veryold) {
513                                                 LogDbg('DXCommand', sprintf("$ref->{call} deleted, POSITIVELY ANCIENT at %s", difft($t, ' ')));
514                                                 ++$del;
515                                                 ++$ancient;
516                                                 eval {$dbm->del($key)};
517                                                 dbg(carp("Export Error2: delete '$key' => '$val' $@")) if $@;
518                                                 next;
519                                         }
520                                         if ($ref->{lockout} == 1 && $ref->{priv} == 1) {
521                                                 LogDbg('DXCommand', "$ref->{call} depriv'd and unlocked");
522                                                 $ref->{lockout} = $ref->{priv} = 0;
523                                                 $ref->put;
524                                                 ++$unlocked;
525                                         }
526                                         if ($ref->is_node && $main::systime > $t + $veryold) {
527                                                 LogDbg('DXCommand', sprintf("NODE $ref->{call} deleted (%s) old", difft($t, ' ')));
528                                                 ++$del;
529                                                 ++$nodes;
530                                                 eval {$dbm->del($key)};
531                                                 dbg(carp("Export Error2: delete '$key' => '$val' $@")) if $@;
532                                                 next;
533                                         }
534                                         
535                                         my $normcall = normalise_call($key);
536                                         if ($normcall ne $key) {
537                                                 # if the normalised call does not exist, create it from the duff call.
538                                                 my $nref = DXUser::get_current($normcall);
539                                                 unless ($nref) {
540                                                         $ref->{call} = $normcall;
541                                                         $ref->put;
542                                                         LogDbg('DXCommand', "DXProt: spurious call $key normalises to $normcall renaming $key -> $normcall");
543                                                         ++$renamed;
544                                                 } 
545                                                 LogDbg('DXCommand', "DXProt: spurious call $key (should be $normcall), removing");
546                                                 eval {$dbm->del($key)};
547                                                 dbg(carp("Export Error1: delete $key => '$val' $@")) if $@;
548                                                 ++$spurious;
549                                                 ++$del;
550                                                 next;
551                                         }
552                                 }
553                         } else {
554                                 LogDbg('DXCommand', "Export Error3: '$key'\t" . carp($val) ."\n$@");
555                                 eval {$dbm->del($key)};
556                                 dbg(carp("Export Error3: delete '$key' => '$val' $@")) if $@;
557                                 ++$err;
558                                 next;
559                         }
560                         
561                         # only store users that are reasonably active or have useful information
562                         print $fh "$key\t" . encode($ref) . "\n";
563                         ++$count;
564                 }
565         } 
566         $fh->close;
567
568         my $diff = _diffms($ta);
569         my $s = qq{Exported users to $fn - $count Users,  $del Deleted ($old empty \& too old, $ancient ancient, $nodes nodes, $spurious spurious), $renamed renamed, $unlocked Unlocked, $err Errors in $diff mS ('sh/log Export' for details)};
570         LogDbg('command', $s);
571         return $s;
572 }
573
574 #
575 # group handling
576 #
577
578 # add one or more groups
579 sub add_group
580 {
581         my $self = shift;
582         my $ref = $self->{group} || [ 'local' ];
583         $self->{group} = $ref if !$self->{group};
584         push @$ref, @_ if @_;
585 }
586
587 # remove one or more groups
588 sub del_group
589 {
590         my $self = shift;
591         my $ref = $self->{group} || [ 'local' ];
592         my @in = @_;
593         
594         $self->{group} = $ref if !$self->{group};
595         
596         @$ref = map { my $a = $_; return (grep { $_ eq $a } @in) ? () : $a } @$ref;
597 }
598
599 # does this thing contain all the groups listed?
600 sub union
601 {
602         my $self = shift;
603         my $ref = $self->{group};
604         my $n;
605         
606         return 0 if !$ref || @_ == 0;
607         return 1 if @$ref == 0 && @_ == 0;
608         for ($n = 0; $n < @_; ) {
609                 for (@$ref) {
610                         my $a = $_;
611                         $n++ if grep $_ eq $a, @_; 
612                 }
613         }
614         return $n >= @_;
615 }
616
617 # simplified group test just for one group
618 sub in_group
619 {
620         my $self = shift;
621         my $s = shift;
622         my $ref = $self->{group};
623         
624         return 0 if !$ref;
625         return grep $_ eq $s, $ref;
626 }
627
628 # set up a default group (only happens for them's that connect direct)
629 sub new_group
630 {
631         my $self = shift;
632         $self->{group} = [ 'local' ];
633 }
634
635 # set up empty buddies (only happens for them's that connect direct)
636 sub new_buddies
637 {
638         my $self = shift;
639         $self->{buddies} = [  ];
640 }
641
642 #
643 # return a prompt for a field
644 #
645
646 sub field_prompt
647
648         my ($self, $ele) = @_;
649         return $valid{$ele};
650 }
651
652 # some variable accessors
653 sub sort
654 {
655         my $self = shift;
656         @_ ? $self->{'sort'} = shift : $self->{'sort'} ;
657 }
658
659 # some accessors
660
661 # want is default = 1
662 sub _want
663 {
664         my $n = shift;
665         my $self = shift;
666         my $val = shift;
667         my $s = "want$n";
668         $self->{$s} = $val if defined $val;
669         return exists $self->{$s} ? $self->{$s} : 1;
670 }
671
672 # wantnot is default = 0
673 sub _wantnot
674 {
675         my $n = shift;
676         my $self = shift;
677         my $val = shift;
678         my $s = "want$n";
679         $self->{$s} = $val if defined $val;
680         return exists $self->{$s} ? $self->{$s} : 0;
681 }
682
683 sub wantbeep
684 {
685         return _want('beep', @_);
686 }
687
688 sub wantann
689 {
690         return _want('ann', @_);
691 }
692
693 sub wantwwv
694 {
695         return _want('wwv', @_);
696 }
697
698 sub wantwcy
699 {
700         return _want('wcy', @_);
701 }
702
703 sub wantecho
704 {
705         return _want('echo', @_);
706 }
707
708 sub wantwx
709 {
710         return _want('wx', @_);
711 }
712
713 sub wantdx
714 {
715         return _want('dx', @_);
716 }
717
718 sub wanttalk
719 {
720         return _want('talk', @_);
721 }
722
723 sub wantgrid
724 {
725         return _wantnot('grid', @_);
726 }
727
728 sub wantemail
729 {
730         return _want('email', @_);
731 }
732
733 sub wantann_talk
734 {
735         return _want('ann_talk', @_);
736 }
737
738 sub wantpc16
739 {
740         return _want('pc16', @_);
741 }
742
743 sub wantsendpc16
744 {
745         return _want('sendpc16', @_);
746 }
747
748 sub wantroutepc16
749 {
750         return _want('routepc16', @_);
751 }
752
753 sub wantusstate
754 {
755         return _want('usstate', @_);
756 }
757
758 sub wantdxcq
759 {
760         return _wantnot('dxcq', @_);
761 }
762
763 sub wantdxitu
764 {
765         return _wantnot('dxitu', @_);
766 }
767
768 sub wantgtk
769 {
770         return _want('gtk', @_);
771 }
772
773 sub wantpc9x
774 {
775         return _want('pc9x', @_);
776 }
777
778 sub wantlogininfo
779 {
780         my $self = shift;
781         my $val = shift;
782         $self->{wantlogininfo} = $val if defined $val;
783         return $self->{wantlogininfo};
784 }
785
786 sub is_node
787 {
788         my $self = shift;
789         return $self->{sort} =~ /^[ACRSX]$/;
790 }
791
792 sub is_local_node
793 {
794         my $self = shift;
795         return grep $_ eq 'local_node', @{$self->{group}};
796 }
797
798 sub is_user
799 {
800         my $self = shift;
801         return $self->{sort} =~ /^[UW]$/;
802 }
803
804 sub is_web
805 {
806         my $self = shift;
807         return $self->{sort} eq 'W';
808 }
809
810 sub is_bbs
811 {
812         my $self = shift;
813         return $self->{sort} eq 'B';
814 }
815
816 sub is_spider
817 {
818         my $self = shift;
819         return $self->{sort} eq 'S';
820 }
821
822 sub is_clx
823 {
824         my $self = shift;
825         return $self->{sort} eq 'C';
826 }
827
828 sub is_dxnet
829 {
830         my $self = shift;
831         return $self->{sort} eq 'X';
832 }
833
834 sub is_arcluster
835 {
836         my $self = shift;
837         return $self->{sort} eq 'R';
838 }
839
840 sub is_ak1a
841 {
842         my $self = shift;
843         return $self->{sort} eq 'A';
844 }
845
846 sub is_rbn
847 {
848         my $self = shift;
849         return $self->{sort} eq 'N'
850 }
851
852 sub unset_passwd
853 {
854         my $self = shift;
855         delete $self->{passwd};
856 }
857
858 sub unset_passphrase
859 {
860         my $self = shift;
861         delete $self->{passphrase};
862 }
863
864 sub set_believe
865 {
866         my $self = shift;
867         my $call = uc shift;
868         $self->{believe} ||= [];
869         push @{$self->{believe}}, $call unless grep $_ eq $call, @{$self->{believe}};
870 }
871
872 sub unset_believe
873 {
874         my $self = shift;
875         my $call = uc shift;
876         if (exists $self->{believe}) {
877                 $self->{believe} = [grep {$_ ne $call} @{$self->{believe}}];
878                 delete $self->{believe} unless @{$self->{believe}};
879         }
880 }
881
882 sub believe
883 {
884         my $self = shift;
885         return exists $self->{believe} ? @{$self->{believe}} : ();
886 }
887
888 sub lastping
889 {
890         my $self = shift;
891         my $call = shift;
892         $self->{lastping} ||= {};
893         $self->{lastping} = {} unless ref $self->{lastping};
894         my $b = $self->{lastping};
895         $b->{$call} = shift if @_;
896         return $b->{$call};     
897 }
898
899 sub registered
900 {
901         my $self = shift;
902         if (exists $self->{registered}) {
903                 return $self->{registered} || 0;
904         }
905         return '';                                      # to stop undef warnings
906 }
907
908 1;
909 __END__
910
911
912
913
914