2 # DX cluster user routines
4 # Copyright (c) 1998 - Dirk Koopman G1TLH
22 use vars qw(%u $dbm $filename %valid $lastoperinterval $lasttime);
27 $lastoperinterval = 30*24*60*60;
30 # hash of valid elements and a simple prompt
33 alias => '0,Real Callsign',
36 lat => '0,Latitude,slat',
37 long => '0,Longitude,slong',
39 email => '0,E-mail Address',
40 priv => '9,Privilege Level',
41 lastin => '0,Last Time in,cldatetime',
42 passwd => '9,Password',
43 addr => '0,Full Address',
44 'sort' => '0,Type of User', # A - ak1a, U - User, S - spider cluster, B - BBS
45 xpert => '0,Expert Status,yesno',
47 node => '0,Last Node',
48 homenode => '0,Home Node',
49 lockout => '9,Locked out?,yesno', # won't let them in at all
50 dxok => '9,Accept DX Spots?,yesno', # accept his dx spots?
51 annok => '9,Accept Announces?,yesno', # accept his announces?
52 reg => '0,Registered?,yesno', # is this user registered?
54 hmsgno => '0,Highest Msgno',
55 group => '0,Access Group,parray', # used to create a group of users/nodes for some purpose or other
56 isolate => '9,Isolate network,yesno',
57 wantbeep => '0,Rec Beep,yesno',
58 wantann => '0,Rec Announce,yesno',
59 wantwwv => '0,Rec WWV,yesno',
60 wantwcy => '0,Rec WCY,yesno',
61 wantecho => '0,Rec Echo,yesno',
62 wanttalk => '0,Rec Talk,yesno',
63 wantwx => '0,Rec WX,yesno',
64 wantdx => '0,Rec DX Spots,yesno',
65 pagelth => '0,Current Pagelth',
66 pingint => '9,Node Ping interval',
67 nopings => '9,Ping Obs Count',
68 wantlogininfo => '9,Login info req,yesno',
69 wantgrid => '0,DX Grid Info,yesno',
70 lastoper => '9,Last for/oper,cldatetime',
79 return if $name =~ /::DESTROY$/;
82 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
84 $self->{$name} = shift;
86 return $self->{$name};
90 # initialise the system
94 my ($pkg, $fn, $mode) = @_;
96 confess "need a filename in User" if !$fn;
99 $dbm = tie (%u, 'DB_File', $fn, O_CREAT|O_RDWR, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)";
101 $dbm = tie (%u, 'DB_File', $fn, O_RDONLY, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)";
110 # periodic processing
114 if ($main::systime > $lasttime + 15) {
116 $lasttime = $main::systime;
131 # new - create a new user
138 # $call =~ s/-\d+$//o;
140 # confess "can't create existing call $call in User\n!" if $u{$call};
142 my $self = bless {}, $pkg;
143 $self->{call} = $call;
144 $self->{'sort'} = 'U';
150 # get - get an existing user - this seems to return a different reference everytime it is
159 unless ($dbm->get($call, $data)) {
160 return decode($data);
166 # get an existing either from the channel (if there is one) or from the database
168 # It is important to note that if you have done a get (for the channel say) and you
169 # want access or modify that you must use this call (and you must NOT use get's all
170 # over the place willy nilly!)
178 my $dxchan = DXChannel->get($call);
179 return $dxchan->user if $dxchan;
181 unless ($dbm->get($call, $data)) {
182 return decode($data);
188 # get all callsigns in the database
193 return (sort keys %u);
203 confess "Trying to put nothing!" unless $self && ref $self;
204 my $call = $self->{call};
205 # delete all instances of this
206 for ($dbm->get_dup($call)) {
207 $dbm->del_dup($call, $_);
209 delete $self->{annok} if $self->{annok};
210 delete $self->{dxok} if $self->{dxok};
211 $dbm->put($call, $self->encode);
215 # create a string from a user reference
220 my $dd = new Data::Dumper([$self]);
223 $dd->Quotekeys($] < 5.005 ? 1 : 0);
228 # create a hash from a string
236 dbg('err', $@) if $@;
237 Log('err', $@) if $@;
244 # del - delete a user
250 my $call = $self->{call};
251 # delete all instances of this
252 for ($dbm->get_dup($call)) {
253 $dbm->del_dup($call, $_);
258 # close - close down a user
264 $self->{lastin} = time;
278 # return a list of valid elements
288 # export the database to an ascii file
296 rename "$fn.oooo", "$fn.ooooo" if -e "$fn.oooo";
297 rename "$fn.ooo", "$fn.oooo" if -e "$fn.ooo";
298 rename "$fn.oo", "$fn.ooo" if -e "$fn.oo";
299 rename "$fn.o", "$fn.oo" if -e "$fn.o";
300 rename "$fn", "$fn.o" if -e "$fn";
303 my $fh = new IO::File ">$fn" or return "cannot open $fn ($!)";
308 my $t = scalar localtime;
309 print $fh "#!/usr/bin/perl
311 # The exported userfile for a DXSpider System
313 # Input file: $filename
322 for ($action = R_FIRST; !$dbm->seq($key, $ref, $action); $action = R_NEXT) {
323 print $fh "'$key' => $ref,\n";
326 print $fh ");\n#\n# there were $count records\n#\n";
336 # add one or more groups
340 my $ref = $self->{group} || [ 'local' ];
341 $self->{group} = $ref if !$self->{group};
342 push @$ref, @_ if @_;
345 # remove one or more groups
349 my $ref = $self->{group} || [ 'local' ];
352 $self->{group} = $ref if !$self->{group};
354 @$ref = map { my $a = $_; return (grep { $_ eq $a } @in) ? () : $a } @$ref;
357 # does this thing contain all the groups listed?
361 my $ref = $self->{group};
364 return 0 if !$ref || @_ == 0;
365 return 1 if @$ref == 0 && @_ == 0;
366 for ($n = 0; $n < @_; ) {
369 $n++ if grep $_ eq $a, @_;
375 # simplified group test just for one group
380 my $ref = $self->{group};
383 return grep $_ eq $s, $ref;
386 # set up a default group (only happens for them's that connect direct)
390 $self->{group} = [ 'local' ];
394 # return a prompt for a field
399 my ($self, $ele) = @_;
403 # some variable accessors
407 @_ ? $self->{'sort'} = shift : $self->{'sort'} ;
417 $self->{$s} = $val if defined $val;
418 return exists $self->{$s} ? $self->{$s} : 1;
423 return _want('beep', @_);
428 return _want('ann', @_);
433 return _want('wwv', @_);
438 return _want('wcy', @_);
443 return _want('echo', @_);
448 return _want('wx', @_);
453 return _want('dx', @_);
458 return _want('talk', @_);
463 return _want('grid', @_);
470 $self->{wantlogininfo} = $n if $n;
471 return exists $self->{wantlogininfo} ? $self->{wantlogininfo} : 0;
477 return $self->{sort} =~ /[ACRSX]/;
483 return $self->{sort} eq 'U';
489 return $self->{sort} eq 'B';
495 return $self->{sort} eq 'S';
501 return $self->{sort} eq 'C';
507 return $self->{sort} eq 'X';
513 return $self->{sort} eq 'R';
519 return $self->{sort} eq 'A';