use DXVars;
use DXUtil;
use DXDebug;
+use DXTimer;
+
use IO::File;
use IO::Socket;
use IPC::Open3;
{
my ($conn, $msg) = @_;
unless ($msg =~ /^[ABZ]/) {
- if ($msg =~ /^E[-\w]+\|([01])/ && $conn->{csort} eq 'telnet') {
+ if ($msg =~ m{^E[-\w\/]+\|([01])} && $conn->{csort} eq 'telnet') {
$conn->{echo} = $1;
if ($1) {
# $conn->send_raw("\xFF\xFC\x01");
# $conn->send_raw("\xFF\xFB\x01");
}
} else {
- $msg =~ s/^[-\w]+\|//;
+ $msg =~ s{^[-\w\/]+\|}{};
push (@{$conn->{outqueue}}, $msg . $conn->{lineend});
}
}
$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;
} else {
$conn->{msg} =~ s/([^\cM\cJ]*)\cM?\cJ//g;
}
+ $conn->{linesin} += @lines;
+ $Msg::total_lines_in += @lines;
while (defined ($msg = shift @lines)) {
dbg("connect $conn->{cnum}: $msg") if $conn->{state} ne 'C' && isdbg('connect');
&{$conn->{rproc}}($conn, "I$conn->{call}|$msg");
} elsif ($conn->{state} eq 'WL' ) {
$msg = uc $msg;
- if (is_callsign($msg) && $msg !~ m|/| ) {
- my $sort = $conn->{csort};
- $sort = 'local' if $conn->{peerhost} =~ /127\.\d+\.\d+\.\d+$/ || $conn->{peerhost} eq '::1';
- my $uref;
- if ($main::passwdreq || ($uref = DXUser::get_current($msg)) && $uref->passwd ) {
- $conn->conns($msg);
- $conn->{state} = 'WP';
- $conn->{decho} = $conn->{echo};
- $conn->{echo} = 0;
- $conn->send_raw('password: ');
+ 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)) {
+ my $call = normalise_call($msg);
+ if ($main::allowslashcall || $msg !~ m|/|) {
+ my $sort = $conn->{csort};
+ $sort = 'local' if $conn->{peerhost} =~ /127\.\d+\.\d+\.\d+$/ || $conn->{peerhost} eq '::1';
+ my $uref;
+ if ($main::passwdreq || ($uref = DXUser::get_current($call)) && $uref->passwd ) {
+ $conn->conns($call);
+ $conn->{state} = 'WP';
+ $conn->{decho} = $conn->{echo};
+ $conn->{echo} = 0;
+ $conn->send_raw('password: ');
+ } else {
+ $conn->to_connected($msg, 'A', $sort);
+ }
} else {
- $conn->to_connected($msg, 'A', $sort);
+ $conn->send_now("Sorry $msg is an invalid callsign");
+ $conn->disconnect;
}
} else {
$conn->send_now("Sorry $msg is an invalid callsign");
$conn->_send_file(localdata("issue"));
$conn->send_raw("login: ");
$conn->_dotimeout(60);
- $conn->{echo} = 1;
+# $conn->{echo} = 1;
}
sub start_connect
dbg("connect $conn->{cnum}: timeout set to $val") if isdbg('connect');
$conn->{timeout}->del if $conn->{timeout};
$conn->{timeval} = $val;
- $conn->{timeout} = Timer->new($val, sub{ &_timedout($conn) });
+ $conn->{timeout} = DXTimer->new($val, sub{ &_timedout($conn) });
}
sub _dolineend