ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/myhttpd/shell.pl
Revision: 1.2
Committed: Fri Aug 10 04:16:41 2001 UTC (22 years, 11 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.1: +12 -4 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 # a server command shell
2    
3     use Coro;
4     use Coro::Handle;
5     use Coro::Socket;
6     use Event;
7    
8     sub shell {
9     my $fh = shift;
10    
11     while (defined (print $fh "cmd> "), $_ = <$fh>) {
12 root 1.2 s/\015?\012$//;
13 root 1.1 chomp;
14 root 1.2 if (/^q/) {
15 root 1.1 Event::unloop;
16 root 1.2 } elsif (/^i/) {
17 root 1.1 my @conn;
18     push @conn, values %$_ for values %conn::conn;
19     for (values %conn::conn) {
20     for (values %$_) {
21     next unless $_;
22 root 1.2 print $fh "$_: $_->{remote_addr} $_->{uri}\n";
23 root 1.1 }
24     }
25 root 1.2 } elsif (/^r/) {
26     $::RESTART = 1;
27     unloop;
28     print $fh "bye bye.\n";
29     last;
30 root 1.1 } else {
31 root 1.2 print $fh "try quit, info, restart\n";
32 root 1.1 }
33     }
34     }
35    
36     # bind to tcp port
37     if ($CMDSHELL_PORT) {
38     my $port = new Coro::Socket
39     LocalAddr => "127.0.0.1",
40     LocalPort => $CMDSHELL_PORT,
41     ReuseAddr => 1,
42     Listen => 1,
43     or die "unable to bind cmdshell port: $!";
44 root 1.2
45     push @listen_sockets, $port;
46 root 1.1
47     async {
48     async \&shell, $port->accept;
49     };
50     }
51    
52     # bind to stdin (debug)
53     if (1) {
54     my $tty;
55     open $tty, "+</dev/tty"
56     and async \&shell, unblock $tty;
57     }
58