Part 2 virtualmin , roundcube installation password change plugin

virtualmin > edit server > makesure mysql is enabled
 

Virtualmin > Server Configuration > website options



If there is any change in the user permission or group name enter:-

chown root.VIRTUAL_SERVER_GROUP_NAME plugins/password/helpers/chgvirtualminpasswd 

strip plugins/password/helpers/chgvirtualminpasswd 

chmod 4550 plugins/password/helpers/chgvirtualminpasswd


if above doesnt work then ....

vim /home/axonadvisers/public_html/roundcube/plugins/password/drivers/virtualmin.php

        $username = escapeshellarg($username);
       /** $domain   = escapeshellarg($domain); **/
        $domain   = "axonadvisers.com";
        $newpass  = escapeshellarg($newpass);
        $curdir   = RCUBE_PLUGINS_DIR . 'password/helpers';

/**        exec("$curdir/chgvirtualminpasswd modify-user --domain $domain --user $username --pass $newpass", $output, $returnvalue);  **/
//        /home/axonadvisers/public_html/roundcube/plugins/password/helpers

   exec("/home/axonadvisers/public_html/roundcube/plugins/password/helpers/chgvirtualminpasswd modify-user --domain axonadvisers.com --user $username --pass $newpass", $output, $returnvalue);

restart httpd
and DONE

Part 1 Virtualmin installation on centos 7.3

set FQDN for hostname

yum -y update

yum install epel-release

yum install wget curl rsync gcc -y

wget http://software.virtualmin.com/gpl/scripts/install.sh -O /tmp/virtualmin-install.sh


cd /tmp


#Add mysql repository to your centos 7

rpm -Uvh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
yum install mysql-server -y

chmod +x /tmp/virtualmin-install.sh

bash /tmp/virtualmin-install.sh

done

login to virtualmin using https://<ip>:10000

  • Login to Virtualmin, and click on Webmin at the top of the left menu.
  • Open the Webmin category, click on Usermin Configuration, then on Usermin Module Configuration, and finally on Read Mail.
  • On the form that appears, change the Mail storage format for Inbox to Maildir.
  • Click Save.
cp /etc/postfix/main.cnf  /etc/postfix/main.cnf.BAK
sudo postconf -e 'smtp_tls_security_level = may'
sudo postconf -e 'smtpd_tls_security_level = may'
sudo postconf -e 'smtp_tls_note_starttls_offer = yes'

service saslauthd restart

Install roundcube
https://www.virtualmin.com/documentation/id%2Cwebmail_and_virtualmin

Make sure to enable mysql in website settings or See here

http://urgenphp.blogspot.com/2017/07/part-2-virtualmin-roundcube.html

Install a Roundcube Password plugin in Virtualmin

  1. Install the Roundcube script usually from Virtualmin dashboard by selecting server and then going into Install Scripts->Roundcube from the Available Scripts and install it the way you require by selecting the sub folder you wish to install
  2. Now Log into the server over SSH with the virtualmin username and password you created during creation of the virtual server. Go into the sub directory you just installed Roundcube script into. We are assuming you selected folder name as roundcube .Now navigate into path from server via SSH as
    cd /home/USERNAME/public_html/roundcube/
  3. Edit config/main.inc.php, and change this line:
    $rcmail_config['plugins'] = array('virtuser_file');
    To this line:
    $rcmail_config['plugins'] = array('virtuser_file', 'password');
  4. Setup the password plugin config file with the help of this command in SSH in the roundcube folder:
     cp plugins/password/config.inc.php.dist   plugins/password/config.inc.php
  5. Enable Virtualmin driver. To do that, go ahead and edit “plugins/password/config.inc.php”, and change this line:
  6. $rcmail_config['password_driver'] = 'sql';
    To this:
     $rcmail_config['password_driver'] = 'virtualmin';
  7. Compile C wrapper with this command ,If gcc is not installed,install it by using command if you are in Centos
    yum install gcc
    and then type
     gcc -o plugins/password/helpers/chgvirtualminpasswd plugins/password/helpers/chgvirtualminpasswd.c
  8. Permissions are required by roundcude password plugin to access and change virtualmin functions so enter
    chown root.VIRTUAL_SERVER_GROUP_NAME plugins/password/helpers/chgvirtualminpasswd 
     strip plugins/password/helpers/chgvirtualminpasswd 
    chmod 4550 plugins/password/helpers/chgvirtualminpasswd
  9. Fix syntax error in virtualmin.php driver by editing “plugins/password/drivers/virtualmin.php”, and jump to
    line 54. You’ll see a line with just “break”. That line should end with a semicolon (;) character.The line should look like this:
    break;
  10. You should now be able to log into RoundCube, go into Settings -> Password, and change your user’s roundcube password

mysql slow query due to function in where

Query which take more than 13 secs to return output i did create the indexes but the execution plan doesnt seem to use them. Below are some information regarding

Query

SELECT  userinfo.username,userinfo.firstname,userinfo.lastname,userinfo.email,
radcheck.attribute,radcheck.value,radusergroup.groupname, userinfo.id,
userinfo.workphone,userinfo.homephone,
userinfo.mobilephone,userinfo.address, userinfo.zone,
userinfo.account_state,userinfo.device_owner,userinfo.link_type,userinfo.account_type 
FROM userinfo  
INNER JOIN radcheck ON userinfo.username = radcheck.username  
INNER JOIN radusergroup ON userinfo.username = radusergroup.username 
WHERE  radcheck.attribute='Expiration'  and 
STR_TO_DATE(radcheck.value, '%d %M %Y') < CURDATE() 
and radusergroup.groupname='Customer30M';

