attempt to prevent echoing on ExtMsg login
[spider.git] / perl / ExtMsg.pm
index 44846c53312f12a370b2babd6cd5acd888605c4d..6b3a30b1c0f00624fa573fc79c35cba28eb314a4 100644 (file)
@@ -64,6 +64,24 @@ sub echo
        $conn->{echo} = shift;
 }
 
+sub _rcv
+{
+    my $conn = shift; # $rcv_now complement of $flush
+       my $msg = shift;
+    my $sock = $conn->{sock};
+    return unless defined($sock);
+       return if $conn->{disconnecting};
+
+       if ($conn->{state} eq 'WL' && $conn->{sort} =~ /^I/ && $msg =~ /^PROXY/) {
+               my $echo = $conn->{echo};
+               $conn->{echo} = 0;
+               $conn->SUPER::_rcv($msg);
+               $conn->{echo} = $echo;
+       } else {
+               $conn->SUPER::_rcv($msg);
+       }
+}
+
 sub dequeue
 {
        my $conn = shift;
@@ -99,7 +117,19 @@ sub dequeue
                                &{$conn->{rproc}}($conn, "I$conn->{call}|$msg");
                        } elsif ($conn->{state} eq 'WL' ) {
                                $msg = uc $msg;
-                               if (is_callsign($msg)) {
+                               if ($conn->{sort} =~ /^I/ && (my ($ip, $from) = $msg =~ /^PROXY TCP[46] ([\da-fA-F:\.]+) ([\da-fA-F:\.]+)/) ) {
+                                       # SOMEONE appears to have affixed an HA Proxy to my connection
+                                       $ip =~ s|^::ffff:||; # chop off leading pseudo IPV6 stuff on dual stack listeners
+                                       $from =~ s|^::ffff:||;
+                                       if ($from eq $conn->{peerhost}) {
+                                               dbg("ExtMsg: connect - PROXY IP change from '$conn->{peerhost}' -> '$ip'");
+                                               $conn->{peerhost} = $ip;
+                                       } else {
+                                               dbg("ExtMsg: connect - PROXY someone ($from) is trying to spoof '$ip'");
+                                               $conn->send_now("Sorry $msg is an invalid callsign");
+                                               $conn->disconnect;
+                                       }
+                               } elsif (is_callsign($msg)) {
                                        if ($main::allowslashcall || $msg !~ m|/|) {
                                                my $sort = $conn->{csort};
                                                $sort = 'local' if $conn->{peerhost} =~ /127\.\d+\.\d+\.\d+$/ || $conn->{peerhost} eq '::1';
@@ -170,7 +200,7 @@ sub new_client {
        $conn->_send_file(localdata("issue"));
        $conn->send_raw("login: ");
        $conn->_dotimeout(60);
-       $conn->{echo} = 1;
+#      $conn->{echo} = 1;
 }
 
 sub start_connect