Skip to content

Instantly share code, notes, and snippets.

@warewolf
Created July 12, 2019 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warewolf/30f140d52e9ef943a21efdb03a7221ac to your computer and use it in GitHub Desktop.
Save warewolf/30f140d52e9ef943a21efdb03a7221ac to your computer and use it in GitHub Desktop.
fax interception asterisk
; set dahdi-channels.conf's fax line to use this context
[fax-intercept]
include => from-internal
; expects "immediate=yes" on dahdi line
exten => s,1,Answer()
; emulate dialtone while reading the number being dialed
same => n,ReadExten(FAXOUT,dial,${CONTEXT},i,30)
same => n,Verbose(10,Dialing fax to ${FAXOUT})
same => n,Ringing()
; It takes ~ 4 seconds to dial a 10 digit number from the fax
same => n,Wait(5)
; normal calls continue here
same => n,GoTo(${CONTEXT},${FAXOUT},1)
; fax interception - dahdi hijacking the call starts here
exten => fax,1,Verbose(5,Sending fax to ${FAXOUT})
same => n,Verbose(10,**** FAX RECEIVE ****)
same => n,Set(__FAXFILE=outgoing-${FAXOUT}-${STRFTIME(,,%C%y%m%d%H%M)}.tif)
same => n,Verbose(10,**** SETTING FAXOPT ****)
same => n,Set(FAXOPT(ecm)=yes)
same => n,Set(FAXOPT(maxrate)=14400)
same => n,Set(FAXOPT(minrate)=2400)
same => n,Verbose(10,FAXOPT(ecm) : ${FAXOPT(ecm)})
same => n,Verbose(10,FAXOPT(headerinfo) : ${FAXOPT(headerinfo)})
same => n,Verbose(10,FAXOPT(localstationid) : ${FAXOPT(localstationid)})
same => n,Verbose(10,FAXOPT(maxrate) : ${FAXOPT(maxrate)})
same => n,Verbose(10,FAXOPT(minrate) : ${FAXOPT(minrate)})
same => n,Verbose(10,**** FAX RECEIVE FILE : ${FAXFILE} ****)
same => n,ReceiveFAX(/var/spool/asterisk/fax/${FAXFILE})
same => n,Hangup()
exten => h,1,Verbose(10,**** FAX RECEIVE COMPLETE ***)
; This needs to be global otherwise the Originate context doesn't know the fax filename
same => n,Set(GLOBAL(FAXFILE)=${FAXFILE})
same => n,GoToIf(Len(${FAXFILE})>0?RelayFax:FaxHangup)
same => n(RelayFax),Verbose(10,Relaying fax to ${FAXOUT})
; send this to the upstream PBX that actually has a SIP trunk to the PSTN
same => n,Originate(SIP/${FAXOUT}@UPSTREAM_PBX,exten,fax-relay,start,1)
same => n,Verbose(10,Originate status ${ORIGINATE_STATUS})
same => n(FaxHangup),Verbose(10,Hanging up on Fax)
same => n,Hangup()
[fax-relay]
exten => start,1,Verbose(10,*** FAX RELAY ***)
same => n,Verbose(10,Fax file is ${FAXFILE})
same => n,SendFax(/var/spool/asterisk/fax/${FAXFILE})
same => n,Verbose(10,Fax relay status: ${FAXSTATUS})
exten => h,1,Verbose(10,(Reached hangup fallthrough)
same => n,Hangup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment