2 # DX cluster user routines
4 # Copyright (c) 1998 - Dirk Koopman G1TLH
22 use vars qw(%u $dbm $filename %valid $lastoperinterval);
27 $lastoperinterval = 30*24*60*60;
29 # hash of valid elements and a simple prompt
32 alias => '0,Real Callsign',
35 lat => '0,Latitude,slat',
36 long => '0,Longitude,slong',
38 email => '0,E-mail Address',
39 priv => '9,Privilege Level',
40 lastin => '0,Last Time in,cldatetime',
41 passwd => '9,Password',
42 addr => '0,Full Address',
43 'sort' => '0,Type of User', # A - ak1a, U - User, S - spider cluster, B - BBS
44 xpert => '0,Expert Status,yesno',
46 node => '0,Last Node',
47 homenode => '0,Home Node',
48 lockout => '9,Locked out?,yesno', # won't let them in at all
49 dxok => '9,Accept DX Spots?,yesno', # accept his dx spots?
50 annok => '9,Accept Announces?,yesno', # accept his announces?
51 reg => '0,Registered?,yesno', # is this user registered?
53 hmsgno => '0,Highest Msgno',
54 group => '0,Access Group,parray', # used to create a group of users/nodes for some purpose or other
55 isolate => '9,Isolate network,yesno',
56 wantbeep => '0,Rec Beep,yesno',
57 wantann => '0,Rec Announce,yesno',
58 wantwwv => '0,Rec WWV,yesno',
59 wantwcy => '0,Rec WCY,yesno',
60 wantecho => '0,Rec Echo,yesno',
61 wanttalk => '0,Rec Talk,yesno',
62 wantwx => '0,Rec WX,yesno',
63 wantdx => '0,Rec DX Spots,yesno',
64 pagelth => '0,Current Pagelth',
65 pingint => '9,Node Ping interval',
66 nopings => '9,Ping Obs Count',
67 wantlogininfo => '9,Login info req,yesno',
68 wantgrid => '0,DX Grid Info,yesno',
69 lastoper => '9,Last for/oper,cldatetime',
78 return if $name =~ /::DESTROY$/;
81 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
83 $self->{$name} = shift;
85 return $self->{$name};
89 # initialise the system
93 my ($pkg, $fn, $mode) = @_;
95 confess "need a filename in User" if !$fn;
98 $dbm = tie (%u, 'DB_File', $fn, O_CREAT|O_RDWR, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)";
100 $dbm = tie (%u, 'DB_File', $fn, O_RDONLY, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)";
119 # new - create a new user
126 # $call =~ s/-\d+$//o;
128 # confess "can't create existing call $call in User\n!" if $u{$call};
130 my $self = bless {}, $pkg;
131 $self->{call} = $call;
132 $self->{'sort'} = 'U';
138 # get - get an existing user - this seems to return a different reference everytime it is
146 # $call =~ s/-\d+$//o; # strip ssid
148 return $s ? decode($s) : undef;
152 # get all callsigns in the database
157 return (sort keys %u);
161 # get an existing either from the channel (if there is one) or from the database
163 # It is important to note that if you have done a get (for the channel say) and you
164 # want access or modify that you must use this call (and you must NOT use get's all
165 # over the place willy nilly!)
172 # $call =~ s/-\d+$//o; # strip ssid
174 my $dxchan = DXChannel->get($call);
175 return $dxchan->user if $dxchan;
176 return get($pkg, $call);
186 confess "Trying to put nothing!" unless $self && ref $self;
187 my $call = $self->{call};
188 # delete all instances of this
189 for ($dbm->get_dup($call)) {
190 $dbm->del_dup($call, $_);
192 delete $self->{annok} if $self->{annok};
193 delete $self->{dxok} if $self->{dxok};
194 $u{$call} = $self->encode();
199 # create a string from a user reference
204 my $dd = new Data::Dumper([$self]);
207 $dd->Quotekeys($] < 5.005 ? 1 : 0);
212 # create a hash from a string
220 Log('DXUser', $@) if $@;
226 # del - delete a user
232 my $call = $self->{call};
233 # delete all instances of this
234 for ($dbm->get_dup($call)) {
235 $dbm->del_dup($call, $_);
241 # close - close down a user
247 $self->{lastin} = time;
252 # return a list of valid elements
262 # export the database to an ascii file
270 rename "$fn.oooo", "$fn.ooooo" if -e "$fn.oooo";
271 rename "$fn.ooo", "$fn.oooo" if -e "$fn.ooo";
272 rename "$fn.oo", "$fn.ooo" if -e "$fn.oo";
273 rename "$fn.o", "$fn.oo" if -e "$fn.o";
274 rename "$fn", "$fn.o" if -e "$fn";
277 my $fh = new IO::File ">$fn" or return "cannot open $fn ($!)";
282 my $t = scalar localtime;
283 print $fh "#!/usr/bin/perl
285 # The exported userfile for a DXSpider System
287 # Input file: $filename
296 for ($action = R_FIRST; !$dbm->seq($key, $ref, $action); $action = R_NEXT) {
297 print $fh "'$key' => $ref,\n";
300 print $fh ");\n#\n# there were $count records\n#\n";
310 # add one or more groups
314 my $ref = $self->{group} || [ 'local' ];
315 $self->{group} = $ref if !$self->{group};
316 push @$ref, @_ if @_;
319 # remove one or more groups
323 my $ref = $self->{group} || [ 'local' ];
326 $self->{group} = $ref if !$self->{group};
328 @$ref = map { my $a = $_; return (grep { $_ eq $a } @in) ? () : $a } @$ref;
331 # does this thing contain all the groups listed?
335 my $ref = $self->{group};
338 return 0 if !$ref || @_ == 0;
339 return 1 if @$ref == 0 && @_ == 0;
340 for ($n = 0; $n < @_; ) {
343 $n++ if grep $_ eq $a, @_;
349 # simplified group test just for one group
354 my $ref = $self->{group};
357 return grep $_ eq $s, $ref;
360 # set up a default group (only happens for them's that connect direct)
364 $self->{group} = [ 'local' ];
368 # return a prompt for a field
373 my ($self, $ele) = @_;
377 # some variable accessors
381 @_ ? $self->{'sort'} = shift : $self->{'sort'} ;
391 $self->{$s} = $val if defined $val;
392 return exists $self->{$s} ? $self->{$s} : 1;
397 return _want('beep', @_);
402 return _want('ann', @_);
407 return _want('wwv', @_);
412 return _want('wcy', @_);
417 return _want('echo', @_);
422 return _want('wx', @_);
427 return _want('dx', @_);
432 return _want('talk', @_);
437 return _want('grid', @_);
444 $self->{wantlogininfo} = $n if $n;
445 return exists $self->{wantlogininfo} ? $self->{wantlogininfo} : 0;
451 return $self->{sort} =~ /[ACRSX]/;
457 return $self->{sort} eq 'U';
463 return $self->{sort} eq 'B';
469 return $self->{sort} eq 'S';
475 return $self->{sort} eq 'C';
481 return $self->{sort} eq 'X';
487 return $self->{sort} eq 'R';
493 return $self->{sort} eq 'A';