comparison plugins/password/drivers/expect.php @ 0:1e000243b222

vanilla 1.3.3 distro, I hope
author Charlie Root
date Thu, 04 Jan 2018 15:50:29 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1e000243b222
1 <?php
2
3 /**
4 * expect driver
5 *
6 * Driver that adds functionality to change the systems user password via
7 * the 'expect' command.
8 *
9 * For installation instructions please read the README file.
10 *
11 * @version 2.0
12 * @author Andy Theuninck <gohanman@gmail.com)
13 *
14 * Based on chpasswd roundcubemail password driver by
15 * @author Alex Cartwright <acartwright@mutinydesign.co.uk)
16 * and expect horde passwd driver by
17 * @author Gaudenz Steinlin <gaudenz@soziologie.ch>
18 *
19 * Configuration settings:
20 * password_expect_bin => location of expect (e.g. /usr/bin/expect)
21 * password_expect_script => path to "password-expect" file
22 * password_expect_params => arguments for the expect script
23 * see the password-expect file for details. This is probably
24 * a good starting default:
25 * -telent -host localhost -output /tmp/passwd.log -log /tmp/passwd.log
26 *
27 * Copyright (C) 2005-2014, The Roundcube Dev Team
28 *
29 * This program is free software: you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by
31 * the Free Software Foundation, either version 3 of the License, or
32 * (at your option) any later version.
33 *
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
38 *
39 * You should have received a copy of the GNU General Public License
40 * along with this program. If not, see http://www.gnu.org/licenses/.
41 */
42
43 class rcube_expect_password
44 {
45 public function save($currpass, $newpass)
46 {
47 $rcmail = rcmail::get_instance();
48 $bin = $rcmail->config->get('password_expect_bin');
49 $script = $rcmail->config->get('password_expect_script');
50 $params = $rcmail->config->get('password_expect_params');
51 $username = $_SESSION['username'];
52
53 $cmd = $bin . ' -f ' . $script . ' -- ' . $params;
54 $handle = popen($cmd, "w");
55 fwrite($handle, "$username\n");
56 fwrite($handle, "$currpass\n");
57 fwrite($handle, "$newpass\n");
58
59 if (pclose($handle) == 0) {
60 return PASSWORD_SUCCESS;
61 }
62 else {
63 rcube::raise_error(array(
64 'code' => 600,
65 'type' => 'php',
66 'file' => __FILE__, 'line' => __LINE__,
67 'message' => "Password plugin: Unable to execute $cmd"
68 ), true, false);
69 }
70
71 return PASSWORD_ERROR;
72 }
73 }