… | |
… | |
2 | |
2 | |
3 | use Coro; |
3 | use Coro; |
4 | use Coro::Handle; |
4 | use Coro::Handle; |
5 | use Coro::Socket; |
5 | use Coro::Socket; |
6 | use Event; |
6 | use Event; |
|
|
7 | use Time::HiRes 'time'; |
|
|
8 | |
|
|
9 | my $last_ts = time; |
7 | |
10 | |
8 | sub shell { |
11 | sub shell { |
9 | my $fh = shift; |
12 | my $fh = shift; |
10 | |
13 | |
11 | while (defined (print $fh "cmd> "), $_ = <$fh>) { |
14 | while (defined (print $fh "cmd> "), $_ = <$fh>) { |
12 | s/\015?\012$//; |
15 | s/\015?\012$//; |
13 | chomp; |
16 | chomp; |
14 | if (/^q/) { |
17 | if (/^q/) { |
15 | Event::unloop; |
18 | Event::unloop; |
16 | } elsif (/^i/) { |
19 | } elsif (/^i/) { |
|
|
20 | $::NOW = time+1e-6; |
17 | my @data; |
21 | my @data; |
18 | for (values %conn::conn) { |
22 | for (values %conn::conn) { |
19 | for (values %$_) { |
23 | for (values %$_) { |
20 | next unless $_; |
24 | next unless $_; |
21 | push @data, "$_: $_->{remote_addr} $_->{uri}\n"; |
25 | my $rate = sprintf "%.1f", $_->{written} / ($::NOW - $_->{time}); |
|
|
26 | push @data, "$_->{country}/$_->{remote_addr} $_->{written} $rate $_->{method} $_->{uri}\n"; |
22 | } |
27 | } |
23 | } |
28 | } |
24 | print $fh sort @data; |
29 | print $fh sort @data; |
25 | print $fh scalar@data, " connections\n";#d# |
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; |
26 | } elsif (/^r/) { |
36 | } elsif (/^r/) { |
27 | $::RESTART = 1; |
37 | $::RESTART = 1; |
28 | unloop; |
38 | unloop; |
29 | print $fh "bye bye.\n"; |
39 | print $fh "bye bye.\n"; |
30 | last; |
40 | last; |
|
|
41 | } elsif (/^co\S*\s+(\S+)/) { |
|
|
42 | print $fh ip_request($1), "\n"; |
31 | } else { |
43 | } else { |
32 | print $fh "try quit, info, restart\n"; |
44 | print $fh "try quit, info, restart, refresh\n"; |
33 | } |
45 | } |
34 | } |
46 | } |
35 | } |
47 | } |
36 | |
48 | |
37 | # bind to tcp port |
49 | # bind to tcp port |
… | |
… | |
44 | or die "unable to bind cmdshell port: $!"; |
56 | or die "unable to bind cmdshell port: $!"; |
45 | |
57 | |
46 | push @listen_sockets, $port; |
58 | push @listen_sockets, $port; |
47 | |
59 | |
48 | async { |
60 | async { |
|
|
61 | while () { |
49 | async \&shell, $port->accept; |
62 | async \&shell, scalar $port->accept; |
|
|
63 | } |
50 | }; |
64 | }; |
51 | } |
65 | } |
52 | |
66 | |
53 | # bind to stdin (debug) |
67 | # bind to stdin (debug) |
54 | if (1) { |
68 | if (1) { |