fix call/call-ssid locking issue
authorDirk Koopman <djk@tobit.co.uk>
Thu, 21 May 2020 15:32:30 +0000 (16:32 +0100)
committerDirk Koopman <djk@tobit.co.uk>
Thu, 21 May 2020 15:32:30 +0000 (16:32 +0100)
Fix the situation where GB7DXC exists and is locked out and $allowmultiple
is active than GB7DXC-5 logs in and is locked by dint of GB7DXC's locked
status and ignores GB7DXC-5's unlocked status.

Run convert-users-v3-to-v4.pl automatically if there are no users.v4[.o/.n]
files present in local_data or data. Then copy users.v4 to users.v4,n and
do an export_users, creating users_json.

File user export so that it actually works!

cmd/export_users.pl
perl/DXChannel.pm
perl/DXUser.pm
perl/cluster.pl

index 69cecc797f86bb0dd8a353e729d5dd7bc6c282e2..3a07d23a79899409a22bfcbc1eed4e34975fe85d 100644 (file)
@@ -15,7 +15,7 @@ unless ($fn && $fn eq 'user_json') {
 }
 my $strip = $flag eq 'strip';
 
-my @out = DXUser::export(undef, $strip); # for now
+my @out = DXUser::export(); # for now
 
 return (1, @out);
 
