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.8 by root, Sat Aug 11 19:59:20 2001 UTC vs.
Revision 1.22 by pcg, Thu Feb 12 22:18:27 2004 UTC

4use Coro::Handle; 4use Coro::Handle;
5use Coro::Socket; 5use Coro::Socket;
6use Event; 6use Event;
7use Time::HiRes 'time'; 7use Time::HiRes 'time';
8 8
9use Text::Abbrev;
10
9my $last_ts = time; 11my $last_ts = time;
12
13my %complete;
14my @commands = qw(quit squit refresh country restart block info print clrdiridx);
15
16abbrev \%complete, @commands;
10 17
11sub shell { 18sub shell {
12 my $fh = shift; 19 my $fh = shift;
13 20
14 while (defined (print $fh "cmd> "), $_ = <$fh>) { 21 while (defined (print $fh "cmd> "), $_ = <$fh>) {
15 s/\015?\012$//; 22 s/\015?\012$//;
16 chomp; 23 if (s/^(\S+)\s*// && (my $cmd = $complete{$1})) {
17 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#
18 Event::unloop; 29 Event::unloop;
19 } 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, "blocked by operator"];
38 } elsif ($cmd eq "info") {
20 $::NOW = time+1e-6; 39 $::NOW = time+1e-6;
21 my @data; 40 my @data;
22 for (values %conn::conn) { 41 for (values %conn::conn) {
23 for (values %$_) { 42 for (values %$_) {
24 next unless $_; 43 next unless $_;
25 my $rate = sprintf "%.1f", $_->{written} / ($::NOW - $_->{time}); 44 my $rate = sprintf "%.1f", $_->{written} / ($::NOW - $_->{time});
26 push @data, "$_->{country}/$_->{remote_addr} $_->{written} $rate $_->{method} $_->{uri}\n"; 45 push @data, "$_->{country}/$_->{remote_addr} $_->{written} $rate $_->{method} $_->{uri}\n";
46 }
27 } 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 "clrdiridx") {
60 %statdata_cache = ();
61 delete $diridx{$_} for keys %diridx; # server error on %diridx = ();
62 } elsif ($cmd eq "restart") {
63 $::RESTART = 1;
64 unloop;
65 print $fh "restarting, cu!\n";
66 last;
67 } elsif ($cmd eq "country") {
68 print $fh netgeo::ip_request($_), "\n";
28 } 69 }
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";
43 } else { 70 } else {
44 print $fh "try quit, info, restart, refresh\n"; 71 print $fh "try one of @commands\n";
45 } 72 }
46 } 73 }
47} 74}
48 75
49# bind to tcp port 76# bind to tcp port
50if ($CMDSHELL_PORT) { 77if ($CMDSHELL_PORT) {
51 my $port = new Coro::Socket 78 my $port = new Coro::Socket
52 LocalAddr => "127.0.0.1", 79 #LocalAddr => "127.0.0.1",
53 LocalPort => $CMDSHELL_PORT, 80 LocalPort => $CMDSHELL_PORT,
54 ReuseAddr => 1, 81 ReuseAddr => 1,
55 Listen => 1, 82 Listen => 1,
56 or die "unable to bind cmdshell port: $!"; 83 or die "unable to bind cmdshell port: $!";
57 84

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines