403Webshell
Server IP : 157.22.201.140  /  Your IP : 216.73.216.74
Web Server : nginx/1.30.1
System : Linux mit.vincode.fvds.ru 6.8.0-111-generic #111-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 11 23:16:02 UTC 2026 x86_64
User : root ( 0)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /usr/share/roundcube/bin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/share/roundcube/bin/init_roundcube_db.sh
#!/bin/sh

if [ -f /etc/redhat-release ] || [ -f /etc/centos-release ]; then
    OS_TYPE="CENTOS"
    APP_DIR=/usr/share/roundcubemail
    CONFDBFILE=/etc/roundcubemail/config.inc.php
elif [ -f /etc/debian_version ]; then
    OS_TYPE="DEBIAN"
    APP_DIR=/usr/share/roundcube
    CONFDBFILE=/etc/roundcube/debian-db.php
fi

if [ -f /root/.my.cnf ]; then
    MYSQLOPTS="--defaults-file=/root/.my.cnf"
elif [ -f /usr/local/mgr5/etc/my.cnf ]; then
    MYSQLOPTS="--defaults-file=/usr/local/mgr5/etc/my.cnf"
else
    MYSQLOPTS=""
fi

PHP_BIN=/opt/php74/bin/php

DB_GRANT="false"
DB_CONF_NEW="false"
DB_USER="roundcube"
DB_PASS=""
DB_NAME="roundcube"


make_db_bkp() {
    local db_bkp_file=${APP_DIR}.bkp/${DB_NAME}.dump-$(date +%F-%H%M%S).sql
    test -d ${APP_DIR}.bkp || mkdir -p ${APP_DIR}.bkp
    if [ ! -f ${db_bkp_file} ]; then
        mysqldump ${MYSQLOPTS} ${DB_NAME} > ${db_bkp_file} 2>&1 || rm -f ${db_bkp_file} || true
    fi
}

make_db_config() {
    DB_PASS="$(env LANG=C LC_ALL=C tr -dc "[:alnum:]" < /dev/urandom | dd bs=1 count=12 2>/dev/null)"
    DB_USER="roundcube"
    DB_NAME="roundcube"

    if [ "${OS_TYPE}" = "DEBIAN" ]; then
        cat > ${CONFDBFILE} <<-EOF
<?php
\$dbuser='${DB_USER}';
\$dbpass='${DB_PASS}';
\$basepath='';
\$dbname='${DB_NAME}';
\$dbserver='localhost';
\$dbport='3306';
\$dbtype='mysql';
EOF

        chown www-data ${CONFDBFILE}
        chmod 0660 ${CONFDBFILE}
    else
        local db_dsnw="\$config['db_dsnw'] = 'mysql://${DB_USER}:${DB_PASS}@localhost/${DB_NAME}';"
        test -f ${CONFDBFILE} || {
            cp /etc/roundcubemail/config.inc.php.sample ${CONFDBFILE}
            chown apache ${CONFDBFILE}
            chmod 0600 ${CONFDBFILE}
        }
        sed -i "s|^\$config\['db_dsnw'\].*;$|$db_dsnw|g" ${CONFDBFILE}
    fi

    DB_CONF_NEW="true"
}

mysql_bin() {
    local execute_arg="${1}"
    local execute_command="${2}"
    case $execute_arg in
        -execute)
            echo "${execute_command}" | mysql ${MYSQLOPTS} mysql >/dev/null 2>&1  || true
            ;;
        -check)
            echo $(mysql ${MYSQLOPTS} -se "${execute_command}" --skip-column-names 2>&1 || true)
            ;;
        *)
            exit 0
            ;;
    esac

}

if [ -f ${CONFDBFILE} ]; then
    if [ "${OS_TYPE}" = "DEBIAN" ]; then
        DB_PASS="$(sed -n "s|\$dbpass='\(.*\)';|\1|p" ${CONFDBFILE})"
        DB_USER="$(sed -n "s|\$dbuser='\(.*\)';|\1|p" ${CONFDBFILE})"
        DB_NAME="$(sed -n "s|\$dbname='\(.*\)';|\1|p" ${CONFDBFILE})"
    else
        DB_USER="$(sed -n "s|^\$config\['db_dsnw'\] = 'mysql://\(.*\):\(.*\)@\(.*\)/\(.*\)';|\1|p" ${CONFDBFILE})"
        DB_PASS="$(sed -n "s|^\$config\['db_dsnw'\] = 'mysql://\(.*\):\(.*\)@\(.*\)/\(.*\)';|\2|p" ${CONFDBFILE})"    
        DB_NAME="$(sed -n "s|^\$config\['db_dsnw'\] = 'mysql://\(.*\):\(.*\)@\(.*\)/\(.*\)';|\4|p" ${CONFDBFILE})"
    fi

    CHECK_VAR_FAIL="false"
    test -z ${DB_PASS} && CHECK_VAR_FAIL="true"
    test ${DB_PASS} = "pass" && CHECK_VAR_FAIL="true"
    test -z ${DB_USER} && CHECK_VAR_FAIL="true"
    test -z ${DB_NAME} && CHECK_VAR_FAIL="true"

    if [ "${CHECK_VAR_FAIL}" = "true" ]; then
        make_db_config
    fi
else
    make_db_config
fi

CHECK_DB=$(mysql_bin -check "show databases LIKE '${DB_NAME}'")
if [ "${CHECK_DB}" != "${DB_NAME}" ]; then
    mysql_bin -execute "CREATE DATABASE IF NOT EXISTS \`${DB_NAME}\`"
    mysql ${MYSQLOPTS} "${DB_NAME}" < ${APP_DIR}/SQL/mysql.initial.sql 2>&1 || true
    DB_GRANT="true"
fi

CHECK_USER=$(mysql_bin -check "SELECT user FROM mysql.user WHERE user='${DB_USER}'")
if [ "${CHECK_USER}" != "${DB_USER}" ] || [ "${DB_CONF_NEW}" = "true" ]; then
    mysql_bin -execute "DROP USER '${DB_USER}'@'localhost'"
    mysql_bin -execute "CREATE USER '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PASS}'"
    mysql_bin -execute "GRANT USAGE ON * . * TO '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PASS}'"
    DB_GRANT="true"
fi

if [ "${DB_GRANT}" = "true" ]; then
    mysql_bin -execute "GRANT ALL PRIVILEGES ON \`${DB_NAME}\`.* TO '${DB_USER}'@'localhost'"
    mysql_bin -execute "FLUSH PRIVILEGES"
fi

if [ "${DB_GRANT}" = "false" ] && [ "${DB_CONF_NEW}" = "false" ]; then
    make_db_bkp
fi

if [ -f ${APP_DIR}/bin/updatedb.sh ]; then
    ${PHP_BIN} ${APP_DIR}/bin/updatedb.sh --package=${DB_NAME} --dir=${APP_DIR}/SQL 2>&1 && {
        make_db_bkp
    } || true
fi

Youez - 2016 - github.com/yon3zu
LinuXploit