Aleksander Machniak
2014-09-08 4baf96a4ca1621a267c10c67e84e80e6bf72dbfd
commit | author | age
159966 1 <?php
9d2550 2
159966 3 /**
MA 4  * Gearman Password Driver
5  *
6  * Payload is json string containing username, oldPassword and newPassword
7  * Return value is a json string saying result: true if success.
8  *
9  * @version 1.0
10  * @author Mohammad Anwari <mdamt@mdamt.net>
4baf96 11  *
AM 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/.
159966 26  */
MA 27
28 class rcube_gearman_password
29 {
9d2550 30     function save($currpass, $newpass)
AM 31     {
32         if (extension_loaded('gearman')) {
33             $rcmail  = rcmail::get_instance();
34             $user    = $_SESSION['username'];
35             $payload = array(
36                 'username'    => $user,
37                 'oldPassword' => $currpass,
38                 'newPassword' => $newpass,
39             );
159966 40
9d2550 41             $gmc = new GearmanClient();
AM 42             $gmc->addServer($rcmail->config->get('password_gearman_host'));
159966 43
9d2550 44             $result  = $gmc->doNormal('setPassword', json_encode($payload));
AM 45             $success = json_decode($result);
46
47             if ($success && $success->result == 1) {
48                 return PASSWORD_SUCCESS;
49             }
50             else {
51                 rcube::raise_error(array(
52                     'code' => 600,
53                     'type' => 'php',
54                     'file' => __FILE__, 'line' => __LINE__,
55                     'message' => "Password plugin: Gearman authentication failed for user $user: $error"
56                 ), true, false);
57             }
58         }
59         else {
60             rcube::raise_error(array(
61                 'code' => 600,
62                 'type' => 'php',
63                 'file' => __FILE__, 'line' => __LINE__,
64                 'message' => "Password plugin: PECL Gearman module not loaded"
65             ), true, false);
66         }
67
68         return PASSWORD_ERROR;
159966 69     }
MA 70 }