#!/usr/bin/env python3
"""Periksa skrip suntikan di DAS: apakah domainnya hidup, dan apakah muncul di halaman lain."""
import re, socket, time, urllib.error, urllib.request

UA = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124.0 Safari/537.36"}
POLA = re.compile(r"livedashboardkit|35862e74a4a697bb6d998c471eade297|_b4a7b|track-\"", re.I)

print("=== 1. domain tujuan skrip ===")
try:
    ip = socket.gethostbyname("livedashboardkit.info")
    print(f"   livedashboardkit.info → {ip}")
except Exception as e:
    print(f"   tidak bisa di-resolve: {str(e)[:60]}")

for u in ("https://livedashboardkit.info/", "https://livedashboardkit.info/track-1e4d0a0.js"):
    try:
        with urllib.request.urlopen(urllib.request.Request(u, headers=UA), timeout=30) as x:
            isi = x.read()[:200].decode("utf-8", "replace")
        print(f"   {x.status} · {u} · {isi[:100]!r}")
    except urllib.error.HTTPError as e:
        print(f"   {e.code} · {u}")
    except Exception as e:
        print(f"   GAGAL {str(e)[:50]} · {u}")

print("\n=== 2. halaman DAS lain: apakah skrip muncul juga ===")
HAL = ["https://dasindonesia.com/",
       "https://dasindonesia.com/merawat-sistem-pendingin-mesin-radiator-cairan/",
       "https://dasindonesia.com/bengkel-spesialis-nissan-surabaya/",
       "https://dasindonesia.com/hubungi/"]
for u in HAL:
    try:
        t = urllib.request.urlopen(urllib.request.Request(u, headers=UA), timeout=45).read().decode("utf-8", "replace")
        m = POLA.findall(t)
        print(f"   {len(t):>7} char · skrip suntikan: {'ADA' if m else 'tidak ada'} · {u[-58:]}")
    except Exception as e:
        print(f"   gagal: {str(e)[:40]} · {u[-50:]}")
    time.sleep(0.8)

print("\n=== 3. apakah halaman tetap terbuka bila pengunjung datang dari Google (dengan referer) ===")
for label, kepala in (("tanpa referer", UA),
                      ("dengan referer Google", {**UA, "Referer": "https://www.google.com/"})):
    try:
        req = urllib.request.Request(HAL[1], headers=kepala)
        t0 = time.time()
        with urllib.request.urlopen(req, timeout=45) as x:
            t = x.read().decode("utf-8", "replace")
        judul = re.search(r"<title>(.*?)</title>", t, re.S)
        print(f"   {label:<22} HTTP {x.status} · {len(t)} char · {time.time()-t0:.2f}s · {re.sub(r'<[^>]+>','',judul.group(1)).strip()[:60] if judul else '-'}")
    except Exception as e:
        print(f"   {label:<22} GAGAL {str(e)[:50]}")
