korsygfhrtzangaiide
Elepffwdsff
/
usr
/
lib64
/
monarx-protect
/
Upload FileeE
HOME
#!/usr/bin/env bash mx_dir="$(dirname "$(readlink -f "$0")")" mx_libdir="$(dirname "${mx_dir}")" phpversions_file="${mx_dir}/phpversions.txt" do_enhance() { # Check to see if enchance is installed if [ -d "/var/local/enhance" ]; then echo "Enhance detected. Copying files." enh_php_versions=("php56" "php70" "php71" "php72" "php73" "php74" "php80" "php81" "php82" "php83") # Loop through each PHP version and copy the corresponding .so file for version in "${enh_php_versions[@]}"; do src_file="/usr/lib/monarx-protect/monarxprotect-${version}.so" dest_file="/var/enhance_container_images/${version}/overlay/usr/local/lib/php/extensions/monarxprotect.so" cp "$src_file" "$dest_file" # Should we echo for each file? done fi } message_php_version() { echo '' echo "Detected PHP version $1" echo "($2)" } create_symlink() { if [ ! -f "$2" ] then echo "Creating symlink to extension: $2" ln -s ${mx_dir}/monarxprotect-php$1.so $2 fi } create_extension_ini() { if [ ! -f "$2" ] then echo "Creating extension ini: $2" echo "extension=monarxprotect-php$1.so" > $2 fi } create_ini_symlink() { if [ ! -f "$2" ] then echo "Creating ini symlink: $2" ln -sf "$1" "$2" fi } strip_trailing_slash() { echo "${1%/}" } restart_apache() { if systemctl is-active --quiet httpd; then echo "Restarting Webserver (Apache)."; service httpd restart apache_return_value=$? if [ $apache_return_value -ne 0 ] then echo "Unable to restart Apache. Please restart your webserver for changes to take effect."; fi else if systemctl is-active --quiet apache2; then echo "Restarting Webserver (Apache)."; service apache2 restart apache_return_value=$? if [ $apache_return_value -ne 0 ] then echo "Unable to restart Apache. Please restart your webserver for changes to take effect."; fi else echo "Please restart your webserver for changes to take effect."; fi fi } install() { echo "Adding Monarx to PHP installations" installed=false do_enhance # generic installs if [ -d "/usr/lib64/php/modules/" ] && [ -d "/etc/php.d/" ] then php_command=$(command -v php) php_command_retval=$? if [ "$php_command_retval" -eq 0 ] then php_version=$($php_command -r 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;' 2> /dev/null) php_version_retval=$? if [ -n "$php_version" ] && [ -f "${mx_dir}/monarxprotect-php${php_version//.}.so" ] then message_php_version "$php_version" "/usr/lib64/php/modules" create_symlink ${php_version//.} "/usr/lib64/php/modules/monarxprotect-php${php_version//.}.so" create_extension_ini ${php_version//.} /etc/php.d/monarxprotect.ini installed=true fi fi fi #uninstall php5 for line in $(cat "${phpversions_file}"); do IFS="|" read -ra ADDR <<< "$line" VERSION=${ADDR[0]} LIBDIR=${ADDR[1]} EXTDIR=${ADDR[2]} if [ -d "$LIBDIR" ] && [[ ${VERSION##*/} == 5* ]] ; then # message_php_version "$VERSION" "$LIBDIR" rm -f $LIBDIR/monarxprotect-php${VERSION//.}.so if [ -d "$EXTDIR" ] ; then rm -f $EXTDIR/monarxprotect.ini fi installed=true fi done IFS=$'\n' # curated install list for line in $(cat "${phpversions_file}"); do IFS="|" read -ra tuple <<< "$line" php_version=${tuple[0]} php_libdir="$(strip_trailing_slash "${tuple[1]}")" php_extdir="$(strip_trailing_slash "${tuple[2]}")" php_symdir="$(strip_trailing_slash "${tuple[3]}")" if [ -d "$php_libdir" ] && [[ ${php_version##*/} != 5* ]] then message_php_version "$php_version" "$php_libdir" create_symlink "${php_version//.}" "$php_libdir/monarxprotect-php${php_version//.}.so" if [ -d "$php_extdir" ] then create_extension_ini "${php_version//.}" "$php_extdir/monarxprotect.ini" if [ -n "$php_symdir" -a -d "$php_symdir" ] then create_ini_symlink "$php_extdir/monarxprotect.ini" "$php_symdir/20-monarxprotect.ini" fi fi installed=true fi done IFS=$'\n' #cloudlinux php enable phpversions=("7.0" "7.1" "7.2" "7.3" "7.4" "8.0" "8.1" "8.2" "8.3") if command -v selectorctl &> /dev/null then for phpversion in ${phpversions[@]}; do echo "Enabling monarx extension in CloudLinux for PHP version $phpversion" selectorctl --enable-extensions=monarxprotect --version=$phpversion if selectorctl --enable-user-extensions=monarxprotect --version=$phpversion --for-all-users 2>/dev/null ; then echo "Successfully enabled extension for version $phpversion" else for directoryname in $(ls /home -1 | grep -v '^\.'); do selectorctl --enable-user-extensions=monarxprotect --version=$phpversion --user=$directoryname 2>/dev/null printf "." done printf "\nSuccessfully enabled extension for version $phpversion\n" fi done fi #restart services if [ "$installed" = false ] then echo 'No versions of PHP detected.' else if [ "$(pidof systemd)" ] then for i in $(systemctl list-units php*fpm* | grep active | grep -o -E php.*fpm); do echo "Restarting service $i" systemctl restart "$i" done for i in $(systemctl list-units ea*fpm* | grep active | grep -o -E ea.*fpm); do echo "Restarting service $i" systemctl restart "$i" done fi fi restart_apache } uninstall() { echo "Removing Monarx from PHP installations" installed=false for line in $(cat "${phpversions_file}"); do IFS="|" read -ra ADDR <<< "$line" VERSION=${ADDR[0]} LIBDIR=${ADDR[1]} EXTDIR=${ADDR[2]} if [ -d "$LIBDIR" ] ; then message_php_version "$VERSION" "$LIBDIR" rm -f $LIBDIR/monarxprotect-php${VERSION//.}.so if [ -d "$EXTDIR" ] ; then rm -f $EXTDIR/monarxprotect.ini fi installed=true fi done IFS=$'\n' if [ "$installed" = false ] ; then echo 'No versions of PHP detected for uninstallation.' else if [ "$(pidof systemd)" ] then for i in $(systemctl list-units php*fpm* | grep active | grep -o -E php.*fpm); do echo "Restarting service $i." systemctl restart "$i" done fi # Restart FPM if [ -f /usr/local/cpanel/scripts/restartsrv_apache_php_fpm ]; then echo "Restarting cPanel PHP FPM."; /usr/local/cpanel/scripts/restartsrv_apache_php_fpm fi # Restart cPanel FPM if [ -f /usr/local/cpanel/scripts/restartsrv_cpanel_php_fpm ]; then echo "Restarting cPanel PHP FPM."; /usr/local/cpanel/scripts/restartsrv_cpanel_php_fpm fi fi restart_apache } if [ "$1" = "-u" ] ; then uninstall else install fi