vesta.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. fputs($fp, $send);
  39. $result = fread($fp, 2048);
  40. fclose($fp);
  41. if(strpos($result, 'ok') && !strpos($result, 'error'))
  42. {
  43. return PASSWORD_SUCCESS;
  44. }
  45. else {
  46. return PASSWORD_ERROR;
  47. }
  48. }
  49. }