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.12 by root, Wed Aug 15 03:06:22 2001 UTC vs.
Revision 1.21 by root, Mon Dec 3 04:57:22 2001 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines