Thomas Bruederli
2013-06-20 07c6c69eca8751c0e96a846afb30c24ab2638b1f
commit | author | age
48e9c1 1 <?php
T 2
3 /**
4  * hMailserver password driver
5  *
6  * @version 2.0
7  * @author Roland 'rosali' Liebl <myroundcube@mail4us.net>
8  *
9  */
10
11 class rcube_hmail_password
12 {
13     public function save($curpass, $passwd)
14     {
15         $rcmail = rcmail::get_instance();
16
17         if ($curpass == '' || $passwd == '') {
18             return PASSWORD_ERROR;
19         }
20
21         try {
22             $remote = $rcmail->config->get('hmailserver_remote_dcom', false);
23             if ($remote)
24                 $obApp = new COM("hMailServer.Application", $rcmail->config->get('hmailserver_server'));
25             else
26                 $obApp = new COM("hMailServer.Application");
27         }
28         catch (Exception $e) {
61be82 29             rcube::write_log('errors', "Plugin password (hmail driver): " . trim(strip_tags($e->getMessage())));
AM 30             rcube::write_log('errors', "Plugin password (hmail driver): This problem is often caused by DCOM permissions not being set.");
48e9c1 31             return PASSWORD_ERROR;
T 32         }
33
34         $username = $rcmail->user->data['username'];
35         if (strstr($username,'@')){
36             $temparr = explode('@', $username);
37             $domain = $temparr[1];
38         }
39         else {
40             $domain = $rcmail->config->get('username_domain',false);
41             if (!$domain) {
61be82 42                 rcube::write_log('errors','Plugin password (hmail driver): $rcmail_config[\'username_domain\'] is not defined.');
AM 43                 rcube::write_log('errors','Plugin password (hmail driver): Hint: Use hmail_login plugin (http://myroundcube.googlecode.com');
48e9c1 44                 return PASSWORD_ERROR;
T 45             }
46             $username = $username . "@" . $domain;
47         }
48
49         $obApp->Authenticate($username, $curpass);
50         try {
51             $obDomain = $obApp->Domains->ItemByName($domain);
52             $obAccount = $obDomain->Accounts->ItemByAddress($username);
53             $obAccount->Password = $passwd;
54             $obAccount->Save();
55             return PASSWORD_SUCCESS;
56         }
57         catch (Exception $e) {
61be82 58             rcube::write_log('errors', "Plugin password (hmail driver): " . trim(strip_tags($e->getMessage())));
AM 59             rcube::write_log('errors', "Plugin password (hmail driver): This problem is often caused by DCOM permissions not being set.");
48e9c1 60             return PASSWORD_ERROR;
T 61         }
62     }
63 }