本帖最後由 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.- [from-pstn-custom]
- include => dongle-incoming-sms
- include => dongle-incoming-ussd
- [dongle-incoming-sms]
- exten => sms,1,Noop(Incoming SMS from ${CALLERID(num)} ${BASE64_DECODE(${SMS_BASE64})})
- 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)
- 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)
- exten => sms,5,System(mysql -uxxx -pxxx -hxxx.xxx.xxx.xxx -P3307 smslog < /var/log/asterisk/smssql${DONGLENAME}.txt)
- exten => sms,6,Set(channelID=${CHANNEL:-10:8})
- exten => sms,7,System(echo '${CMGR}' > /var/log/asterisk/smsCMGRraw${DONGLENAME}_${channelID})
- exten => sms,8,System(awk '{if ( NR == "2" ) print}' /var/log/asterisk/smsCMGRraw${DONGLENAME}_${channelID} | tee -a /var/log/asterisk/smsPDUraw${DONGLENAME}_${channelID})
- exten => sms,9,NoOp(cmdstr = /usr/bin/python /etc/asterisk/pdudecode.py $(cat /var/log/asterisk/smsPDUraw${DONGLENAME}_${channelID})))
- exten => sms,n,Set(completeSMS=${SHELL(/usr/bin/python /etc/asterisk/pdudecode.py $(cat /var/log/asterisk/smsPDUraw${DONGLENAME}_${channelID}))})
- exten => sms,n,NoOp(result is ${completeSMS})
- exten => sms,n,Set(completeSMS=${completeSMS:0:3})
- exten => sms,n,Set(smsTotal=${completeSMS:-1:1})
- exten => sms,n,Set(smsPart=${completeSMS:0:1})
- exten => sms,NoOp(Total ${smsTotal} Part ${smsPart})
- exten => sms,n,System(echo '${BASE64_DECODE(${SMS_BASE64})}' > /var/log/asterisk/smscontent${DONGLENAME}_${smsPart})
- exten => sms,n,System(rm -f /var/log/asterisk/smsPDUraw${DONGLENAME}_${channelID})
- exten => sms,n,System(rm -f /var/log/asterisk/smsCMGRraw${DONGLENAME}_${channelID})
- exten => sms,n,ExecIf($[ ${smsTotal}!=${smsPart} ]?Hangup())
- ;exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?wait(1))
- exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(echo 'Subject: SMS received from ${CALLERID(num)}' > /var/log/asterisk/smsmail${DONGLENAME})
- exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(echo ' ' >> /var/log/asterisk/smsmail${DONGLENAME})
- exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(echo '${STRFTIME(${EPOCH},Hongkong,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME}' >> /var/log/asterisk/smsmail${DONGLENAME})
- exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(echo ' ' >> /var/log/asterisk/smsmail${DONGLENAME})
- exten => sms,n,Set(i=1)
- exten => sms,n,Set(errorCount=0)
- exten => sms,n,While($[${i} <= ${smsTotal}])
- exten => sms,n,NoOp(Loop ${i})
- exten => sms,n,Set(fileExist=0)
- exten => sms,n,ExecIf($[ ${SHELL(test -f /var/log/asterisk/smscontent${DONGLENAME}_${i} && echo -n 1 || echo -n 0)}=1 ]?Set(fileExist=1))
- exten => sms,n,ExecIf($[ ${fileExist}=1 ]?System(head -c -1 -q '/var/log/asterisk/smscontent${DONGLENAME}_${i}' >> /var/log/asterisk/smsmail${DONGLENAME})
- exten => sms,n,ExecIf($[ ${fileExist}=1 ]?Set(i=$[${i} + 1]))
- exten => sms,n,ExecIf($[ ${fileExist}=0 ]?wait(2))
- exten => sms,n,ExecIf($[ ${fileExist}=0 ]?Set(errorCount=$[${errorCount} + 1]))
- exten => sms,n,ExecIf($[ ${errorCount} > 5 ]?Set(i=$[${smsTotal} + 1]))
- exten => sms,n,EndWhile
- 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)
- exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(rm -f /var/log/asterisk/smscontent${DONGLENAME})
- exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(echo 'I am DONE' >> /var/log/asterisk/test${DONGLENAME})
- exten => sms,n,ExecIf($[ ${smsTotal}=${smsPart} ]?System(echo '${STRFTIME(${EPOCH},Hongkong,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME} - ${completeSMS}' >> /var/log/asterisk/test${DONGLENAME})
- exten => sms,n,System(asterisk -rx 'dongle cmd ${DONGLENAME} AT+CMGD=1,4')
- exten => sms,n,Hangup()
- [dongle-incoming-ussd]
- exten => ussd,1,Noop(Incoming USSD: ${BASE64_DECODE(${USSD_BASE64})})
- 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)
- 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)
- exten => ussd,n,Hangup()
複製代碼 |