vesta.php 1.6 KB

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