Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    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')
Ejemplo n.º 4
0
    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')
Ejemplo n.º 5
0
    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')
Ejemplo n.º 6
0
    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')
Ejemplo n.º 7
0
    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')
Ejemplo n.º 8
0
    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')
Ejemplo n.º 9
0
    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)
Ejemplo n.º 10
0
    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)
Ejemplo n.º 11
0
    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
Ejemplo n.º 12
0
    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)
Ejemplo n.º 13
0
    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
Ejemplo n.º 14
0
    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)
Ejemplo n.º 15
0
    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)
Ejemplo n.º 16
0
    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
Ejemplo n.º 17
0
    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()
Ejemplo n.º 18
0
    def sendPDU(self, pdu):
        twistedSMPPServerProtocol.sendPDU(self, pdu)

        self.factory.stats.set('last_sent_pdu_at', datetime.now())
Ejemplo n.º 19
0
 def connectionMade(self):
     twistedSMPPServerProtocol.connectionMade(self)
     self.factory.stats.inc('connect_count')
     self.factory.stats.inc('connected_count')
Ejemplo n.º 20
0
    def onPDURequest_enquire_link(self, reqPDU):
        twistedSMPPServerProtocol.onPDURequest_enquire_link(self, reqPDU)

        self.factory.stats.set('last_received_elink_at', datetime.now())
Ejemplo n.º 21
0
    def sendPDU(self, pdu):
        twistedSMPPServerProtocol.sendPDU(self, pdu)

        # Stats:
        self.factory.stats.set('last_sent_pdu_at', datetime.now())
Ejemplo n.º 22
0
 def connectionMade(self):
     twistedSMPPServerProtocol.connectionMade(self)
     self.factory.stats.inc('connect_count')
     self.factory.stats.inc('connected_count')
Ejemplo n.º 23
0
    def onPDURequest_enquire_link(self, reqPDU):
        twistedSMPPServerProtocol.onPDURequest_enquire_link(self, reqPDU)

        self.factory.stats.set('last_received_elink_at', datetime.now())