# See if there's a connection waiting on the $server by getting the list of handles with data to # read, if the handle is the server then we're off. Note the 0.1 second delay here when waiting # around. This means that we don't hog the processor while waiting for connections. my ($ready) = $selector->can_read(0.1); my ($uiready) = $uiselector->can_read(0.1); # Handle HTTP requests for the UI if ( $uiready == $ui ) { if ( my $client = $ui->accept() ) { # Check that this is a connection from the local machine, if it's not then we drop it immediately # without any further processing. We don't want to allow remote users to admin my ( $remote_port, $remote_host ) = sockaddr_in( $client->peername() ); if ( $remote_host eq inet_aton( "127.0.0.1" ) ) { if ( my $request = <$client> ) { debug( $request ); while ( <$client> ) { if ( !/(.*): (.*)/ ) { last; } } if ( $request =~ /GET (.*) HTTP\/1\./ ) { my $url = $1; print $client handle_url($url); } else { print $client http_error(500); } } } close $client;