X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXUser.pm;h=7c9a4b369e56de0f63aabe15bf242d7e1ebe31dc;hb=985ef8460d1cd74eee9576e6d32e625fdeb6a76c;hp=277b2a5f4d7ae89354078156d42a9e050f217057;hpb=70908cf7f69eb4fc0caf5d735382bc2c1c1466a3;p=spider.git diff --git a/perl/DXUser.pm b/perl/DXUser.pm index 277b2a5f..7c9a4b36 100644 --- a/perl/DXUser.pm +++ b/perl/DXUser.pm @@ -14,22 +14,26 @@ use Data::Dumper; use Fcntl; use IO::File; use DXDebug; +use DXUtil; +use LRU; use strict; use vars qw($VERSION $BRANCH); $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ ); -$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ ) || 0; +$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0)); $main::build += $VERSION; $main::branch += $BRANCH; -use vars qw(%u $dbm $filename %valid $lastoperinterval $lasttime); +use vars qw(%u $dbm $filename %valid $lastoperinterval $lasttime $lru $lrusize $tooold); %u = (); $dbm = undef; $filename = undef; $lastoperinterval = 60*24*60*60; $lasttime = 0; +$lrusize = 2000; +$tooold = 86400 * 365; # this marks an old user who hasn't given enough info to be useful # hash of valid elements and a simple prompt %valid = ( @@ -44,6 +48,7 @@ $lasttime = 0; priv => '9,Privilege Level', lastin => '0,Last Time in,cldatetime', passwd => '9,Password,yesno', + passphrase => '9,Pass Phrase,yesno', addr => '0,Full Address', 'sort' => '0,Type of User', # A - ak1a, U - User, S - spider cluster, B - BBS xpert => '0,Expert Status,yesno', @@ -73,6 +78,10 @@ $lasttime = 0; wantgrid => '0,DX Grid Info,yesno', wantann_talk => '0,Talklike Anns,yesno', wantpc90 => '1,Req PC90,yesno', + wantnp => '1,Req New Protocol,yesno', + wantpc16 => '9,Want Users from node,yesno', + wantsendpc16 => '9,Send PC16,yesno', + wantroutepc19 => '9,Route PC19,yesno', lastoper => '9,Last for/oper,cldatetime', nothere => '0,Not Here Text', registered => '9,Registered?,yesno', @@ -81,26 +90,23 @@ $lasttime = 0; build => '1,Build', ); -no strict; +#no strict; sub AUTOLOAD { - my $self = shift; + no strict; my $name = $AUTOLOAD; return if $name =~ /::DESTROY$/; - $name =~ s/.*:://o; + $name =~ s/^.*:://o; confess "Non-existant field '$AUTOLOAD'" if !$valid{$name}; # this clever line of code creates a subroutine which takes over from autoload # from OO Perl - Conway - *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}} ; - if (@_) { - $self->{$name} = shift; - } - return $self->{$name}; + *$AUTOLOAD = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}}; + goto &$AUTOLOAD; } -use strict; +#use strict; # # initialise the system @@ -112,12 +118,13 @@ sub init confess "need a filename in User" if !$fn; $fn .= ".v2"; if ($mode) { - $dbm = tie (%u, 'DB_File', $fn, O_CREAT|O_RDWR, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)"; + $dbm = tie (%u, 'DB_File', $fn, O_CREAT|O_RDWR, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!) [rebuild it from user_asc?]"; } else { - $dbm = tie (%u, 'DB_File', $fn, O_RDONLY, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)"; + $dbm = tie (%u, 'DB_File', $fn, O_RDONLY, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!) [rebuild it from user_asc?]"; } $filename = $fn; + $lru = LRU->newbase("DXUser", $lrusize); } sub del_file @@ -179,8 +186,16 @@ sub get my $pkg = shift; my $call = uc shift; my $data; + + # is it in the LRU cache? + my $ref = $lru->get($call); + return $ref if $ref; + + # search for it unless ($dbm->get($call, $data)) { - return decode($data); + $ref = decode($data); + $lru->put($call, $ref); + return $ref; } return undef; } @@ -200,11 +215,9 @@ sub get_current my $dxchan = DXChannel->get($call); return $dxchan->user if $dxchan; - my $data; - unless ($dbm->get($call, $data)) { - return decode($data); - } - return undef; + my $rref = Route::get($call); + return $rref->user if $rref && exists $rref->{user}; + return $pkg->get($call); } # @@ -232,7 +245,9 @@ sub put $dbm->del($call); delete $self->{annok} if $self->{annok}; delete $self->{dxok} if $self->{dxok}; - $dbm->put($call, $self->encode); + $lru->put($call, $self); + my $ref = $self->encode; + $dbm->put($call, $ref); } # @@ -276,6 +291,7 @@ sub del # for ($dbm->get_dup($call)) { # $dbm->del_dup($call, $_); # } + $lru->remove($call); $dbm->del($call); } @@ -325,10 +341,12 @@ sub export rename "$fn", "$fn.o" if -e "$fn"; my $count = 0; + my $err = 0; + my $del = 0; my $fh = new IO::File ">$fn" or return "cannot open $fn ($!)"; if ($fh) { - my $ref = 0; my $key = 0; + my $val = undef; my $action; my $t = scalar localtime; print $fh q{#!/usr/bin/perl @@ -376,19 +394,59 @@ if (@ARGV) { DXUser->del_file($main::userfn); DXUser->init($main::userfn, 1); - -%u = ( - }; - - for ($action = R_FIRST; !$dbm->seq($key, $ref, $action); $action = R_NEXT) { - print $fh "'$key' => q{$ref},\n"; - ++$count; +%u = (); +my $count = 0; +my $err = 0; +while () { + chomp; + my @f = split /\t/; + my $ref = decode($f[1]); + if ($ref) { + $ref->put(); + $count++; + } else { + print "# Error: $f[0]\t$f[1]\n"; + $err++ + } +} +DXUser->sync; DXUser->finish; +print "There are $count user records and $err errors\n"; +}; + print $fh "__DATA__\n"; + + for ($action = R_FIRST; !$dbm->seq($key, $val, $action); $action = R_NEXT) { + if (!is_callsign($key) || $key =~ /^0/) { + Log('DXCommand', "Export Error1: $key\t$val"); + eval {$dbm->del($key)}; + dbg(carp("Export Error1: $key\t$val\n$@")) if $@; + ++$err; + next; + } + my $ref = decode($val); + if ($ref) { + my $t = $ref->{lastin} || 0; + if ($main::systime > $t + $tooold) { + unless ($ref->{lat} && $ref->{long} || $ref->{qth} || $ref->{qra}) { + eval {$dbm->del($key)}; + dbg(carp("Export Error2: $key\t$val\n$@")) if $@; + Log('DXCommand', "$ref->{call} deleted, too old"); + $del++; + next; + } + } + # only store users that are reasonably active or have useful information + print $fh "$key\t" . $ref->encode . "\n"; + ++$count; + } else { + Log('DXCommand', "Export Error3: $key\t$val"); + eval {$dbm->del($key)}; + dbg(carp("Export Error3: $key\t$val\n$@")) if $@; + ++$err; + } } - print $fh ");\n#\nprint \"there were $count records\\n\";\n#\n"; - print $fh "DXUser->sync; DXUser->finish;\n#\n"; $fh->close; } - return $count; + return "$count Users $del Deleted $err Errors ('sh/log Export' for details)"; } # @@ -535,6 +593,21 @@ sub wantann_talk return _want('ann_talk', @_); } +sub wantpc16 +{ + return _want('pc16', @_); +} + +sub wantsendpc16 +{ + return _want('sendpc16', @_); +} + +sub wantroutepc16 +{ + return _want('routepc16', @_); +} + sub wantlogininfo { my $self = shift; @@ -596,6 +669,12 @@ sub unset_passwd my $self = shift; delete $self->{passwd}; } + +sub unset_passphrase +{ + my $self = shift; + delete $self->{passphrase}; +} 1; __END__