pssht  latest
SSH server library written in PHP
TestService.php
1 <?php
2 /*
3 * This file is part of pssht.
4 *
5 * (c) François Poirotte <clicky@erebot.net>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10 
12 
13 use \fpoirotte\Pssht\Messages\DISCONNECT;
14 
24 {
25  public function __construct(
26  \fpoirotte\Pssht\Transport $transport,
27  \fpoirotte\Pssht\Connection $connection,
28  \fpoirotte\Pssht\Messages\MessageInterface $message
29  ) {
30  $logging = \Plop\Plop::getInstance();
31 
32  if (!($message instanceof \fpoirotte\Pssht\Messages\CHANNEL\REQUEST\Exec)) {
33  throw new DISCONNECT(
35  'No shell for you!'
36  );
37  }
38 
39  $logging->info("Sending number back (%s)", array($message->getCommand()));
40  $response = new \fpoirotte\Pssht\Messages\CHANNEL\DATA(
41  $message->getChannel(),
42  'Your number: ' . $message->getCommand() . PHP_EOL
43  );
44  $transport->writeMessage($response);
45 
46  $logging->info("Sending EOF message");
47  $response = new \fpoirotte\Pssht\Messages\CHANNEL\EOF(
48  $message->getChannel()
49  );
50  $transport->writeMessage($response);
51 
53  // for the "type" & "want-replay" fields.
54  $logging->info("Sending exit status (%s)", array($message->getCommand()));
55  $response = new \fpoirotte\Pssht\Messages\CHANNEL\REQUEST\ExitStatus(
56  $message->getChannel(),
57  "exit-status",
58  false,
59  (int) $message->getCommand()
60  );
61  $transport->writeMessage($response);
62 
64  // for the "type" & "want-replay" fields.
65  $logging->info("Sending EOW message");
66  $response = new \fpoirotte\Pssht\Messages\CHANNEL\REQUEST\OpensshCom\Eow(
67  $message->getChannel(),
68  "eow@openssh.com",
69  false
70  );
71  $transport->writeMessage($response);
72 
73  $logging->info("Closing the channel");
74  $response = new \fpoirotte\Pssht\Messages\CHANNEL\CLOSE(
75  $message->getChannel()
76  );
77  $transport->writeMessage($response);
78  }
79 
80  public function handle(
81  $msgType,
82  \fpoirotte\Pssht\Wire\Decoder $decoder,
83  \fpoirotte\Pssht\Transport $transport,
84  array &$context
85  ) {
86  // Unused, but still required by the interface.
87  }
88 }
handle($msgType,\fpoirotte\Pssht\Wire\Decoder $decoder,\fpoirotte\Pssht\Transport $transport, array &$context)
Definition: TestService.php:80
const SSH_DISCONNECT_SERVICE_NOT_AVAILABLE
Disconnected because the requested service is not available.
Definition: DISCONNECT.php:38