add ip addresses to dxspots emitted as PC61
authorDirk Koopman <djk@tobit.co.uk>
Thu, 17 Jun 2010 10:45:21 +0000 (11:45 +0100)
committerDirk Koopman <djk@tobit.co.uk>
Thu, 17 Jun 2010 10:45:21 +0000 (11:45 +0100)
Changes
cmd/dx.pl
perl/DXProt.pm
perl/DXProtHandle.pm
perl/DXProtout.pm
perl/DXUtil.pm
perl/Spot.pm
perl/Version.pm

diff --git a/Changes b/Changes
index 4865b15b738b21b183db03886fadcf7f2f188519..077acc7cfde0956bd36b8674d82b80f816ab1452 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,3 +1,5 @@
+17Jun10=======================================================================
+1. Add ip address to dxspots and default to PC61 output to dxspider nodes
 16Jun10=======================================================================
 1. Increase default ephemeral dupe time for PC41 and such like lines.
 2. Include CTY-2004 updates.
index 1836f1fe979d7f5529c827d64c9910aec95911fb..d8dd56cbbd7ee76bf0507242d3eea7d9d8ee1ead 100644 (file)
--- a/cmd/dx.pl
+++ b/cmd/dx.pl
@@ -120,10 +120,17 @@ if ($spotted le ' ') {
 
 return (1, @out) unless $valid;
 
+my $ipaddr;
+
+if ($self->conn->peerhost) {
+       my $addr = $self->conn->peerhost;
+       $ipaddr = $addr unless !is_ipaddr($addr) || $addr =~ /^127\./ || $addr =~ /^::[0-9a-f]+$/;
+}
+
 # Store it here (but only if it isn't baddx)
 my $t = (int ($main::systime/60)) * 60;
 return (1, $self->msg('dup')) if Spot::dup($freq, $spotted, $t, $line, $spotter);
-my @spot = Spot::prepare($freq, $spotted, $t, $line, $spotter, $main::mycall);
+my @spot = Spot::prepare($freq, $spotted, $t, $line, $spotter, $main::mycall, $ipaddr);
 
 if ($freq =~ /^69/ || $localonly) {
 
@@ -140,7 +147,11 @@ if ($freq =~ /^69/ || $localonly) {
                Spot::add(@spot);
 
                # send orf to the users
-               DXProt::send_dx_spot($self, DXProt::pc11($spotter, $freq, $spotted, $line), @spot);
+               if ($ipaddr) {
+                       DXProt::send_dx_spot($self, DXProt::pc61($spotter, $freq, $spotted, $line, $ipaddr), @spot);
+               } else {
+                       DXProt::send_dx_spot($self, DXProt::pc11($spotter, $freq, $spotted, $line), @spot);
+               }
        }
 }
 
index 72f411949861f581e7567d1edcb4203d00fe0164..92a36d1ee826b192f8c699e247c33755a9e7b16a 100644 (file)
@@ -134,7 +134,7 @@ $pc92_find_timeout = 30;            # maximum time to wait for a reply
  undef,
  undef,
  undef,                                                        # pc60
- undef,
+ [ qw(i f m d t m c c a h) ],          # pc61
  undef,
  undef,
  undef,
@@ -205,6 +205,8 @@ sub check
                        return $i unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
                } elsif ($act eq 'l') {
                        return $i unless $_[$i] =~ /^[A-Z]$/;
+               } elsif ($act eq 'a') {
+                       return $i unless is_ipaddr($_[$i]);
                }
        }
        return 0;
@@ -544,14 +546,22 @@ sub send_dx_spot
        my $line = shift;
        my @dxchan = DXChannel::get_all();
        my $dxchan;
+       my $pc11;
 
        # send it if it isn't the except list and isn't isolated and still has a hop count
        # taking into account filtering and so on
        foreach $dxchan (@dxchan) {
                next if $dxchan == $main::me;
                next if $dxchan == $self && $self->is_node;
-               next if $line =~ /PC61/ && !$dxchan->is_spider && !$dxchan->is_user;
-               $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
+               if ($line =~ /PC61/ && !($dxchan->is_spider || $dxchan->is_user)) {
+                       unless ($pc11) {
+                               my @f = split /\^/, $line;
+                               $pc11 = join '^', 'PC11', @f[1..7,9];
+                       }
+                       $dxchan->dx_spot($pc11, $self->{isolate}, @_, $self->{call});
+               } else {
+                       $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
+               }
        }
 }
 
index c5d4bf4e756a77516b12080000f0bd14e7b37a63..43e5670cf4d511311658ecf6cd9e6875bf17d8b0 100644 (file)
@@ -171,13 +171,13 @@ sub handle_11
        # convert the date to a unix date
        my $d = cltounix($_[3], $_[4]);
        # bang out (and don't pass on) if date is invalid or the spot is too old (or too young)
