You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ssh.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. # Use the interface
  3. require 'sieve_transfer.php';
  4. class SSHTransfer extends SieveTransfer
  5. {
  6. public function LoadScript($path)
  7. {
  8. $script = '';
  9. $tmpFile = tempnam("/tmp", "sieve");
  10. $user = $this->params['user'];
  11. $host = $this->params['host'];
  12. $options = $this->params['options'];
  13. if ( !$user ) $user = 'vmail';
  14. if ( !$host ) $host = 'localhost';
  15. if ( !$options ) $options = '';
  16. # Copy the file
  17. $status = 0;
  18. $command = sprintf("/usr/bin/scp -q %s %s@%s:%s '%s'", $options, $user, $host, $path, $tmpFile);
  19. system($command, $status);
  20. $script = file_get_contents($tmpFile);
  21. unlink($tmpFile);
  22. return $script;
  23. }
  24. public function SaveScript($path,$script)
  25. {
  26. $tmpFile = tempnam("/tmp", "sieve");
  27. file_put_contents($tmpFile, $script);
  28. $user = $this->params['user'];
  29. $host = $this->params['host'];
  30. $options = $this->params['options'];
  31. if ( !$user ) $user = 'vmail';
  32. if ( !$host ) $host = 'localhost';
  33. if ( !$options ) $options = '';
  34. # Copy the file
  35. $status = 0;
  36. $command = sprintf("/usr/bin/scp -q %s '%s' %s@%s:%s", $options, $tmpFile, $user, $host, $path);
  37. system($command, $status);
  38. if ( $status == 0 && !empty($this->params['sievecbin']) )
  39. {
  40. # Compile the file. I don't think this is necessary with Dovecot
  41. # as it compiles the files on the fly by default.
  42. $sievecbin = $this->params['sievecbin'];
  43. $command = sprintf("/usr/bin/ssh %s %s@%s '%s \"%s\"'", $options, $user, $host, $sievecbin, $path);
  44. system($command, $status);
  45. }
  46. else
  47. {
  48. $this->lastError = sprintf('Error when copying the sieve script on the server (status=%d)', $status);
  49. }
  50. # Clean up
  51. unlink($tmpFile);
  52. return ($status == 0);
  53. }
  54. }