vesta.php 2.1 KB

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