vesta.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Vesta Control Panel Password Driver
  4. *
  5. * @version 1.0
  6. * @author Serghey Rodin <skid@vestacp.com>
  7. */
  8. class rcube_vesta_password {
  9. function save($curpass, $passwd)
  10. {
  11. $rcmail = rcmail::get_instance();
  12. $vesta_host = $rcmail->config->get('password_vesta_host');
  13. if (empty($vesta_host))
  14. {
  15. $vesta_host = 'localhost';
  16. }
  17. $vesta_port = $rcmail->config->get('password_vesta_port');
  18. if (empty($vesta_port))
  19. {
  20. $vesta_port = '8083';
  21. }
  22. $postvars = array(
  23. 'email' => $_SESSION['username'],
  24. 'password' => $curpass,
  25. 'new' => $passwd
  26. );
  27. $postdata = http_build_query($postvars);
  28. $send = 'POST /reset/mail/ HTTP/1.1' . PHP_EOL;
  29. $send .= 'Host: ' . $vesta_host . PHP_EOL;
  30. $send .= 'User-Agent: PHP Script' . PHP_EOL;
  31. $send .= 'Content-length: ' . strlen($postdata) . PHP_EOL;
  32. $send .= 'Content-type: application/x-www-form-urlencoded' . PHP_EOL;
  33. $send .= 'Connection: close' . PHP_EOL;
  34. $send .= PHP_EOL;
  35. $send .= $postdata . PHP_EOL . PHP_EOL;
  36. //$fp = fsockopen('ssl://' . $vesta_host, $vesta_port);
  37. $errno = "";
  38. $errstr = "";
  39. $context = stream_context_create();
  40. $result = stream_context_set_option($context, 'ssl', 'verify_peer', false);
  41. $result = stream_context_set_option($context, 'ssl', 'verify_peer_name', false);
  42. $result = stream_context_set_option($context, 'ssl', 'verify_host', false);
  43. $result = stream_context_set_option($context, 'ssl', 'allow_self_signed', true);
  44. $fp = stream_socket_client('ssl://' . $vesta_host . ':'.$vesta_port, $errno, $errstr, 60, STREAM_CLIENT_CONNECT, $context);
  45. fputs($fp, $send);
  46. $result = fread($fp, 2048);
  47. fclose($fp);
  48. $fp = fopen("/tmp/roundcube.log", 'w');
  49. fwrite($fp, "test ok");
  50. fwrite($fp, "\n");
  51. fclose($fp);
  52. if(strpos($result, 'ok') && !strpos($result, 'error'))
  53. {
  54. return PASSWORD_SUCCESS;
  55. }
  56. else {
  57. return PASSWORD_ERROR;
  58. }
  59. }
  60. }