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.14 by root, Thu Aug 16 16:40:07 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); 14my @commands = qw(quit squit refresh country restart block info print);
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;
30 last;
31 } elsif ($cmd eq "print") {
32 my @res = eval $_;
33 print $fh "eval: $@\n" if $@;
34 print $fh "RES = ", (join " : ", @res), "\n";
29 } elsif ($cmd eq "block") { 35 } elsif ($cmd eq "block") {
30 print "blocked '$_'\n";#d# 36 print "blocked '$_'\n";#d#
31 $conn::blocked{$_} = time + $::BLOCKTIME; 37 $conn::blocked{$_} = time + $::BLOCKTIME;
32 } elsif ($cmd eq "info") { 38 } elsif ($cmd eq "info") {
33 $::NOW = time+1e-6; 39 $::NOW = time+1e-6;
43 print $fh scalar@data, " ($::conns) connections\n";#d# 49 print $fh scalar@data, " ($::conns) connections\n";#d#
44 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";
45 printf $fh "(%.1f bytes/s)\n", $::written / ($::NOW - $last_ts); 51 printf $fh "(%.1f bytes/s)\n", $::written / ($::NOW - $last_ts);
46 ($last_ts, $::written) = ($::NOW, 0); 52 ($last_ts, $::written) = ($::NOW, 0);
47 } elsif ($cmd eq "refresh") { 53 } elsif ($cmd eq "refresh") {
54 do "config.pl";
55 print $fh "config.pl: $@\n" if $@;
48 read_blocklist; 56 read_blocklist;
49 } elsif ($cmd eq "restart") { 57 } elsif ($cmd eq "restart") {
50 $::RESTART = 1; 58 $::RESTART = 1;
51 unloop; 59 unloop;
52 print $fh "restarting, cu!\n"; 60 print $fh "restarting, cu!\n";
61} 69}
62 70
63# bind to tcp port 71# bind to tcp port
64if ($CMDSHELL_PORT) { 72if ($CMDSHELL_PORT) {
65 my $port = new Coro::Socket 73 my $port = new Coro::Socket
66 LocalAddr => "127.0.0.1", 74 #LocalAddr => "127.0.0.1",
67 LocalPort => $CMDSHELL_PORT, 75 LocalPort => $CMDSHELL_PORT,
68 ReuseAddr => 1, 76 ReuseAddr => 1,
69 Listen => 1, 77 Listen => 1,
70 or die "unable to bind cmdshell port: $!"; 78 or die "unable to bind cmdshell port: $!";
71 79

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines