X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXUser.pm;h=49745722ffd29ae51badd4e665a9f192853a8d00;hb=329702a31bd4a526077c713b12ede457276c79db;hp=65aab42bdf164ed52a686ae40611955288b260b9;hpb=f155969d600561b9ef151a7ce2494a0c89aed033;p=spider.git diff --git a/perl/DXUser.pm b/perl/DXUser.pm index 65aab42b..49745722 100644 --- a/perl/DXUser.pm +++ b/perl/DXUser.pm @@ -15,14 +15,17 @@ use DXLog; use DB_File; use Data::Dumper; use Fcntl; +use IO::File; use DXDebug; use strict; -use vars qw(%u $dbm $filename %valid); +use vars qw(%u $dbm $filename %valid $lastoperinterval $lasttime); %u = (); $dbm = undef; $filename = undef; +$lastoperinterval = 30*24*60*60; +$lasttime = 0; # hash of valid elements and a simple prompt %valid = ( @@ -63,6 +66,8 @@ $filename = undef; pingint => '9,Node Ping interval', nopings => '9,Ping Obs Count', wantlogininfo => '9,Login info req,yesno', + wantgrid => '0,DX Grid Info,yesno', + lastoper => '9,Last for/oper,cldatetime', ); no strict; @@ -101,6 +106,17 @@ sub init use strict; +# +# periodic processing +# +sub process +{ + if ($main::systime > $lasttime + 15) { + $dbm->sync; + $lasttime = $main::systime; + } +} + # # close the system # @@ -126,9 +142,6 @@ sub new my $self = bless {}, $pkg; $self->{call} = $call; $self->{'sort'} = 'U'; - $self->{dxok} = '1'; - $self->{annok} = '1'; - $self->{lang} = $main::lang; $self->put; return $self; } @@ -142,18 +155,11 @@ sub get { my $pkg = shift; my $call = uc shift; - # $call =~ s/-\d+$//o; # strip ssid - my $s = $u{$call}; - return $s ? decode($s) : undef; -} - -# -# get all callsigns in the database -# - -sub get_all_calls -{ - return (sort keys %u); + my $data; + unless ($dbm->get($call, $data)) { + return decode($data); + } + return undef; } # @@ -168,12 +174,23 @@ sub get_current { my $pkg = shift; my $call = uc shift; - # $call =~ s/-\d+$//o; # strip ssid my $dxchan = DXChannel->get($call); return $dxchan->user if $dxchan; - my $s = $u{$call}; - return $s ? decode($s) : undef; + my $data; + unless ($dbm->get($call, $data)) { + return decode($data); + } + return undef; +} + +# +# get all callsigns in the database +# + +sub get_all_calls +{ + return (sort keys %u); } # @@ -185,7 +202,13 @@ sub put my $self = shift; confess "Trying to put nothing!" unless $self && ref $self; my $call = $self->{call}; - $u{$call} = $self->encode(); + # delete all instances of this + for ($dbm->get_dup($call)) { + $dbm->del_dup($call, $_); + } + delete $self->{annok} if $self->{annok}; + delete $self->{dxok} if $self->{dxok}; + $dbm->put($call, $self->encode); } # @@ -208,10 +231,12 @@ sub decode { my $s = shift; my $ref; - $s = '$ref = ' . $s; - eval $s; - Log('DXUser', $@) if $@; - $ref = undef if $@; + eval '$ref = ' . $s; + if ($@) { + dbg('err', $@) if $@; + Log('err', $@) if $@; + $ref = undef; + } return $ref; } @@ -223,7 +248,10 @@ sub del { my $self = shift; my $call = $self->{call}; - delete $u{$call}; + # delete all instances of this + for ($dbm->get_dup($call)) { + $dbm->del_dup($call, $_); + } } # @@ -237,6 +265,15 @@ sub close $self->put(); } +# +# sync the database +# + +sub sync +{ + $dbm->sync; +} + # # return a list of valid elements # @@ -246,6 +283,52 @@ sub fields return keys(%valid); } + +# +# export the database to an ascii file +# + +sub export +{ + my $fn = shift; + + # save old ones + rename "$fn.oooo", "$fn.ooooo" if -e "$fn.oooo"; + rename "$fn.ooo", "$fn.oooo" if -e "$fn.ooo"; + rename "$fn.oo", "$fn.ooo" if -e "$fn.oo"; + rename "$fn.o", "$fn.oo" if -e "$fn.o"; + rename "$fn", "$fn.o" if -e "$fn"; + + my $count = 0; + my $fh = new IO::File ">$fn" or return "cannot open $fn ($!)"; + if ($fh) { + my $ref; + my $key; + my $action; + my $t = scalar localtime; + print $fh "#!/usr/bin/perl +# +# The exported userfile for a DXSpider System +# +# Input file: $filename +# Time: $t +# + +package DXUser; + +%u = ( +"; + + for ($action = R_FIRST; !$dbm->seq($key, $ref, $action); $action = R_NEXT) { + print $fh "'$key' => $ref,\n"; + ++$count; + } + print $fh ");\n#\n# there were $count records\n#\n"; + $fh->close; + } + return $count; +} + # # group handling # @@ -375,6 +458,11 @@ sub wanttalk return _want('talk', @_); } +sub wantgrid +{ + return _want('grid', @_); +} + sub wantlogininfo { my $self = shift; @@ -425,6 +513,11 @@ sub is_arcluster return $self->{sort} eq 'R'; } +sub is_ak1a +{ + my $self = shift; + return $self->{sort} eq 'A'; +} 1; __END__