index 0e543e9cea6f424c9dfe4cc6634b8b97ef7dc74c..d680251b2fa27afcd31853d0cf0ad72593bb3115 100644 (file)
@@ -427,7 +427,7 @@ sub send                                            # this is always later and always data
        my $call = $self->{call};
 
        foreach my $l (@_) {
-               for (ref $l ? @$l : $l) {
+               for (ref($l) eq 'ARRAY' ? @$l : $l) {
                        my @lines = split /\n/;
                        for (@lines) {
                                $conn->send_later("D$call|$_");
index 85a22195f9a08de314cf0389b194cb273d4db51c..3ad8d5c2849bb6fda63b7e4653b67ec0ff6607a0 100644 (file)
@@ -187,18 +187,28 @@ sub init
 {
        my $mode = shift;
   
-       my $ufn;
-       my $convert;
-       
+       my $convert = "$main::root/perl/convert-users-v3-to-v4.pl";
+       my $export;
+               
        $json = JSON->new()->canonical(1);
        $filename = localdata("users.v4");
        
        if (-e $filename || -e "$filename.n" || -e "$filename.o") {
                $v4 = 1;
-               readinjson();
        } else {
-               die "User file $filename missing, please run convert-users-v3-to-v4.pl or copy a user_json backup from somewhere\n";
+               if (-e localdata('users.v3')) {
+                       LogDbg('DXUser', "Converting " . localdata('users.v3') . " to new json version of users file, please wait");
+                       if (-x $convert) {
+                               system($convert);
+                               ++$export;
+                       }
+               }
+               
+               die "User file $filename missing, please run $convert or copy a user_json backup from somewhere\n" unless -e "$filename.n" || -s $filename;
        }
+       readinjson();
+       copy $filename, "$filename.n" unless -e "$filename.n";
+       export() if $export;
 }
 
 sub del_file
@@ -508,6 +518,7 @@ sub export
        my $name = shift;
 
        my $fn = $name || localdata("user_json"); # force use of local_data
+       my $ta = [gettimeofday];
        
        # save old ones
        move "$fn.oooo", "$fn.ooooo" if -e "$fn.oooo";
@@ -517,7 +528,7 @@ sub export
        move "$fn", "$fn.o" if -e "$fn";
 
        my $json = JSON->new;
-       $json->canonical(1);
+       $json->canonical(1);;
        
        my $count = 0;
        my $err = 0;
@@ -527,10 +538,10 @@ sub export
                my $key = 0;
                my $val = undef;
                foreach my $k (sort keys %u) {
-                       my $r = $u{$k};
+                       my $r = get($k);
                        if ($r->{sort} eq 'U' && !$r->{priv} && $main::systime > $r->{lastin}+$tooold ) {
                                unless ($r->{lat} || $r->{long} || $r->{qra} || $r->{qth} || $r->{name}) {
-                                       LogDbg('DXUser', "DXUser::export deleting $k - too old, last in " . cldatetime($r->lastin) . " " . difft([$r->lastin, $main::systime]));
+                                       LogDbg('export', "DXUser::export deleting $k - too old, last in " . cldatetime($r->lastin) . " " . difft([$r->lastin, $main::systime]));
                                        delete $u{$k};
                                        ++$del;
                                        next;
@@ -538,7 +549,7 @@ sub export
                        }
                        eval {$val = json_encode($r);};
                        if ($@) {
-                               LogDbg('DXUser', "DXUser::export error encoding call: $k $@");
+                               LogDbg('export', "DXUser::export error encoding call: $k $@");
                                ++$err;
                                next;
                        } 
@@ -547,7 +558,8 @@ sub export
                }
         $fh->close;
     }
-       my $s = qq{Exported users to $fn - $count Users $del Deleted $err Errors ('sh/log Export' for details)};
+       my $t = _diffms($ta);
+       my $s = qq{Exported users to $fn - $count Users $del Deleted $err Errors in $t mS ('sh/log Export' for details)};
        LogDbg('DXUser', $s);
        return $s;
 }
index 9735aa30b10b5a42649625ad42ef03ae40eb9f60..3e57deb6dca15f9acebf0bd847f96228a88dbb8a 100755 (executable)
@@ -251,16 +251,18 @@ sub new_channel
                $basecall =~ s/-\d+$//; # remember this for later multiple user processing
                my $lock;
                if ($user) {
-                       # we are a real user
+                       # make sure we act on any locked status that the actual incoming call has.
                        $lock = $user->lockout;
-               } elsif ($allowmultiple) {
-                       # could we be a potential "pseudo" connection   
+               } elsif ($allowmultiple && $call ne $basecall) {
+                   # if we are allowing multiple connections and there is a basecall minus incoming ssid, use the basecall's lock status
                        $user = DXUser::get_current($basecall);
                        $lock = $user->lockout if $user;
                }
+
+               # now deal with the lock
                if ($lock) {
                        my $host = $conn->peerhost;
-                       LogDbg('DXCommand', "$call on $host is locked out, disconnected");
+                       LogDbg('', "$call on $host is locked out, disconnected");
                        $conn->disconnect;
                        return;
                }
@@ -281,7 +283,7 @@ sub new_channel
                                my $allow = 0;
                                if (@lastconns >= $DXUser::maxconnlist) {
                                        $allow = $lastconns[-1]->[0] - $lastconns[0]->[0] < $min_reconnection_rate;
-                               }
+                               } 
                                # search for a spare ssid
                        L1:     for (my $count = $call =~ /-\d+$/?0:1; $allow && $count < $allowmultiple; ) { # remember we have one call already
                                        my $lastid = 1;
@@ -303,7 +305,7 @@ sub new_channel
                                if ($bumpexisting) {
                                        my $ip = $dxchan->hostname;
                                        $dxchan->send_now('D', DXM::msg($lang, 'conbump', $call, $ip));
-                                       Log('', "$call bumped off by $ip, disconnected");
+                                       LogDbg('', "$call bumped off by $ip, disconnected");
                                        $dxchan->disconnect;
                                } else {
                                        already_conn($conn, $call, DXM::msg($lang, 'conother', $call, $main::mycall));
@@ -327,7 +329,7 @@ sub new_channel
                        $v = defined $c ? $c : $m;
                        if ($v && @n >= $v+$allowmultiple) {
                                my $nodes = join ',', @n;
-                               LogDbg('DXCommand', "$call has too many connections ($v) at $nodes - disconnected");
+                               LogDbg('', "$call has too many connections ($v) at $nodes - disconnected");
                                already_conn($conn, $call, DXM::msg($lang, 'contomany', $call, $v, $nodes));
                                return;
                        }
@@ -354,7 +356,7 @@ sub new_channel
        
 
        # set callbacks
-       $conn->set_error(sub {my $err = shift; LogDbg('DXCommand', "Comms error '$err' received for call $dxchan->{call}"); $dxchan->disconnect(1);});
+       $conn->set_error(sub {my $err = shift; LogDbg('', "Comms error '$err' received for call $dxchan->{call}"); $dxchan->disconnect(1);});
        $conn->set_on_eof(sub {$dxchan->disconnect});
        $conn->set_rproc(sub {my ($conn,$msg) = @_; $dxchan->rec($msg);});
        if ($sort eq 'W') {