jookies / jasmin

Jasmin - Open source SMS gateway
http://jasminsms.com
Other
1.02k stars 550 forks source link

Append string to sms message content via interception bcode.py failed #533

Closed 101t closed 7 years ago

101t commented 7 years ago

Hi, I am trying to append string " BXXX" to message content, but it is sometimes failed for long concatenated sms.

For example:

we have long message. original message Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

modified message Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. B999

I wrote some script using python language to handle message content:

from jasmin.vendor.smpp.pdu.pdu_types import CommandStatus
destination_addr = routable.pdu.params['destination_addr']
if destination_addr[0:4] == "0090" or destination_addr[0:2] == "90" or destination_addr[0:3] == "+90":
    #routable.pdu.params['short_message'] = str(routable.pdu.params['esm_class'].gsmFeatures) #"%s B999" % routable.pdu.params['short_message']
    # UDH is set ?
    if routable.pdu.status == CommandStatus.ESME_ROK:
        short_message = ""
        UDHI_INDICATOR_SET = False
        if hasattr(routable.pdu.params['esm_class'], 'gsmFeatures'):
            for gsmFeature in routable.pdu.params['esm_class'].gsmFeatures:
                if str(gsmFeature) == 'UDHI_INDICATOR_SET':
                    UDHI_INDICATOR_SET = True
                    break
        # What type of splitting ?
        splitMethod = None
        if 'sar_msg_ref_num' in routable.pdu.params:
            splitMethod = 'sar'
        elif UDHI_INDICATOR_SET and routable.pdu.params['short_message'][:3] == '\x05\x00\x03':
            splitMethod = 'udh'
        if splitMethod is not None:
            _pdu = routable.pdu
            if splitMethod == 'sar':
                short_message = _pdu.params["short_message"]
            else:
                short_message = _pdu.params["short_message"][6:]
            while hasattr(_pdu, 'nextPdu'):
                _pdu = _pdu.nextPdu
                if splitMethod == 'sar':
                    short_message += _pdu.params['short_message']
                else:
                    short_message += _pdu.params['short_message'][6:]
                if not hasattr(_pdu, 'nextPdu'):
                    short_message += _pdu.params["short_message"] if splitMethod == 'sar' else _pdu.params['short_message'][6:]
                    routable.pdu.params["short_message"] = "%s B999" % short_message
        else:
            short_message = "%s B999" % routable.pdu.params["short_message"]
            routable.pdu.params["short_message"] = short_message

I've got status error "ERROR/ESME_RINVESMCLASS". the message.log state is:

2017-02-02 13:52:34 INFO     2170 SMS-MT [cid:infobip] [queue-msgid:4631d0d8-46b3-4a0d-82b0-c4bc318cc6cb] [status:ERROR/ESME_RINVESMCLASS] [retry:False] [prio:0] [dlr:NO_SMSC_DELIVERY_RECEIPT_REQUESTED] [validity:none] [from:TarekKalaji] [to:905312089995] [content:'An asynchronous SMPP client and server built on Node.js. Shorty is sponsored and maintained by SMS Cloud, a subsidiary of MediaTech Designs, LLC. wefwe wef ewf wef wef wefef ewf wef wef wef B999']

The Question is: Is it possible to add/modify message content via routable.pdu.params["short_message"]? how?

Kind regards.

farirat commented 7 years ago

Please share a tcp trace showing your transformed part.

101t commented 7 years ago

Hi,

I captured one concatenated message using wireshark tcp detailed trace,

