defa
2012-09-05 921408eba600a7dc51271c35480e9114cac5ecec
commit | author | age
48e9c1 1 <?php
T 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
17 class rcube_virtualmin_password
18 {
19     function save($currpass, $newpass)
20     {
21         $rcmail = rcmail::get_instance();
22
23         $format   = $rcmail->config->get('password_virtualmin_format', 0);
24         $username = $_SESSION['username'];
25
26         switch ($format) {
27         case 1: // username%domain
28             $domain = substr(strrchr($username, "%"), 1);
29             break;
30         case 2: // username.domain (could be bogus)
31             $pieces = explode(".", $username);
32             $domain = $pieces[count($pieces)-2]. "." . end($pieces);
33             break;
34         case 3: // domain.username (could be bogus)
35             $pieces = explode(".", $username);
36             $domain = $pieces[0]. "." . $pieces[1];
37             break;
38         case 4: // username-domain
39             $domain = substr(strrchr($username, "-"), 1);
40             break;
41         case 5: // domain-username
42             $domain = str_replace(strrchr($username, "-"), "", $username);
43             break;
44         case 6: // username_domain
45             $domain = substr(strrchr($username, "_"), 1);
46             break;
47         case 7: // domain_username
48             $pieces = explode("_", $username);
49             $domain = $pieces[0];
50             break;
a0f006 51         case 8: // domain taken from alias, username left as it was
G 52             $email = $rcmail->user->data['alias'];
53             $domain = substr(strrchr($email, "@"), 1);
145503 54             break;
48e9c1 55         default: // username@domain
T 56             $domain = substr(strrchr($username, "@"), 1);
57         }
58
59         $username = escapeshellcmd($username);
60         $domain   = escapeshellcmd($domain);
61         $newpass  = escapeshellcmd($newpass);
62         $curdir   = INSTALL_PATH . 'plugins/password/helpers';
63
64         exec("$curdir/chgvirtualminpasswd modify-user --domain $domain --user $username --pass $newpass", $output, $returnvalue);
65
66         if ($returnvalue == 0) {
67             return PASSWORD_SUCCESS;
68         }
69         else {
70             raise_error(array(
71                 'code' => 600,
72                 'type' => 'php',
73                 'file' => __FILE__, 'line' => __LINE__,
74                 'message' => "Password plugin: Unable to execute $curdir/chgvirtualminpasswd"
75                 ), true, false);
76         }
77
78         return PASSWORD_ERROR;
79     }
80 }