source: github/plugins/password/drivers/virtualmin.php @ 884add1

Last change on this file since 884add1 was 884add1, checked in by thomascube <thomas@…>, 15 months ago

Tagging plugins for 0.8-beta

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[884add1]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
17class 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;
51        default: // username@domain
52            $domain = substr(strrchr($username, "@"), 1);
53        }
54
55        $username = escapeshellcmd($username);
56        $domain   = escapeshellcmd($domain);
57        $newpass  = escapeshellcmd($newpass);
58        $curdir   = realpath(dirname(__FILE__));
59
60        exec("$curdir/chgvirtualminpasswd modify-user --domain $domain --user $username --pass $newpass", $output, $returnvalue);
61
62        if ($returnvalue == 0) {
63            return PASSWORD_SUCCESS;
64        }
65        else {
66            raise_error(array(
67                'code' => 600,
68                'type' => 'php',
69                'file' => __FILE__, 'line' => __LINE__,
70                'message' => "Password plugin: Unable to execute $curdir/chgvirtualminpasswd"
71                ), true, false);
72        }
73
74        return PASSWORD_ERROR;
75    }
76}
Note: See TracBrowser for help on using the repository browser.