GET /send?username=foo&password=bar&from=TarekKalaji&to=905312089995&content=An%20asynchronous%20SMPP%20client%20and%20server%20built%20on%20Node.js.%20Shorty%20is%20sponsored%20and%20maintained%20by%20SMS%20Cloud,%20a%20subsidiary%20of%20MediaTech%20Designs,%20LLC.%20wefwe%20wef%20ewf%20wef%20wef%20wef HTTP/1.1
Host: 1.2.3.4:1401
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/55.0.2883.87 Chrome/55.0.2883.87 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Cookie: sessionid=k0zjw6qkr20ib7j3dz750o5nmqts1miy; csrftoken=Na8BldRXS4u8THxMUnka204zVzxFnqwcM6hbQPSC08tRTkTgVZaO9WA7IoV5aE9Z

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Fri, 03 Feb 2017 14:00:05 GMT
Content-Type: text/plain
Server: TwistedWeb/16.0.0

2e
Success "7b7c1087-5254-47de-a62a-7990374ceadf"
0

GET /send?username=foo&password=bar&from=TarekKalaji&to=905312089995&content=An%20asynchronous%20SMPP%20client%20and%20server%20built%20on%20Node.js.%20Shorty%20is%20sponsored%20and%20maintained%20by%20SMS%20Cloud,%20a%20subsidiary%20of%20MediaTech%20Designs,%20LLC.%20wefwe%20wef%20ewf%20wef%20wef%20wef HTTP/1.1
Host: 1.2.3.4:1401
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/55.0.2883.87 Chrome/55.0.2883.87 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Cookie: sessionid=k0zjw6qkr20ib7j3dz750o5nmqts1miy; csrftoken=Na8BldRXS4u8THxMUnka204zVzxFnqwcM6hbQPSC08tRTkTgVZaO9WA7IoV5aE9Z

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Fri, 03 Feb 2017 14:02:01 GMT
Content-Type: text/plain
Server: TwistedWeb/16.0.0

2e
Success "33dd1b4f-980f-4bb2-85d3-889e0128d0d0"
0

GET /send?username=foo&password=bar&from=TarekKalaji&to=905312089995&content=An%20asynchronous%20SMPP%20client%20and%20server%20built%20on%20Node.js.%20Shorty%20is%20sponsored%20and%20maintained%20by%20SMS%20Cloud,%20a%20subsidiary%20of%20MediaTech%20Designs,%20LLC.%20wefwe%20wef%20ewf%20wef%20wef%20wef HTTP/1.1
Host: 1.2.3.4:1401
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/55.0.2883.87 Chrome/55.0.2883.87 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Cookie: sessionid=k0zjw6qkr20ib7j3dz750o5nmqts1miy; csrftoken=Na8BldRXS4u8THxMUnka204zVzxFnqwcM6hbQPSC08tRTkTgVZaO9WA7IoV5aE9Z

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Fri, 03 Feb 2017 14:02:20 GMT
Content-Type: text/plain
Server: TwistedWeb/16.0.0

2e
Success "f62e2d8c-409a-4d35-a252-a36a4df1131b"
0

. message content is that: An asynchronous SMPP client and server built on Node.js. Shorty is sponsored and maintained by SMS Cloud, a subsidiary of MediaTech Designs, LLC. wefwe wef ewf wef wef wef

Thank you for respond.

tarikogut commented 7 years ago

decode pdu before sending after encode :)

101t commented 7 years ago

The issue solved successfully by:

I just modified some script inside of gateway source code as:

 nano /usr/lib/python2.7/dist-packages/jasmin/protocols/smpp/operations.py

inside this file inside SMPPOperationFactory class in SubmitSM method

class SMPPOperationFactory(object):
    ...
    ...
    ...
    def SubmitSM(self, short_message, data_coding=0, **kwargs):
        """Depending on the short_message length, this method will return a classical SubmitSM or
        a serie of linked SubmitSMs (parted message)
        """

        kwargs['short_message'] = "%s BXXX" % short_message
        kwargs['data_coding'] = data_coding
        ...

That is made my day. :))

mrsanvicente commented 1 year ago

Hello @101t This is great solution.
Another issue with the concatenated sm, is that if you change the source address dinamic in the interceptor, the sm will be sent with diferent source address, and the destination will not be able to identify all concatenated sm as parts of the same one.

Any idea how to change the source address after the serie of linked SubmitSMs is set?