@@ -75,10 +75,9 @@ The following example code demonstrates how this library can be used to send a
75
75
plaintext HTTP request to google.com through a remote SSH server:
76
76
77
77
``` php
78
- $loop = React\EventLoop\Factory::create( );
78
+ $
proxy =
new Clue\ React\
SshProxy\SshProcessConnector('[email protected] ' );
79
79
80
- $proxy = new Clue\React\SshProxy\SshProcessConnector('
[email protected] ', $loop);
81
- $connector = new React\Socket\Connector($loop, array(
80
+ $connector = new React\Socket\Connector(null, array(
82
81
'tcp' => $proxy,
83
82
'dns' => false
84
83
));
@@ -92,8 +91,6 @@ $connector->connect('tcp://google.com:80')->then(function (React\Socket\Connecti
92
91
echo '[DONE]';
93
92
});
94
93
}, 'printf');
95
-
96
- $loop->run();
97
94
```
98
95
99
96
See also the [ examples] ( examples ) .
@@ -121,17 +118,22 @@ systems, you may simply install it like this:
121
118
$ sudo apt install openssh-client
122
119
```
123
120
124
- Its constructor simply accepts an SSH proxy server URL and a loop to bind to :
121
+ Its constructor simply accepts an SSH proxy server URL:
125
122
126
123
``` php
127
- $loop = React\EventLoop\Factory::create();
128
- $proxy = new Clue\React\SshProxy\SshProcessConnector('
[email protected] ', $loop);
124
+ $proxy = new Clue\React\SshProxy\SshProcessConnector('
[email protected] ');
129
125
```
130
126
131
127
The proxy URL may or may not contain a scheme and port definition. The default
132
128
port will be ` 22 ` for SSH, but you may have to use a custom port depending on
133
129
your SSH server setup.
134
130
131
+ This class takes an optional ` LoopInterface|null $loop ` parameter that can be used to
132
+ pass the event loop instance to use for this object. You can use a ` null ` value
133
+ here in order to use the [ default loop] ( https://github.com/reactphp/event-loop#loop ) .
134
+ This value SHOULD NOT be given unless you're sure you want to explicitly use a
135
+ given event loop instance.
136
+
135
137
Keep in mind that this class is implemented as a lightweight process wrapper
136
138
around the ` ssh ` client binary and that it will spawn one ` ssh ` process for each
137
139
connection. If you open more connections, it will spawn one ` ssh ` process for
@@ -160,7 +162,7 @@ higher-level component:
160
162
161
163
``` diff
162
164
- $acme = new AcmeApi($connector);
163
- + $proxy = new Clue\React\SshProxy\SshProcessConnector('[email protected] ', $loop );
165
+ + $proxy = new Clue\React\SshProxy\SshProcessConnector('[email protected] ');
164
166
+ $acme = new AcmeApi($proxy);
165
167
```
166
168
@@ -189,17 +191,22 @@ simply install it like this:
189
191
$ sudo apt install openssh-client
190
192
```
191
193
192
- Its constructor simply accepts an SSH proxy server URL and a loop to bind to :
194
+ Its constructor simply accepts an SSH proxy server URL:
193
195
194
196
``` php
195
- $loop = React\EventLoop\Factory::create();
196
- $proxy = new Clue\React\SshProxy\SshSocksConnector('
[email protected] ', $loop);
197
+ $proxy = new Clue\React\SshProxy\SshSocksConnector('
[email protected] ');
197
198
```
198
199
199
200
The proxy URL may or may not contain a scheme and port definition. The default
200
201
port will be ` 22 ` for SSH, but you may have to use a custom port depending on
201
202
your SSH server setup.
202
203
204
+ This class takes an optional ` LoopInterface|null $loop ` parameter that can be used to
205
+ pass the event loop instance to use for this object. You can use a ` null ` value
206
+ here in order to use the [ default loop] ( https://github.com/reactphp/event-loop#loop ) .
207
+ This value SHOULD NOT be given unless you're sure you want to explicitly use a
208
+ given event loop instance.
209
+
203
210
Keep in mind that this class is implemented as a lightweight process wrapper
204
211
around the ` ssh ` client binary and that it will spawn one ` ssh ` process for
205
212
multiple connections. This process will take some time to create a new SSH
@@ -216,7 +223,7 @@ to use multiple instances of this class to connect to different SSH proxy
216
223
servers, you may optionally pass a unique bind address like this:
217
224
218
225
``` php
219
- $proxy = new Clue\React\SshProxy\SshSocksConnector('
[email protected] ?bind=127.1.1.1:1081',
$loop );
226
+ $proxy = new Clue\React\SshProxy\SshSocksConnector('
[email protected] ?bind=127.1.1.1:1081',);
220
227
```
221
228
222
229
> * Security note for multi-user systems* : This class will spawn the SSH client
@@ -244,7 +251,7 @@ higher-level component:
244
251
245
252
``` diff
246
253
- $acme = new AcmeApi($connector);
247
- + $proxy = new Clue\React\SshProxy\SshSocksConnector('[email protected] ', $loop );
254
+ + $proxy = new Clue\React\SshProxy\SshSocksConnector('[email protected] ');
248
255
+ $acme = new AcmeApi($proxy);
249
256
```
250
257
@@ -260,9 +267,9 @@ a streaming plain TCP/IP connection on the `SshProcessConnector` or `SshSocksCon
260
267
and use any higher level protocol like so:
261
268
262
269
``` php
263
- $proxy = new Clue\React\SshProxy\SshProcessConnector('
[email protected] '
, $loop );
270
+ $proxy = new Clue\React\SshProxy\SshProcessConnector('
[email protected] ');
264
271
// or
265
- $proxy = new Clue\React\SshProxy\SshSocksConnector('
[email protected] '
, $loop );
272
+ $proxy = new Clue\React\SshProxy\SshSocksConnector('
[email protected] ');
266
273
267
274
$proxy->connect('tcp://smtp.googlemail.com:587')->then(function (React\Socket\ConnectionInterface $connection) {
268
275
$connection->write("EHLO local\r\n");
@@ -276,11 +283,11 @@ You can either use the `SshProcessConnector` or `SshSocksConnector` directly or
276
283
may want to wrap this connector in ReactPHP's [ ` Connector ` ] ( https://github.com/reactphp/socket#connector ) :
277
284
278
285
``` php
279
- $proxy = new Clue\React\SshProxy\SshProcessConnector('
[email protected] '
, $loop );
286
+ $proxy = new Clue\React\SshProxy\SshProcessConnector('
[email protected] ');
280
287
// or
281
- $proxy = new Clue\React\SshProxy\SshSocksConnector('
[email protected] '
, $loop );
288
+ $proxy = new Clue\React\SshProxy\SshSocksConnector('
[email protected] ');
282
289
283
- $connector = new React\Socket\Connector($loop , array(
290
+ $connector = new React\Socket\Connector(null , array(
284
291
'tcp' => $proxy,
285
292
'dns' => false
286
293
));
@@ -309,9 +316,9 @@ ReactPHP's [`Connector`](https://github.com/reactphp/socket#connector) or the
309
316
low-level [ ` SecureConnector ` ] ( https://github.com/reactphp/socket#secureconnector ) :
310
317
311
318
``` php
312
- $proxy = new Clue\React\SshProxy\SshSocksConnector('
[email protected] '
, $loop );
319
+ $proxy = new Clue\React\SshProxy\SshSocksConnector('
[email protected] ');
313
320
314
- $connector = new React\Socket\Connector($loop , array(
321
+ $connector = new React\Socket\Connector(null , array(
315
322
'tcp' => $proxy,
316
323
'dns' => false
317
324
));
@@ -341,14 +348,14 @@ In order to send HTTP requests, you first have to add a dependency for
341
348
This allows you to send both plain HTTP and TLS-encrypted HTTPS requests like this:
342
349
343
350
``` php
344
- $proxy = new Clue\React\SshProxy\SshSocksConnector('
[email protected] '
, $loop );
351
+ $proxy = new Clue\React\SshProxy\SshSocksConnector('
[email protected] ');
345
352
346
- $connector = new React\Socket\Connector($loop , array(
353
+ $connector = new React\Socket\Connector(null , array(
347
354
'tcp' => $proxy,
348
355
'dns' => false
349
356
));
350
357
351
- $browser = new React\Http\Browser($loop , $connector);
358
+ $browser = new React\Http\Browser(null , $connector);
352
359
353
360
$browser->get('https://example.com/')->then(function (Psr\Http\Message\ResponseInterface $response) {
354
361
var_dump($response->getHeaders(), (string) $response->getBody());
@@ -378,11 +385,10 @@ the above SSH proxy server setup, so we can access a firewalled MySQL database
378
385
server through an SSH tunnel. Here's the gist:
379
386
380
387
``` php
381
- $loop = React\EventLoop\Factory::create();
382
- $proxy = new Clue\React\SshProxy\SshProcessConnector('
[email protected] ', $loop);
388
+ $proxy = new Clue\React\SshProxy\SshProcessConnector('
[email protected] ');
383
389
384
390
$uri = 'test:test@localhost/test';
385
- $factory = new React\MySQL\Factory($loop , $proxy);
391
+ $factory = new React\MySQL\Factory(null , $proxy);
386
392
$connection = $factory->createLazyConnection($uri);
387
393
388
394
$connection->query('SELECT * FROM book')->then(
@@ -395,8 +401,6 @@ $connection->query('SELECT * FROM book')->then(
395
401
);
396
402
397
403
$connection->quit();
398
-
399
- $loop->run();
400
404
```
401
405
402
406
See also [ example #21 ] ( examples ) for more details.
@@ -427,11 +431,11 @@ It provides the same `connect()` method, but will automatically reject the
427
431
underlying connection attempt if it takes too long:
428
432
429
433
``` php
430
- $proxy = new Clue\React\SshProxy\SshProcessConnector('
[email protected] '
, $loop );
434
+ $proxy = new Clue\React\SshProxy\SshProcessConnector('
[email protected] ');
431
435
// or
432
- $proxy = new Clue\React\SshProxy\SshSocksConnector('
[email protected] '
, $loop );
436
+ $proxy = new Clue\React\SshProxy\SshSocksConnector('
[email protected] ');
433
437
434
- $connector = new React\Socket\Connector($loop , array(
438
+ $connector = new React\Socket\Connector(null , array(
435
439
'tcp' => $proxy,
436
440
'dns' => false,
437
441
'timeout' => 3.0
@@ -473,11 +477,11 @@ Given that remote DNS resolution is assumed to be the preferred mode, all
473
477
other examples explicitly disable DNS resolution like this:
474
478
475
479
``` php
476
- $proxy = new Clue\React\SshProxy\SshProcessConnector('
[email protected] '
, $loop );
480
+ $proxy = new Clue\React\SshProxy\SshProcessConnector('
[email protected] ');
477
481
// or
478
- $proxy = new Clue\React\SshProxy\SshSocksConnector('
[email protected] '
, $loop );
482
+ $proxy = new Clue\React\SshProxy\SshSocksConnector('
[email protected] ');
479
483
480
- $connector = new React\Socket\Connector($loop , array(
484
+ $connector = new React\Socket\Connector(null , array(
481
485
'tcp' => $proxy,
482
486
'dns' => false
483
487
));
@@ -486,12 +490,12 @@ $connector = new React\Socket\Connector($loop, array(
486
490
If you want to explicitly use * local DNS resolution* , you can use the following code:
487
491
488
492
``` php
489
- $proxy = new Clue\React\SshProxy\SshProcessConnector('
[email protected] '
, $loop );
493
+ $proxy = new Clue\React\SshProxy\SshProcessConnector('
[email protected] ');
490
494
// or
491
- $proxy = new Clue\React\SshProxy\SshSocksConnector('
[email protected] '
, $loop );
495
+ $proxy = new Clue\React\SshProxy\SshSocksConnector('
[email protected] ');
492
496
493
497
// set up Connector which uses Google's public DNS (8.8.8.8)
494
- $connector = new React\Socket\Connector($loop , array(
498
+ $connector = new React\Socket\Connector(null , array(
495
499
'tcp' => $proxy,
496
500
'dns' => '8.8.8.8'
497
501
));
@@ -525,9 +529,9 @@ If your SSH proxy server requires password authentication, you may pass the
525
529
username and password as part of the SSH proxy server URL like this:
526
530
527
531
``` php
528
- $proxy = new Clue\React\SshProxy\SshProcessConnector('user:
[email protected] '
, $loop );
532
+ $proxy = new Clue\React\SshProxy\SshProcessConnector('user:
[email protected] ');
529
533
// or
530
- $proxy = new Clue\React\SshProxy\SshSocksConnector('user:
[email protected] '
, $loop );
534
+ $proxy = new Clue\React\SshProxy\SshSocksConnector('user:
[email protected] ');
531
535
```
532
536
533
537
For this to work, you will have to have the ` sshpass ` binary installed. On
@@ -545,8 +549,7 @@ $user = 'he:llo';
545
549
$pass = 'p@ss';
546
550
547
551
$proxy = new Clue\React\SshProxy\SshProcessConnector(
548
- rawurlencode($user) . ':' . rawurlencode($pass) . '@example.com:2222',
549
- $loop
552
+ rawurlencode($user) . ':' . rawurlencode($pass) . '@example.com:2222'
550
553
);
551
554
```
552
555
0 commit comments