返回列表 發帖
wow... you are amazing.

TOP

I am now still facing some issues.
If different message part come together, the python may finish in different time in reserve order and the sms will be displayed and sent in wrong order, and may receive multiple email or incomplete message email.

TOP

This is the bug results....

券(可兑换等额 “沃尔玛、京东、天猫、唯品会、百果园”等30多家电子消费券),充值本金分5/5/10/10个月到账。办理步骤:1、微信
关注“广东联通”公众号—服务—话费充值相应金额;2、请按短信提示拨打10010135按3登记参与活动,电子券于3个工作日内下发;3、通
【红包任性派、惊喜享不停】即日起至10月8日期间,单笔充值100/200/300/500元送50/100/150/250元“红包”电子
过“广东联通”微信公众号—发现—电子券红包,查询并兑换电子券。多充多送,叠加生效,重复参与需重复登记,申请成功后不可取消。【深圳联通】

TOP

本帖最後由 mcdull 於 2017-10-5 18:36 編輯

I have revised my work to potentially fix the problem.
  1. #!/usr/bin/env python
  2. #coding:utf-8
  3. import sys
  4. import signal

  5. from selenium import webdriver
  6. from bs4 import BeautifulSoup

  7. driver = webdriver.PhantomJS()
  8. pdu = str(sys.argv[1])
  9. concatpart = '1'
  10. concattotal = '1'
  11. url = 'http://192.168.100.253/pdudecode/jsPduDecoder-master/index.html?pdu='
  12. driver.get(url+pdu)
  13. soup = BeautifulSoup(driver.page_source, 'html.parser')
  14. udhs = soup.findAll('td', text = 'User Data Header')
  15. for i in udhs:
  16. #    print i.get_text()
  17.     if i.next_sibling.get_text().find('Concatenated message') != -1:
  18.         s = i.next_sibling.get_text()
  19. #        print s
  20.         concatpart = s[s.find("part")+5:s.find("part")+6]
  21.         concattotal = s[s.find("parts")-2:s.find("parts")-1]
  22. #        print concatpart
  23. #        print concattotal
  24.         if concatpart == concattotal:
  25.             print concatpart + ',' + concattotal + ' Message Completed'
  26.             driver.service.process.send_signal(signal.SIGKILL)
  27.             driver.quit()
  28.             sys.exit()
  29.         else:
  30.             print concatpart + ',' + concattotal + ' Message Incomplete. ' + s
  31.             driver.service.process.send_signal(signal.SIGKILL)
  32.             driver.quit()
  33.             sys.exit()
  34. print '1,1 Single Message'
  35. driver.service.process.send_signal(signal.SIGKILL)
  36. driver.quit()
  37. sys.exit()
複製代碼

TOP

