Archive for July 27th, 2011

FreePBX – Call Recording and RAMDISK

Asterisk call recording is resource intensive especially when the number of calls in the PBX is high. If you record all the calls directly to the HDD in asterisk  pbx and you got a large call volume (number of calls) then it will damage your PBX’s HDD very soon. On such cases using RAMDISK and seperate HDD may solve the problem.

Install freepbx. If you are not using SAN  use 2 HDDs for better results. One for OS+asterisk and one as a storage for recorded files.  Here I’m using /record as the storage location and  /astrec as the mount point for RAMDISK. Format and mount the 2nd HDD  to /record at the time of OS installation(or create an fstab entry if you are doing it later). After installation give write permission or assign asterisk user as the owner of /record & /astrec.

/bin/chown -R asterisk.asterisk /record
/bin/mkdir  /astrec
/bin/chown -R asterisk.asterisk /astrec

After the freepbx installation edit “/boot/grub/grub.conf” and put the the ramdisk size.

#boot=/dev/hda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Elastix (2.6.18-194.3.1.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-194.3.1.el5 ro root=LABEL=/
ramdisk_size=1000000
initrd /initrd-2.6.18-194.3.1.el5.img

Here I used RAMDISK size as 1GB(1000000) . The size depends on the number of calls,the average time for one call,and the recording format.

Remove the 3 directories from asterisk spool directory because we are going to use ramdisk instead of those.

rm -rf /var/spool/asterisk/monitor
rm -rf /var/spool/asterisk/system
rm -rf /var/spool/asterisk/tmp

Edit the file “/etc/rc.local” and append the  below code.

#Put this in rc.local to create ramdisk during bootup
/sbin/mke2fs -m 0 /dev/ram0
/bin/mount /dev/ram0 /astrec
/bin/mkdir /astrec/monitor
/bin/mkdir /astrec/system
/bin/mkdir /astrec/tmp
/bin/chown -R asterisk.asterisk /astrec
#For more infor on ramdisk:
#http://www.vanemery.com/Linux/Ramdisk/ramdisk.html

#Link asterisk's default folders to our ramdisk
/bin/ln -s /astrec/system /var/spool/asterisk
/bin/ln -s /astrec/tmp /var/spool/asterisk
/bin/ln -s /astrec/monitor /var/spool/asterisk

At the time of booting the above lines in rc.local creates RAMDISK and mount it to “/astrec”.

Create the file “/var/lib/asterisk/agi-bin/mvrec.sh” and put the below contents.

#!/bin/bash
/bin/mv $1/$2.$3 /record 3>&1 1>&2 2>&3 | tee /var/log/asterisk/mvrec.log

The above code will transfer the recorded file from RAMDISK to the location /record., Use the file “/var/log/asterisk/mvrec.log”  for troubleshooting purpose. Make the script executable.

chmod 755 /var/lib/asterisk/agi-bin/mvrec.sh

Log in to freepbx interface and change the General Settings as shown in screen shot.

Extension Recording Override:Enabled
Call recording format:	wav
Recording Location:	/var/spool/asterisk/monitor/
Run after record: /var/lib/asterisk/agi-bin/mvrec.sh ^{MIXMON_DIR} ^{CALLFILENAME} ^{MIXMON_FORMAT}

On FreePBX GUI goto  ”Extensions” and select one of the extensions in which you want to enable call recording.

If you are using Elastix change the recording directory in elastix monitoring configuration file.

 /var/www/html/modules/monitoring/configs/default.conf.php
 $arrConfModule['records_dir']       = '/record/';

Select the appropriate recording option.

Try calling between 2 extension after enabling call recording.  See the asterisk cli output. Use the file “/var/log/asterisk/mvrec.log” for troubleshooting.

If you are using specific context other than from-internnal context, don’t forget to add the Macros. For example

[custom-checklock]
exten => _.,1,NoOp(AMPUSER/${CALLERID(num)}/locked)
exten => _.,n,Gotoif($[${DB_EXISTS(AMPUSER/${CALLERID(num)}/locked)}=0]?carryon)
exten => _.,n,Set(PINCOUNT=0)
;exten => _.,n,Set(VALIDPIN=1234)
exten => _.,n(readpin),Read(PIN,vm-password,4,,,4)
exten => _.,n,Gotoif($[${PIN}=${VALIDPIN}]?carryon)
exten => _.,n,Gotoif($[${PIN}=${DB(AMPUSER/${CALLERID(num)}/locked)}]?carryon)
exten => _.,n,Set(PINCOUNT=$[${PINCOUNT}+1])
exten => _.,n,Playback(vm-incorrect)
exten => _.,n,GotoIf($[${PINCOUNT}>2]?h)
exten => _.,n,Wait(1)
exten => _.,n,Goto(readpin)
exten => _.,n(carryon),Set(DB(AMPUSER/${CALLERID(num)}/unlocked)=${PIN})
exten => _.,n,NoOp(${DB_DELETE(AMPUSER/${CALLERID(num)}/locked)})
;exten => _.,n,Dial(DAHDI/g0/${EXTEN})
exten => _.,n,Macro(user-callerid,SKIPTTL,)
exten => _.,n,Macro(record-enable,${AMPUSER},OUT,)
exten => _.,n,Macro(dialout-trunk,2,${EXTEN},)
exten => h,1,Macro(hangupcall,)
;exten => 911,1,Goto(CallingRule_Out39,${EXTEN},1)
;exten => h,1,Hangup

[custom-setlock]
exten => s,1,NoOp(In Set Lock)
exten => s,n,Gotoif($[${DB_EXISTS(AMPUSER/${CALLERID(num)}/unlocked)}=1]?lockit)
exten => s,n,Gotoif($[${DB_EXISTS(AMPUSER/${CALLERID(num)}/locked)}=0]?readit)
exten => s,n,Read(LOCKEY,vm-password,4,,,4)
exten => s,n,Gotoif($[${LOCKEY}=${DB(AMPUSER/${CALLERID(num)}/locked)}]?readit)
exten => s,n,Playback(vm-pls-try-again)
exten => s,n,Hangup
exten => s,n(readit),Read(PIN1,vm-newpassword,4,,,4)
exten => s,n,Read(PIN2,vm-reenterpassword,4,,,4)
exten => s,n,Gotoif($[${PIN1}=${PIN2}]?okey)
exten => s,n,Playback(an-error-has-occured)
exten => s,n,Hangup
exten => s,n(okey),Set(DB(AMPUSER/${CALLERID(num)}/locked)=${PIN1})
exten => s,n,Playback(locked)
exten => s,n,Hangup
exten => s,n(lockit),Set(DB(AMPUSER/${CALLERID(num)}/locked)=${DB(AMPUSER/${CALLERID(num)}/unlocked)})
exten => s,n,NoOp(${DB_DELETE(AMPUSER/${CALLERID(num)}/unlocked)})
exten => s,n,Playback(locked)
exten => h,1,Hangup

[national]
include => from-internal
exten => _XXXXXXXXX,1,Goto(custom-checklock,${EXTEN},1)

[international]
include => from-internal
exten => _XXXX.,1,NoOp(AMPUSER/${CALLERID(num)}/locked)
exten => _XXXX.,n,Goto(custom-checklock,${EXTEN},1)

[mobile]
include => from-internal
exten => 123,1,Goto(custom-setlock,s,1)
exten => _XXXXXXXXX,1,Goto(custom-checklock,${EXTEN},1)
exten => _XXXXXXXXXX,1,Goto(custom-checklock,${EXTEN},1)

[changepw]
exten => s,1,Read(LOCKEY,vm-password,4,,,4)
exten => s,n,Gotoif($[${LOCKEY}=2008]?okey)
exten => s,n,Hangup
exten => s,n(okey),Read(EXTNO,superlock,3,,,4)
exten => s,n,Set(DB(AMPUSER/${EXTNO}/locked)=1234)
exten => s,n,Playback(locked)
exten => h,1,Hangup

, , , , , , , , , , , , , ,

11 Comments

Useful Commands

Windows simple setup file maker

Start>Run>iexpress

Rename multiple files/ Remove characters from beginning of a file name

# for f in monitor*; do mv “$f” “${f#monitor}”;done

Send a command error to file

The following command will put linux command error output to a file.

mv /tmp/dfa /record/ 3>&1 1>&2 2>&3 | tee /tmp/stderr.txt

If  /tmp/dfa does not exists you will get following line in /tmp/stderr.txt file

mv: cannot stat `/tmp/dfa’: No such file or directory

Find Text in a folder 

grep -lir “text to find” *

Steps to Reverse SSH:

 client : Is the Server which is behind nat and  you want to access it without altering firewall configuration.

 Server: Is the machine which can be accessed through WAN(internet).

  1. On the client run the following commands:
    $ mkdir -p $HOME/.ssh
    $ chmod 0700 $HOME/.ssh
    $ ssh-keygen -t dsa -f $HOME/.ssh/id_dsa -P ''

    This should result in two files, $HOME/.ssh/id_dsa (private key) and $HOME/.ssh/id_dsa.pub (public key).

  2. Copy $HOME/.ssh/id_dsa.pub to the server.
    scp ~/.ssh/id_dsa.pub server:
  3. On the server run the following commands:
    $ cat id_dsa.pub >> $HOME/.ssh/authorized_keys2
    $ chmod 0600 $HOME/.ssh/authorized_keys2

    Depending on the version of OpenSSH the following commands may also be required:

    $ cat id_dsa.pub >> $HOME/.ssh/authorized_keys
    $ chmod 0600 $HOME/.ssh/authorized_keys

    An alternative is to create a link from authorized_keys2 to authorized_keys:

    $ cd $HOME/.ssh && ln -s authorized_keys2 authorized_keys
  4. On the client test the results by ssh’ing to the server:
    $ ssh -i $HOME/.ssh/id_dsa server
  5. (Optional) Add the following $HOME/.ssh/config on the client:
    Host server
             IdentityFile ~/.ssh/id_dsa

    This allows ssh access to the server without having to specify the path to the id_dsa file as an argument to ssh each time.

  6. Test the connectivity by ssh. It should not ask for password.
    ssh user@server -p 8022
  7. Put the below command in client’s /etc/rc.local
    nohup ssh -f -N -R 10000:localhost:22 user@server -p 8022
  8. To access the client run following command from the server.
    ssh user@localhost -p 10000

Unzip Multiple files with full path

#for z in *.zip; do 7za x -o/mnt/oebs/oracle/ $z;  done

If you are using command unzip use "unzip $z" instead of  "7za x -o/mnt/oebs/oracle/ $z;"
Another Option
#!/bin/bash
for zipfile in `ls /mnt/c/zipfiles/*.zip`; do unzip -o $zipfile -d /extracted/;
done
linux Find physical memory module installed in each memory slot
dmidecode --type 17
Enable x86 processors to access more than 4 GB of physical memory for Windows

Windows Server 2003 and Windows XP/2000:  To enable PAE, use the /PAE switch in the boot.ini file. To disable PAE, use the /NOPAE switch. To disable DEP, use the /EXECUTE switch.

bcdedit /set  pae ForceEnable

PAE is only used in 32 bit Windows versions. 32 GB is the limit for 64 bit Windows 2003 Standard Edition.

In 32-bit Windows running on x64-based systems, PAE also enables several advanced system and processor features, including hardware-enabled Data Execution Prevention (DEP), non-uniform memory access (NUMA), and the ability to add memory to a system while it is running (hot-add memory).

, , , , , , , , , , , , , , , , , , , , , , , , ,

Leave a Comment

Follow

Get every new post delivered to your Inbox.