HEX
Server: Apache/2.4.65 (Unix) OpenSSL/1.1.1k
System: Linux vps109042.inmotionhosting.com 4.18.0 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64
User: cisa (1010)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //opt/cwprads/cwp_ini_update.sh
#!/bin/bash

# Grab the timezone from timedatectl and prompt the agent to set it in CWP admin panel if needed
zone=$(timedatectl | awk '/Time zone/ {print $3}')
echo -e "Timezone detected as: $zone \n"

if [[ "$zone" != *"/"* ]]; then
  echo "Timezone detected as ('$zone'). Format wrong please correct via 'Change Server Date & Time' in CWP Admin and resubmit"
    exit 1
fi

# Grab a list of php.ini files on the server, print that list and then confirm the user wants to proceed with the update
echo "Searching for ini files, this may take a few minutes..."
ini_list=$(find / -type f -name php.ini 2>/dev/null)

echo "The following php.ini files were found:"
echo -e "$ini_list \n"

read -r -p "Do you want to update these files to use the server timezone ($zone)? [y/n]: " response
if [[ ! "$response" =~ ^[Yy]$ ]]; then
  echo "No changes were made."
    exit 0
fi

# Update date.timezone in each php.ini file
echo -e "\nUpdating php.ini files, please standby...\n"
for file in $ini_list;
  do
    echo "Modifying $file"
if grep -q "^[^#]*date\.timezone" "$file"; then
    sed -i "s|date\.timezone\s*=.*|date.timezone = ${zone}|g" "${file}"
    echo "Updated date.timezone in $file"
else
  echo "date.timezone = ${zone}" > "${file}"
  echo "Appended date.timezone to $file"
fi
done

echo -e "\nAll php.ini updates completed."

# Grab a list of PHP-FPM services and restart each of them
php_services=$(systemctl list-units --type=service --state=running | grep "^php-fpm" |awk '{print $1}')

echo -e "\nRestarting the following PHP-FPM services:"
echo -e "$php_services \n"
for service in $php_services;
  do
  echo "Restarting $service"
  sudo systemctl restart "$service"
done

# Restart CWP
echo -e "\nRestarting CWP"
sudo /scripts/restart_cwpsrv

echo -e "\nAll Changes Completed :)"