def newNtfHeart(secret, basip = None, chap = True, mac = None): """0x0f NTF_HEARTBEAT""" pkt = Portal.newMessage(NTF_HEARTBEAT, '0.0.0.0', CurrentSN(), 0, secret, chap=chap) bas_addr = basip and pktutils.EncodeAddress(basip) or None if bas_addr: pkt.attrNum = 1 pkt.attrs = [(10, bas_addr)] return pkt
def newReqLogout(userIp, secret, basip = None, serialNo = None, chap = True, mac = None): """0x05""" pkt = Portal.newMessage(REQ_LOGOUT, userIp, serialNo or CurrentSN(), 0, secret, chap=chap) bas_addr = basip and pktutils.EncodeAddress(basip) or None if bas_addr: pkt.attrNum = 1 pkt.attrs = [(10, bas_addr)] return pkt
def newAffAckAuth(userIp, secret, basip = None, serialNo = None, reqId = None, chap = True, mac = None): """0x07""" pkt = Portal.newMessage(AFF_ACK_AUTH, userIp, serialNo or CurrentSN(), reqId or 0, secret, chap=chap) bas_addr = basip and pktutils.EncodeAddress(basip) or None if bas_addr: pkt.attrNum = 1 pkt.attrs = [(10, bas_addr)] return pkt
def newMessage(typ, userIp, serialNo, reqId, secret, basip=None, chap=False): return Portal(type=typ, isChap=0 if chap else 1, userIp=pktutils.EncodeAddress(userIp), serialNo=serialNo, reqId=reqId, secret=six.b(secret))
def newReqAuth(userIp, username, password, reqId, challenge, secret, basip = None, serialNo = None, chap = False, mac = None): """0x03""" pkt = Portal.newMessage(REQ_AUTH, userIp, serialNo or CurrentSN(), reqId, secret, chap=chap) username = pktutils.EncodeString(username) password = pktutils.EncodeString(password) bas_addr = basip and pktutils.EncodeAddress(basip) or None if chap: _reqid = struct.pack('>H', reqId) chap_pwd = md5_constructor('%s%s%s' % (_reqid[1], password, challenge)).digest() pkt.attrNum = 3 pkt.attrs = [(1, username), (3, challenge), (4, chap_pwd)] if bas_addr: pkt.attrNum += 1 pkt.attrs.append((10, bas_addr)) else: pkt.attrNum = 2 pkt.attrs = [(1, username), (2, password)] if bas_addr: pkt.attrNum += 1 pkt.attrs.append((10, bas_addr)) return pkt