]> git.donarmstrong.com Git - roundcube.git/blob - plugins/password/drivers/virtualmin.php
Imported Upstream version 0.5.2+dfsg
[roundcube.git] / plugins / password / drivers / virtualmin.php
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 2.0
14  * @author Martijn de Munnik
15  */
16
17 function password_save($currpass, $newpass)
18 {
19     $rcmail = rcmail::get_instance();
20
21     $format   = $rcmail->config->get('password_virtualmin_format', 0);
22     $username = $_SESSION['username'];
23
24     switch ($format) {
25         case 1: // username%domain
26             $domain = substr(strrchr($username, "%"), 1);
27             break;
28         case 2: // username.domain (could be bogus)
29             $pieces = explode(".", $username);
30             $domain = $pieces[count($pieces)-2]. "." . end($pieces);
31             break;
32         case 3: // domain.username (could be bogus)
33             $pieces = explode(".", $username);
34             $domain = $pieces[0]. "." . $pieces[1];
35             break;
36         case 4: // username-domain
37             $domain = substr(strrchr($username, "-"), 1);
38             break;
39         case 5: // domain-username
40             $domain = str_replace(strrchr($username, "-"), "", $username);
41             break;
42         case 6: // username_domain
43             $domain = substr(strrchr($username, "_"), 1);
44             break;
45         case 7: // domain_username
46             $pieces = explode("_", $username);
47             $domain = $pieces[0];
48             break;
49         default: // username@domain
50             $domain = substr(strrchr($username, "@"), 1);
51     }
52                                                                                                                                                                                                                                                                                                             
53     $username = escapeshellcmd($username);
54     $domain   = escapeshellcmd($domain);
55     $newpass  = escapeshellcmd($newpass);
56     $curdir   = realpath(dirname(__FILE__));
57
58     exec("$curdir/chgvirtualminpasswd modify-user --domain $domain --user $username --pass $newpass", $output, $returnvalue);
59
60     if ($returnvalue == 0) {
61         return PASSWORD_SUCCESS;
62     }
63     else {
64         raise_error(array(
65             'code' => 600,
66             'type' => 'php',
67             'file' => __FILE__, 'line' => __LINE__,
68             'message' => "Password plugin: Unable to execute $curdir/chgvirtualminpasswd"
69             ), true, false);
70     }
71
72     return PASSWORD_ERROR;
73 }
74
75 ?>