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.4 by root, Sat Aug 11 00:37:32 2001 UTC vs.
Revision 1.10 by root, Tue Aug 14 02:28:51 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
9use Text::Abbrev;
10
11my $last_ts = time;
12
13my %complete;
14my @commands = qw(quit squit refresh country restart block info);
15
16abbrev \%complete, @commands;
7 17
8sub shell { 18sub shell {
9 my $fh = shift; 19 my $fh = shift;
10 20
11 while (defined (print $fh "cmd> "), $_ = <$fh>) { 21 while (defined (print $fh "cmd> "), $_ = <$fh>) {
12 s/\015?\012$//; 22 s/\015?\012$//;
13 chomp; 23 if (s/^(\S+)\s*// && (my $cmd = $complete{$1})) {
14 if (/^q/) { 24 if ($cmd eq "quit") {
25 print "bye bye.\n";#d#
26 last;
27 } elsif ($cmd eq "squit") {
15 Event::unloop; 28 Event::unloop;
16 } elsif (/^i/) { 29 } elsif ($cmd eq "block") {
30 print "blocked '$_'\n";#d#
31 $conn::blocked{$_} = time + $::BLOCKTIME;
32 } elsif ($cmd eq "info") {
33 $::NOW = time+1e-6;
17 my @data; 34 my @data;
18 for (values %conn::conn) { 35 for (values %conn::conn) {
19 for (values %$_) { 36 for (values %$_) {
20 next unless $_; 37 next unless $_;
21 push @data, "$_: $_->{remote_addr} $_->{uri}\n"; 38 my $rate = sprintf "%.1f", $_->{written} / ($::NOW - $_->{time});
39 push @data, "$_->{country}/$_->{remote_addr} $_->{written} $rate $_->{method} $_->{uri}\n";
40 }
22 } 41 }
42 print $fh sort @data;
43 print $fh scalar@data, " ($::conns) connections\n";#d#
44 print $fh "$::written bytes written in the last ",$::NOW - $last_ts, " seconds\n";
45 printf $fh "(%.1f bytes/s)\n", $::written / ($::NOW - $last_ts);
46 ($last_ts, $::written) = ($::NOW, 0);
47 } elsif ($cmd eq "refresh") {
48 read_blocklist;
49 } elsif ($cmd eq "restart") {
50 $::RESTART = 1;
51 unloop;
52 print $fh "restarting, cu!\n";
53 last;
54 } elsif ($cmd eq "country") {
55 print $fh ip_request($_), "\n";
23 } 56 }
24 print $fh sort @data;
25 print $fh scalar@data, " connections\n";#d#
26 } elsif (/^r/) {
27 $::RESTART = 1;
28 unloop;
29 print $fh "bye bye.\n";
30 last;
31 } else { 57 } else {
32 print $fh "try quit, info, restart\n"; 58 print $fh "try one of @commands\n";
33 } 59 }
34 } 60 }
35} 61}
36 62
37# bind to tcp port 63# bind to tcp port
44 or die "unable to bind cmdshell port: $!"; 70 or die "unable to bind cmdshell port: $!";
45 71
46 push @listen_sockets, $port; 72 push @listen_sockets, $port;
47 73
48 async { 74 async {
75 while () {
49 async \&shell, $port->accept 76 async \&shell, scalar $port->accept;
50 while 1; 77 }
51 }; 78 };
52} 79}
53 80
54# bind to stdin (debug) 81# bind to stdin (debug)
55if (1) { 82if (1) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines