PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/code/classes/Daemon/SSHd/Session.class.php

https://github.com/blekkzor/pinetd2
PHP | 56 lines | 47 code | 7 blank | 2 comment | 5 complexity | c2d06271cb2770edfe82524e05d9183a MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. namespace Daemon\SSHd;
  3. class Session extends Channel {
  4. private $mode = NULL;
  5. protected function init($pkt) {
  6. // nothing to do, in fact :D
  7. }
  8. protected function parseBuffer() {
  9. if (is_null($this->mode)) return;
  10. $func = 'parseBuffer_'.$this->mode;
  11. $this->$func();
  12. if ($this->recv_spent > 1024) {
  13. // restore remote window
  14. $this->window($this->recv_spent);
  15. $this->recv_spent = 0;
  16. }
  17. }
  18. protected function parseBuffer_shell() {
  19. if (strpos($this->buf_in, "\x04") !== false) {
  20. $pos = strpos($this->buf_in, "\x04");
  21. if ($pos > 0) $this->send(substr($this->buf_in, 0, $pos));
  22. $this->send("\r\nGood bye!\r\n");
  23. $this->eof();
  24. $this->close();
  25. return;
  26. }
  27. $this->buf_in = str_replace("\r", "\r\n\$ ", $this->buf_in);
  28. $this->send($this->buf_in);
  29. $this->buf_in = '';
  30. }
  31. protected function _req_shell() {
  32. if (!is_null($this->mode)) return false;
  33. $this->mode = 'shell';
  34. $this->send("Welcome to the PHP/".phpversion()." SSH server!\r\n\r\n");
  35. $this->send("This may look like a shell but it's just echoing back to you whatever you type. Too bad heh!\r\n\r\n");
  36. $this->send("Press ^D to exit.\r\n\r\n");
  37. $this->send('$ ');
  38. return true; // I am a shell
  39. }
  40. protected function _req_subsystem($pkt) {
  41. $opkt = $pkt;
  42. $syst = $this->parseStr($pkt);
  43. if ($syst != 'sftp') return false;
  44. $class = $this->translate('SFTP');
  45. return $class->request('subsystem', $opkt);
  46. }
  47. }