The version of vichan running on lainchan.org
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

65 wiersze
1.7KB

  1. <?php
  2. /*
  3. * Copyright (c) 2010-2013 Tinyboard Development Group
  4. */
  5. defined('TINYBOARD') or exit;
  6. class Remote {
  7. public function __construct($config) {
  8. foreach ($config as $name => $value) {
  9. $this->{$name} = $value;
  10. }
  11. $methods = array();
  12. if (!isset($this->auth['method']))
  13. error('Unspecified authentication method.');
  14. // Connect
  15. $this->connection = ssh2_connect($this->host, isset($this->port) ? $this->port : 22, $methods);
  16. switch ($this->auth['method']) {
  17. case 'pubkey':
  18. if (!isset($this->auth['public']))
  19. error('Public key filename not specified.');
  20. if (!isset($this->auth['private']))
  21. error('Private key filename not specified.');
  22. if (!ssh2_auth_pubkey_file($this->connection, $this->auth['username'], $this->auth['public'], $this->auth['private'], isset($this->auth['passphrase']) ? $this->auth['passphrase']: null))
  23. error('Public key authentication failed.');
  24. break;
  25. case 'plain':
  26. if (!ssh2_auth_password($this->connection, $this->auth['username'], $this->auth['password']))
  27. error('Plain-text authentication failed.');
  28. break;
  29. default:
  30. error('Unknown authentication method: "' . $this->auth['method'] . '".');
  31. }
  32. }
  33. public function write($data, $remote_path) {
  34. global $config;
  35. switch ($this->type) {
  36. case 'sftp':
  37. $sftp = ssh2_sftp($this->connection);
  38. file_write('ssh2.sftp://' . $sftp . $remote_path, $data, true);
  39. break;
  40. case 'scp':
  41. $file = tempnam($config['tmp'], 'tinyboard-scp');
  42. // Write to temp file
  43. file_write($file, $data);
  44. ssh2_scp_send($this->connection, $file, $remote_path, 0755);
  45. break;
  46. default:
  47. error('Unknown send method.');
  48. }
  49. }
  50. };