2 # DX cluster user routines
4 # Copyright (c) 1998 - Dirk Koopman G1TLH
22 use vars qw(%u $dbm $filename %valid);
28 # hash of valid elements and a simple prompt
31 alias => '0,Real Callsign',
34 lat => '0,Latitude,slat',
35 long => '0,Longitude,slong',
37 email => '0,E-mail Address',
38 priv => '9,Privilege Level',
39 lastin => '0,Last Time in,cldatetime',
40 passwd => '9,Password',
41 addr => '0,Full Address',
42 'sort' => '0,Type of User', # A - ak1a, U - User, S - spider cluster, B - BBS
43 xpert => '0,Expert Status,yesno',
45 node => '0,Last Node',
46 homenode => '0,Home Node',
47 lockout => '9,Locked out?,yesno', # won't let them in at all
48 dxok => '9,Accept DX Spots?,yesno', # accept his dx spots?
49 annok => '9,Accept Announces?,yesno', # accept his announces?
50 reg => '0,Registered?,yesno', # is this user registered?
52 hmsgno => '0,Highest Msgno',
53 group => '0,Access Group,parray', # used to create a group of users/nodes for some purpose or other
54 isolate => '9,Isolate network,yesno',
55 wantbeep => '0,Rec Beep,yesno',
56 wantann => '0,Rec Announce,yesno',
57 wantwwv => '0,Rec WWV,yesno',
58 wantwcy => '0,Rec WCY,yesno',
59 wantecho => '0,Rec Echo,yesno',
60 wanttalk => '0,Rec Talk,yesno',
61 wantwx => '0,Rec WX,yesno',
62 wantdx => '0,Rec DX Spots,yesno',
63 pagelth => '0,Current Pagelth',
64 pingint => '9,Node Ping interval',
65 nopings => '9,Ping Obs Count',
66 wantlogininfo => '9,Login info req,yesno',
67 wantgrid => '0,DX Grid Info,yesno',
68 lastoper => '9,Last for/oper,cldatetime',
77 return if $name =~ /::DESTROY$/;
80 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
82 $self->{$name} = shift;
84 return $self->{$name};
88 # initialise the system
92 my ($pkg, $fn, $mode) = @_;
94 confess "need a filename in User" if !$fn;
97 $dbm = tie (%u, 'DB_File', $fn, O_CREAT|O_RDWR, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)";
99 $dbm = tie (%u, 'DB_File', $fn, O_RDONLY, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)";
118 # new - create a new user
125 # $call =~ s/-\d+$//o;
127 # confess "can't create existing call $call in User\n!" if $u{$call};
129 my $self = bless {}, $pkg;
130 $self->{call} = $call;
131 $self->{'sort'} = 'U';
137 # get - get an existing user - this seems to return a different reference everytime it is
145 # $call =~ s/-\d+$//o; # strip ssid
147 return $s ? decode($s) : undef;
151 # get all callsigns in the database
156 return (sort keys %u);
160 # get an existing either from the channel (if there is one) or from the database
162 # It is important to note that if you have done a get (for the channel say) and you
163 # want access or modify that you must use this call (and you must NOT use get's all
164 # over the place willy nilly!)
171 # $call =~ s/-\d+$//o; # strip ssid
173 my $dxchan = DXChannel->get($call);
174 return $dxchan->user if $dxchan;
175 return get($pkg, $call);
185 confess "Trying to put nothing!" unless $self && ref $self;
186 my $call = $self->{call};
187 # delete all instances of this
188 for ($dbm->get_dup($call)) {
189 $dbm->del_dup($call, $_);
191 delete $self->{annok} if $self->{annok};
192 delete $self->{dxok} if $self->{dxok};
193 $u{$call} = $self->encode();
198 # create a string from a user reference
203 my $dd = new Data::Dumper([$self]);
206 $dd->Quotekeys($] < 5.005 ? 1 : 0);
211 # create a hash from a string
219 Log('DXUser', $@) if $@;
225 # del - delete a user
231 my $call = $self->{call};
232 # delete all instances of this
233 for ($dbm->get_dup($call)) {
234 $dbm->del_dup($call, $_);
240 # close - close down a user
246 $self->{lastin} = time;
251 # return a list of valid elements
261 # export the database to an ascii file
269 rename "$fn.oooo", "$fn.ooooo" if -e "$fn.oooo";
270 rename "$fn.ooo", "$fn.oooo" if -e "$fn.ooo";
271 rename "$fn.oo", "$fn.ooo" if -e "$fn.oo";
272 rename "$fn.o", "$fn.oo" if -e "$fn.o";
273 rename "$fn", "$fn.o" if -e "$fn";
276 my $fh = new IO::File ">$fn" or return "cannot open $fn ($!)";
281 my $t = scalar localtime;
282 print $fh "#!/usr/bin/perl
284 # The exported userfile for a DXSpider System
286 # Input file: $filename
295 for ($action = R_FIRST; !$dbm->seq($key, $ref, $action); $action = R_NEXT) {
296 print $fh "'$key' => $ref,\n";
299 print $fh ");\n#\n# there were $count records\n#\n";
309 # add one or more groups
313 my $ref = $self->{group} || [ 'local' ];
314 $self->{group} = $ref if !$self->{group};
315 push @$ref, @_ if @_;
318 # remove one or more groups
322 my $ref = $self->{group} || [ 'local' ];
325 $self->{group} = $ref if !$self->{group};
327 @$ref = map { my $a = $_; return (grep { $_ eq $a } @in) ? () : $a } @$ref;
330 # does this thing contain all the groups listed?
334 my $ref = $self->{group};
337 return 0 if !$ref || @_ == 0;
338 return 1 if @$ref == 0 && @_ == 0;
339 for ($n = 0; $n < @_; ) {
342 $n++ if grep $_ eq $a, @_;
348 # simplified group test just for one group
353 my $ref = $self->{group};
356 return grep $_ eq $s, $ref;
359 # set up a default group (only happens for them's that connect direct)
363 $self->{group} = [ 'local' ];
367 # return a prompt for a field
372 my ($self, $ele) = @_;
376 # some variable accessors
380 @_ ? $self->{'sort'} = shift : $self->{'sort'} ;
390 $self->{$s} = $val if defined $val;
391 return exists $self->{$s} ? $self->{$s} : 1;
396 return _want('beep', @_);
401 return _want('ann', @_);
406 return _want('wwv', @_);
411 return _want('wcy', @_);
416 return _want('echo', @_);
421 return _want('wx', @_);
426 return _want('dx', @_);
431 return _want('talk', @_);
436 return _want('grid', @_);
443 $self->{wantlogininfo} = $n if $n;
444 return exists $self->{wantlogininfo} ? $self->{wantlogininfo} : 0;
450 return $self->{sort} =~ /[ACRSX]/;
456 return $self->{sort} eq 'U';
462 return $self->{sort} eq 'B';
468 return $self->{sort} eq 'S';
474 return $self->{sort} eq 'C';
480 return $self->{sort} eq 'X';
486 return $self->{sort} eq 'R';
492 return $self->{sort} eq 'A';