added registration
[spider.git] / perl / ExtMsg.pm
index 75b025f397cf34f553799460ed57318584c01490..8e17cfa875c251dbb2c850bc4d636bd48b2fffe0 100644 (file)
@@ -60,6 +60,12 @@ sub send_raw
     Msg::set_event_handler ($sock, "write" => sub {$conn->_send(0)});
 }
 
+sub echo
+{
+       my $conn = shift;
+       $conn->{echo} = shift;
+}
+
 sub dequeue
 {
        my $conn = shift;
@@ -98,11 +104,34 @@ sub dequeue
                                if (is_callsign($msg) && $msg !~ m|/| ) {
                                        my $sort = $conn->{csort};
                                        $sort = 'local' if $conn->{peerhost} eq "127.0.0.1";
-                                       $conn->to_connected($msg, 'A', $sort);
+                                       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;
                                }
+                       } 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} eq "127.0.0.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);
@@ -160,6 +189,7 @@ sub new_client {
                                $conn->_send_file("$main::data/issue");
                                $conn->send_raw("login: ");
                                $conn->_dotimeout(60);
+                               $conn->{echo} = 1;
                        } else { 
                                &{$conn->{eproc}}() if $conn->{eproc};
                                $conn->disconnect();