"""verifyRecaptcha() ne refuse plus : renvoie true, note le doute.
Usage : python3 fix_vr.py [--apply] fichier...
"""
import sys, shutil, re
APPLY = "--apply" in sys.argv
for f in [a for a in sys.argv[1:] if a != "--apply"]:
    s = open(f, encoding="utf-8", errors="surrogateescape").read()
    if "rc-souple-20261106" in s:
        print("DEJA", f); continue
    m = re.search(r"function verifyRecaptcha\(.*?\n\}", s, re.S)
    if not m:
        print("PAS_DE_FONCTION", f); continue
    body = m.group(0)
    rep = ("{ /* rc-souple-20261106 */ $GLOBALS['RC_FLAG'] = 'reCAPTCHA douteux'; "
           "@error_log('[verifyRecaptcha] doute (envoye quand meme)'); return true; }")
    nb, n = re.subn(r"return false;", rep, body)
    if n == 0:
        print("RIEN", f); continue
    print("OK", n, f)
    if APPLY:
        shutil.copy2(f, f + ".bak-recaptcha-20261106")
        with open(f, "r+", encoding="utf-8", errors="surrogateescape") as fh:
            fh.seek(0); fh.write(s.replace(body, nb, 1)); fh.truncate()
