some changes
This commit is contained in:
parent
81b1454b2e
commit
b0824e048e
|
@ -38,7 +38,7 @@ require_once $config['homedir'].'/godmode/wizards/Wizard.main.php';
|
|||
class Diagnostics extends Wizard
|
||||
{
|
||||
|
||||
const INNODB_FLUSH_LOG_AT_TRX_COMMIT = 1;
|
||||
const INNODB_FLUSH_LOG_AT_TRX_COMMIT = 2;
|
||||
|
||||
/**
|
||||
* Ajax controller page.
|
||||
|
|
|
@ -204,11 +204,21 @@ class WSManager extends WebSocketServer
|
|||
/**
|
||||
* Read from user's socket.
|
||||
*
|
||||
* @param object $user Target user connection.
|
||||
* @param object $user Target user connection.
|
||||
* @param integer $flags Socket receive flags:
|
||||
* Flag Description
|
||||
* MSG_OOB Process out-of-band data.
|
||||
* MSG_PEEK Receive data from the beginning of the receive
|
||||
* queue without removing it from the queue.
|
||||
* MSG_WAITALL Block until at least len are received. However,
|
||||
* if a signal is caught or the remote host
|
||||
* disconnects, the function may return less data.
|
||||
* MSG_DONTWAIT With this flag set, the function returns even
|
||||
* if it would normally have blocked.
|
||||
*
|
||||
* @return string Buffer.
|
||||
*/
|
||||
public function readSocket($user)
|
||||
public function readSocket($user, $flags=0)
|
||||
{
|
||||
$buffer = '';
|
||||
|
||||
|
@ -216,7 +226,7 @@ class WSManager extends WebSocketServer
|
|||
$user->socket,
|
||||
$buffer,
|
||||
$this->maxBufferSize,
|
||||
0
|
||||
$flags
|
||||
);
|
||||
if ($numBytes === false) {
|
||||
// Failed. Disconnect.
|
||||
|
@ -225,7 +235,7 @@ class WSManager extends WebSocketServer
|
|||
} else if ($numBytes == 0) {
|
||||
$this->disconnect($user->socket);
|
||||
$this->stderr(
|
||||
'Client disconnected. TCP connection lost: '.$user->socket
|
||||
'Client disconnected. TCP connection lost: '.$user->id
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
@ -246,7 +256,7 @@ class WSManager extends WebSocketServer
|
|||
public function writeSocket($user, $message)
|
||||
{
|
||||
if (is_resource($user->socket)) {
|
||||
if (!socket_write($user->socket, $message)) {
|
||||
if (socket_write($user->socket, $message) === false) {
|
||||
$this->disconnect($user->socket);
|
||||
}
|
||||
} else {
|
||||
|
@ -259,7 +269,6 @@ class WSManager extends WebSocketServer
|
|||
$this->disconnect($user->redirect->socket);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -218,8 +218,6 @@ abstract class WebSocketServer
|
|||
|
||||
$this->sockets['m'] = $this->master;
|
||||
$this->stderr('Listening on: '.$addr.':'.$port);
|
||||
$this->stderr('Master socket: '.\obhd($this->master)."\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -353,7 +351,7 @@ abstract class WebSocketServer
|
|||
/**
|
||||
* Manage behaviour on socket error.
|
||||
*
|
||||
* @param socket $socket Target socket.
|
||||
* @param \socket $socket Target socket.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
@ -449,15 +447,15 @@ abstract class WebSocketServer
|
|||
if ($socket == $this->master) {
|
||||
// External to master connection. New client.
|
||||
$client = socket_accept($socket);
|
||||
if ($client < 0) {
|
||||
$this->stderr('Failed: socket_accept()');
|
||||
if ((bool) $client !== true) {
|
||||
$this->stderr('Failed: socket_accept(), reason: ', socket_last_error());
|
||||
continue;
|
||||
} else {
|
||||
$this->connect($client);
|
||||
$this->stderr('Client connected. '.\obhd($client));
|
||||
$this->stderr('Client connected. '.obhd($client));
|
||||
}
|
||||
} else {
|
||||
if (!$socket) {
|
||||
if ((bool) $socket !== true) {
|
||||
$this->disconnect($socket);
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -60,12 +60,15 @@ function connectInt(
|
|||
$to_url
|
||||
) {
|
||||
$intSocket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||
// Not sure.
|
||||
$connect = socket_connect(
|
||||
$intSocket,
|
||||
$to_addr,
|
||||
$to_port
|
||||
);
|
||||
if (!$connect) {
|
||||
|
||||
if ($connect === false) {
|
||||
$ws_object->stderr(socket_last_error($intSocket));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -80,7 +83,7 @@ function connectInt(
|
|||
$c_str .= 'Sec-WebSocket-Protocol: '.$headers['Sec-WebSocket-Protocol']."\r\n";
|
||||
}
|
||||
|
||||
$c_str .= "\r\n";
|
||||
$c_str .= "\r\n\r\n";
|
||||
|
||||
// Send.
|
||||
// Register user - internal.
|
||||
|
@ -92,6 +95,7 @@ function connectInt(
|
|||
'origin' => $to_addr,
|
||||
'sec-websocket-protocol' => 'gotty',
|
||||
];
|
||||
|
||||
$ws_object->writeSocket($intUser, $c_str);
|
||||
|
||||
return $intUser;
|
||||
|
@ -118,9 +122,9 @@ function proxyConnected(
|
|||
*/
|
||||
|
||||
// Gotty. Based on the command selected, redirect to a target port.
|
||||
if ($user->requestedResource == '/ssh') {
|
||||
if ($user->requestedResource === '/ssh') {
|
||||
$port = $config['gotty_ssh_port'];
|
||||
} else if ($user->requestedResource == '/telnet') {
|
||||
} else if ($user->requestedResource === '/telnet') {
|
||||
$port = $config['gotty_telnet_port'];
|
||||
} else {
|
||||
$ws_object->disconnect($user->socket);
|
||||
|
@ -154,7 +158,8 @@ function proxyConnected(
|
|||
$ws_object->remoteUsers[$intUser->id] = $intUser;
|
||||
|
||||
// Ignore. Cleanup socket.
|
||||
$response = $ws_object->readSocket($user->intUser);
|
||||
// $response = $ws_object->readSocket($user->intUser);
|
||||
flush();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue