WriteCommand($socket, 'FILE', array('cid' => $_GET['cid'], 'action' => 'start')); $cmd = ReadCommand($socket); socket_close($socket); $size = $cmd->size; header('Content-type: ' . $cmd->contentType); header('Content-length: ' . $size); $sentBytes = 0; while ($sentBytes < $size) { $socket = getConnection(); WriteCommand($socket, 'FILE', array('cid' => $_GET['cid'], 'action' => 'data')); $cmd = ReadCommand($socket); socket_close($socket); if (strlen($cmd->data) == 0) { throw new Exception('File transfer error'); } echo $cmd->data; if (connection_aborted()) { break; } $sentBytes += strlen($cmd->data); } $socket = getConnection(); WriteCommand($socket, 'FILE', array('cid' => $_GET['cid'], 'action' => 'end')); socket_close($socket); } catch (Exception $ex) { $socket = getConnection(); WriteCommand($socket, 'FILE', array('cid' => $_GET['cid'], 'action' => 'end')); socket_close($socket); echo $ex->getMessage(); exit(1); }
WriteCommand($socket, 'COMM', NULL, $content); $cmd = ReadCommand($socket); socket_close($socket); } catch (Exception $ex) { // Give the daemon some time to collect error output usleep(500000); try { $socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($socket === false) { throw new Exception("socket_create() failed: reason: " . socket_strerror(socket_last_error())); } $result = @socket_connect($socket, $WEBCONFIG['address'], $WEBCONFIG['port']); if ($result === false) { throw new Exception("socket_connect() failed.\nReason: ({$result}) " . socket_strerror(socket_last_error($socket))); } WriteCommand($socket, 'GETERROR', array('clientid' => $_GET['clientid'])); $cmd = ReadCommand($socket); if ($cmd->found) { ReturnError('php_error', $cmd->data); } else { ReturnError('php_error', 'webfrontend comm: ReadCommand failed'); } } catch (Exception $ex) { ReturnError('unspecified_error', $ex->getMessage()); } } if (substr($cmd->data, -16) != '"EXEC_COMPLETE";') { ReturnError('php_error', $cmd->data); } else { ReturnResult($cmd->data); }