You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

domainfactory.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. * Copyright (C) 2005-2014, The Roundcube Dev Team
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation, either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see http://www.gnu.org/licenses/.
  26. */
  27. class rcube_domainfactory_password
  28. {
  29. function save($curpass, $passwd)
  30. {
  31. $rcmail = rcmail::get_instance();
  32. if (is_null($curpass)) {
  33. $curpass = $rcmail->decrypt($_SESSION['password']);
  34. }
  35. if ($ch = curl_init()) {
  36. // initial login
  37. curl_setopt_array($ch, array(
  38. CURLOPT_RETURNTRANSFER => true,
  39. CURLOPT_URL => 'https://ssl.df.eu/chmail.php',
  40. CURLOPT_POST => true,
  41. CURLOPT_POSTFIELDS => http_build_query(array(
  42. 'login' => $rcmail->user->get_username(),
  43. 'pwd' => $curpass,
  44. 'action' => 'change'
  45. ))
  46. ));
  47. if ($result = curl_exec($ch)) {
  48. // login successful, get token!
  49. $postfields = array(
  50. 'pwd1' => $passwd,
  51. 'pwd2' => $passwd,
  52. 'action[update]' => 'Speichern'
  53. );
  54. preg_match_all('~<input name="(.+?)" type="hidden" value="(.+?)">~i', $result, $fields);
  55. foreach ($fields[1] as $field_key => $field_name) {
  56. $postfields[$field_name] = $fields[2][$field_key];
  57. }
  58. // change password
  59. $ch = curl_copy_handle($ch);
  60. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields));
  61. if ($result = curl_exec($ch)) {
  62. // has the password been changed?
  63. if (strpos($result, 'Einstellungen erfolgreich') !== false) {
  64. return PASSWORD_SUCCESS;
  65. }
  66. // show error message(s) if possible
  67. if (strpos($result, '<div class="d-msg-text">') !== false) {
  68. preg_match_all('#<div class="d-msg-text">(.*?)</div>#s', $result, $errors);
  69. if (isset($errors[1])) {
  70. $error_message = '';
  71. foreach ($errors[1] as $error) {
  72. $error_message .= trim(mb_convert_encoding( $error, 'UTF-8', 'ISO-8859-15' )).' ';
  73. }
  74. return array('code' => PASSWORD_ERROR, 'message' => $error_message);
  75. }
  76. }
  77. }
  78. else {
  79. return PASSWORD_CONNECT_ERROR;
  80. }
  81. }
  82. else {
  83. return PASSWORD_CONNECT_ERROR;
  84. }
  85. }
  86. else {
  87. return PASSWORD_CONNECT_ERROR;
  88. }
  89. return PASSWORD_ERROR;
  90. }
  91. }