Allow synonyms for localhost staging
authorDirk Koopman <djk@tobit.co.uk>
Fri, 20 Jan 2023 09:56:51 +0000 (09:56 +0000)
committerDirk Koopman <djk@tobit.co.uk>
Fri, 20 Jan 2023 09:56:51 +0000 (09:56 +0000)
This allows all internal addresses to be identified and then masked
as one IPV4 and one IPV6 external address.

Changes
cmd/dx.pl
perl/DXCommandmode.pm
perl/cluster.pl

diff --git a/Changes b/Changes
index f9f83e6bbd30f33e45f43802dc9026a4aad6bac0..ce05214ad2eea99e5c9140180ad30bd2281a7055 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,3 +1,21 @@
+20Jan23=======================================================================
+1. Add the variable @main::localhost_names to allow other IP addresses to
+   be treated in the same way as localhost in item 1 on 19Jan23 below. NOTE
+   you must include ALL the normal localhost names + any other interface
+   names that you might want to include:
+
+      set/var @main::localhost_names qw(127.0.0.1 ::1 192.168.1.30)
+
+   using the qw() construction is easier than:
+
+      set/var @main::localhost_names ('127.0.0.1', '::1', '192.168.1.30')
+
+   but either will work. You can define as many IP addresses as you like and
+   they can be IPV4 or 6. 
+   
+   You do NOT need to fiddle with this unless you specifically have more
+   than just the normal definitions of localhost. So for 'normal' nodes with
+   one external interface, you DO NOT NEED TO DO ANY OF THIS. 
 19Jan23=======================================================================
 1. Introduce aliasing for localhost in DX Spots and outgoing PC92 A records
    on login. There are two variables which can be set with the alias to use:
index 956dc4c17b6a2e2233bb63b09862871fb3b2421f..d1e278837d49fe018083121bf7cf44b77050424b 100644 (file)
--- a/cmd/dx.pl
+++ b/cmd/dx.pl
@@ -24,9 +24,7 @@ return (1, $self->msg('e5')) if $self->remotecmd || $self->inscript;
 return (1, $self->msg('e28')) unless $self->isregistered;
 
 
-my $addr = $self->hostname || '127.0.0.1';
-$addr = $main::localhost_alias_ipv6 if $addr eq '::1' && $main::localhost_alias_ipv6;
-$addr = $main::localhost_alias_ipv4 if $addr =~ /^127\./ && $main::localhost_alias_ipv4;
+my $addr = DXCommandmode::alias_localhost($self->hostname || '127.0.0.1');
 
 Log('cmd', "$self->{call}|$addr|dx|$line");
 
index 3226399746a15385b4582544994e4c0f7b959ba9..ffad39cf1506a6ced64cb3e948d1498a7a4605af 100644 (file)
@@ -49,7 +49,8 @@ use DXCIDR;
 
 use strict;
 use vars qw(%Cache %cmd_cache $errstr %aliases $scriptbase %nothereslug
-       $maxbadcount $msgpolltime $default_pagelth $cmdimportdir $users $maxusers);
+       $maxbadcount $msgpolltime $default_pagelth $cmdimportdir $users $maxusers
+);
 
 %Cache = ();                                   # cache of dynamically loaded routine's mod times
 %cmd_cache = ();                               # cache of short names
@@ -75,9 +76,7 @@ sub new
        my $pkg = shift;
        my $call = shift;
        #       my @rout = $main::routeroot->add_user($call, Route::here(1));
-       my $ipaddr = $self->hostname;
-       $ipaddr = $main::localhost_alias_ipv6 if $ipaddr eq '::1' && $main::localhost_alias_ipv6;
-       $ipaddr = $main::localhost_alias_ipv4 if $ipaddr =~ /^127\./ && $main::localhost_alias_ipv4;
+       my $ipaddr = alias_localhost($self->hostname);
        DXProt::_add_thingy($main::routeroot, [$call, 0, 0, 1, undef, undef, $ipaddr], );
 
        # ALWAYS output the user
@@ -1441,5 +1440,20 @@ sub user_count
     return ($users, $maxusers);
 }
 
+# alias localhost if required. This is designed to repress all localhost and other
+# internal interfaces to a fixed (outside) IPv4 or IPV6 address
+sub alias_localhost
+{
+       my $hostname = shift;
+       if ($hostname =~ /./) {
+               return $hostname unless $main::localhost_alias_ipv4;
+               return (grep $hostname eq $_, @main::localhost_names) ? $main::localhost_alias_ipv4 : $hostname;
+       } elsif ($hostname =~ /:/) {
+               return $hostname unless $main::localhost_alias_ipv6;
+               return (grep $hostname eq $_, @main::localhost_names) ? $main::localhost_alias_ipv6 : $hostname;
+       }
+       return $hostname;
+}
+
 1;
 __END__
index 5d26be28e0144f2db6033fc8976ab23a6c17b8d0..900d57a8b125a105765eda9bb096759da09a915e 100755 (executable)
@@ -218,6 +218,8 @@ our $clssecs;                                       # the amount of cpu time the DXSpider process have consumed
 our $cldsecs;                                  # the amount of cpu time any child processes have consumed
 our $allowslashcall;                   # Allow / in connecting callsigns (ie PA0/G1TLH, or even PA0/G1TLH/2) 
 
+our @localhost_names = qw(127.0.0.1 ::1); # all ip addresses that will need to be aliased below (ipv4 or ipv6)
+
 our $localhost_alias_ipv4;             # these are the IPV4 & 6 aliases for localhost connected clients
 our $localhost_alias_ipv6;             # for things (PC92, PC61 etc) that expose IP addresses. These *may*
                                 # be set by Msg.pm stuff if they are left undefined but, if you need