# and out
#
#
-#
# Copyright (c) 2001 - Dirk Koopman G1TLH
#
+# Modified Jan 2006 by John Wiseman G8BPQ to support connections to BPQ32 node,
+# and fix pattern matching on 'chat' abort handling
+#
package ExtMsg;
{
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});
}
}
sub send_raw
{
my ($conn, $msg) = @_;
- my $sock = $conn->{sock};
- return unless defined($sock);
- push (@{$conn->{outqueue}}, $msg);
- dbg("connect $conn->{cnum}: $msg") if $conn->{state} ne 'C' && isdbg('connect');
- Msg::set_event_handler ($sock, "write" => sub {$conn->_send(0)});
+ dbg((ref $conn) . " connect $conn->{cnum}: $msg") if $conn->{state} ne 'C' && isdbg('connect');
+ $conn->SUPER::send_raw($msg);
}
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;
my $msg;
- if ($conn->{csort} eq 'ax25' && exists $conn->{msg}) {
+ if ($conn->ax25 && exists $conn->{msg}) {
$conn->{msg} =~ s/\cM/\cJ/g;
}
if ($conn->{state} eq 'WC') {
} 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} eq "127.0.0.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)) {
+ 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($msg)) && $uref->passwd ) {
+ $conn->conns($msg);
+ $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->disconnect;
}
} elsif ($conn->{state} eq 'WP' ) {
- my $uref = DXUser->get_current($conn->{call});
+ my $uref = DXUser::get_current($conn->{call});
$msg =~ s/[\r\n]+$//;
if ($uref && $msg eq $uref->passwd) {
my $sort = $conn->{csort};
$conn->{echo} = $conn->{decho};
delete $conn->{decho};
- $sort = 'local' if $conn->{peerhost} eq "127.0.0.1";
+ $sort = 'local' if $conn->{peerhost} =~ /127\.\d+\.\d+\.\d+$/ || $conn->{peerhost} eq '::1';
$conn->{usedpasswd} = 1;
$conn->to_connected($conn->{call}, 'A', $sort);
} else {
delete $conn->{cmd};
$conn->{timeout}->del if $conn->{timeout};
delete $conn->{timeout};
- $conn->nolinger unless $conn->isa('AGWMsg');
+ $conn->{csort} = $sort;
&{$conn->{rproc}}($conn, "$dir$call|$sort");
- $conn->_send_file("$main::data/connected") unless $conn->{outgoing};
+ $conn->_send_file(localdata("connected")) unless $conn->{outgoing};
}
sub new_client {
+
my $server_conn = shift;
- my $sock = $server_conn->{sock}->accept();
- if ($sock) {
- my $conn = $server_conn->new($server_conn->{rproc});
- $conn->{sock} = $sock;
- $conn->nolinger;
- Msg::blocking($sock, 0);
- $conn->{blocking} = 0;
- eval {$conn->{peerhost} = $sock->peerhost};
- if ($@) {
- dbg($@) if isdbg('connll');
- $conn->disconnect;
- } else {
- eval {$conn->{peerport} = $sock->peerport};
- $conn->{peerport} = 0 if $@;
- my ($rproc, $eproc) = &{$server_conn->{rproc}} ($conn, $conn->{peerhost}, $conn->{peerport});
- dbg("accept $conn->{cnum} from $conn->{peerhost} $conn->{peerport}") if isdbg('connll');
- if ($eproc) {
- $conn->{eproc} = $eproc;
- Msg::set_event_handler ($sock, "error" => $eproc);
- }
- if ($rproc) {
- $conn->{rproc} = $rproc;
- my $callback = sub {$conn->_rcv};
- Msg::set_event_handler ($sock, "read" => $callback);
- # send login prompt
- $conn->{state} = 'WL';
- # $conn->send_raw("\xff\xfe\x01\xff\xfc\x01\ff\fd\x22");
- # $conn->send_raw("\xff\xfa\x22\x01\x01\xff\xf0");
- # $conn->send_raw("\xFF\xFC\x01");
- $conn->_send_file("$main::data/issue");
- $conn->send_raw("login: ");
- $conn->_dotimeout(60);
- $conn->{echo} = 1;
- } else {
- &{$conn->{eproc}}() if $conn->{eproc};
- $conn->disconnect();
- }
- }
- } else {
- dbg("ExtMsg: error on accept ($!)") if isdbg('err');
- }
+ my $client = shift;
+ my $conn = $server_conn->SUPER::new_client($client);
+ # send login prompt
+ $conn->{state} = 'WL';
+ $conn->_send_file(localdata("issue"));
+ $conn->send_raw("login: ");
+ $conn->_dotimeout(60);
+# $conn->{echo} = 1;
}
sub start_connect
# turn it into an AGW object
bless $conn, 'AGWMsg';
$r = $conn->connect($line);
+ } elsif ($sort eq 'bpq') {
+ # turn it into an BPQ object
+ bless $conn, 'BPQMsg';
+ $r = $conn->connect($line);
} elsif ($sort eq 'ax25' || $sort eq 'prog') {
$r = $conn->start_program($line, $sort);
} else {
if ($line) {
if ($expect) {
dbg("connect $conn->{cnum}: expecting: \"$expect\" received: \"$line\"") if isdbg('connect');
- if ($conn->{abort} && $line =~ /\Q$conn->{abort}/i) {
+ if ($conn->{abort} && $line =~ /$conn->{abort}/i) {
dbg("connect $conn->{cnum}: aborted on /$conn->{abort}/") if isdbg('connect');
$conn->disconnect;
delete $conn->{cmd};
$conn->conns($call);
$conn->{csort} = $f[1] if $f[1];
$conn->{state} = 'C';
+ eval {$conn->{peerhost} = $conn->{sock}->handle->peerhost} unless $conn->ax25;
&{$conn->{rproc}}($conn, "O$call|$conn->{csort}");
delete $conn->{cmd};
$conn->{timeout}->del if $conn->{timeout};