-       if (!$d || ($pcno == 11 && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
+       if (!$d || (($pcno == 11 || $pcno == 61) && ($d < $main::systime - $pc11_max_age || $d > $main::systime + 900))) {
                dbg("PCPROT: Spot ignored, invalid date or out of range ($_[3] $_[4])\n") if isdbg('chanerr');
                return;
        }
 
        # is it 'baddx'
-       if ($baddx->in($_[2]) || BadWords::check($_[2]) || $_[2] =~ /COCK/) {
+       if ($baddx->in($_[2]) || BadWords::check($_[2])) {
                dbg("PCPROT: Bad DX spot, ignored") if isdbg('chanerr');
                return;
        }
@@ -197,7 +197,7 @@ sub handle_11
                }
        }
 
-       my @spot = Spot::prepare($_[1], $_[2], $d, $_[5], $nossid, $_[7]);
+       my @spot = Spot::prepare($_[1], $_[2], $d, $_[5], $nossid, $_[7], $_[8]);
        # global spot filtering on INPUT
        if ($self->{inspotsfilter}) {
                my ($filter, $hops) = $self->{inspotsfilter}->it(@spot);
index f01a1481cc0a06681bc3ceccc065809f0c63f20e..ba3013389b8f13b26dc6acf7f900621734498e9c 100644 (file)
@@ -47,7 +47,7 @@ sub pc10
        return "PC10^$from^$user1^$text^*^$user2^$origin^~";
 }
 
-# create a dx message (call, freq, dxcall, text)
+# create a dx message (call, freq, dxcall, text) see also pc61
 sub pc11
 {
        my ($mycall, $freq, $dxcall, $text) = @_;
@@ -58,6 +58,17 @@ sub pc11
        return sprintf "PC11^%.1f^$dxcall^%s^%s^$text^$mycall^$main::mycall^$hops^~", $freq, cldate($t), ztime($t);
 }
 
+# create a dx message (call, freq, dxcall, text, $ipaddr) see also pc11
+sub pc61
+{
+       my ($mycall, $freq, $dxcall, $text, $ipaddr) = @_;
+       my $hops = get_hops(61) || get_hops(11);
+       my $t = time;
+       $text = ' ' if !$text;
+       $text =~ s/\^/%5E/g;
+       return sprintf "PC61^%.1f^$dxcall^%s^%s^$text^$mycall^$main::mycall^$ipaddr^$hops^~", $freq, cldate($t), ztime($t);
+}
+
 # create an announce message
 sub pc12
 {
index 512c30efcc0e35609c3d931f0c20bf172af517ef..49cba9e972ad55fab0d4300c5d4eb72103254382 100644 (file)
@@ -22,9 +22,9 @@ require Exporter;
 @EXPORT = qw(atime ztime cldate cldatetime slat slong yesno promptf 
                         parray parraypairs phex phash shellregex readfilestr writefilestr
                         filecopy ptimelist
-             print_all_fields cltounix unpad is_callsign is_latlong
+             print_all_fields cltounix unpad is_callsign is_long_callsign is_latlong
                         is_qra is_freq is_digits is_pctext is_pcflag insertitem deleteitem
-                        is_prefix dd
+                        is_prefix dd is_ipaddr
             );
 
 
@@ -383,6 +383,18 @@ sub is_callsign
                                         $!x;
 }
 
+# check that a field only has callsign characters in it but has more than the standard 3 callsign letters
+sub is_long_callsign
+{
+       return $_[0] =~ m!^(?:[A-Z]{1,2}\d+ | \d[A-Z]{1,2}\d+)        # basic prefix
+                       (?:/(?:[A-Z]{1,2}\d+ | \d[A-Z]{1,2}\d+))?  # / another one (possibly)
+                                          [A-Z]{1,5}                                 # callsign letters
+                                          (?:/(?:[A-Z]{1,2}\d+ | \d[A-Z]{1,2}\d+))?  # / another prefix possibly
+                       (?:/[0-9A-Z]{1,2})?                        # /0-9A-Z+ possibly
+                                          (?:-\d{1,2})?                              # - nn possibly
+                                        $!x;
+}
+
 sub is_prefix
 {
        return $_[0] =~ m!^(?:[A-Z]{1,2}\d+ | \d[A-Z]{1,2}\d+)!x        # basic prefix
@@ -427,6 +439,12 @@ sub is_latlong
        return $_[0] =~ /^\s*\d{1,2}\s+\d{1,2}\s*[NnSs]\s+1?\d{1,2}\s+\d{1,2}\s*[EeWw]\s*$/;
 }
 
+# is it an ip address?
+sub is_ipaddr
+{
+    return $_[0] =~ /^\d+\.\d+\.\d+\.\d+$/ || $_[0] =~ /^[0-9a-f:]+$/;
+}
+
 # insert an item into a list if it isn't already there returns 1 if there 0 if not
 sub insertitem
 {
index e7227ab1b2cdff4e313b95266b935756e2d0d5c5..b8efd3d17c7af576ef387c908e41acfbb3eef8d5 100644 (file)
@@ -161,7 +161,7 @@ sub prefix
 # fix up the full spot data from the basic spot data
 sub prepare
 {
-       # $freq, $call, $t, $comment, $spotter = @_
+       # $freq, $call, $t, $comment, $spotter, node, ip address = @_
        my @out = @_[0..4];      # just up to the spotter
 
        # normalise frequency
@@ -180,7 +180,9 @@ sub prepare
        my @spt = Prefix::cty_data($out[4]);
        push @out, $spt[0];
        push @out, $_[5];
-       return (@out, @spd[1,2], @spt[1,2], $spd[3], $spt[3]);
+       push @out, @spd[1,2], @spt[1,2], $spd[3], $spt[3];
+       push @out, $_[6] if $_[6] && is_ipaddr($_[6]);
+       return @out;
 }
 
 sub add
index ddd32c66c0152b8f1b8fdd22194ecead59f4a31f..143e0055a84c2052f68a70c575709f5c26399f18 100644 (file)
@@ -11,6 +11,6 @@ use vars qw($version $subversion $build);
 
 $version = '1.55';
 $subversion = '0';
-$build = '69';
+$build = '70';
 
 1;