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