hestia.php 1.9 KB

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