1<?php 2 3/** 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> 11 * 12 * Copyright (C) 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 28class rcube_gearman_password 29{ 30 function save($currpass, $newpass, $username) 31 { 32 if (extension_loaded('gearman')) { 33 $rcmail = rcmail::get_instance(); 34 $payload = [ 35 'username' => $username, 36 'oldPassword' => $currpass, 37 'newPassword' => $newpass, 38 ]; 39 40 $gmc = new GearmanClient(); 41 $gmc->addServer($rcmail->config->get('password_gearman_host', 'localhost')); 42 43 $result = $gmc->doNormal('setPassword', json_encode($payload)); 44 $success = json_decode($result); 45 46 if ($success && $success->result == 1) { 47 return PASSWORD_SUCCESS; 48 } 49 50 rcube::raise_error([ 51 'code' => 600, 52 'file' => __FILE__, 53 'line' => __LINE__, 54 'message' => "Password plugin: Gearman authentication failed for user $username" 55 ], true, false 56 ); 57 } 58 else { 59 rcube::raise_error([ 60 'code' => 600, 61 'file' => __FILE__, 62 'line' => __LINE__, 63 'message' => "Password plugin: PECL Gearman module not loaded" 64 ], true, false 65 ); 66 } 67 68 return PASSWORD_ERROR; 69 } 70} 71