ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/myhttpd/shell.pl
(Generate patch)

Comparing Coro/myhttpd/shell.pl (file contents):
Revision 1.1 by root, Fri Aug 10 02:29:01 2001 UTC vs.
Revision 1.8 by root, Sat Aug 11 19:59:20 2001 UTC

2 2
3use Coro; 3use Coro;
4use Coro::Handle; 4use Coro::Handle;
5use Coro::Socket; 5use Coro::Socket;
6use Event; 6use Event;
7use Time::HiRes 'time';
8
9my $last_ts = time;
7 10
8sub shell { 11sub shell {
9 my $fh = shift; 12 my $fh = shift;
10 13
11 while (defined (print $fh "cmd> "), $_ = <$fh>) { 14 while (defined (print $fh "cmd> "), $_ = <$fh>) {
15 s/\015?\012$//;
12 chomp; 16 chomp;
13 if (/quit/) { 17 if (/^q/) {
14 Event::unloop; 18 Event::unloop;
15 } elsif (/info/) { 19 } elsif (/^i/) {
20 $::NOW = time+1e-6;
16 my @conn; 21 my @data;
17 push @conn, values %$_ for values %conn::conn;
18 for (values %conn::conn) { 22 for (values %conn::conn) {
19 for (values %$_) { 23 for (values %$_) {
20 next unless $_; 24 next unless $_;
21 print "$_: $_->{remote_addr} $_->{uri}\n"; 25 my $rate = sprintf "%.1f", $_->{written} / ($::NOW - $_->{time});
26 push @data, "$_->{country}/$_->{remote_addr} $_->{written} $rate $_->{method} $_->{uri}\n";
22 } 27 }
23 } 28 }
29 print $fh sort @data;
30 print $fh scalar@data, " connections\n";#d#
31 print $fh "$::written bytes written in the last ",$::NOW - $last_ts, " seconds\n";
32 printf $fh "(%.1f bytes/s)\n", $::written / ($::NOW - $last_ts);
33 ($last_ts, $::written) = ($::NOW, 0);
34 } elsif (/^ref/) {
35 read_blocklist;
36 } elsif (/^r/) {
37 $::RESTART = 1;
38 unloop;
39 print $fh "bye bye.\n";
40 last;
41 } elsif (/^co\S*\s+(\S+)/) {
42 print $fh ip_request($1), "\n";
24 } else { 43 } else {
25 print "try quit\n"; 44 print $fh "try quit, info, restart, refresh\n";
26 } 45 }
27 } 46 }
28} 47}
29 48
30# bind to tcp port 49# bind to tcp port
34 LocalPort => $CMDSHELL_PORT, 53 LocalPort => $CMDSHELL_PORT,
35 ReuseAddr => 1, 54 ReuseAddr => 1,
36 Listen => 1, 55 Listen => 1,
37 or die "unable to bind cmdshell port: $!"; 56 or die "unable to bind cmdshell port: $!";
38 57
58 push @listen_sockets, $port;
59
39 async { 60 async {
61 while () {
40 async \&shell, $port->accept; 62 async \&shell, scalar $port->accept;
63 }
41 }; 64 };
42} 65}
43 66
44# bind to stdin (debug) 67# bind to stdin (debug)
45if (1) { 68if (1) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines