Current File : //etc/zpanel/panel/modules/server/panel.exec_command.php
<?php

error_reporting(E_ALL);

function panel_exec_command ($command) 
{

	/* 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));

	$in="command " . $command ;

	$out = '';
		
	echo "Sending request...";
	socket_write($socket, $in, strlen($in));

	echo "Reading response:\n\n";

	$output = "" ;

	while(true)
	{
		sleep(10);
		$out = socket_read($socket, 2048);			
		$output .= $out ;
		echo "Output=".$out."\n\n" ;
		if ($out)
		break ;
	}
	
	socket_close($socket);

	return $output ;
}


?>