- if ($conn->{state} eq 'C') {
- &{$conn->{rproc}}($conn, "I$conn->{call}|$msg", $!);
- $! = 0;
- } elsif ($conn->{state} eq 'WL' ) {
- $msg = uc $msg;
- if (is_callsign($msg)) {
- _send_file($conn, "$main::data/connected");
- $conn->{call} = $msg;
- &{$conn->{rproc}}($conn, "A$conn->{call}|telnet");
- $conn->{state} = 'C';
- } else {
- $conn->send_now("Sorry $msg is an invalid callsign");
- $conn->disconnect;
- }
- } elsif ($conn->{state} eq 'WC') {
- if (exists $conn->{cmd} && @{$conn->{cmd}}) {
- $conn->_docmd($msg);
- unless (exists $conn->{cmd} && @{$conn->{cmd}}) {
- $conn->{state} = 'C';
- &{$conn->{rproc}}($conn, "O$conn->{call}|telnet");
- delete $conn->{cmd};
- $conn->{timeout}->del_timer if $conn->{timeout};
+ if ($conn->ax25 && exists $conn->{msg}) {
+ $conn->{msg} =~ s/\cM/\cJ/g;
+ }
+ if ($conn->{state} eq 'WC') {
+ if (exists $conn->{cmd}) {
+ if (@{$conn->{cmd}}) {
+ dbg("connect $conn->{cnum}: $conn->{msg}") if isdbg('connect');
+ $conn->_docmd($conn->{msg});
+ }
+ }
+ if ($conn->{state} eq 'WC' && exists $conn->{cmd} && @{$conn->{cmd}} == 0) {
+ $conn->to_connected($conn->{call}, 'O', $conn->{csort});
+ }
+ } elsif ($conn->{msg} =~ /\cJ/) {
+ my @lines = $conn->{msg} =~ /([^\cM\cJ]*)\cM?\cJ/g;
+ if ($conn->{msg} =~ /\cJ$/) {
+ delete $conn->{msg};
+ } 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');
+
+ $msg =~ s/\xff\xfa.*\xff\xf0|\xff[\xf0-\xfe].//g; # remove telnet options
+# $msg =~ s/[\x00-\x08\x0a-\x19\x1b-\x1f\x80-\x9f]/./g; # immutable CSI sequence + control characters
+
+ if ($conn->{state} eq 'C') {
+ &{$conn->{rproc}}($conn, "I$conn->{call}|$msg");
+ } elsif ($conn->{state} eq 'WL' ) {
+ $msg = uc $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';
+ 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->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});
+ $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} =~ /127\.\d+\.\d+\.\d+$/ || $conn->{peerhost} eq '::1';
+ $conn->{usedpasswd} = 1;
+ $conn->to_connected($conn->{call}, 'A', $sort);
+ } else {
+ $conn->send_now("Sorry");
+ $conn->disconnect;
+ }
+ } elsif ($conn->{state} eq 'WC') {
+ if (exists $conn->{cmd} && @{$conn->{cmd}}) {
+ $conn->_docmd($msg);
+ if ($conn->{state} eq 'WC' && exists $conn->{cmd} && @{$conn->{cmd}} == 0) {
+ $conn->to_connected($conn->{call}, 'O', $conn->{csort});
+ }