Current File : //etc/zpanel/panel/modules/daemonserver/client.php |
<?php
error_reporting(E_ALL);
echo "<h2>TCP/IP Connection</h2>\n";
/* Get the port for the WWW service. */
$service_port = 4444 ;
/* Get the IP address for the target host. */
$address = gethostbyname('localhost');
/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
} else {
echo "OK.\n";
}
echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
} else {
echo "OK.\n";
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
//while($in = fgets(STDIN))
//{
$in="command exec /usr/bin/php /etc/sentora/panel/bin/daemon.php 2>&1";
$out = '';
echo "Sending request...";
socket_write($socket, $in, strlen($in));
echo "OK.\n";
echo "Reading response:\n\n";
while ($out = socket_read($socket, 2048))
{
echo $out;
}
echo "Enter the text to send to client" ;
//}
echo "Closing socket...";
socket_close($socket);
?>