ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/myhttpd/shell.pl
Revision: 1.7
Committed: Sat Aug 11 16:53:59 2001 UTC (22 years, 11 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.6: +3 -2 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.3 my @data;
18 root 1.1 for (values %conn::conn) {
19     for (values %$_) {
20     next unless $_;
21 root 1.6 push @data, "$_->{country}/$_->{remote_addr} $_->{method} $_->{uri}\n";
22 root 1.1 }
23     }
24 root 1.3 print $fh sort @data;
25     print $fh scalar@data, " connections\n";#d#
26 root 1.5 } elsif (/^ref/) {
27     read_blocklist;
28 root 1.2 } elsif (/^r/) {
29     $::RESTART = 1;
30     unloop;
31     print $fh "bye bye.\n";
32     last;
33 root 1.1 } else {
34 root 1.5 print $fh "try quit, info, restart, refresh\n";
35 root 1.1 }
36     }
37     }
38    
39     # bind to tcp port
40     if ($CMDSHELL_PORT) {
41     my $port = new Coro::Socket
42     LocalAddr => "127.0.0.1",
43     LocalPort => $CMDSHELL_PORT,
44     ReuseAddr => 1,
45     Listen => 1,
46     or die "unable to bind cmdshell port: $!";
47 root 1.2
48     push @listen_sockets, $port;
49 root 1.1
50     async {
51 root 1.7 while () {
52     async \&shell, scalar $port->accept;
53     }
54 root 1.1 };
55     }
56    
57     # bind to stdin (debug)
58     if (1) {
59     my $tty;
60     open $tty, "+</dev/tty"
61     and async \&shell, unblock $tty;
62     }
63