comparison plugins/password/drivers/virtualmin.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 * Virtualmin Password Driver
5 *
6 * Driver that adds functionality to change the users Virtualmin password.
7 * The code is derrived from the Squirrelmail "Change Cyrus/SASL Password" Plugin
8 * by Thomas Bruederli.
9 *
10 * It only works with virtualmin on the same host where Roundcube runs
11 * and requires shell access and gcc in order to compile the binary.
12 *
13 * @version 3.0
14 * @author Martijn de Munnik
15 *
16 * Copyright (C) 2005-2013, The Roundcube Dev Team
17 *
18 * This program is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see http://www.gnu.org/licenses/.
30 */
31
32 class rcube_virtualmin_password
33 {
34 function save($currpass, $newpass)
35 {
36 $rcmail = rcmail::get_instance();
37 $format = $rcmail->config->get('password_virtualmin_format', 0);
38 $username = $_SESSION['username'];
39
40 switch ($format) {
41 case 1: // username%domain
42 $domain = substr(strrchr($username, "%"), 1);
43 break;
44 case 2: // username.domain (could be bogus)
45 $pieces = explode(".", $username);
46 $domain = $pieces[count($pieces)-2]. "." . end($pieces);
47 break;
48 case 3: // domain.username (could be bogus)
49 $pieces = explode(".", $username);
50 $domain = $pieces[0]. "." . $pieces[1];
51 break;
52 case 4: // username-domain
53 $domain = substr(strrchr($username, "-"), 1);
54 break;
55 case 5: // domain-username
56 $domain = str_replace(strrchr($username, "-"), "", $username);
57 break;
58 case 6: // username_domain
59 $domain = substr(strrchr($username, "_"), 1);
60 break;
61 case 7: // domain_username
62 $pieces = explode("_", $username);
63 $domain = $pieces[0];
64 break;
65 default: // username@domain
66 $domain = substr(strrchr($username, "@"), 1);
67 }
68
69 if (!$domain) {
70 $domain = $rcmail->user->get_username('domain');
71 }
72
73 $username = escapeshellarg($username);
74 $domain = escapeshellarg($domain);
75 $newpass = escapeshellarg($newpass);
76 $curdir = RCUBE_PLUGINS_DIR . 'password/helpers';
77
78 exec("$curdir/chgvirtualminpasswd modify-user --domain $domain --user $username --pass $newpass", $output, $returnvalue);
79
80 if ($returnvalue == 0) {
81 return PASSWORD_SUCCESS;
82 }
83 else {
84 rcube::raise_error(array(
85 'code' => 600,
86 'type' => 'php',
87 'file' => __FILE__, 'line' => __LINE__,
88 'message' => "Password plugin: Unable to execute $curdir/chgvirtualminpasswd"
89 ), true, false);
90 }
91
92 return PASSWORD_ERROR;
93 }
94 }