0x1949 Team - FAZEMRX - MANAGER
Edit File: wp-toolkit-cpanel.preinst
### Copyright 1999-2021. Plesk International GmbH. All rights reserved. [ -z "$WP_TOOLKIT_INSTALLER_DEBUG" ] || set -x [ -z "$WP_TOOLKIT_INSTALLER_STRICT_MODE" ] || set -e create_wp_toolkit_user() { # Check that WPT user exist and create in case of absence /usr/bin/getent passwd wp-toolkit >/dev/null 2>&1 || /usr/sbin/useradd --user-group --system --shell /bin/false -d /usr/local/cpanel/3rdparty/wp-toolkit/var wp-toolkit } chown_var_directory() { chown -R wp-toolkit:wp-toolkit /usr/local/cpanel/3rdparty/wp-toolkit/var 2>/dev/null } configure_sudo() { # Allow sudo without password prompt cat << EOF > /etc/sudoers.d/48-wp-toolkit # Rules for wp-toolkit system user. # WPT needs ability to impersonate other system users to perform WordPress management and maintenance # tasks under the system users who own the affected WordPress installations. wp-toolkit ALL=(ALL) NOPASSWD:ALL Defaults:wp-toolkit secure_path = /sbin:/bin:/usr/sbin:/usr/bin Defaults:wp-toolkit !requiretty EOF } validate_sudo_configuration() { # Verify that sudo works, check performed in non-interactive mode to avoid password prompts su -s /bin/bash wp-toolkit -c 'sudo -n -l' if [ $? -ne 0 ]; then echo "##############################################################################" echo "# ERROR #" echo "# #" echo "# WP Toolkit installer has detected that \"sudo\" configuration #" echo "# does not conform to WP Toolkit requirements, #" echo "# so user action is required. #" echo "# #" echo "# WP Toolkit uses sudo for passwordless impersonation, #" echo "# creating a /etc/sudoers.d/48-wp-toolkit file with #" echo "# configuration for wp-toolkit user. #" echo "# #" echo "# Make sure that /etc/sudoers file has the following include: #" echo "# \"#includedir /etc/sudoers.d\" and run WP Toolkit #" echo "# installation again. #" echo "# #" echo "# If WP Toolkit installation fails after applying the advice above, #" echo "# perform the following steps to make sure that WP Toolkit will be #" echo "# able to escalate privileges using \"sudo\" utility: #" echo "# #" echo "# 1. Log in to the server under \"root\" user #" echo "# 2. Create test user by running \"adduser mytestuser\" command #" echo "# 3. Create file /etc/sudoers.d/00-mytestuser with the following content: #" echo "# mytestuser ALL=(ALL) NOPASSWD:ALL #" echo "# Defaults:mytestuser secure_path = /sbin:/bin:/usr/sbin:/usr/bin #" echo "# Defaults:mytestuser !requiretty #" echo "# 4. Ensure that the following command is executed without errors: #" echo "# \"su -s /bin/bash mytestuser -c 'sudo -n -l'\" #" echo "# Note: make sure to execute \"echo \$?\" after command and verify #" echo "# that it shows \"0\" #" echo "# 5. Remove test user by running \"userdel -r mytestuser\" command #" echo "# 6. Remove the /etc/sudoers.d/00-mytestuser file #" echo "# #" echo "# If command returns non-zero exit code, you will need to modify your #" echo "# sudo configuration so that WP Toolkit can escalate #" echo "# privileges via \"sudo\". #" echo "# Once you've ensured that sudo configuration is correct, run #" echo "# WP Toolkit installation again. #" echo "# #" echo "##############################################################################" exit 1 fi } case "$1" in install) create_wp_toolkit_user chown_var_directory configure_sudo validate_sudo_configuration ;; upgrade) ;; abort-upgrade) ;; *) echo "preinst called with unknown argument \`$1'" >&2 exit 1 ;; esac exit 0