ROOTPLOIT
Server: Apache
System: Linux node6122.myfcloud.com 6.14.3-x86_64-linode168 #1 SMP PREEMPT_DYNAMIC Mon Apr 21 19:47:55 EDT 2025 x86_64
User: bashacomputer (1004)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib64/nagios/plugins/check_a2_redis_opcache.shared
#!/bin/bash

# Ref: BFENG-1101
# To verify that redis and opcache extensions are available in the specified php versions.

# Exit if isn't cPanel
if [ ! -s "/usr/local/cpanel/version" ]; then
    exit
fi

_php_versions_list=("5.2" "5.3" "5.4" "5.5" "5.6" "7.0" "7.1" "7.2" "7.3" "7.4" "8.0" "8.1" "8.2" "8.3")
_php_missing_opcache=""
_php_missing_redis=""

for _php_version in "${_php_versions_list[@]}"
do
  _php_extensions=$(selectorctl --interpreter=php --list-extensions --version=$_php_version | grep -wE 'opcache|redis')
  if [[ $_php_extensions != *"+ opcache"* ]]; then
    _php_missing_opcache+="$_php_version, "
  fi
  if [[ $_php_extensions != *"+ redis"* ]]; then
    _php_missing_redis+="$_php_version, "
  fi
done

if [[ -z $_php_missing_opcache && -z $_php_missing_redis ]]; then
  echo "check_redis_opcache - All PHP versions have opcache and redis extensions enabled."
  exit 0
else
  if [[ -n $_php_missing_opcache && -n $_php_missing_redis ]]; then
    echo "check_redis_opcache - PHP ${_php_missing_opcache%, } missing opcache extension and PHP ${_php_missing_redis%, } missing redis extension."
    exit 2
  elif [[ -n $_php_missing_opcache ]]; then
    echo "check_redis_opcache - PHP ${_php_missing_opcache%, } missing opcache extension."
    exit 2
  elif [[ -n $_php_missing_redis ]]; then
    echo "check_redis_opcache - PHP ${_php_missing_redis%, } missing redis extension."
    exit 2
  fi
fi