hestia.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. public 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. $url = "https://{$hestia_host}:{$hestia_port}/reset/mail/";
  25. $ch = curl_init();
  26. if (
  27. false ===
  28. curl_setopt_array($ch, [
  29. CURLOPT_URL => $url,
  30. CURLOPT_RETURNTRANSFER => true,
  31. CURLOPT_HEADER => true,
  32. CURLOPT_POST => true,
  33. CURLOPT_POSTFIELDS => http_build_query($postvars),
  34. CURLOPT_USERAGENT => "Hestia Control Panel Password Driver",
  35. CURLOPT_SSL_VERIFYPEER => false,
  36. CURLOPT_SSL_VERIFYHOST => false,
  37. ])
  38. ) {
  39. // should never happen
  40. throw new Exception("curl_setopt_array() failed: " . curl_error($ch));
  41. }
  42. $result = curl_exec($ch);
  43. if (curl_errno($ch) !== CURLE_OK) {
  44. throw new Exception("curl_exec() failed: " . curl_error($ch));
  45. }
  46. curl_close($ch);
  47. if (strpos($result, "ok") && !strpos($result, "error")) {
  48. return PASSWORD_SUCCESS;
  49. } else {
  50. return PASSWORD_ERROR;
  51. }
  52. }
  53. }