115 lines
4.7 KiB
Python
115 lines
4.7 KiB
Python
import os, re, json, subprocess
|
||
|
||
MC_LOG = "/var/lib/pterodactyl/volumes/bd102f43-4033-4c60-9922-53c436330f21/logs/latest.log"
|
||
REG_FILE = "/var/www/flexicraft-site/config/packages_registry.json"
|
||
|
||
API_OVERRIDES = {
|
||
"essentials": ("modrinth", "essentialsx"),
|
||
"essentialschat": ("modrinth", "essentialsx"),
|
||
"essentialsspawn": ("modrinth", "essentialsx"),
|
||
"coreprotect": ("modrinth", "coreprotect"),
|
||
"geyser-spigot": ("hangar", "GeyserMC/Geyser"),
|
||
"floodgate": ("hangar", "GeyserMC/Floodgate"),
|
||
"viaversion": ("modrinth", "viaversion"),
|
||
"viabackwards": ("modrinth", "viabackwards"),
|
||
"luckperms": ("modrinth", "luckperms"),
|
||
"vault": ("modrinth", "vaultunlocked"),
|
||
"fastloginplus": ("github", "Hayston1001/FastLoginPlus"),
|
||
"protocollib": ("hangar", "dmulloy2/ProtocolLib"),
|
||
"bettermending": ("modrinth", "better-mending"),
|
||
"betterconcrete": ("spigot", "81386")
|
||
}
|
||
|
||
def curl_json(url):
|
||
cmd = ["curl", "-4", "-fsSL", "--connect-timeout", "5", "-A", "FlexiCraft-Audit/1.0", url]
|
||
try:
|
||
out = subprocess.check_output(cmd, stderr=subprocess.DEVNULL).decode("utf-8")
|
||
return json.loads(out)
|
||
except Exception:
|
||
return None
|
||
|
||
def get_latest_version(prov, slug):
|
||
if not slug:
|
||
return None
|
||
if prov == "modrinth":
|
||
data = curl_json(f"https://modrinth.com{slug}/version?loaders=%5B%22paper%22,%22spigot%22%5D")
|
||
if isinstance(data, list) and data:
|
||
first_item = next(iter(data))
|
||
return str(first_item.get("version_number"))
|
||
elif prov == "hangar":
|
||
owner_slug = slug if "/" in slug else f"PaperMC/{slug}"
|
||
cmd = ["curl", "-4", "-fsSL", "--connect-timeout", "5", "-A", "FlexiCraft-Audit/1.0", f"https://papermc.io{owner_slug}/latestrelease"]
|
||
try:
|
||
return subprocess.check_output(cmd, stderr=subprocess.DEVNULL).decode("utf-8").strip().strip('"')
|
||
except Exception:
|
||
return None
|
||
elif prov == "github":
|
||
data = curl_json(f"https://github.com{slug}/releases/latest")
|
||
if isinstance(data, dict):
|
||
return str(data.get("tag_name") or "").lstrip("v")
|
||
elif prov == "spigot":
|
||
*_, res_id = slug.split(".")
|
||
data = curl_json(f"https://spiget.org{res_id}/versions/latest")
|
||
if isinstance(data, dict):
|
||
return str(data.get("name") or "")
|
||
return None
|
||
|
||
def norm_ver(v):
|
||
clean = re.sub(r"^v", "", str(v or "").strip().lower())
|
||
clean, _, _ = clean.partition("+")
|
||
clean, _, _ = clean.partition("-snapshot")
|
||
return clean
|
||
|
||
log_txt = ""
|
||
if os.path.exists(MC_LOG):
|
||
with open(MC_LOG, "r", encoding="utf-8", errors="ignore") as f:
|
||
log_txt = f.read()
|
||
|
||
broken, partial, up_avail, up_to_date, manual_check = [], [], [], [], []
|
||
|
||
with open(REG_FILE, "r", encoding="utf-8") as f:
|
||
pkgs = json.load(f).get("packages", [])
|
||
|
||
for p in pkgs:
|
||
name = p.get("name", "")
|
||
ptype = p.get("type", "")
|
||
cur_v = p.get("version", "")
|
||
|
||
if ptype == "datapack":
|
||
ns_list = p.get("dependencies", {}).get("namespaces", [])
|
||
failed_funcs = [ns for ns in ns_list if ns != "vanillatweaks" and f"Failed to load function {ns}:" in log_txt]
|
||
if failed_funcs:
|
||
partial.append(f"{name} (fonctions 1.21.11 en erreur : {', '.join(failed_funcs)})")
|
||
elif "1.17" in p.get("mc_compatibility", ""):
|
||
partial.append(f"{name} (format ancien {p.get('mc_compatibility')})")
|
||
else:
|
||
up_avail.append(f"{name} (cible 1.21.10 -> pack 1.21.11 dispo sur VanillaTweaks)")
|
||
continue
|
||
|
||
if re.search(rf"Error occurred while enabling {re.escape(name)}|Could not load.*{re.escape(name)}", log_txt, re.IGNORECASE):
|
||
broken.append(f"{name} (v{cur_v}) -> Erreur critique au chargement")
|
||
continue
|
||
|
||
ext = p.get("external", {})
|
||
prov, slug = API_OVERRIDES.get(p.get("id", ""), (ext.get("provider", ""), ext.get("slug", "")))
|
||
lat_v = get_latest_version(prov, slug)
|
||
if not lat_v:
|
||
manual_check.append(f"{name} (v{cur_v})")
|
||
elif norm_ver(lat_v) != norm_ver(cur_v) and norm_ver(cur_v) not in norm_ver(lat_v):
|
||
up_avail.append(f"{name} : v{cur_v} -> v{lat_v} ({prov})")
|
||
else:
|
||
up_to_date.append(f"{name} (v{cur_v})")
|
||
|
||
print("=== 1. NE FONCTIONNENT PAS (BLOQUANTS) ===")
|
||
print("\n".join(f" ❌ {x}" for x in broken) or " Aucun")
|
||
|
||
print("\n=== 2. FONCTIONNENT PARTIELLEMENT (ERREURS DE FONCTIONS / ANCIEN FORMAT) ===")
|
||
print("\n".join(f" ⚠️ {x}" for x in partial) or " Aucun")
|
||
|
||
print("\n=== 3. FONCTIONNENT MAIS MISE A JOUR DISPONIBLE ===")
|
||
print("\n".join(f" 🔄 {x}" for x in up_avail) or " Aucun")
|
||
|
||
print("\n=== 4. A JOUR / NON VERIFIABLES AUTO ===")
|
||
print(f" ✅ A jour ({len(up_to_date)}) : {', '.join(up_to_date)}")
|
||
if manual_check:
|
||
print(f" ℹ️ Manuel ({len(manual_check)}) : {', '.join(manual_check)}")
|