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.6 by root, Sat Aug 11 16:34:47 2001 UTC vs.
Revision 1.12 by root, Wed Aug 15 03:06:22 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 print);
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 last;
30 } elsif ($cmd eq "print") {
31 my @res = eval $_;
32 print $fh "eval: $@\n" if $@;
33 print $fh "RES = ", (join " : ", @res), "\n";
34 } elsif ($cmd eq "block") {
35 print "blocked '$_'\n";#d#
36 $conn::blocked{$_} = time + $::BLOCKTIME;
37 } elsif ($cmd eq "info") {
38 $::NOW = time+1e-6;
17 my @data; 39 my @data;
18 for (values %conn::conn) { 40 for (values %conn::conn) {
19 for (values %$_) { 41 for (values %$_) {
20 next unless $_; 42 next unless $_;
43 my $rate = sprintf "%.1f", $_->{written} / ($::NOW - $_->{time});
21 push @data, "$_->{country}/$_->{remote_addr} $_->{method} $_->{uri}\n"; 44 push @data, "$_->{country}/$_->{remote_addr} $_->{written} $rate $_->{method} $_->{uri}\n";
45 }
22 } 46 }
47 print $fh sort @data;
48 print $fh scalar@data, " ($::conns) connections\n";#d#
49 print $fh "$::written bytes written in the last ",$::NOW - $last_ts, " seconds\n";
50 printf $fh "(%.1f bytes/s)\n", $::written / ($::NOW - $last_ts);
51 ($last_ts, $::written) = ($::NOW, 0);
52 } elsif ($cmd eq "refresh") {
53 do "config.pl";
54 print $fh "config.pl: $@\n" if $@;
55 read_blocklist;
56 } elsif ($cmd eq "restart") {
57 $::RESTART = 1;
58 unloop;
59 print $fh "restarting, cu!\n";
60 last;
61 } elsif ($cmd eq "country") {
62 print $fh ip_request($_), "\n";
23 } 63 }
24 print $fh sort @data;
25 print $fh scalar@data, " connections\n";#d#
26 } elsif (/^ref/) {
27 read_blocklist;
28 } elsif (/^r/) {
29 $::RESTART = 1;
30 unloop;
31 print $fh "bye bye.\n";
32 last;
33 } else { 64 } else {
34 print $fh "try quit, info, restart, refresh\n"; 65 print $fh "try one of @commands\n";
35 } 66 }
36 } 67 }
37} 68}
38 69
39# bind to tcp port 70# bind to tcp port
46 or die "unable to bind cmdshell port: $!"; 77 or die "unable to bind cmdshell port: $!";
47 78
48 push @listen_sockets, $port; 79 push @listen_sockets, $port;
49 80
50 async { 81 async {
82 while () {
51 async \&shell, $port->accept 83 async \&shell, scalar $port->accept;
52 while 1; 84 }
53 }; 85 };
54} 86}
55 87
56# bind to stdin (debug) 88# bind to stdin (debug)
57if (1) { 89if (1) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines