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.10 by root, Tue Aug 14 02:28:51 2001 UTC vs.
Revision 1.23 by root, Sat Dec 8 21:01:17 2007 UTC

1# a server command shell 1# a server command shell
2 2
3use EV;
3use Coro; 4use Coro;
5use Coro::EV;
4use Coro::Handle; 6use Coro::Handle;
5use Coro::Socket; 7use Coro::Socket;
6use Event;
7use Time::HiRes 'time'; 8use Time::HiRes 'time';
8 9
9use Text::Abbrev; 10use Text::Abbrev;
10 11
11my $last_ts = time; 12my $last_ts = time;
12 13
13my %complete; 14my %complete;
14my @commands = qw(quit squit refresh country restart block info); 15my @commands = qw(quit squit refresh country restart block info print clrdiridx);
15 16
16abbrev \%complete, @commands; 17abbrev \%complete, @commands;
17 18
18sub shell { 19sub shell {
19 my $fh = shift; 20 my $fh = shift;
20 21
21 while (defined (print $fh "cmd> "), $_ = <$fh>) { 22 while (defined (print $fh "cmd> "), $_ = <$fh>) {
22 s/\015?\012$//; 23 s/\015?\012$//;
23 if (s/^(\S+)\s*// && (my $cmd = $complete{$1})) { 24 if (s/^(\S+)\s*// && (my $cmd = $complete{$1})) {
24 if ($cmd eq "quit") { 25 if ($cmd eq "quit") {
25 print "bye bye.\n";#d# 26 print $fh "bye bye.\n";#d#
26 last; 27 last;
27 } elsif ($cmd eq "squit") { 28 } elsif ($cmd eq "squit") {
29 print $fh "server quit.\n";#d#
28 Event::unloop; 30 EV::unloop;
31 last;
32 } elsif ($cmd eq "print") {
33 my @res = eval $_;
34 print $fh "eval: $@\n" if $@;
35 print $fh "RES = ", (join " : ", @res), "\n";
29 } elsif ($cmd eq "block") { 36 } elsif ($cmd eq "block") {
30 print "blocked '$_'\n";#d# 37 print "blocked '$_'\n";#d#
31 $conn::blocked{$_} = time + $::BLOCKTIME; 38 $conn::blocked{$_} = [time + $::BLOCKTIME, "blocked by operator"];
32 } elsif ($cmd eq "info") { 39 } elsif ($cmd eq "info") {
33 $::NOW = time+1e-6; 40 $::NOW = time+1e-6;
34 my @data; 41 my @data;
35 for (values %conn::conn) { 42 for (values %conn::conn) {
36 for (values %$_) { 43 for (values %$_) {
39 push @data, "$_->{country}/$_->{remote_addr} $_->{written} $rate $_->{method} $_->{uri}\n"; 46 push @data, "$_->{country}/$_->{remote_addr} $_->{written} $rate $_->{method} $_->{uri}\n";
40 } 47 }
41 } 48 }
42 print $fh sort @data; 49 print $fh sort @data;
43 print $fh scalar@data, " ($::conns) connections\n";#d# 50 print $fh scalar@data, " ($::conns) connections\n";#d#
44 print $fh "$::written bytes written in the last ",$::NOW - $last_ts, " seconds\n"; 51 print $fh "$::written bytes written in the last ", $::NOW - $last_ts, " seconds\n";
45 printf $fh "(%.1f bytes/s)\n", $::written / ($::NOW - $last_ts); 52 printf $fh "(%.1f bytes/s)\n", $::written / ($::NOW - $last_ts);
46 ($last_ts, $::written) = ($::NOW, 0); 53 ($last_ts, $::written) = ($::NOW, 0);
47 } elsif ($cmd eq "refresh") { 54 } elsif ($cmd eq "refresh") {
55 do "config.pl";
56 print $fh "config.pl: $@\n" if $@;
57 %statdata_cache = ();
48 read_blocklist; 58 conn::read_blockuri;
59 conn::read_blockref;
60 } elsif ($cmd eq "clrdiridx") {
61 %statdata_cache = ();
62 delete $diridx{$_} for keys %diridx; # server error on %diridx = ();
49 } elsif ($cmd eq "restart") { 63 } elsif ($cmd eq "restart") {
50 $::RESTART = 1; 64 $::RESTART = 1;
51 unloop; 65 EV::unloop;
52 print $fh "restarting, cu!\n"; 66 print $fh "restarting, cu!\n";
53 last; 67 last;
54 } elsif ($cmd eq "country") { 68 } elsif ($cmd eq "country") {
55 print $fh ip_request($_), "\n"; 69 print $fh netgeo::ip_request($_), "\n";
56 } 70 }
57 } else { 71 } else {
58 print $fh "try one of @commands\n"; 72 print $fh "try one of @commands\n";
59 } 73 }
60 } 74 }
61} 75}
62 76
63# bind to tcp port 77# bind to tcp port
64if ($CMDSHELL_PORT) { 78if ($CMDSHELL_PORT) {
65 my $port = new Coro::Socket 79 my $port = new Coro::Socket
66 LocalAddr => "127.0.0.1", 80 #LocalAddr => "127.0.0.1",
67 LocalPort => $CMDSHELL_PORT, 81 LocalPort => $CMDSHELL_PORT,
68 ReuseAddr => 1, 82 ReuseAddr => 1,
69 Listen => 1, 83 Listen => 1,
70 or die "unable to bind cmdshell port: $!"; 84 or die "unable to bind cmdshell port: $!";
71 85

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines