4 * Virtualmin Password Driver
6 * Driver that adds functionality to change the users Virtualmin password.
7 * The code is derrived from the Squirrelmail "Change Cyrus/SASL Password" Plugin
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.
14 * @author Martijn de Munnik
17 function password_save($currpass, $newpass)
19 $rcmail = rcmail::get_instance();
21 $format = $rcmail->config->get('password_virtualmin_format', 0);
22 $username = $_SESSION['username'];
25 case 1: // username%domain
26 $domain = substr(strrchr($username, "%"), 1);
28 case 2: // username.domain (could be bogus)
29 $pieces = explode(".", $username);
30 $domain = $pieces[count($pieces)-2]. "." . end($pieces);
32 case 3: // domain.username (could be bogus)
33 $pieces = explode(".", $username);
34 $domain = $pieces[0]. "." . $pieces[1];
36 case 4: // username-domain
37 $domain = substr(strrchr($username, "-"), 1);
39 case 5: // domain-username
40 $domain = str_replace(strrchr($username, "-"), "", $username);
42 case 6: // username_domain
43 $domain = substr(strrchr($username, "_"), 1);
45 case 7: // domain_username
46 $pieces = explode("_", $username);
49 default: // username@domain
50 $domain = substr(strrchr($username, "@"), 1);
53 $username = escapeshellcmd($username);
54 $domain = escapeshellcmd($domain);
55 $newpass = escapeshellcmd($newpass);
56 $curdir = realpath(dirname(__FILE__));
58 exec("$curdir/chgvirtualminpasswd modify-user --domain $domain --user $username --pass $newpass", $output, $returnvalue);
60 if ($returnvalue == 0) {
61 return PASSWORD_SUCCESS;
67 'file' => __FILE__, 'line' => __LINE__,
68 'message' => "Password plugin: Unable to execute $curdir/chgvirtualminpasswd"
72 return PASSWORD_ERROR;