#! /bin/bash

CONFDIR=/var/opi/etc
CONFFILE=roundcubemail.conf

if [ ! -e $CONFDIR/$CONFFILE ]
then

	DB_PASS=$(pwgen -N1 -s 24)

cat > $CONFDIR/$CONFFILE << eof
_DBC_DBUSER_=roundcubemail
_DBC_DBPASS_=$DB_PASS
_DBC_DBHOST_=localhost
_DBC_DBNAME_=roundcubemail
eof
fi

. $CONFDIR/$CONFFILE

_RC_SESSCRYPT=$(pwgen -N1 -s 24)

cat > /usr/share/roundcube/config/config.inc.php <<EOF
<?php
define("CONFIGWRAPPER","/usr/share/kinguard-utils/sysconfigWrapper.php");
if (is_file(CONFIGWRAPPER))	include CONFIGWRAPPER;
\$config = array();
\$config['db_dsnw'] = 'mysql://$_DBC_DBUSER_:$_DBC_DBPASS_@$_DBC_DBHOST_/$_DBC_DBNAME_';

\$config['default_host'] = 'tls://localhost';

\$config['imap_conn_options'] = array (
        'ssl' => array (
                'verify_peer' => false,
                'verify_peer_name' => false,
        ),
);


\$config['smtp_server'] = 'tls://localhost';
\$config['smtp_port'] = 587;
\$config['smtp_user'] = '%u';
\$config['smtp_pass'] = '%p';
\$config['smtp_conn_options'] = array(
	'ssl'         => array(
		'verify_peer'  => false,
		'verify_peer_name' => false,
	),
);

\$config['password_charset'] = 'UTF-8';

\$config['support_url'] = 'https://www.openproducts.com';
\$config['product_name'] = 'KGP Webmail';
\$config['log_driver'] = 'syslog';

\$config['create_default_folders'] = true;
// Disable default address book to only use NC source
\$config['address_book_type'] = '';

// this key is used to encrypt the users imap password which is stored
// in the session record (and the client cookie if remember password is enabled).
// please provide a string of exactly 24 chars.
// YOUR KEY MUST BE DIFFERENT THAN THE SAMPLE VALUE FOR SECURITY REASONS
\$config['des_key'] = '$_RC_SESSCRYPT';

\$config['plugins'] = array(
    'archive',
    'opi_addressbook',
    'opi_identities',
    'zipdownload',
);

\$config['log_dir'] = RCUBE_INSTALL_PATH . 'logs/';
\$config['temp_dir'] = RCUBE_INSTALL_PATH . 'temp/';
\$config['preview_pane'] = true;
\$config['skin'] = function_exists("getConfigValue") && getConfigValue("webapps","theme") ? getConfigValue("webapps","theme") : "kgp";
EOF

