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
158 # $call =~ s/-\d+$//o; # strip ssid
160 return $s ? decode($s) : undef;
164 # get all callsigns in the database
169 return (sort keys %u);
173 # get an existing either from the channel (if there is one) or from the database
175 # It is important to note that if you have done a get (for the channel say) and you
176 # want access or modify that you must use this call (and you must NOT use get's all
177 # over the place willy nilly!)
184 # $call =~ s/-\d+$//o; # strip ssid
186 my $dxchan = DXChannel->get($call);
187 return $dxchan->user if $dxchan;
188 return get($pkg, $call);
198 confess "Trying to put nothing!" unless $self && ref $self;
199 my $call = $self->{call};
200 # delete all instances of this
201 for ($dbm->get_dup($call)) {
202 $dbm->del_dup($call, $_);
204 delete $self->{annok} if $self->{annok};
205 delete $self->{dxok} if $self->{dxok};
206 $u{$call} = $self->encode();
210 # create a string from a user reference
215 my $dd = new Data::Dumper([$self]);
218 $dd->Quotekeys($] < 5.005 ? 1 : 0);
223 # create a hash from a string
231 Log('DXUser', $@) if $@;
237 # del - delete a user
243 my $call = $self->{call};
244 # delete all instances of this
245 for ($dbm->get_dup($call)) {
246 $dbm->del_dup($call, $_);
251 # close - close down a user
257 $self->{lastin} = time;
271 # return a list of valid elements
281 # export the database to an ascii file
289 rename "$fn.oooo", "$fn.ooooo" if -e "$fn.oooo";
290 rename "$fn.ooo", "$fn.oooo" if -e "$fn.ooo";
291 rename "$fn.oo", "$fn.ooo" if -e "$fn.oo";
292 rename "$fn.o", "$fn.oo" if -e "$fn.o";
293 rename "$fn", "$fn.o" if -e "$fn";
296 my $fh = new IO::File ">$fn" or return "cannot open $fn ($!)";
301 my $t = scalar localtime;
302 print $fh "#!/usr/bin/perl
304 # The exported userfile for a DXSpider System
306 # Input file: $filename
315 for ($action = R_FIRST; !$dbm->seq($key, $ref, $action); $action = R_NEXT) {
316 print $fh "'$key' => $ref,\n";
319 print $fh ");\n#\n# there were $count records\n#\n";
329 # add one or more groups
333 my $ref = $self->{group} || [ 'local' ];
334 $self->{group} = $ref if !$self->{group};
335 push @$ref, @_ if @_;
338 # remove one or more groups
342 my $ref = $self->{group} || [ 'local' ];
345 $self->{group} = $ref if !$self->{group};
347 @$ref = map { my $a = $_; return (grep { $_ eq $a } @in) ? () : $a } @$ref;
350 # does this thing contain all the groups listed?
354 my $ref = $self->{group};
357 return 0 if !$ref || @_ == 0;
358 return 1 if @$ref == 0 && @_ == 0;
359 for ($n = 0; $n < @_; ) {
362 $n++ if grep $_ eq $a, @_;
368 # simplified group test just for one group
373 my $ref = $self->{group};
376 return grep $_ eq $s, $ref;
379 # set up a default group (only happens for them's that connect direct)
383 $self->{group} = [ 'local' ];
387 # return a prompt for a field
392 my ($self, $ele) = @_;
396 # some variable accessors
400 @_ ? $self->{'sort'} = shift : $self->{'sort'} ;
410 $self->{$s} = $val if defined $val;
411 return exists $self->{$s} ? $self->{$s} : 1;
416 return _want('beep', @_);
421 return _want('ann', @_);
426 return _want('wwv', @_);
431 return _want('wcy', @_);
436 return _want('echo', @_);
441 return _want('wx', @_);
446 return _want('dx', @_);
451 return _want('talk', @_);
456 return _want('grid', @_);
463 $self->{wantlogininfo} = $n if $n;
464 return exists $self->{wantlogininfo} ? $self->{wantlogininfo} : 0;
470 return $self->{sort} =~ /[ACRSX]/;
476 return $self->{sort} eq 'U';
482 return $self->{sort} eq 'B';
488 return $self->{sort} eq 'S';
494 return $self->{sort} eq 'C';
500 return $self->{sort} eq 'X';
506 return $self->{sort} eq 'R';
512 return $self->{sort} eq 'A';