def newReqAuth(userIp, username, password, reqId, challenge, secret, basip, serialNo=None, chap=True): """0x03""" pkt = PortalV2.newMessage(REQ_AUTH, userIp, (serialNo or CurrentSN()), reqId, secret, chap=chap) username = pktutils.EncodeString(username) password = pktutils.EncodeString(password) bas_addr = pktutils.EncodeAddress(basip) if chap: _reqid = struct.pack('>H', reqId) chap_pwd = md5_constructor( "%s%s%s" % (_reqid[1], password, challenge)).digest() pkt.attrNum = 4 pkt.attrs = [(0x01, username), (0x04, chap_pwd), (0x03, challenge), (0x0a, bas_addr)] else: pkt.attrNum = 3 pkt.attrs = [(0x01, username), (0x02, password), (0x0a, bas_addr)] pkt.auth_packet() return pkt
def newNtfHeart(secret, basip): """0x0f NTF_HEARTBEAT""" pkt = PortalV2.newMessage(NTF_HEARTBEAT, '0.0.0.0', CurrentSN(), 0, secret) bas_addr = pktutils.EncodeAddress(basip) pkt.attrNum = 1 pkt.attrs = [(0x0a, bas_addr)] pkt.auth_packet() return pkt
def newReqLogout(userIp, secret, basip, serialNo=None): """0x05""" pkt = PortalV2.newMessage(REQ_LOGOUT, userIp, (serialNo or CurrentSN()), 0, secret) bas_addr = pktutils.EncodeAddress(basip) pkt.attrNum = 1 pkt.attrs = [(0x0a, bas_addr)] pkt.auth_packet() return pkt
def newAffAckAuth(userIp, secret, basip, serialNo=None, reqId=None): """0x07""" pkt = PortalV2.newMessage(AFF_ACK_AUTH, userIp, (serialNo or CurrentSN()), (reqId or 0), secret) bas_addr = pktutils.EncodeAddress(basip) pkt.attrNum = 1 pkt.attrs = [(0x0a, bas_addr)] pkt.auth_packet() return pkt
def newMessage( typ, userIp, serialNo, reqId, secret, auth='\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' ): return PortalV2(type=typ, userIp=pktutils.EncodeAddress(userIp), serialNo=serialNo, reqId=reqId, auth=auth, secret=six.b(secret))
def newMessage( typ, userIp, serialNo, reqId, secret, auth='\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', chap=True): isChap = 0x01 if chap: isChap = 0x00 return PortalV2( type=typ, isChap=isChap, userIp=pktutils.EncodeAddress(userIp), serialNo=serialNo, reqId=reqId, # auth = auth, secret=six.b(secret))