Interceptor help to override source address

31 views
Skip to first unread message

Abdelhalim Ahmed

unread,
Jul 4, 2024, 11:27:01 AMJul 4
to Jasmin SMS Gateway
What I am trying to achieve is to create an interceptor to override the source_addr so it can show as the sender id instead of the shortcode in the users device.

The interceptor is binded with the filter and below is the DEBUG logs from the interceptor.log, however the source_addr is not being changed.

Appreciate your help to provide a script that worked with you.


2024-07-04 17:48:05 DEBUG    49971 ... took 0 seconds.
2024-07-04 17:59:30 INFO     51790 Interceptor configured and ready.
2024-07-04 17:59:31 INFO     51790 Authenticated Avatar: iadmin
2024-07-04 17:59:34 INFO     51813 Interceptor configured and ready.
2024-07-04 17:59:35 INFO     51813 Authenticated Avatar: iadmin
2024-07-04 18:00:04 INFO     51813 Running with a CommandId.submit_sm (from:b'****', to:b'************').
2024-07-04 18:00:04 DEBUG    51813 Running [#this script will override sender-id

def intercept(routable):
    # Import necessary classes
    from smpp.pdu.pdu_types import AddrTon, AddrNpi

    # Override the source address
    routable.pdu.params['source_addr'] = b'TESTSD'

    # Activate logging
    import logging
    # Set logger
    logger = logging.getLogger('interception-script')
    if len(logger.handlers) != 1:
        hdlr = logging.FileHandler('/var/log/jasmin/interceptor.log')
        formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
        hdlr.setFormatter(formatter)
        logger.addHandler(hdlr)
        logger.setLevel(logging.DEBUG)
   
    # Log the modified PDU
    logger.info('Modified PDU: %s' % routable.pdu)

    return routable

]
2024-07-04 18:00:04 DEBUG    51813 ... having routable with pdu: PDU [command: CommandId.submit_sm, sequence_number: None, command_status: CommandStatus.ESME_ROK
service_type: None
source_addr_ton: <AddrTon.NATIONAL: 3>
source_addr_npi: <AddrNpi.ISDN: 2>
source_addr: b'****'
dest_addr_ton: <AddrTon.INTERNATIONAL: 2>
dest_addr_npi: <AddrNpi.ISDN: 2>
destination_addr: b'***********'
esm_class: EsmClass[mode: EsmClassMode.STORE_AND_FORWARD, type: EsmClassType.DEFAULT, gsmFeatures: set()]
protocol_id: None
priority_flag: <PriorityFlag.LEVEL_0: 1>
schedule_delivery_time: None
validity_period: None
registered_delivery: RegisteredDelivery[receipt: RegisteredDeliveryReceipt.NO_SMSC_DELIVERY_RECEIPT_REQUESTED, smeOriginatedAcks: set(), intermediateNotification: False]
replace_if_present_flag: <ReplaceIfPresentFlag.DO_NOT_REPLACE: 1>
data_coding: 3
sm_default_msg_id: 0
short_message: b'TTEST'
]
2024-07-04 18:00:04 DEBUG    51813 ... took 0 seconds.
Reply all
Reply to author
Forward
0 new messages