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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines