Tuesday, May 8, 2012

FAX to Email [Asterisk] . T.38

Hi all

I always like to get involved new / challenging project. I got one   .  One of my client likes to have FAX to Email service at a very minimum cost.

Project:  Install FAX to Email service using 100% freeware and open source  Platform.


Same as before:   I tried Google and found quit lot information. But none of them [I found] gave me total step by step solution.

I like to share my experience and solution with everyone.

Target :

FAX to Email service.


Software and Hardware I used:

OS: CentOS release 6.2 [64bit] .
Server: Dell R510.
Asterisk version:  Asterisk 10.4.0

Some tools need to make tiff to pdf   and send email using smtp :

*. yum install poppler-utils.x86_64
*. Download sendEmail-v1.56.tar.gz  and setup . very easy just read the README .

Setup:

1. Install the Asterisk   :  you could do that or you don’t need to do FAXing.

2. Go to http://store.digium.com/products.php?category_id=94  buy [FREE or Paid. I use FREE] Fax for Asterisk License.   After purchase they will email you the license key.

3. Go to http://downloads.digium.com/pub/register/   download the register file. I used x86-64.

4. Chmod +x  register

5. ./ register  and it will ask you for KEY. Follow the steps.

6. Go to http://www.digium.com/en/docs/FAX/faa-download.php.  Download the files what matches your system .
        I used 64bit and  Flavor:  Core 2 [http://downloads.digium.com/pub/telephony/fax/res_fax_digium/asterisk-10.1/x86-64/res_fax_digium-10.1_1.3.0-core2_64.tar.gz]

7. untar the file and copy res_fax_digium.so  to  /usr/lib/asterisk/modules/   and res_fax_digium.conf to /etc/asterisk

8. Reboot your system


Verify the setting:  bellow is my running system log.  


asterisk –r


did*CLI> fax show  stats

FAX Statistics:
---------------

Current Sessions     : 0
Reserved Sessions    : 0
Transmit Attempts    : 0
Receive Attempts     : 9
Completed FAXes      : 9
Failed FAXes         : 2

Digium G.711
Licensed Channels    : 1
Max Concurrent       : 1
Success              : 7
Switched to T.38     : 0
Canceled             : 0
No FAX               : 0
Partial              : 1
Negotiation Failed   : 0
Train Failure        : 1
Protocol Error       : 0
IO Partial           : 0
IO Fail              : 0

Digium T.38
Licensed Channels    : 1
Max Concurrent       : 0
Success              : 0
Canceled             : 0
No FAX               : 0
Partial              : 0
Negotiation Failed   : 0
Train Failure        : 0
Protocol Error       : 0
IO Partial           : 0
IO Fail              : 0

did*CLI> fax show settings
FAX For Asterisk Settings:
        ECM: Enabled
        Status Events: On
        Minimum Bit Rate: 2400
        Maximum Bit Rate: 14400
        Modem Modulations Allowed: V17,V27,V29


FAX Technology Modules:

DIGIUM (Digium FAX Driver) Settings:
        Maximum T.38 Packet Delay: 800
        T.38 Session Packet Capture: Off
        G.711 Session Audio Capture: Off


did*CLI> fax show licenses
Fax Licensing Information
==============================
Free fax licenses: 1
Total licensed ports: 1

Licenses Found:
File: FFA-XXXXXXXXXXX.lic -- Key: FFA-XXXXXXXXXXXXX -- Product: XXXXXXXX -- Host-ID:  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -- Ports: 1 (OK)


did*CLI> fax show version
FAX For Asterisk Components:
        Applications: 10.4.0
        Digium FAX Driver: 10.1_1.3.0 (optimized for core2_64)



did*CLI> fax show capabilities


Registered FAX Technology Modules:

Type            : DIGIUM
Description     : Digium FAX Driver
Capabilities    : SEND RECEIVE T.38 G.711 MULTI-DOC
1 registered modules

Now:  Extension and Context: 

Sip.conf :

[general]
XXXXX
t38pt_udptl = yes
allow=all
allowguest=no
XXXXX

; provider


[My provider]
type=peer
insecure=port,invite
host=1.1.1.1
canreinvite=no
allow=all
qualify=no
nat=yes
dtmfmode=rfc2833
t38pt_udptl=no


exentsion.conf

[macro-startfax]
exten => s,1,Set(FAXOPT(ecm)=yes)
exten => s,n,Set(FAXOPT(maxrate)=14400)
exten => s,n,Set(FAXOPT(minrate)=2400)
exten => s,n,NoOp(FAXOPT(ecm) : ${FAXOPT(ecm)})
exten => s,n,Set(EXTEMAIL=a@s.com)
exten => s,n,Set(EXTNAME=VACL)
exten => s,n,Set(EXTCOMPANY=SNFax  www.snfax.com)
exten => s,n,Set(FAXFILE=/var/spool/asterisk/fax/${CALLEDFAX}/${UNIQUEID})
exten => s,n,ReceiveFAX(${FAXFILE}.tif)
exten => s,n,Hangup

[fax]
exten => xxx,1,Macro(startfax)
exten =>xxx,n,Hangup
exten => h,1,System(/var/lib/asterisk/scripts/mailfax "${CALLERID(num)}" "${CALLEDFAX}" "${EXTNAME}" "${EXTEMAIL}" "${FAXFILE}" "${EXTCOMPANY}" "${CALLERID(name)}")

;Debuging log
exten => h,n,NoOp(FAXOPT(ecm) : ${FAXOPT(ecm)})
exten => h,n,NoOp(FAXOPT(filename) : ${FAXOPT(filename)})
exten => h,n,NoOp(FAXOPT(headerinfo) : ${FAXOPT(headerinfo)})
exten => h,n,NoOp(FAXOPT(localstationid) : ${FAXOPT(localstationid)})
exten => h,n,NoOp(FAXOPT(maxrate) : ${FAXOPT(maxrate)})
exten => h,n,NoOp(FAXOPT(minrate) : ${FAXOPT(minrate)})
exten => h,n,NoOp(FAXOPT(pages) : ${FAXOPT(pages)})
exten => h,n,NoOp(FAXOPT(rate) : ${FAXOPT(rate)})
exten => h,n,NoOp(FAXOPT(remotestationid) : ${FAXOPT(remotestationid)})
exten => h,n,NoOp(FAXOPT(resolution) : ${FAXOPT(resolution)})
exten => h,n,NoOp(FAXOPT(status) : ${FAXOPT(status)})
exten => h,n,NoOp(FAXOPT(error) : ${FAXOPT(error)})

[default]
;FAX extension
exten => xxx,1,Wait(2)
exten => xxx,n,Ringing()
exten => xxx,n,Set(CALLEDFAX=${EXTEN})
exten => xx,n,Goto(fax,${EXTEN},1)
;End  Fax setting


Script : I found it from google and did some modification :

echo Received paramters $1 $2 $3 $4 $5 $6 $7 >>/var/log/faxmail.log
DATETIME=`date +"%A %d %b %Y %H:%M"`
if [ -e $5.tif ]
then
/usr/bin/tiff2pdf  -p A4 $5.tif  -o $5.pdf
echo fax file $5.pdf found. Sending email to $4 .... >>/var/log/faxmail.log
PAGES=$(pdfinfo $5.pdf | grep "Pages")
DT=$(pdfinfo  $5.pdf | grep "ModDate")
DTFAX=${DT#*:}
COUNT=${PAGES#*-}
rm -f $5.txt
echo Dear $3, >>$5.txt
echo >>$5.txt
echo You have just recieved a new fax document. Details as follow >>$5.txt
echo >>$5.txt
echo "From : "$1 >>$5.txt
echo "To : "$2 >>$5.txt
echo "Date Time : "$DATETIME " Eastern Daylight Time [EDT,New York]">>$5.txt
echo "Number of "$COUNT>>$5.txt

echo >>$5.txt
echo >>$5.txt

echo Thank you for using $6 >>$5.txt
echo sendEmail -f fax@vacl.us -t $4 -u "New fax received" -a $5.tif -o message-file=$5.txt \ >> /var/log/faxmail.log
echo "<<<<<<<<<<<<<<<<<<<<---------------->>>>>>>>>>>>>>>>>>>>>>>>>" >> /var/log/faxmail.log
/usr/local/bin/sendEmail -l /var/log/sendEmail.log -s  d.com  -xu d@d.com -xp aaa  -f fax@snfax.com -t $4 -u  "eFax message from $7 - $PAGES page(s), Caller-ID: $1" -a $5.pdf -o "message-file=$5.txt"
else
rm -f $5.txt
echo Dear $3, >>$5.txt
echo >>$5.txt
echo A call was recieved on your fax line, however no fax was recieved or the attempt failed. Details as follow >>$5.txt
echo >>$5.txt
echo "From : "$1 >>$5.txt
echo "To : "$2 >>$5.txt

    echo $DATETIME >>$5.txt

echo "When : "$DATETIME >>$5.txt

    echo " "$COUNT>>$5.txt

echo >>$5.txt

echo This notification is for your conveniance, if it is not required please notify your system administrator >>$5.txt

    echo >>$5.txt

echo >>$5.txt
echo Thank you for using $6 >>$5.txt
echo sendEmail -f msalaque@vacl.us -t $4 -u "Fax reception failed" -o message-file=$5.txt \ >> /var/log/faxmail.log
echo "<<<<<<<<<<<<<<<<<<<<---------------->>>>>>>>>>>>>>>>>>>>>>>>>" >> /var/log/faxmail.log
/usr/local/bin/sendEmail -l /var/log/sendEmail.log -s  d.com -xu d@d.com -xp d -f fax@snfax.com -t $4  -u  "eFax error message:  From  Caller-ID: $1"  -o "message-file=$5.txt"
exit
fi



====================================== END =========================================

Ok like always if you can't do that I could help.  I will charge 200 US$ for this .  I work as prepaid .

Tuesday, October 13, 2009

Still can't do that ?

If you still don't understand please email me, moreover if you like me to do your setup I will charge 1000 US$ per 4E1s.

I accept paypal only and I work as prepay. my paypal id is msalaque A@T gmail d.o.t com


Thanks
Salaque

Hidding caller ID

If you like to hide your caller id or like to assign caller ID from a group of pool
follow bellow :


I did two solutions for that:

Solution one : By using small php script [I used PHPAGI ]
Download : http://downloads.sourceforge.net/project/phpagi/phpagi/2.14/phpagi-2.14.tgz?use_mirror=transact

cd /var/lib/asterisk/agi-bin

step 2:

#!/usr/bin/php -q

$agi = new AGI();

$start = Start caller id you like to use ;
$end = End caller id you like to use ;

$cidnum = rand ($start,$end);

$agi->set_variable("CALLERID(num)", $cidnum);

?>

Create a file and save that as rad-id.php

chmod +x rad-id.php


step 3: In your extension.conf

exten => _X.,1,AGI(rand-cid.php)
exten => _X.,n,Dial(DAHDI/g1/${EXTEN})
exten => _X.,n,Hangup




Solution two : [Thanks Nahid]

extension.conf

exten => _X.,1,Set(CALLERID(num)=callerid${RAND(start,end)})
exten => _X.,n,Dial(DAHDI/g1/${EXTEN})
exten => _X.,n,Hangup

E1 grouping

Hello all,

If you like to assign different E1 to different client follow bellow:

step 1: group your E1s

edit : /etc/asterisk/chan_dahdi.conf

group=1
cicbeginswith=1
channel=1-15
cicbeginswith=17
channel=17-31

group=2
cicbeginswith=32
channel=32-62

group=3
cicbeginswith=63
channel=63-93

group=4
cicbeginswith=94
channel=94-124

step 2:
edit : /etc/asterisk/extensions.conf

; Dial plan for 1st E1
exten => _110XXXXXX.,1,Dial(DAHDI/g1/${EXTEN:2})
exten => _110XXXXXX.,n,Hangup

; End of 1st E1

; Dial plan for 2nd E1

exten => _220XXXXXX.,1,Dial(DAHDI/g2/${EXTEN:2})
exten => _220XXXXXX.,n,Hangup

; End of 2nd E1

; Dial plan for 3rd E1
exten => _330XXXXXX.,1,Dial(DAHDI/g3/${EXTEN:2})
exten => _330XXXXXX.,n,Hangup

; End of 3rd E1

; Dial plan for 4th E1
exten => _440XXXXXX.,1,Dial(DAHDI/g4/${EXTEN:2})
exten => _440XXXXXX.,n,Hangup

; End of 4th E1

Monday, September 28, 2009

Asterisk + libss7 [3rd]

Connecting and placing calls:

[X ~]# cat /etc/asterisk/sip.conf

[general]
context=[your context] ; Default context for incoming calls
allowoverlap=no ; Disable overlap dialing support. (Default is yes)
bindport=5060 ; UDP Port to bind to (SIP standard port is 5060)
bindaddr=[your IP] ; IP address to bind to (0.0.0.0 binds to all)
srvlookup=yes ; Enable DNS SRV lookups on outbound calls
tos_sip=cs3 ; Sets TOS for SIP packets.
tos_audio=ef ; Sets TOS for RTP audio packets.
cos_sip=3
cos_audio=5

relaxdtmf=yes
canreinvite=no
disallow=all ; see doc/rtp-packetization for framing options
allow=g729 ; add whatever codec you have and like to use
;allow=ulaw
;allow=alaw
allowguest=no
notransfer=yes ; part of rtp timeout
rtptimeout=19
rtpholdtimeout=20

[client1]
type=peer
insecure=port,invite
host=[client ip]
notransfer=yes
disallow=all
allow=g729
;allow=g723
allow=ulaw
;nat=yes
qualify=no
canreinvite=no

[client2]
type=peer
insecure=port,invite
host=[client ip]
notransfer=yes
disallow=all
allow=g729
;allow=g723
allow=ulaw
;nat=yes
qualify=no
canreinvite=no


[x~]# cat /etc/asterisk/extensions.conf

[your context]

; Dial plan for client1
exten => _110XXXXXX.,n,Dial(DAHDI/g1/${EXTEN:2},80,L(3300000))
exten => _110XXXXXX.,n,Hangup

; End of 1st E1

; Dial plan for client2

exten => _220XXXXXX.,n,Dial(DAHDI/g1/${EXTEN:2},80,L(3300000))
exten => _220XXXXXX.,n,Hangup





----------------------------------

Those are my general setting .

Have done quit a lot change in production setting . If you face any issue please drop me a line . I will try to solve that .


thanks
Salaque

----------------------------------

Asterisk + libss7 [2nd]

Starting your asterisk :

1. copy source-asterisk/contrib/init.d/rc.redhat.asterisk into your /etc/init.d/asterisk
2. chmod +x /etc/init.d/asterisk
3. chkconfig --levels 345 asterisk on
4. service asterisk restart

Asterisk should start. check that with ps -ef | grep asterisk output will be something likt :

[X~]# ps -ef | grep asterisk
root 2239 1 0 Sep24 ? 00:00:00 /bin/sh /usr/sbin/safe_asterisk
root 13047 2239 42 Sep24 ? 1-12:43:56 /usr/sbin/asterisk -f -vvvg -c
root 28546 27340 0 09:37 pts/0 00:00:00 grep asterisk

now try to connect your asterisk box. :

[X~]# asterisk -r [ will give you CLI access to your asterisk box ]

--------------------------------------------------------------------

Checking your Dahdi:
[X~]#dahdi_hardware [ this will show your degium hardware ]
[X~]#dahdi_scan [ This will show your card status with details ]

sample output :

Without signal:

active=yes
alarms=RED <-- Watch this
description=T4XXP (PCI) Card 0 Span 3
name=TE4/0/3
manufacturer=Digium
devicetype=Wildcard TE420 (4th Gen)
location=Board ID Switch 0
basechan=63
totchans=31
irq=169
type=digital-E1
syncsrc=0
lbo=0 db (CSU)/0-133 feet (DSX-1)
coding_opts=HDB3
framing_opts=CCS,CRC4
coding=HDB3
framing=CCS

With proper Signal :

active=yes
alarms=OK <-- Watch this
description=T4XXP (PCI) Card 0 Span 3
name=TE4/0/3
manufacturer=Digium
devicetype=Wildcard TE420 (4th Gen)
location=Board ID Switch 0
basechan=63
totchans=31
irq=169
type=digital-E1
syncsrc=4
lbo=0 db (CSU)/0-133 feet (DSX-1)
coding_opts=HDB3
framing_opts=CCS,CRC4
coding=HDB3
framing=CCS

Checking the ss7 link :

X*CLI> ss7 show linkset 1
SS7 linkset 1 status: Up

X*CLI> dahdi show status
Description Alarms IRQ bpviol CRC4 Fra Codi Options LBO
T4XXP (PCI) Card 0 Span 1 OK 0 0 0 CCS HDB3 YEL 0 db (CSU)/0-133 feet (DSX-1)
T4XXP (PCI) Card 0 Span 2 OK 0 0 0 CCS HDB3 YEL 0 db (CSU)/0-133 feet (DSX-1)
T4XXP (PCI) Card 0 Span 3 OK 0 0 0 CCS HDB3 YEL 0 db (CSU)/0-133 feet (DSX-1)
T4XXP (PCI) Card 0 Span 4 OK 0 0 0 CCS HDB3 YEL 0 db (CSU)/0-133 feet (DSX-1)



[X ~]# cat /proc/dahdi/* [ Card and Signal ok ]
Span 1: TE4/0/1 "T4XXP (PCI) Card 0 Span 1" (MASTER) HDB3/CCS

1 TE4/0/1/1 Clear (In use)
2 TE4/0/1/2 Clear (In use)
3 TE4/0/1/3 Clear (In use)
4 TE4/0/1/4 Clear (In use)
..........................


[X]# cat /proc/dahdi/* [ Problem ]
Span 1: TE4/0/1 "T4XXP (PCI) Card 0 Span 1" (MASTER) HDB3/CCS RED

1 TE4/0/1/1 Clear RED
2 TE4/0/1/2 Clear RED
3 TE4/0/1/3 Clear RED
4 TE4/0/1/4 Clear RED
.....................


---------------------------------------------------
Make sure your Digium card is not sharing IRQ with any other devices:

1. Disable all [ I really mean all ] unnecessary devices like Sound card, ports. from Bios
2. cat /proc/interrupts [ this will show if your card share IRQ with other devices
---------------------------------------------------

Thursday, September 17, 2009

Asterisk + libss7

Hi all

Last month i got a project in Asterisk where I have to work with ss7 signal . As I never work on SS7 signalling I tried google and found quit a lot information. but non of them [I found] gave me total step by step solution.

I like to share my experience and solution with everyone.

Target

Signalling : ss7
Number of E1 : 32 [ 4 E1 per server X 8]
Type of Setup : Termination


Software and Hardware I used

OS : CentOS 5.3 [64bit] .
Server : Hp Proliant .
Card Model : Digium TE420 with Echo chan
E1 Mux : Ad-net
Asterisk version : 1.6.0.13
libss7 verssion :1.0.0
dahdi-linux-complete-2.2.0.2+2.2.0
dahdi-tools-2.2.0


Setup :

E1 Mux : Zero configuration required . All you need to connect E1 [cat 5] cables from Digium card to your mux.

Digium Card: TE420 has four E1/T1 ports. Change the jumper as you need to make that E1 or T1. All you need to put that card into your server's PCIe slot. Connect four E1 to your MUX using standard drop cables.

OS: Install the OS

Libss7:
download from : http://downloads.asterisk.org/pub/telephony/libss7/releases/libss7-1.0.0.tar.gz

make
make install

Dahdi:

dahdi-linux-complete-2.2.0.2+2.2.0
dahdi-tools-2.2.0



Asterisk :
download from : http://downloads.asterisk.org/pub/telephony/asterisk/releases/asterisk-1.6.0.13.tar.gz

./configure
make
make install
make samples


Information you need to collect from your Teleco :

OPC
DPC
Signalling channels:

Note: Asterisk libss7 read those setting from /etc/asterisk/chan_dahdi.conf and it reads that as decimal value. But some telco gives that in hex value. so you need to change that from hex to decimal . I used http://www.statman.info/conversions/hexadecimal.html for that.


Configuration:
1. /etc/dahdi/system.conf
span=1,1,0,ccs,hdb3
bchan=1-15,17-31
mtp2=
span=2,1,0,ccs,hdb3
bchan=32-62
span=3,1,0,ccs,hdb3
bchan=63-93
span=4,1,0,ccs,hdb3
bchan=94-124
loadzone = us
defaultzone=us


2. /etc/asterisk/chan_dahdi.conf
[trunkgroups]
[channels]
echocancel=yes
echocancelwhenbridged=yes
group=1
signalling=ss7
ss7type=itu
ss7_called_nai=national
ss7_calling_nai=national
linkset=1
pointcode= < OPC you get from your telco in decimal formate >
adjpointcode= < DPC you get from your telco in decimal formate >
defaultdpc= < DPC you get from your telco in decimal formate >

networkindicator=national

sigchan= < what you get from telco >
cicbeginswith=1
channel=1-15
cicbeginswith=17
channel=17-31
cicbeginswith=32
channel=32-62
cicbeginswith=63
channel=63-93
cicbeginswith=94
channel=94-124

ss7_internationalprefix = 00
ss7_nationalprefix = 0