PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/etc/apps/webmail/plugins/password/drivers/domainfactory.php

https://github.com/raiman264/zpanelx
PHP | 89 lines | 58 code | 15 blank | 16 comment | 10 complexity | 3633f62c632d3942508396fefa683a25 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0, LGPL-2.1, CC-BY-SA-4.0, GPL-3.0
  1. <?php
  2. /**
  3. * domainFACTORY Password Driver
  4. *
  5. * Driver to change passwords with the hosting provider domainFACTORY.
  6. * http://www.df.eu/
  7. *
  8. * @version 2.1
  9. * @author Till Kr端ss <me@tillkruess.com>
  10. * @link http://tillkruess.com/projects/roundcube/
  11. *
  12. */
  13. class rcube_domainfactory_password
  14. {
  15. function save($curpass, $passwd)
  16. {
  17. $rcmail = rcmail::get_instance();
  18. if (is_null($curpass)) {
  19. $curpass = $rcmail->decrypt($_SESSION['password']);
  20. }
  21. if ($ch = curl_init()) {
  22. // initial login
  23. curl_setopt_array($ch, array(
  24. CURLOPT_RETURNTRANSFER => true,
  25. CURLOPT_URL => 'https://ssl.df.eu/chmail.php',
  26. CURLOPT_POST => true,
  27. CURLOPT_POSTFIELDS => http_build_query(array(
  28. 'login' => $rcmail->user->get_username(),
  29. 'pwd' => $curpass,
  30. 'action' => 'change'
  31. ))
  32. ));
  33. if ($result = curl_exec($ch)) {
  34. // login successful, get token!
  35. $postfields = array(
  36. 'pwd1' => $passwd,
  37. 'pwd2' => $passwd,
  38. 'action[update]' => 'Speichern'
  39. );
  40. preg_match_all('~<input name="(.+?)" type="hidden" value="(.+?)">~i', $result, $fields);
  41. foreach ($fields[1] as $field_key => $field_name) {
  42. $postfields[$field_name] = $fields[2][$field_key];
  43. }
  44. // change password
  45. $ch = curl_copy_handle($ch);
  46. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields));
  47. if ($result = curl_exec($ch)) {
  48. // has the password been changed?
  49. if (strpos($result, 'Einstellungen erfolgreich') !== false) {
  50. return PASSWORD_SUCCESS;
  51. }
  52. // show error message(s) if possible
  53. if (strpos($result, '<div class="d-msg-text">') !== false) {
  54. preg_match_all('#<div class="d-msg-text">(.*?)</div>#s', $result, $errors);
  55. if (isset($errors[1])) {
  56. $error_message = '';
  57. foreach ( $errors[1] as $error ) {
  58. $error_message .= trim(mb_convert_encoding( $error, 'UTF-8', 'ISO-8859-15' )).' ';
  59. }
  60. return array('code' => PASSWORD_ERROR, 'message' => $error_message);
  61. }
  62. }
  63. } else {
  64. return PASSWORD_CONNECT_ERROR;
  65. }
  66. } else {
  67. return PASSWORD_CONNECT_ERROR;
  68. }
  69. } else {
  70. return PASSWORD_CONNECT_ERROR;
  71. }
  72. return PASSWORD_ERROR;
  73. }
  74. }