vesta.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. $errno = "";
  37. $errstr = "";
  38. $context = stream_context_create();
  39. $result = stream_context_set_option($context, 'ssl', 'verify_peer', false);
  40. $result = stream_context_set_option($context, 'ssl', 'verify_peer_name', false);
  41. $result = stream_context_set_option($context, 'ssl', 'verify_host', false);
  42. $result = stream_context_set_option($context, 'ssl', 'allow_self_signed', true);
  43. $fp = stream_socket_client('ssl://' . $vesta_host . ':'.$vesta_port, $errno, $errstr, 60, STREAM_CLIENT_CONNECT, $context);
  44. fputs($fp, $send);
  45. $result = fread($fp, 2048);
  46. fclose($fp);
  47. $fp = fopen("/tmp/roundcube.log", 'w');
  48. fwrite($fp, "test ok");
  49. fwrite($fp, "\n");
  50. fclose($fp);
  51. if(strpos($result, 'ok') && !strpos($result, 'error'))
  52. {
  53. return PASSWORD_SUCCESS;
  54. }
  55. else {
  56. return PASSWORD_ERROR;
  57. }
  58. }