本帖最後由 mcdull 於 2017-9-27 18:37 編輯
  1. [from-pstn-custom]
  2. include => dongle-incoming-sms
  3. include => dongle-incoming-ussd

  4. [dongle-incoming-sms]
  5. exten => sms,1,Noop(Incoming SMS from ${CALLERID(num)} ${BASE64_DECODE(${SMS_BASE64})})
  6. exten => sms,3,System(echo '${STRFTIME(${EPOCH},Hongkong,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME} - ${CALLERID(num)} - ${CALLERID(dnid)}: ${BASE64_DECODE(${SMS_BASE64})}  /////  ${CMGR}' >> /var/log/asterisk/sms${DONGLENAME}.txt)
  7. exten => sms,4,System(echo "INSERT INTO sms (DONGLENAME,CALLERID,EPOCH,SMS_BASE64,DONGLENUMBER,CMGR) values ('${DONGLENAME}','${CALLERID(num)}','${STRFTIME(${EPOCH},Hongkong,%Y-%m-%d %H:%M:%S)}','${BASE64_DECODE(${SMS_BASE64})}','${DONGLENUMBER}','${CMGR}')\;" > /var/log/asterisk/smssql${DONGLENAME}.txt)
  8. exten => sms,5,System(mysql -uxxxxx -pxxxxx -hxxx.xxx.xxx.xxx -P3307 smslog < /var/log/asterisk/smssql${DONGLENAME}.txt)
  9. exten => sms,6,Set(channelID=${CHANNEL:-10:8})
  10. exten => sms,7,System(echo '${CMGR}' > /var/log/asterisk/smsCMGRraw${DONGLENAME}_${channelID})
  11. exten => sms,8,System(awk '{if ( NR == "2" ) print}' /var/log/asterisk/smsCMGRraw${DONGLENAME}_${channelID} | tee -a /var/log/asterisk/smsPDUraw${DONGLENAME}_${channelID})
  12. exten => sms,9,NoOp(cmdstr = /usr/bin/python /etc/asterisk/pdudecode.py $(cat /var/log/asterisk/smsPDUraw${DONGLENAME}_${channelID})))
  13. exten => sms,n,Set(completeSMS=${SHELL(/usr/bin/python /etc/asterisk/pdudecode.py $(cat /var/log/asterisk/smsPDUraw${DONGLENAME}_${channelID}))})
  14. exten => sms,n,NoOp(result is ${completeSMS})
  15. exten => sms,n,Set(completeSMS=${completeSMS:0:3})
  16. exten => sms,n,Set(smsTotal=${completeSMS:-1:1})
  17. exten => sms,n,Set(smsPart=${completeSMS:0:1})
  18. exten => sms,NoOp(Total ${smsTotal}  Part ${smsPart})
  19. exten => sms,n,System(echo '${BASE64_DECODE(${SMS_BASE64})}' > /var/log/asterisk/smscontent${DONGLENAME}_${smsPart})
  20. exten => sms,n,System(rm -f /var/log/asterisk/smsPDUraw${DONGLENAME}_${channelID})
  21. exten => sms,n,System(rm -f /var/log/asterisk/smsCMGRraw${DONGLENAME}_${channelID})
  22. exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?wait(1))
  23. exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(echo 'Subject: SMS received from ${CALLERID(num)}' > /var/log/asterisk/smsmail${DONGLENAME})
  24. exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(echo ' ' >> /var/log/asterisk/smsmail${DONGLENAME})
  25. exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(echo '${STRFTIME(${EPOCH},Hongkong,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME}' >> /var/log/asterisk/smsmail${DONGLENAME})
  26. exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(echo ' ' >> /var/log/asterisk/smsmail${DONGLENAME})
  27. exten => sms,n,Set(i=1)
  28. exten => sms,n,While($[${i} <= ${smsTotal}])
  29. exten => sms,n,NoOp(Loop ${i})
  30. exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(cat '/var/log/asterisk/smscontent${DONGLENAME}_${i}' >> /var/log/asterisk/smsmail${DONGLENAME})
  31. exten => sms,n,ExecIf($[ ${SHELL(test -f /etc/asterisk/asterisk.conf && echo -n 1 || echo -n 0)}=1 ]?Set(i=$[${i} + 1]))
  32. exten => sms,n,ExecIf($[ ${SHELL(test -f /etc/asterisk/asterisk.conf && echo -n 1 || echo -n 0)}=0 ]?wait(2))
  33. exten => sms,n,EndWhile
  34. exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(cat '/var/log/asterisk/smsmail${DONGLENAME}' | tr -d '\r' | mailx -s 'SMS Recevied from ${CALLERID(num)} by ${DONGLENUMBER} ' -r 'xxx@xxx.com' -S smtp='xxx.xxx.xxx.xxx' xxx@xxx.com)
  35. exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(rm -f /var/log/asterisk/smscontent${DONGLENAME})
  36. exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(echo 'I am DONE' >> /var/log/asterisk/test${DONGLENAME})
  37. exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(echo '${STRFTIME(${EPOCH},Hongkong,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME} - ${completeSMS}' >> /var/log/asterisk/test${DONGLENAME})
  38. exten => sms,n,System(asterisk -rx 'dongle cmd ${DONGLENAME} AT+CMGD=1,4')
  39. exten => sms,n,Hangup()


  40. [dongle-incoming-ussd]
  41. exten => ussd,1,Noop(Incoming USSD: ${BASE64_DECODE(${USSD_BASE64})})
  42. exten => ussd,n,System(echo '${STRFTIME(${EPOCH},Hongkong,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME}: ${BASE64_DECODE(${USSD_BASE64})}' > /var/log/asterisk/ussd${DONGLENAME}.txt)
  43. exten => ussd,n,System(cat '/var/log/asterisk/ussd${DONGLENAME}.txt' | tr -d '\r' | mailx -s 'USSD Recevied from ${CALLERID(num)} by ${DONGLENUMBER}' -r 'xxx@xxx.xxx' -S smtp='xxx.xxx.xxx.xxx' xxx@xxx.com)
  44. exten => ussd,n,Hangup()
