import asyncio, re
import aiohttp

SITES = ["azleabsolutely.com", "llc.net", "smileshoponline.com", "talkandhra.com",
         "abdatapartnerships.ca", "rogueklamathtransfer.com", "nreach.com", "dockon.com"]
PATHS = ["/", "/contact/", "/contact-us/", "/about/", "/contact", "/quote/", "/get-a-quote/"]
UA = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"}


async def fetch(sess, url, read=200000):
    async with sess.get(url, ssl=False, allow_redirects=True) as r:
        raw = await r.content.read(read)
        return r.status, str(r.url), raw.decode("utf-8", "replace")


async def main():
    tout = aiohttp.ClientTimeout(total=20, connect=8, sock_read=12)
    async with aiohttp.ClientSession(timeout=tout, headers=UA) as s:
        for dom in SITES:
            base = None
            for scheme in ("https", "http"):
                try:
                    st, url, html = await fetch(s, f"{scheme}://{dom}/", 60000)
                    base = f"{scheme}://{dom}"
                    break
                except Exception:
                    continue
            if not base:
                print(f"=== {dom} unreachable", flush=True)
                continue
            print(f"=== {dom} {base}", flush=True)
            seen = set()
            for p in PATHS:
                try:
                    st, url, html = await fetch(s, base + p, 250000)
                except Exception:
                    continue
                if st != 200:
                    continue
                if "wpcf7" not in html.lower():
                    continue
                ids = set(re.findall(r'name="_wpcf7"\s+value="(\d+)"', html))
                aids = set(re.findall(r'id="wpcf7-f(\d+)-', html))
                files = re.findall(r'<input[^>]*type="file"[^>]*name="([^"]+)"', html, re.I)
                accepts = re.findall(r'<input[^>]*accept="([^"]*)"[^>]*>', html)
                act = re.findall(r'<form[^>]*class="[^"]*wpcf7-form[^"]*"[^>]*action="([^"]*)"', html)
                key = (url, tuple(sorted(ids)))
                if key in seen:
                    continue
                seen.add(key)
                print(f"   {url} st={st} cf7_ids={sorted(ids)} form_ids={sorted(aids)} "
                      f"file_fields={files} accept={accepts[:3]} action={act[:1]}", flush=True)
                # also count total file inputs anywhere
                n_file = len(re.findall(r'type="file"', html, re.I))
                if n_file:
                    print(f"      file inputs total: {n_file}", flush=True)
            if not seen:
                print("   no CF7 forms found on probed paths", flush=True)

asyncio.run(main())
