Roundcube: Vacation message with Virtualmin Plugin

None of the vacation/forwarding plugins work with Virtualmin so this is my workaround. Firstly, users need to be created as Mail and FTP users, since we will be using FTP to place the .forward files. Download and unzip the plugin:

wget http://downloads.sourceforge.net/project/rcubevacation/vacation-1.9.9.zip?use_mirror=ovh&ts=1280145947
unzip vacation-1.9.9.zip
cd vacation
vi config.ini

We are going to use Usermin’s own function (installing the Vacation program doesn’t work) – so change these lines:

binary = "/etc/usermin/forward/autoreply.pl"
alias_identities = false

At this point I usually edit default.txt and change the default text. Now, I have mail usernames in Virtualmin formatted user@domain, so a few changes need to be made to accommodate this:

cd lib
vi dotforward.class.php

We are going to change some lines. Type :set number to see line numbers.
Line 42 change to:
$arrDotForward[] = $this->options['keepcopy'] = "\\".str_replace('@','-',$this->options['username']);
Line 94 change to:
$this->options['keepcopy'] = ($first_element == str_replace('@','-',$this->options['username']));

We need to tell the script the path to the mailbox, so we need to add some code. There’s a gap around line 68 which we can put the following in – note that this is very hacky and will only work with top level domains (not subdomains) where the username is the first part of the domain. If anyone has a better way to do this, do let me know (the virtualmin files containing the home directory paths are in /etc/webmin/virtual-server/domains but are readable by the root user only or we could parse /etc/passwd for the usernames…):

$user_parts = explode('@',$this->options['username']);
$domain_parts = explode('.',$user_parts[1]);
$this->options['flags'] = '/home/'.$domain_parts[0].'/homes/'.$user_parts[0].'/.vacation.msg';

[EDIT – thanks to Iain, the code to get the correct directory from /etc/passwd follows – use this instead of the previous code block:]

$user_accounts = file_get_contents( "/etc/passwd");
$matches = preg_grep( "/" . $this->options['username'] . "/i", explode( "\n",$user_accounts));
$user_info = explode( ":", current($matches));
$this->options['flags'] = $user_info[5] . '/.vacation.msg';

[/EDIT]

Now just add the plugin to the plugins array:

cd ../../../config/
vi main.inc.php

Change the line to:
$rcmail_config['plugins'] = array('vacation');

Update: in Roundcube 0.5 the page layout has changed and the plugin displays incorrectly. To fix this, edit plugins/vacation/skins/default/vacation.css and add in some padding:
#pagecontent {
width: 800px;
padding-top:70px;
}

Roundcube: Change Virtualmin Password Plugin

I can never get the Virtualmin binary file compilation to work properly, so here’s my workaround to enable changing a user’s Virtualmin password in Roundcube Webmail.

Firstly, let’s go to the plugins/password directory (your path will be different):

cd ~username/public_html/webmail/plugins/password
cp config.inc.php.dist config.inc.php
vi config.inc.php

We need to change the password driver to virtualmin (hit i for insert mode), so it reads:

$rcmail_config['password_driver'] = 'virtualmin';

(Hit Esc to exist insert mode and then ZZ to save. You’ll need these commands throughout this tutorial.)
Now we’ll use sudo instead of the binary compilation:

cd drivers
yum -y install sudo
visudo

Comment out the line: Defaults requiretty
At the end, add the following line (change the username to whatever user your webmail directory runs as): username ALL=NOPASSWD: /usr/sbin/virtualmin

If you can’t work out which user it is, create and execute a PHP script in the webmail directory with the following contents: <?php exec('whoami',$output,$return_code); print_r($output); ?>

Now we need to change the exec line in the virtualmin script:

vi virtualmin.php

Change the line that starts with exec to:
exec("sudo /usr/sbin/virtualmin modify-user --domain $domain --user $username --pass $newpass", $output, $returnvalue);

Finally, add password to the plugins array to activate it:

cd ../../../config
vi main.inc.php

Change plugins array to: $rcmail_config['plugins'] = array('password');