複製代碼

TOP

本帖最後由 mcdull 於 2017-9-27 22:41 編輯

Some stupid copy&paste issue in the code above..... dont use....

fixed with code below.. it should now be properly formatted.
  1. [from-pstn-custom]
  2. include => dongle-incoming-sms
  3. include => dongle-incoming-ussd

  4. [dongle-incoming-sms]
  5. exten => sms,1,Noop(Incoming SMS from ${CALLERID(num)} ${BASE64_DECODE(${SMS_BASE64})})
  6. exten => sms,3,System(echo '${STRFTIME(${EPOCH},Hongkong,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME} - ${CALLERID(num)} - ${CALLERID(dnid)}: ${BASE64_DECODE(${SMS_BASE64})}  /////  ${CMGR}' >> /var/log/asterisk/sms${DONGLENAME}.txt)
  7. exten => sms,4,System(echo "INSERT INTO sms (DONGLENAME,CALLERID,EPOCH,SMS_BASE64,DONGLENUMBER,CMGR) values ('${DONGLENAME}','${CALLERID(num)}','${STRFTIME(${EPOCH},Hongkong,%Y-%m-%d %H:%M:%S)}','${BASE64_DECODE(${SMS_BASE64})}','${DONGLENUMBER}','${CMGR}')\;" > /var/log/asterisk/smssql${DONGLENAME}.txt)
  8. exten => sms,5,System(mysql -uxxx -pxxx -hxxx.xxx.xxx.xxx -P3307 smslog < /var/log/asterisk/smssql${DONGLENAME}.txt)
  9. exten => sms,6,Set(channelID=${CHANNEL:-10:8})
  10. exten => sms,7,System(echo '${CMGR}' > /var/log/asterisk/smsCMGRraw${DONGLENAME}_${channelID})
  11. exten => sms,8,System(awk '{if ( NR == "2" ) print}' /var/log/asterisk/smsCMGRraw${DONGLENAME}_${channelID} | tee -a /var/log/asterisk/smsPDUraw${DONGLENAME}_${channelID})
  12. exten => sms,9,NoOp(cmdstr = /usr/bin/python /etc/asterisk/pdudecode.py $(cat /var/log/asterisk/smsPDUraw${DONGLENAME}_${channelID})))
  13. exten => sms,n,Set(completeSMS=${SHELL(/usr/bin/python /etc/asterisk/pdudecode.py $(cat /var/log/asterisk/smsPDUraw${DONGLENAME}_${channelID}))})
  14. exten => sms,n,NoOp(result is ${completeSMS})
  15. exten => sms,n,Set(completeSMS=${completeSMS:0:3})
  16. exten => sms,n,Set(smsTotal=${completeSMS:-1:1})
  17. exten => sms,n,Set(smsPart=${completeSMS:0:1})
  18. exten => sms,NoOp(Total ${smsTotal}  Part ${smsPart})
  19. exten => sms,n,System(echo '${BASE64_DECODE(${SMS_BASE64})}' > /var/log/asterisk/smscontent${DONGLENAME}_${smsPart})
  20. exten => sms,n,System(rm -f /var/log/asterisk/smsPDUraw${DONGLENAME}_${channelID})
  21. exten => sms,n,System(rm -f /var/log/asterisk/smsCMGRraw${DONGLENAME}_${channelID})
  22. exten => sms,n,ExecIf($[ ${smsTotal}!=${smsPart} ]?Hangup())
  23. ;exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?wait(1))
  24. exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(echo 'Subject: SMS received from ${CALLERID(num)}' > /var/log/asterisk/smsmail${DONGLENAME})
  25. exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(echo ' ' >> /var/log/asterisk/smsmail${DONGLENAME})
  26. exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(echo '${STRFTIME(${EPOCH},Hongkong,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME}' >> /var/log/asterisk/smsmail${DONGLENAME})
  27. exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(echo ' ' >> /var/log/asterisk/smsmail${DONGLENAME})
  28. exten => sms,n,Set(i=1)
  29. exten => sms,n,Set(errorCount=0)
  30. exten => sms,n,While($[${i} <= ${smsTotal}])
  31. exten => sms,n,NoOp(Loop ${i})
  32. exten => sms,n,Set(fileExist=0)
  33. exten => sms,n,ExecIf($[ ${SHELL(test -f /var/log/asterisk/smscontent${DONGLENAME}_${i} && echo -n 1 || echo -n 0)}=1 ]?Set(fileExist=1))
  34. exten => sms,n,ExecIf($[ ${fileExist}=1 ]?System(head -c -1 -q '/var/log/asterisk/smscontent${DONGLENAME}_${i}' >> /var/log/asterisk/smsmail${DONGLENAME})
  35. exten => sms,n,ExecIf($[ ${fileExist}=1 ]?Set(i=$[${i} + 1]))
  36. exten => sms,n,ExecIf($[ ${fileExist}=0 ]?wait(2))
  37. exten => sms,n,ExecIf($[ ${fileExist}=0 ]?Set(errorCount=$[${errorCount} + 1]))
  38. exten => sms,n,ExecIf($[ ${errorCount} > 5 ]?Set(i=$[${smsTotal} + 1]))
  39. exten => sms,n,EndWhile
  40. exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(cat '/var/log/asterisk/smsmail${DONGLENAME}' | tr -d '\r' | mailx -s 'SMS Recevied from ${CALLERID(num)} by ${DONGLENUMBER} ' -r 'xxx@xxx.com' -S smtp='xxx.xxx.xxx.xxx' xxx@xxx.com)
  41. exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(rm -f /var/log/asterisk/smscontent${DONGLENAME})
  42. exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(echo 'I am DONE' >> /var/log/asterisk/test${DONGLENAME})
  43. exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(echo '${STRFTIME(${EPOCH},Hongkong,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME} - ${completeSMS}' >> /var/log/asterisk/test${DONGLENAME})
  44. exten => sms,n,System(asterisk -rx 'dongle cmd ${DONGLENAME} AT+CMGD=1,4')
  45. exten => sms,n,Hangup()


  46. [dongle-incoming-ussd]
  47. exten => ussd,1,Noop(Incoming USSD: ${BASE64_DECODE(${USSD_BASE64})})
  48. exten => ussd,n,System(echo '${STRFTIME(${EPOCH},Hongkong,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME}: ${BASE64_DECODE(${USSD_BASE64})}' > /var/log/asterisk/ussd${DONGLENAME}.txt)
  49. exten => ussd,n,System(cat '/var/log/asterisk/ussd${DONGLENAME}.txt' | tr -d '\r' | mailx -s 'USSD Recevied from ${CALLERID(num)} by ${DONGLENUMBER}' -r 'xxx@xxx.xxx' -S smtp='xxx.xxx.xxx.xxx' xxx@xxx.com)
  50. exten => ussd,n,Hangup()
複製代碼

TOP

本帖最後由 mcdull 於 2017-10-5 18:37 編輯

Hit a major issue in python.
when sys.exit after calling webdriver.PhantomJS(), it will not clean up the phantomJS child process.   If I add driver.quit(), the phantomJS will not be closed either and the dialplan will not continue.

After a few tens of SMS, the server will run out of memory.  No fix yet.  Damn this simple things coz hell of troubles.

temp fix by issuing SIGKILL

TOP

發現同時入兩個sms的話就會亂.. 所以再引入多一個message reference 既variable試fix..
但唔post出來啦... 太亂... lol.

TOP

返回列表