Thomas Bruederli
2013-06-20 07c6c69eca8751c0e96a846afb30c24ab2638b1f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
 
/**
 * domainFACTORY Password Driver
 *
 * Driver to change passwords with the hosting provider domainFACTORY.
 * See: http://www.df.eu/
 *
 * @version 2.0
 * @author Till Krüss <me@tillkruess.com>
 * @link http://tillkruess.com/projects/roundcube/
 *
 */
 
class rcube_domainfactory_password
{
    function save($curpass, $passwd)
    {
        $rcmail = rcmail::get_instance();
 
        if (is_null($curpass)) {
            $curpass = $rcmail->decrypt($_SESSION['password']);
        }
 
        if ($ch = curl_init()) {
            // initial login
            curl_setopt_array($ch, array(
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_URL => 'https://ssl.df.eu/chmail.php',
                CURLOPT_POST => true,
                CURLOPT_POSTFIELDS => array(
                    'login' => $rcmail->user->get_username(),
                    'pwd' => $curpass,
                    'action' => 'change'
                )
            ));
 
            if ($result = curl_exec($ch)) {
                // login successful, get token!
                $postfields = array(
                    'pwd1' => $passwd,
                    'pwd2' => $passwd,
                    'action[update]' => 'Speichern'
                );
 
                preg_match_all('~<input name="(.+?)" type="hidden" value="(.+?)">~i', $result, $fields);
                foreach ($fields[1] as $field_key => $field_name) {
                    $postfields[$field_name] = $fields[2][$field_key];
                }
 
                // change password
                $ch = curl_copy_handle($ch);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
                if ($result = curl_exec($ch)) {
                    if (strpos($result, 'Einstellungen erfolgreich') !== false) {
                        return PASSWORD_SUCCESS;
                    }
                } else {
                    return PASSWORD_CONNECT_ERROR;
                }
            } else {
                return PASSWORD_CONNECT_ERROR;
            }
        } else {
            return PASSWORD_CONNECT_ERROR;
        }
 
        return PASSWORD_ERROR;
    }
}