… | |
… | |
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 @conn; |
17 | push @conn, values %$_ for values %conn::conn; |
18 | push @conn, values %$_ for values %conn::conn; |
18 | for (values %conn::conn) { |
19 | for (values %conn::conn) { |
19 | for (values %$_) { |
20 | for (values %$_) { |
20 | next unless $_; |
21 | next unless $_; |
21 | print "$_: $_->{remote_addr} $_->{uri}\n"; |
22 | print $fh "$_: $_->{remote_addr} $_->{uri}\n"; |
22 | } |
23 | } |
23 | } |
24 | } |
|
|
25 | } elsif (/^r/) { |
|
|
26 | $::RESTART = 1; |
|
|
27 | unloop; |
|
|
28 | print $fh "bye bye.\n"; |
|
|
29 | last; |
24 | } else { |
30 | } else { |
25 | print "try quit\n"; |
31 | print $fh "try quit, info, restart\n"; |
26 | } |
32 | } |
27 | } |
33 | } |
28 | } |
34 | } |
29 | |
35 | |
30 | # bind to tcp port |
36 | # bind to tcp port |
… | |
… | |
34 | LocalPort => $CMDSHELL_PORT, |
40 | LocalPort => $CMDSHELL_PORT, |
35 | ReuseAddr => 1, |
41 | ReuseAddr => 1, |
36 | Listen => 1, |
42 | Listen => 1, |
37 | or die "unable to bind cmdshell port: $!"; |
43 | or die "unable to bind cmdshell port: $!"; |
38 | |
44 | |
|
|
45 | push @listen_sockets, $port; |
|
|
46 | |
39 | async { |
47 | async { |
40 | async \&shell, $port->accept; |
48 | async \&shell, $port->accept; |
41 | }; |
49 | }; |
42 | } |
50 | } |
43 | |
51 | |