#!/usr/bin/env python3
import sys, os, json, re
import requests
requests.packages.urllib3.disable_warnings()
BIN=os.path.dirname(os.path.abspath(__file__)); CK=os.path.join(BIN,"ck.json")
HOST="https://eee.ruet.ac.bd"; BASE=HOST+"/index.php"
S=requests.Session(); S.verify=False; S.trust_env=False
S.headers.update({"User-Agent":"Mozilla/5.0 Chrome/131.0","Accept":"text/html"})
if os.path.exists(CK):
    for k,v in json.load(open(CK)).items(): S.cookies.set(k,v)
paths=sys.argv[1:]
for p in paths:
    try:
        r=S.get(BASE+p,timeout=30,allow_redirects=False)
        body=r.text
        t=re.search(r'<title>(.*?)</title>',body,re.S)
        title=t.group(1).strip()[:60] if t else "?"
        loc=r.headers.get("location","")
        # count file inputs and forms
        fi=len(re.findall(r'type="file"',body)); fm=len(re.findall(r'<form',body))
        print("%-40s %s len=%d loc=%s | forms=%d file=%d | %s"%(p,r.status_code,len(r.content),loc[:40],fm,fi,title))
    except Exception as e:
        print("%-40s ERR %s"%(p,type(e).__name__))
json.dump({c.name:c.value for c in S.cookies}, open(CK,"w"))

