Mirror del Joomla antiguo: versionar los scripts y reponer los assets que faltaban

Los scripts del mirror (00-90) vivian solo en el disco. Van al repo; los datos que
generan no (16 GB entre crawl, snapshot del origen y Joomla restaurado) -> .gitignore.

Nuevo 91-repone-assets404.sh: repone los ficheros que el crawl no capturo porque se
referencian SOLO desde CSS y el crawler seguia enlaces HTML (system.css, los fondos de
fe_adulta_1, ratingstars.gif de K2). Salian como 404 en los logs de nginx del Hetzner.

Descarga por HTTP desde el Joomla local aislado, nunca del filesystem -- mismo principio
que el crawl, para no arrastrar los .php comprometidos del #183 -- y escanea PHP embebido
antes de copiar a site/.

Resultado sobre las 286 rutas unicas con 404 del log: 196 repuestas y verificadas en
produccion (196/196 en 200 tras el rsync), 82 que dan 301->404 tambien en el origen (ya
estaban rotas en la web original) y 8 rutas basura /%22/... de HTML mal formado.

Refs #180

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-31 14:04:31 -04:00
parent 69e849d38e
commit 275aff1430
71 changed files with 2667 additions and 0 deletions
@@ -0,0 +1,94 @@
#!/usr/bin/env python3
"""Pase B (1/2): extrae de las paginas capturadas los enlaces internos.
Salidas en el directorio de la corrida:
assets-input.txt URLs internas a recursos NO html (css, js, img, pdf, mp3, doc...)
missing-pages.txt paginas .html internas enlazadas que NO estan en el inventario
external-hosts.txt hosts externos referenciados, con recuento
"""
import os, re, sys, html
from collections import Counter
from urllib.parse import urljoin, urlsplit, urlunsplit
BASE = "/home/rafa/joomla-migration/mirror-antiguo"
RUN = open(os.path.join(BASE, "CURRENT_RUN")).read().strip()
DIR = os.path.join(BASE, "runs", RUN)
RAW = os.path.join(DIR, "raw", "antiguo.feadulta.com")
HOST = "antiguo.feadulta.com"
ATTR = re.compile(rb'(?:href|src|data-src|poster)\s*=\s*["\']([^"\'>]+)["\']', re.I)
CSSURL = re.compile(rb'url\(\s*["\']?([^"\')]+)["\']?\s*\)', re.I)
SKIP_SCHEMES = ("mailto:", "javascript:", "tel:", "data:", "#", "skype:", "whatsapp:")
inventory = set()
for line in open(os.path.join(BASE, "inventory", "urls-input.txt")):
inventory.add(line.strip())
assets, pages, ext = set(), set(), Counter()
nfiles = 0
def norm(u, page_url):
u = html.unescape(u.strip())
if not u or u.startswith(SKIP_SCHEMES):
return None
absu = urljoin(page_url, u)
p = urlsplit(absu)
if p.scheme not in ("http", "https"):
return None
if p.netloc.split(":")[0] != HOST:
ext[p.netloc] += 1
return None
# sin fragmento; conservamos query (rara en assets)
return urlunsplit(("http", HOST, p.path, p.query, ""))
for root, _dirs, files in os.walk(RAW):
for fn in files:
path = os.path.join(root, fn)
rel = os.path.relpath(path, RAW)
page_url = "http://%s/%s" % (HOST, rel.replace(os.sep, "/"))
if not fn.lower().endswith((".html", ".htm")):
continue
nfiles += 1
try:
data = open(path, "rb").read()
except OSError:
continue
found = ATTR.findall(data) + CSSURL.findall(data)
for raw in found:
try:
u = norm(raw.decode("utf-8", "replace"), page_url)
except ValueError:
continue
if not u:
continue
tail = urlsplit(u).path.lower()
if tail.endswith((".html", ".htm")) or tail.endswith("/"):
if u not in inventory:
pages.add(u)
else:
assets.add(u)
def dump(name, it):
p = os.path.join(DIR, name)
with open(p, "w") as f:
for x in sorted(it):
f.write(x + "\n")
return p, len(it)
print("paginas HTML analizadas:", nfiles)
for n, c in (dump("assets-input.txt", assets), dump("missing-pages.txt", pages)):
print(n, c)
with open(os.path.join(DIR, "external-hosts.txt"), "w") as f:
for h, c in ext.most_common():
f.write("%7d %s\n" % (c, h))
print("hosts externos distintos:", len(ext))
# reparto de assets por extension
c = Counter()
for u in assets:
e = os.path.splitext(urlsplit(u).path)[1].lower() or "(sin ext)"
c[e] += 1
print("--- assets por extension ---")
for e, n in c.most_common(25):
print("%7d %s" % (n, e))