Explain output

+----+-------------+--------------+------+--------------------+-----------+---------+--------------------------------+------+-----------------------------------+
| id | select_type | table        | type | possible_keys      | key       | key_len | ref                            | rows | Extra                             |
+----+-------------+--------------+------+--------------------+-----------+---------+--------------------------------+------+-----------------------------------+
|  1 | SIMPLE      | radusergroup | ref  | username,groupname | groupname | 66      | const                          |    5 | Using where with pushed condition |
|  1 | SIMPLE      | radcheck     | ref  | username,attribute | attribute | 34      | const                          |    9 | Using where                       |
|  1 | SIMPLE      | userinfo     | ref  | username           | username  | 131     | ctradius.radusergroup.username |   10 | Using where                       |
+----+-------------+--------------+------+--------------------+-----------+---------+--------------------------------+------+-----------------------------------+
3 rows in set (0.00 sec)

Table Info

Table: radusergroup
+-----------+-------------+------+-----+---------+----------------+
| Field     | Type        | Null | Key | Default | Extra          |
+-----------+-------------+------+-----+---------+----------------+
| id        | int(11)     | NO   | PRI | NULL    | auto_increment |
| username  | varchar(64) | NO   | MUL |         |                |
| groupname | varchar(64) | NO   | MUL |         |                |
| priority  | int(11)     | NO   |     | 1       |                |
+-----------+-------------+------+-----+---------+----------------+
radusergroup table Index
+--------------+------------+-------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table        | Non_unique | Key_name          | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+--------------+------------+-------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| radusergroup |          0 | PRIMARY           |            1 | id          | A         |       11292 |     NULL | NULL   |      | BTREE      |         |               |
| radusergroup |          1 | username          |            1 | username    | A         |        NULL |     NULL | NULL   |      | BTREE      |         |               |
| radusergroup |          1 | groupname         |            1 | groupname   | A         |        NULL |     NULL | NULL   |      | BTREE      |         |               |
| radusergroup |          1 | indexradusergroup |            1 | username    | A         |        NULL |     NULL | NULL   |      | BTREE      |         |               |
| radusergroup |          1 | indexradusergroup |            2 | groupname   | A         |        NULL |     NULL | NULL   |      | BTREE      |         |               |
Table : userinfo
---------------------+------------------+------+-----+---------------------+----------------+
| Field               | Type             | Null | Key | Default             | Extra          |
+---------------------+------------------+------+-----+---------------------+----------------+
| id                  | int(11) unsigned | NO   | PRI | NULL                | auto_increment |
| username            | varchar(128)     | YES  | MUL | NULL                |                |
| firstname           | varchar(200)     | YES  |     | NULL                |                |
| lastname            | varchar(200)     | YES  |     | NULL                |                |
| email               | varchar(200)     | YES  |     | NULL                |                |
| workphone           | varchar(200)     | YES  |     | NULL                |                |
| homephone           | varchar(200)     | YES  |     | NULL                |                |
| mobilephone         | varchar(200)     | YES  |     | NULL                |                |
| address             | varchar(200)     | YES  |     | NULL                |                |
| zone                | varchar(20)      | YES  |     | NULL                |                |
| account_state       | varchar(10)      | YES  |     | active              |                |
| change_commit       | tinyint(1)       | YES  |     | NULL                |                |
| link_type           | varchar(8)       | YES  |     | NULL                |                |
| account_type        | varchar(255)     | YES  |     | NULL                |                |
| device_owner        | varchar(255)     | YES  |     | NULL                |                |
| account_name        | varchar(255)     | YES  |     | NULL                |                |
| account_email       | varchar(255)     | YES  |     | NULL                |                |
| account_mobile      | varchar(255)     | YES  |     | NULL                |                |
| groupname           | varchar(255)     | YES  |     | NULL                |                |
+---------------------+------------------+------+-----+---------------------+----------------+
Indexes on userinfo
----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| userinfo |          0 | PRIMARY  |            1 | id          | A         |       11282 |     NULL | NULL   |      | BTREE      |         |               |
| userinfo |          1 | username |            1 | username    | A         |        NULL |     NULL | NULL   | YES  | BTREE      |         |               |
+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
Table: Radcheck
+-----------+------------------+------+-----+---------+----------------+
| Field     | Type             | Null | Key | Default | Extra          |
+-----------+------------------+------+-----+---------+----------------+
| id        | int(11) unsigned | NO   | PRI | NULL    | auto_increment |
| username  | varchar(64)      | NO   | MUL |         |                |
| attribute | varchar(32)      | NO   | MUL |         |                |
| op        | char(2)          | NO   |     | ==      |                |
| value     | varchar(253)     | NO   | MUL |         |                |
+-----------+------------------+------+-----+---------+----------------+
indexes on radcheck
+----------+------------+---------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table    | Non_unique | Key_name      | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+----------+------------+---------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| radcheck |          0 | PRIMARY       |            1 | id          | A         |       33425 |     NULL | NULL   |      | BTREE      |         |               |
| radcheck |          1 | username      |            1 | username    | A         |        NULL |     NULL | NULL   |      | BTREE      |         |               |
| radcheck |          1 | value         |            1 | value       | A         |        NULL |     NULL | NULL   |      | BTREE      |         |               |
| radcheck |          1 | attribute     |            1 | attribute   | A         |        NULL |     NULL | NULL   |      | BTREE      |         |               |
Resolution:-
The function invalidates the use of the index. Despite cardinality showing 11k rows, the table scan ensues and it takes 13 seconds.
Though it  has a join between Radcheck and userinfo, it is the STR_TO_DATE function in the where clause that kills the index use.