Merge pull request #2 from MyTheValentinus/master

Fix specials chars send to gateway
This commit is contained in:
Paul Lecuq 2018-01-25 08:57:02 +01:00 committed by GitHub
commit 83c60c0e21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,6 +22,7 @@ def log(message, level = 'INFO'):
print "=== (INSTANCE) ===" print "=== (INSTANCE) ==="
instanceSeparator = False instanceSeparator = False
if config.log: if config.log:
message = message.encode('ascii', 'ignore').decode('ascii')
date = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') date = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print ("%s [ %s ] %s" % (date, level, message)) print ("%s [ %s ] %s" % (date, level, message))
@ -184,11 +185,22 @@ def pdu_format(phonenumber, message):
:param message: Text message :param message: Text message
:return: pdustring, pdulenght :return: pdustring, pdulenght
""" """
sms = SmsSubmit(phonenumber, message) # Whitelist char
whitelist = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
whitelist = whitelist + range(0, 9)
whitelist = whitelist + [' ', '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
fixed_message = ""
for chr in message:
if chr in whitelist:
fixed_message += chr
else:
fixed_message += "."
sms = SmsSubmit(phonenumber, fixed_message)
pdu = sms.to_pdu()[0] pdu = sms.to_pdu()[0]
pdustring = pdu.pdu pdustring = pdu.pdu
pdulength = pdu.length pdulength = pdu.length
return pdustring, pdulength, phonenumber, message return pdustring, pdulength, phonenumber, fixed_message
def send_ascii_sms(phonenumber, sms): def send_ascii_sms(phonenumber, sms):