def onPDURequest_enquire_link(self, reqPDU): twistedSMPPServerProtocol.onPDURequest_enquire_link(self, reqPDU) self.factory.stats.set('last_received_elink_at', datetime.now()) self.factory.stats.inc('elink_count') if self.user is not None: self.user.getCnxStatus().smpps['elink_count'] += 1
def doPDURequest(self, reqPDU, handler): twistedSMPPServerProtocol.doPDURequest(self, reqPDU, handler) # Stats if reqPDU.commandId == CommandId.enquire_link: self.factory.stats.set('last_received_elink_at', datetime.now()) elif reqPDU.commandId == CommandId.submit_sm: self.factory.stats.inc('submit_sm_request_count')
def onPDURequest_unbind(self, reqPDU): twistedSMPPServerProtocol.onPDURequest_unbind(self, reqPDU) self.factory.stats.inc('unbind_count') if str(self.bind_type) == 'bind_transceiver': self.factory.stats.dec('bound_trx_count') elif str(self.bind_type) == 'bind_receiver': self.factory.stats.dec('bound_rx_count') elif str(self.bind_type) == 'bind_transmitter': self.factory.stats.dec('bound_tx_count')
def connectionLost(self, reason): twistedSMPPServerProtocol.connectionLost(self, reason) self.factory.stats.inc('disconnect_count') self.factory.stats.dec('connected_count') if self.sessionState in [SMPPSessionStates.BOUND_RX, SMPPSessionStates.BOUND_TX, SMPPSessionStates.BOUND_TRX]: if str(self.bind_type) == 'bind_transceiver': self.factory.stats.dec('bound_trx_count') elif str(self.bind_type) == 'bind_receiver': self.factory.stats.dec('bound_rx_count') elif str(self.bind_type) == 'bind_transmitter': self.factory.stats.dec('bound_tx_count')
def __init__( self ): twistedSMPPServerProtocol.__init__(self) # Divert received messages to the handler defined in the config # Note: # twistedSMPPServerProtocol is using a msgHandler from self.config(), this # SMPPServerProtocol is using self.factory's msgHandler just like SMPPClientProtocol self.dataRequestHandler = lambda *args: self.factory.msgHandler(self.system_id, *args) self.system_id = None self.user = None self.session_id = str(uuid.uuid4()) self.log = logging.getLogger(LOG_CATEGORY)
def __init__(self): twistedSMPPServerProtocol.__init__(self) # Divert received messages to the handler defined in the config # Note: # twistedSMPPServerProtocol is using a msgHandler from self.config(), this # SMPPServerProtocol is using self.factory's msgHandler just like SMPPClientProtocol self.dataRequestHandler = lambda *args: self.factory.msgHandler(self.system_id, *args) self.system_id = None self.user = None self.bind_type = None self.session_id = str(uuid.uuid4()) self.log = logging.getLogger(LOG_CATEGORY)
def sendPDU(self, pdu): twistedSMPPServerProtocol.sendPDU(self, pdu) # Prepare for logging if pdu.commandId in [CommandId.deliver_sm, CommandId.data_sm]: message_content = pdu.params.get('short_message', None) if message_content is None: message_content = pdu.params.get('message_payload', '') # Do not log text for privacy reasons # Added in #691 if self.config().log_privacy: logged_content = '** %s byte content **' % len(message_content) else: logged_content = '%r' % re.sub(r'[^\x20-\x7E]+', '.', message_content) # Stats: self.factory.stats.set('last_sent_pdu_at', datetime.now()) if pdu.commandId == CommandId.deliver_sm: self.factory.stats.inc('deliver_sm_count') if self.user is not None: self.log.info( 'DELIVER_SM [uid:%s] [from:%s] [to:%s] [content:%s]', self.user.uid, pdu.params['source_addr'], pdu.params['destination_addr'], logged_content) self.user.getCnxStatus().smpps['deliver_sm_count'] += 1 elif pdu.commandId == CommandId.data_sm: self.factory.stats.inc('data_sm_count') if self.user is not None: self.log.info('DATA_SM [uid:%s] [from:%s] [to:%s] [content:%s]', self.user.uid, pdu.params['source_addr'], pdu.params['destination_addr'], logged_content) self.user.getCnxStatus().smpps['data_sm_count'] += 1 elif pdu.commandId == CommandId.submit_sm_resp: if pdu.status == CommandStatus.ESME_RTHROTTLED: self.factory.stats.inc('throttling_error_count') if self.user is not None: self.user.getCnxStatus().smpps['throttling_error_count'] += 1 elif pdu.status != CommandStatus.ESME_ROK: self.factory.stats.inc('other_submit_error_count') if self.user is not None: self.user.getCnxStatus().smpps['other_submit_error_count'] += 1 else: # We got a ESME_ROK self.factory.stats.inc('submit_sm_count') if self.user is not None: self.user.getCnxStatus().smpps['submit_sm_count'] += 1
def PDUDataRequestReceived(self, reqPDU): if self.sessionState == SMPPSessionStates.BOUND_RX: # Don't accept submit_sm PDUs when BOUND_RX errMsg = 'Received submit_sm when BOUND_RX %s' % reqPDU self.cancelOutboundTransactions(SessionStateError(errMsg, CommandStatus.ESME_RINVBNDSTS)) return self.fatalErrorOnRequest(reqPDU, errMsg, CommandStatus.ESME_RINVBNDSTS) return twistedSMPPServerProtocol.PDUDataRequestReceived(self, reqPDU)
def sendPDU(self, pdu): twistedSMPPServerProtocol.sendPDU(self, pdu) # Stats: self.factory.stats.set('last_sent_pdu_at', datetime.now()) if pdu.commandId == CommandId.deliver_sm: self.factory.stats.inc('deliver_sm_count') if self.user is not None: self.log.info( 'DELIVER_SM [uid:%s] [from:%s] [to:%s] [content:%s]' % (self.user.uid, pdu.params['source_addr'], pdu.params['destination_addr'], re.sub(r'[^\x20-\x7E]+', '.', pdu.params['short_message']))) self.user.getCnxStatus().smpps['deliver_sm_count'] += 1 elif pdu.commandId == CommandId.data_sm: self.factory.stats.inc('data_sm_count') if self.user is not None: self.log.info( 'DATA_SM [uid:%s] [from:%s] [to:%s] [content:%s]' % (self.user.uid, pdu.params['source_addr'], pdu.params['destination_addr'], re.sub(r'[^\x20-\x7E]+', '.', pdu.params['short_message']))) self.user.getCnxStatus().smpps['data_sm_count'] += 1 elif pdu.commandId == CommandId.submit_sm_resp: if pdu.status == CommandStatus.ESME_RTHROTTLED: self.factory.stats.inc('throttling_error_count') if self.user is not None: self.user.getCnxStatus( ).smpps['throttling_error_count'] += 1 elif pdu.status != CommandStatus.ESME_ROK: self.factory.stats.inc('other_submit_error_count') if self.user is not None: self.user.getCnxStatus( ).smpps['other_submit_error_count'] += 1 else: # We got a ESME_ROK self.factory.stats.inc('submit_sm_count') if self.user is not None: self.user.getCnxStatus().smpps['submit_sm_count'] += 1
def sendDataRequest(self, pdu): """If pdu has a 'vendor_specific_bypass' tag, it will be deleted before sending it This is a workaround to let Jasmin accepts messages with vendor TLVs but not forwarding them to downstream users. Related to #325 """ if pdu.commandId == CommandId.deliver_sm and 'vendor_specific_bypass' in pdu.params: del pdu.params['vendor_specific_bypass'] return twistedSMPPServerProtocol.sendDataRequest(self, pdu)
def sendPDU(self, pdu): twistedSMPPServerProtocol.sendPDU(self, pdu) # Stats: self.factory.stats.set('last_sent_pdu_at', datetime.now()) if pdu.commandId == CommandId.deliver_sm: self.factory.stats.inc('deliver_sm_count') if self.user is not None: self.log.info('DELIVER_SM [uid:%s] [from:%s] [to:%s] [content:%s]' % ( self.user.uid, pdu.params['source_addr'], pdu.params['destination_addr'], re.sub(r'[^\x20-\x7E]+','.', pdu.params['short_message']) )) self.user.getCnxStatus().smpps['deliver_sm_count']+= 1 elif pdu.commandId == CommandId.data_sm: self.factory.stats.inc('data_sm_count') if self.user is not None: self.log.info('DATA_SM [uid:%s] [from:%s] [to:%s] [content:%s]' % ( self.user.uid, pdu.params['source_addr'], pdu.params['destination_addr'], re.sub(r'[^\x20-\x7E]+','.', pdu.params['short_message']) )) self.user.getCnxStatus().smpps['data_sm_count']+= 1 elif pdu.commandId == CommandId.submit_sm_resp: if pdu.status == CommandStatus.ESME_RTHROTTLED: self.factory.stats.inc('throttling_error_count') if self.user is not None: self.user.getCnxStatus().smpps['throttling_error_count']+= 1 elif pdu.status != CommandStatus.ESME_ROK: self.factory.stats.inc('other_submit_error_count') if self.user is not None: self.user.getCnxStatus().smpps['other_submit_error_count']+= 1 else: # We got a ESME_ROK self.factory.stats.inc('submit_sm_count') if self.user is not None: self.user.getCnxStatus().smpps['submit_sm_count']+= 1
def PDURequestReceived(self, reqPDU): # Handle only accepted command ids acceptedPDUs = [CommandId.submit_sm, CommandId.bind_transmitter, CommandId.bind_receiver, CommandId.bind_transceiver, CommandId.unbind, CommandId.unbind_resp, CommandId.enquire_link, CommandId.data_sm] if reqPDU.commandId not in acceptedPDUs: errMsg = 'Received unsupported pdu type: %s' % reqPDU.commandId self.cancelOutboundTransactions(SessionStateError(errMsg, CommandStatus.ESME_RSYSERR)) return self.fatalErrorOnRequest(reqPDU, errMsg, CommandStatus.ESME_RSYSERR) twistedSMPPServerProtocol.PDURequestReceived(self, reqPDU) # Update CnxStatus if self.user is not None: self.user.getCnxStatus().smpps['last_activity_at'] = datetime.now()
def sendPDU(self, pdu): twistedSMPPServerProtocol.sendPDU(self, pdu) self.factory.stats.set('last_sent_pdu_at', datetime.now())
def connectionMade(self): twistedSMPPServerProtocol.connectionMade(self) self.factory.stats.inc('connect_count') self.factory.stats.inc('connected_count')
def onPDURequest_enquire_link(self, reqPDU): twistedSMPPServerProtocol.onPDURequest_enquire_link(self, reqPDU) self.factory.stats.set('last_received_elink_at', datetime.now())
def sendPDU(self, pdu): twistedSMPPServerProtocol.sendPDU(self, pdu) # Stats: self.factory.stats.set('last_sent_pdu_at', datetime.now())