… | |
… | |
7 | |
7 | |
8 | sub shell { |
8 | sub shell { |
9 | my $fh = shift; |
9 | my $fh = shift; |
10 | |
10 | |
11 | while (defined (print $fh "cmd> "), $_ = <$fh>) { |
11 | while (defined (print $fh "cmd> "), $_ = <$fh>) { |
|
|
12 | s/\015?\012$//; |
12 | chomp; |
13 | chomp; |
13 | if (/quit/) { |
14 | if (/^q/) { |
14 | Event::unloop; |
15 | Event::unloop; |
15 | } elsif (/info/) { |
16 | } elsif (/^i/) { |
16 | my @conn; |
17 | my @data; |
17 | push @conn, values %$_ for values %conn::conn; |
|
|
18 | for (values %conn::conn) { |
18 | for (values %conn::conn) { |
19 | for (values %$_) { |
19 | for (values %$_) { |
20 | next unless $_; |
20 | next unless $_; |
21 | print "$_: $_->{remote_addr} $_->{uri}\n"; |
21 | push @data, "$_: $_->{remote_addr} $_->{uri}\n"; |
22 | } |
22 | } |
23 | } |
23 | } |
|
|
24 | print $fh sort @data; |
|
|
25 | print $fh scalar@data, " connections\n";#d# |
|
|
26 | } elsif (/^r/) { |
|
|
27 | $::RESTART = 1; |
|
|
28 | unloop; |
|
|
29 | print $fh "bye bye.\n"; |
|
|
30 | last; |
24 | } else { |
31 | } else { |
25 | print "try quit\n"; |
32 | print $fh "try quit, info, restart\n"; |
26 | } |
33 | } |
27 | } |
34 | } |
28 | } |
35 | } |
29 | |
36 | |
30 | # bind to tcp port |
37 | # bind to tcp port |
… | |
… | |
34 | LocalPort => $CMDSHELL_PORT, |
41 | LocalPort => $CMDSHELL_PORT, |
35 | ReuseAddr => 1, |
42 | ReuseAddr => 1, |
36 | Listen => 1, |
43 | Listen => 1, |
37 | or die "unable to bind cmdshell port: $!"; |
44 | or die "unable to bind cmdshell port: $!"; |
38 | |
45 | |
|
|
46 | push @listen_sockets, $port; |
|
|
47 | |
39 | async { |
48 | async { |
40 | async \&shell, $port->accept; |
49 | async \&shell, $port->accept; |
41 | }; |
50 | }; |
42 | } |
51 | } |
43 | |
52 | |