mirror of
https://github.com/myvesta/vesta.git
synced 2024-11-22 21:40:20 -08:00
182 lines
6.8 KiB
Bash
182 lines
6.8 KiB
Bash
#!/bin/bash
|
|
|
|
# info: get database credentials and other basic data of domain
|
|
# options: DOMAIN [SUBFOLDER]
|
|
#
|
|
# The function get database credentials and other basic data of domain.
|
|
|
|
#----------------------------------------------------------#
|
|
# Variable&Function #
|
|
#----------------------------------------------------------#
|
|
|
|
whoami=$(whoami)
|
|
if [ "$whoami" != "root" ]; then
|
|
echo "You must be root to execute this script"
|
|
exit 1
|
|
fi
|
|
|
|
# Argument definition
|
|
DOMAIN=$1
|
|
SUBFOLDER=''
|
|
if [ $# -gt 1 ]; then
|
|
SUBFOLDER=$2
|
|
fi
|
|
|
|
# Importing system environment
|
|
source /etc/profile
|
|
|
|
# Includes
|
|
source /usr/local/vesta/func/main.sh
|
|
source /usr/local/vesta/func/db.sh
|
|
|
|
#----------------------------------------------------------#
|
|
# Verifications #
|
|
#----------------------------------------------------------#
|
|
|
|
check_args '1' "$#" 'DOMAIN [SUBFOLDER]'
|
|
is_domain_format_valid "$DOMAIN"
|
|
|
|
USER=$(/usr/local/vesta/bin/v-search-domain-owner "$DOMAIN")
|
|
if [ -z "$USER" ]; then
|
|
echo "Error: domain $DOMAIN does not exists"
|
|
exit 2
|
|
fi
|
|
|
|
#----------------------------------------------------------#
|
|
# Action #
|
|
#----------------------------------------------------------#
|
|
|
|
PUBLIC_HTML='public_html';
|
|
CHECK_PUBLIC_SHTML=$(/usr/local/vesta/bin/v-list-web-domain "$USER" "$DOMAIN" | grep 'SSL:' | grep -c 'single')
|
|
if [ $CHECK_PUBLIC_SHTML -eq 1 ]; then
|
|
PUBLIC_HTML='public_shtml';
|
|
fi
|
|
SITE_FOLDER="/home/$USER/web/$DOMAIN/$PUBLIC_HTML"
|
|
|
|
if [ ! -z "$SUBFOLDER" ]; then
|
|
SITE_FOLDER="${SITE_FOLDER}/${SUBFOLDER}"
|
|
fi
|
|
|
|
CMS_TYPE=''
|
|
|
|
if [ -f "$SITE_FOLDER/wp-config.php" ]; then
|
|
CMS_TYPE='wordpress'
|
|
CONFIG_FILE="wp-config.php"
|
|
CONFIG_FILE_FULL_PATH="$SITE_FOLDER/$CONFIG_FILE"
|
|
fi
|
|
if [ -f "$SITE_FOLDER/configuration.php" ]; then
|
|
CMS_TYPE='joomla'
|
|
CONFIG_FILE="configuration.php"
|
|
CONFIG_FILE_FULL_PATH="$SITE_FOLDER/$CONFIG_FILE"
|
|
fi
|
|
if [ -f "$SITE_FOLDER/system/engine/model.php" ]; then
|
|
check_grep=$(grep -c 'OpenCart' $SITE_FOLDER/system/engine/model.php)
|
|
if [ "$check_grep" -gt 0 ]; then
|
|
CMS_TYPE='opencart'
|
|
CONFIG_FILE="$PUBLIC_HTML/config.php"
|
|
SUBFOLDER='..'
|
|
SITE_FOLDER="${SITE_FOLDER}/.."
|
|
CONFIG_FILE_FULL_PATH="$SITE_FOLDER/$CONFIG_FILE"
|
|
fi
|
|
fi
|
|
|
|
if [ "$CMS_TYPE" = "wordpress" ]; then
|
|
CONFIG_FILE_FULL_PATH_BACKUP="${CONFIG_FILE_FULL_PATH}_backup"
|
|
cp $CONFIG_FILE_FULL_PATH $CONFIG_FILE_FULL_PATH_BACKUP
|
|
sed -i "s|//.*$||g" $CONFIG_FILE_FULL_PATH_BACKUP
|
|
sed -i "s|\"|'|g" $CONFIG_FILE_FULL_PATH_BACKUP
|
|
sed -i "s|('|( '|g" $CONFIG_FILE_FULL_PATH_BACKUP
|
|
sed -i "s|');|' );|g" $CONFIG_FILE_FULL_PATH_BACKUP
|
|
DATABASE_NAME=$(grep 'DB_NAME' $CONFIG_FILE_FULL_PATH_BACKUP | awk '{print $3}' | sed -e "s/^'//" -e "s/'$//")
|
|
DATABASE_USERNAME=$(grep 'DB_USER' $CONFIG_FILE_FULL_PATH_BACKUP | awk '{print $3}' | sed -e "s/^'//" -e "s/'$//")
|
|
DATABASE_PASSWORD=$(grep 'DB_PASSWORD' $CONFIG_FILE_FULL_PATH_BACKUP | awk '{print $3}' | sed -e "s/^'//" -e "s/'$//")
|
|
DATABASE_HOSTNAME=$(grep 'DB_HOST' $CONFIG_FILE_FULL_PATH_BACKUP | awk '{print $3}' | sed -e "s/^'//" -e "s/'$//")
|
|
rm $CONFIG_FILE_FULL_PATH_BACKUP
|
|
fi
|
|
|
|
if [ "$CMS_TYPE" = "joomla" ]; then
|
|
CONFIG_FILE_FULL_PATH_BACKUP="${CONFIG_FILE_FULL_PATH}_backup"
|
|
cp $CONFIG_FILE_FULL_PATH $CONFIG_FILE_FULL_PATH_BACKUP
|
|
sed -i "s|//.*$||g" $CONFIG_FILE_FULL_PATH_BACKUP
|
|
sed -i "s|='|= '|g" $CONFIG_FILE_FULL_PATH_BACKUP
|
|
sed -i "s|= '| = '|g" $CONFIG_FILE_FULL_PATH_BACKUP
|
|
sed -i "s| =| =|g" $CONFIG_FILE_FULL_PATH_BACKUP
|
|
sed -i "s|';$|'|g" $CONFIG_FILE_FULL_PATH_BACKUP
|
|
DATABASE_NAME=$(grep 'public $db ' $CONFIG_FILE_FULL_PATH_BACKUP | awk '{print $4}' | sed -e "s/^'//" -e "s/'$//")
|
|
DATABASE_USERNAME=$(grep 'public $user ' $CONFIG_FILE_FULL_PATH_BACKUP | awk '{print $4}' | sed -e "s/^'//" -e "s/'$//")
|
|
DATABASE_PASSWORD=$(grep 'public $password ' $CONFIG_FILE_FULL_PATH_BACKUP | awk '{print $4}' | sed -e "s/^'//" -e "s/'$//")
|
|
DATABASE_HOSTNAME=$(grep 'public $host ' $CONFIG_FILE_FULL_PATH_BACKUP | awk '{print $4}' | sed -e "s/^'//" -e "s/'$//")
|
|
rm $CONFIG_FILE_FULL_PATH_BACKUP
|
|
fi
|
|
|
|
if [ "$CMS_TYPE" = "opencart" ]; then
|
|
CONFIG_FILE_FULL_PATH_BACKUP="${CONFIG_FILE_FULL_PATH}_backup"
|
|
cp $CONFIG_FILE_FULL_PATH $CONFIG_FILE_FULL_PATH_BACKUP
|
|
sed -i "s|//.*$||g" $CONFIG_FILE_FULL_PATH_BACKUP
|
|
sed -i "s|('|( '|g" $CONFIG_FILE_FULL_PATH_BACKUP
|
|
sed -i "s|');|' );|g" $CONFIG_FILE_FULL_PATH_BACKUP
|
|
DATABASE_NAME=$(grep 'DB_DATABASE' $CONFIG_FILE_FULL_PATH_BACKUP | awk '{print $3}' | sed -e "s/^'//" -e "s/'$//")
|
|
DATABASE_USERNAME=$(grep 'DB_USERNAME' $CONFIG_FILE_FULL_PATH_BACKUP | awk '{print $3}' | sed -e "s/^'//" -e "s/'$//")
|
|
DATABASE_PASSWORD=$(grep 'DB_PASSWORD' $CONFIG_FILE_FULL_PATH_BACKUP | awk '{print $3}' | sed -e "s/^'//" -e "s/'$//")
|
|
DATABASE_HOSTNAME=$(grep 'DB_HOST' $CONFIG_FILE_FULL_PATH_BACKUP | awk '{print $3}' | sed -e "s/^'//" -e "s/'$//")
|
|
rm $CONFIG_FILE_FULL_PATH_BACKUP
|
|
fi
|
|
|
|
|
|
if [ ! -z "$DATABASE_NAME" ]; then
|
|
DATABASE_NAME_WITHOUT_USER_PREFIX=$(get_database_name_without_user_prefix "$USER" "$DATABASE_NAME")
|
|
fi
|
|
if [ ! -z "$DATABASE_USERNAME" ]; then
|
|
DATABASE_USERNAME_WITHOUT_USER_PREFIX=$(get_database_name_without_user_prefix "$USER" "$DATABASE_USERNAME")
|
|
fi
|
|
|
|
DATABASE_NAME_WITHOUT_USER_PREFIX=$(escape_shell_quote $DATABASE_NAME_WITHOUT_USER_PREFIX)
|
|
echo "DATABASE_NAME_WITHOUT_USER_PREFIX=$DATABASE_NAME_WITHOUT_USER_PREFIX"
|
|
|
|
DATABASE_USERNAME_WITHOUT_USER_PREFIX=$(escape_shell_quote $DATABASE_USERNAME_WITHOUT_USER_PREFIX)
|
|
echo "DATABASE_USERNAME_WITHOUT_USER_PREFIX=$DATABASE_USERNAME_WITHOUT_USER_PREFIX"
|
|
|
|
DATABASE_NAME=$(escape_shell_quote $DATABASE_NAME)
|
|
echo "DATABASE_NAME=$DATABASE_NAME"
|
|
|
|
DATABASE_USERNAME=$(escape_shell_quote $DATABASE_USERNAME)
|
|
echo "DATABASE_USERNAME=$DATABASE_USERNAME"
|
|
|
|
DATABASE_PASSWORD=$(escape_shell_quote $DATABASE_PASSWORD)
|
|
echo "DATABASE_PASSWORD=$DATABASE_PASSWORD"
|
|
|
|
DATABASE_HOSTNAME=$(escape_shell_quote $DATABASE_HOSTNAME)
|
|
echo "DATABASE_HOSTNAME=$DATABASE_HOSTNAME"
|
|
|
|
CONFIG_FILE_FULL_PATH=$(escape_shell_quote $CONFIG_FILE_FULL_PATH)
|
|
echo "CONFIG_FILE_FULL_PATH=$CONFIG_FILE_FULL_PATH"
|
|
|
|
CONFIG_FILE=$(escape_shell_quote $CONFIG_FILE)
|
|
echo "CONFIG_FILE=$CONFIG_FILE"
|
|
|
|
CMS_TYPE=$(escape_shell_quote $CMS_TYPE)
|
|
echo "CMS_TYPE=$CMS_TYPE"
|
|
|
|
SITE_FOLDER=$(escape_shell_quote $SITE_FOLDER)
|
|
echo "SITE_FOLDER=$SITE_FOLDER"
|
|
|
|
SUBFOLDER=$(escape_shell_quote $SUBFOLDER)
|
|
echo "SITE_SUBFOLDER=$SUBFOLDER"
|
|
|
|
USER=$(escape_shell_quote $USER)
|
|
echo "SITE_USER=$USER"
|
|
|
|
if [ "$CMS_TYPE" = "'opencart'" ]; then
|
|
echo "SEARCH_FOR_CONFIGS_DATABASE_NAME=1"
|
|
echo "SEARCH_FOR_CONFIGS_DATABASE_USERNAME=1"
|
|
fi
|
|
|
|
#----------------------------------------------------------#
|
|
# Vesta #
|
|
#----------------------------------------------------------#
|
|
|
|
# Logging
|
|
log_event "$OK" "$ARGUMENTS"
|
|
|
|
exit
|