use strict;
-use vars qw(%u $dbm $filename %valid $lastoperinterval $lasttime $lru $lrusize $tooold $v3);
+use vars qw(%u $dbm $filename %valid $lastoperinterval $lasttime $lru $lrusize $tooold $v3 $noips);
%u = ();
$dbm = undef;
$lrusize = 2000;
$tooold = 86400 * 365; # this marks an old user who hasn't given enough info to be useful
$v3 = 0;
+$noips = 4;
# hash of valid elements and a simple prompt
%valid = (
believe => '1,Believable nodes,parray',
lastping => '1,Last Ping at,ptimelist',
maxconnect => '1,Max Connections',
+ ip => '1,IP addresses,piplist',
);
#no strict;
dbg("This will take a while, I suggest you go and have cup of strong tea");
my $odbm = tie (%oldu, 'DB_File', localdata("users.v2"), O_RDONLY, 0666, $DB_BTREE) or confess "can't open user file: $fn.v2 ($!) [rebuild it from user_asc?]";
for ($action = R_FIRST; !$odbm->seq($key, $val, $action); $action = R_NEXT) {
- my $ref = asc_decode($val);
- if ($ref) {
- $ref->put;
- $count++;
+ my $ref;
+ eval { $ref = asc_decode($val) };
+ unless ($@) {
+ if ($ref) {
+ $ref->put;
+ $count++;
+ } else {
+ $err++
+ }
} else {
- $err++
+ Log('err', "DXUser: error decoding $@");
}
}
undef $odbm;
sub del_file
{
- my $fn = localdata("users");
- $fn .= $v3 ? ".v3" : ".v2";
- unlink $fn;
+ # with extreme prejudice
+ unlink "$main::data/users.v3";
+ unlink "$main::local_data/users.v3";
+}
+
+# IP address handling
+# this allows one to ask whether an IP address has been used with this node or let's one set an IP address for this node.
+sub ip
+{
+ my $self = shift;
+ my $node = shift;
+ my $ipin = shift;
+
+ $self->{ip} = {} unless ref $self->{ip};
+ my $ref = $self->{ip};
+ delete $ref->{''};
+ $ref->{$node} = [$ipin, $main::systime] if $ipin;
+ return $ref->{$node}->[0];
}
#
# search for it
unless ($dbm->get($call, $data)) {
- $ref = decode($data);
+ eval { $ref = decode($data); };
+
if ($ref) {
if (!UNIVERSAL::isa($ref, 'DXUser')) {
dbg("DXUser::get: got strange answer from decode of $call". ref $ref. " ignoring");
}
# we have a reference and it *is* a DXUser
} else {
- dbg("DXUser::get: no reference returned from decode of $call $!");
+ if ($@) {
+ LogDbg('err', "DXUser::get decode error on $call '$@'");
+ } else {
+ dbg("DXUser::get: no reference returned from decode of $call $!");
+ }
return undef;
}
$lru->put($call, $ref);
sub decode
{
goto &asc_decode unless $v3;
- return thaw(shift);
+ my $ref;
+ $ref = thaw(shift);
+ return $ref;
}
#
$s =~ s/\%([0-9A-F][0-9A-F])/chr(hex($1))/eg;
eval '$ref = ' . $s;
if ($@) {
- LogDbg('err', $@);
+ LogDbg('err', "DXUser::asc_decode: on '$s' $@");
$ref = undef;
}
return $ref;
if ($ref) {
$ref->put();
$count++;
+ DXUser::sync() unless $count % 10000;
} else {
print "# Error: $f[0]\t$f[1]\n";
$err++
}
}
-DXUser::sync; DXUser::finish;
+DXUser::sync(); DXUser::finish();
print "There are $count user records and $err errors\n";
};
print $fh "__DATA__\n";
++$err;
next;
}
- my $ref = decode($val);
+ my $ref;
+ eval {$ref = decode($val); };
if ($ref) {
my $t = $ref->{lastin} || 0;
if ($ref->is_user && !$ref->{priv} && $main::systime > $t + $tooold) {
print $fh "$key\t" . $ref->asc_encode($basic_info_only) . "\n";
++$count;
} else {
- LogDbg('DXCommand', "Export Error3: $key\t$val");
+ LogDbg('DXCommand', "Export Error3: $key\t" . carp($val) ."\n$@");
eval {$dbm->del($key)};
dbg(carp("Export Error3: $key\t$val\n$@")) if $@;
++$err;