Thursday, January 17, 2013

Play listen 11 times on Asterisk to irritate caller..


This dialplan is to show how you can use the applicationmap feature in Asterisk to have an inband interruption during a call and force the caller (the other party) to hear something irritating like the word “listen” for 11 times while you listen to soothing music. This come from this forum youtube posting now Malaysian public enemy no .1 . The # in the instructions below means it’s a command you run on your linux box.
  • This is article is designed for FreePBX or adjust it for almost any Asterisk based distros…..
  • This article is to present how simple it is to do so much stuff on Asterisk…
  • This dialplan goes out to everyone in support of freedom of speech… :)
  1. Create an inband DTMF based code, e.g. here would be #9 by
    # nano /etc/asterisk/features_applicationmap_custom.conf
    Add this line below
    listenrant=>#9,peer/callee,Macro,listentome,s,1
  2. Now, create a dialplan in Asterisk
    # nano /etc/asterisk/extension_custom.confPaste like below
    [macro-listentome]
    exten => s,1,NoOp(Start to irritate you la)
    exten => s,n,Playback(custom/listen)
    exten => s,n,Playback(custom/listen)
    exten => s,n,Playback(custom/listen)
    exten => s,n,Playback(custom/listen)
    exten => s,n,Playback(custom/listen)
    exten => s,n,Playback(custom/listen)
    exten => s,n,Playback(custom/listen)
    exten => s,n,Playback(custom/listen)
    exten => s,n,Playback(custom/listen)
    exten => s,n,Playback(custom/listen)
    exten => s,n,Playback(custom/listen)
    exten => s,n,NoOp(There ya go..)
  3. Now, enable the feature in globals
    # nano /etc/asterisk/globals_custom.confEdit or paste to include, if you have more than one applicationmap, separate it with a #
    DYNAMIC_FEATURES = listenrant
  4. Now reload stuff
    # asterisk -rx "dialplan reload"
    # asterisk -rx "features reload"
  5. Now, place this sound file in /var/lib/asterisk/sounds/customs, change directory where relevant and the user which asterisk process runs. These below are defaults
    # mkdir /var/lib/asterisk/sounds/custom
    # cd /var/lib/asterisk/sounds/custom
    # wget
    https://dl.dropbox.com/u/18507018/listen.sln
    # chown asterisk:asteirsk listen.sln
  6. Done. When someone calls you, to irritate them, just hit #9…..lol!

Saturday, January 12, 2013

Asterisk 10 or 11 Messaging (SMS/SIP Messaging) with offline message sending

Article revision: 3
If you read and tried my post here, you would have probably got the AstSMS working. It is important to get that part working first then read the rest of this article. This article enhances that dialplan to add offline sending of SIP message (or SMS) even if a host/SIP peer is offline and they will get the message once they come back online.
HOW IT WORKS
  • It uses Asterisk .call files to requeue
  • It checks device state using the function DEVICE_STATE to determine if a call is successful or not so that it can start/stop the queuing of the .call file
  • Runs a script within dialplan using the SYSTEM application to call a bash file with certain variables that will then auto generate the .call files
IMPORTANT
  • Since the messaging feature will automatically return OK if a device status is seen as online on Asterisk, irregarless of its actual state (probably qualify has not run yet to let asterisk know its offline). So to mitigate, reduce the qualifyfreq value on extensions sip.conf or general section.
  • I’ve not tested this in large setups or production environment. So please take caution and test.
  • DEVICE_STATE must exist/work in order for you to make this work too. E,g SIP/1000 should show me state of NOT_INUSE or UNAVAILABLE etc…Read more on DEVICE_STATES .
  • When sending messages, if there’s a break character, e.g. apostrophe, it will break the script since it runs on CLI and uses BASH, so you need to clean it up through Asterisk dialplan before sending to CLI/SYSTEM app
  • If multiple offline messages are bombarded at once, it may not be received in that order.
  • I don’t regard this as a final final solution, this would just give you an idea how to get to your final solution
  • I don’t enable CDR logs, but if you have CEL they may appear, you can re-enable it by modding NoCDR accordingly and change the priority accordingly too
  • Modify the bash script to suite your operating system, mine was designed for Debian
ENVIRONMENT (that worked for me)
  • Debian 6.0.x
  • Asterisk 10/11
  • FreePBX 2.10/2.11(Beta2) – If you don’t use FBX, modify and code accordingly
  • I had working DEVICE_STATES for SIP extensions
  • PortGo softphone as sender
  • CSIPSimple softphone on Android as recipient

HOWTO

  1. Create a temp spool folder wherever your Asterisk spool folder is at, this here is default, this will be used to spool the .call file temporarily
    # mkdir /var/spool/asterisk/temp
    # chown -R asterisk:asterisk /var/spool/asterisk/temp
  2. Create or modify your astsms context, to use this new one.  Everything should start with exten on single lines.

    [astsms]
    exten => _X.,1,NoOp(SMS receiving dialplan invoked)
    exten => _X.,n,NoOp(To ${MESSAGE(to)})
    exten => _X.,n,NoOp(From ${MESSAGE(from)})
    exten => _X.,n,NoOp(Body ${MESSAGE(body)})
    exten => _X.,n,Set(ACTUALTO=${CUT(MESSAGE(to),@,1)})
    exten => _X.,n,ExecIf($["${ACTUALTO}" != "sip:${EXTEN}"]?Set(ACTUALTO=sip:${EXTEN}))
    exten => _X.,n,MessageSend(${ACTUALTO},${MESSAGE(from)})
    exten => _X.,n,NoOp(Send status is ${MESSAGE_SEND_STATUS})
    exten => _X.,n,GotoIf($["${MESSAGE_SEND_STATUS}" != "SUCCESS"]?sendfailedmsg)
    exten => _X.,n,Hangup()
    ;
    ; Handle failed messaging
    exten => _X.,n(sendfailedmsg),NoOp(Sending error to user)
    exten => _X.,n,Set(SRC=${MESSAGE(from)})
    exten => _X.,n,Set(DST=${MESSAGE(to)})
    exten => _X.,n,Set(MSG=${MESSAGE(body)})
    exten => _X.,n,Set(MESSAGE(body)="[${STRFTIME(${EPOCH},,%d%m%Y-%H:%M:%S)}] Your message to ${EXTEN} has failed. Sending when available")
    exten => _X.,n,Set(ME_1=${CUT(MESSAGE(from),<,2)})
    exten => _X.,n,Set(ACTUALFROM=${CUT(ME_1,@,1)})
    exten => _X.,n,MessageSend(${ACTUALFROM},ServiceCenter)
    exten => _X.,n,GotoIf($["${INQUEUE}" != "1"]?startq)
    exten => _X.,n,Hangup()
    ;
    exten => _X.,n(startq),NoOp(Queueing messaging for offline)
    exten => _X.,n,Set(MSGTIME=${STRFTIME(${EPOCH},,%d%m%Y-%H:%M:%S)})
    exten => _X.,n,SYSTEM(/var/lib/asterisk/agi-bin/astqueue.sh –SRC ‘${SRC}’ –DST ‘${DST}’ –MSG ‘${MSG}’)
    exten => _X.,n,Hangup()
    [app-fakeanswer]
    exten => _X.,1,NoCDR
    exten => _X.,n,Set(DESTDEV=${EXTEN})
    exten => _X.,n,Set(THISDEVSTATE=${DEVICE_STATE(SIP/${DESTDEV})})
    exten => _X.,n,GotoIf($["${THISDEVSTATE}" = "UNAVAILABLE"]?hang)
    exten => _X.,n,GotoIf($["${THISDEVSTATE}" = "UNKNOWN"]?hang)
    exten => _X.,n,Answer
    exten => _X.,n,Hangup()

    exten => _X.,n(hang),Hangup()
  3. Now, here’s the magic script called astqueue.sh, create it like this
    # nano /var/lib/asterisk/agi-bin/astqueue.sh
    Paste this below, adjust the maxretry and retryint so that your Asterisk wont blow up in smokes and act like on steroids retrying like crazy

    #!/bin/bash
    # v0.2
    # copyleft Sanjay Willie sanjayws@gmail.com
    # SCRIPT PURPOSE: GENERATE SMS OFFLINE QUEUE
    # GEN INFO: Change variables sections
    ###########################################
    #
    #VARIABLES
    maxretry=100
    retryint=30
    #
    #CONSTANTS
    ERRORCODE=0
    d_unique=`date +%s`
    d_friendly=`date +%T_%D`
    astbin=`which asterisk`
    myrandom=$[ ( $RANDOM % 1000 )  + 1 ]
    #
    function bail(){
          echo "SMS:[$ERRORCODE] $MSGOUT. Runtime:$d_friendly. UniqueCode:$d_unique"
        exit $ERRORCODE
    }
    while test -n "$1"; do
        case "$1" in
            -SRC)
                source="$2"
                shift
               ;;
            -DST)
                dest="$2"
                shift
               ;;
            -MSG)
                message="$2"
                shift
               ;;
            -TIME)
                originaltime="$2"
                shift
               ;;             
    esac
    shift
    done
    #
    #
    if [[ "$source" == "" ]]; then
        echo "ERROR: No source. Quitting."
        ERRORCODE=1
        bail
    fi
    if [[ "$dest" == "" ]]; then
        echo "ERROR: No usable destination. Quitting."
        ERRORCODE=1
        bail
    fi
    if [[ "$message" == "" ]]; then
        echo "ERROR: No message specified.Quitting."
        ERRORCODE=1
        bail
    fi
    #
    # generate call file
    mydate=`date +%d%m%y`
    logdate=`date`
    #
    # Check to see if extension exist
    destexten=`echo $dest | cut -d @ -f1 | cut -d : -f2`
    ifexist=`$astbin -rx "sip show peers" | grep -c $destexten`
    if [[ "$ifexist" == "0" ]]; then
        echo "Destination extension don't exist, exiting.."
        ERRORCODE=1
        bail
    fi

    # If that conditions pass, then we will queue,
    # you can write other conditions too to keep the sanity of the looping

    filename="$destexten-$d_unique.$myrandom.call"
    echo -e "Channel: Local/$destexten@app-fakeanswer
    CallerID: $source
    Maxretries: $maxretry
    RetryTime: $retryint
    Context: astsms
    Extension: $destexten
    Priority: 1 
    Set: MESSAGE(body)=$message
    Set: MESSAGE(to)=$dest
    Set: MESSAGE(from)=$source
    Set: INQUEUE=1 "> /var/spool/asterisk/temp/$filename
    # move files
    chown asterisk:asterisk /var/spool/asterisk/temp/$filename
    chmod 777 /var/spool/asterisk/temp/$filename
    sleep 3
    mv /var/spool/asterisk/temp/$filename /var/spool/asterisk/outgoing/
    #
    ERRORCODE=0
    bail

  4. Change permission and ownership accordingly
    # chown asterisk:asterisk /var/lib/asterisk/agi-bin/astqueue.sh
    #chmod +X /var/lib/asterisk/agi-bin/astqueue.sh
  5. Try sending a message when the device is online, then try again offline. Then go back online and you should get the message.
  6. Do modify and enhance and do share if you found something interesting or bugs..er

Its already 4am here in Malaysia, …sleep now. Good luck and enjoy your weekend.

Tuesday, January 8, 2013

A basic IPTables (firewall) for just about anyone using Asterisk and FreePBX

Hi guys, developed this simple bash script that will enable and disable IPTABLES based firewall targeted to mainly Asterisk with FreePBX users.
NOTE:
  • This is a basic firewall, feel free to fine tune as much as you want.
  • IT may erase existing FW/IPTABLES rules you have but it does back it up to /root
  • It does not interfere with fail2ban if you are using fail2ban
  • You add this into a startup if you like but it is not formatted to the init format, you need to set that up yourself or include this script into any existing init.d script you may have
  • It only allows SSH from anywhere, rest are allowed internally
  • You can edit the file to set to allow anywhere access to other common protocols if you want
  • Make sure you define your internal network range, by default it will allow RFC1918 …
What are the default rules
  • SSH allow from any
  • HTTP/HTTPS, SIP(and RTP), IAX2, NTP, SSH, TFTP and DHCP (tftp and dhcp accepts both server mode and client mode)
  • For HTTP(insecure http) you need to uncomment inside the script to allow port 80
  • Outbound is unrestrictive
  • Uses default ports as defined by standards
  1. # nano astfw.sh
  2. Copy the script as below and paste into the file you just opened/created, save and exit
  3. # chmod +x astfw.sh
  4. # mv astfw.sh /bin/
  5. Try starting and stopping (MAKE SURE YOU CAN ACCESS CONSOLE IF SOMETHING BREAKS!!!!!!)
    /bin/astfw.sh start
    /bin/astfw.sh stop
  6. Add to an init.d script or edit the rc.local to start this automatically when booting


Copy these below…
#!/bin/bash
# sanjayws@gmail.com
# V.1.1 - Modded for our Asterisk installs, reldate 08-01-2013
# V.1.2 - Added enable disable functinality just incase
# iptables Asterisk related to stop start
# usage ./astfw.sh start[stop]
#
# IMPORTANT READ THIS NOW
# =======================
# ---BE SURE TO DEFINE WHAT IS YOUR INTERNAL NETWORK, BY DEFAULT ALL RFC1918 IPs ARE ALLOWED
# ---DO NOT USE OTHER 3RD PARTY IPTABLES MANAGEMENT SYSTEM WHEN USING THIS, E.G. WEBMIN
# ---There is a section below to define custom ports/rules for incoming, use that
# ---YOU CAN DISABLE ENABLE SCRIPT COMPLETELY NOW
#
# ---DEFAULT SERVICES INBOUND ALLOWED FROM ANYWHERE
# ++++SSH
#
# ---DEFAULT SERVICES INBOUND ALLOWED INTERNAL ONLY
# ++++HTTPS,IAX2,NTP,SSH,SIP(WITH RTP),TFTP (SERVER AND CLIENT MODE), DHCP(SERVER AND CLIENT MODE)
#
# ---DEFAULT SERVICES ALLOWED OUTBOUND
# ++++ANY
#
# ---DEFAULT SERVICES ALLOWED LOCALHOST
# ++++ANY
#
# --- EXISTING RULES WILL ALWAYS BE BACKED UP IN /root/fwrulesbackup.<datetime>
#
# USER DEFINITION
# ENABLE OR DISABLE,IF DISABLED, ONLY FAIL2BAN WILL RUN, YES[NO]
ENABLE=YES
#
# INTERNAL BY DEFAULT ACCEPTS RFC1918 IP RANGES. ADD NEW OR MODIFY NEW ONES BY ADDING COMMAS. DEFINE BY MASK BITS LIKE 192.168.100.0/24
INTERNALNETWORK="10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"
#
# BY DEFAULT ONLY SSH IS ALLOWED FROM ANYWHERE, REST RESTRICTED INTERNAL ONLY, ACCEPTS 0 OR 1
allowextsip=0
allowextntp=0
allowextssh=1
allowextdhcp=0
allowexttftp=0
allowextiax=0
allowextweb=0
allowextntp=0

#
# Starting script here
if [[ "$ENABLE" == "YES" ]]; then
    mydate=`date +%d%m%y-%H%M%S`
    fw=`which iptables`
    fwsave=`which iptables-save`
    opt=$1
    if [[ "$opt" == "" ]]; then
        echo Command not specified, quitting
        exit
    fi
    if [[ "$opt" == "start" ]]; then

            echo "Starting firewall rules"
            echo "Backing up current rules to /root/filename"
            $fwsave > /root/fwrulesbackup.$mydate
            echo "Setting up defaults, clearing other rules"
            $fw -F INPUT
            $fw -F OUTPUT
            $fw -F FORWARD
            $fw -P INPUT ACCEPT
            $fw -P FORWARD ACCEPT
            $fw -P OUTPUT ACCEPT
            echo "Done sweeping"
            echo "Setting specific rules"
           
            #####INBOUND RULES#####
            # DEFAULT ALLOWED
            $fw -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
            $fw -A INPUT -p icmp --icmp-type 8 -s 0/0 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
            #
            if [[ $allowextsip == "1" ]]; then
                $fw -A INPUT -p udp -m udp --dport 5060:5062 -j ACCEPT
                $fw -A INPUT -p udp -m udp --dport 10000:20000 -j ACCEPT
            else
                $fw -A INPUT -s $INTERNALNETWORK -p udp -m udp --dport 5060:5062 -j ACCEPT
                $fw -A INPUT -s $INTERNALNETWORK -p udp -m udp --dport 10000:20000 -j ACCEPT
            fi
            if [[ $allowextiax == "1" ]]; then
                $fw -A INPUT -p udp -m udp --dport 4569 -j ACCEPT
            else
                $fw -A INPUT -s $INTERNALNETWORK -p udp -m udp --dport 4569 -j ACCEPT       
            fi
            if [[ $allowextweb == "1" ]]; then
                $fw -A INPUT -p tcp -m tcp  --dport 443 -j ACCEPT
                #$fw -A INPUT -p tcp -m tcp  --dport 80 -j ACCEPT
            else
                $fw -A INPUT -s $INTERNALNETWORK -p tcp -m tcp --dport 443 -j ACCEPT
                #$fw -A INPUT -s $INTERNALNETWORK -p tcp -m tcp --dport 80 -j ACCEPT
            fi
            if [[ $allowextssh == "1" ]]; then
                $fw -A INPUT -p tcp -m tcp  --dport 22 -j ACCEPT
            else
                $fw -A INPUT -s $INTERNALNETWORK -p tcp -m tcp --dport 22 -j ACCEPT
            fi
            if [[ $allowextntp == "1" ]]; then
                $fw -A INPUT -p udp -m udp --dport 123 -j ACCEPT
            else
                $fw -A INPUT -s $INTERNALNETWORK -p udp -m udp --dport 123 -j ACCEPT       
            fi
            if [[ $allowextdhcp == "1" ]]; then
                $fw -A INPUT -p udp -m udp --dport 67:68 -j ACCEPT
            else
                $fw -A INPUT -s $INTERNALNETWORK -p udp -m udp --dport 67:68 -j ACCEPT       
            fi
            if [[ $allowexttftp == "1" ]]; then
                $fw -A INPUT -p udp -m udp --dport 69 -j ACCEPT
            else
                $fw -A INPUT -s $INTERNALNETWORK -p udp -m udp --dport 69 -j ACCEPT       
            fi
          if [[ $allowextntp== "1" ]]; then
              $fw -A INPUT -p udp -m udp --dport 123 -j ACCEPT
          else
              $fw -A INPUT -s $INTERNALNETWORK -p udp -m udp --dport 123 -j ACCEPT       
          fi


            #
            #
            ###ADD YOUR CUSTOM INBOUND PORTS HERE
            # E.G. MYSQL, INTERNAL ONLY
            # $fw -A INPUT -s $INTERNALNETWORK -p tcp -m tcp --dport 3306 -j ACCEPT
            # E.G. MYSQL EXTERNAL AND INTERNAL
            # $fw -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
           
            #####OUTRULES#####
            #out stuff, currently none only defaults
            $fw -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
            $fw -A OUTPUT -j ACCEPT

            #loopallow, dont mess with this
            $fw -A INPUT -i lo -j ACCEPT
            $fw -A OUTPUT -s 127.0.0.1 -j ACCEPT       
                   
            #policy
            $fw -P INPUT DROP
            $fw -P OUTPUT DROP
            $fw -P FORWARD DROP   
            clear
            tput bel
            echo "Done - FIREWALL RUNNING - SECURED"
            exit 0

    elif [[ "$opt" == "stop" ]]; then       
            echo "Stopping firewall rules"
            echo "Backing up current rules to /root/filename"
            $fwsave > /root/fwrulesbackup.$mydate
            $fw -F INPUT
            $fw -F OUTPUT
            $fw -F FORWARD
            $fw -P INPUT ACCEPT
            $fw -P FORWARD ACCEPT
            $fw -P OUTPUT ACCEPT
            tput bel
            clear
            echo "Done - FIREWALL NOT RUNNING - INSECURE"
            exit 0
    else
            echo "Option not found, quitting"
            exit 1
    fi
    exit 0
   
else
    echo "Bypassing since flag set to ENABLE=$ENABLE"
    exit 0
fi

Friday, January 4, 2013

Asternic (2.0 earlier/later) and latest FreePBX 2.10 (or even 2.11) recording/playback via the GUI doesn’t show anymore after upgrading FBX or a new updated installation of FBX

Hi guys, had encountered an issue with Asternic and FreePBX’s latest Queue module which I noticed was version 2.10.07. Since I updated, the guide and .diff file provided by Asternic doesn’t work. So I had to do some hacks to get it sorted. I guess until Asternic team fixes the .diff file, here’s what you can quickly do to fix it.

IMPORTANT:

  • This only applies for queue module version 2.10.0.7 or newer, you can still use the .diff file provided by Asternic for older versions. If you follow the INSTALL file in the asternic tar.gz package, and when you patch, you don’t get errors, you are then still using the old version. If you do get errors, then you’ve installed the new version of the queue module.
  • If you upgraded/updated your FreePBX then suddenly recordings don’t work, well, then this updated new queues module is the issue.
  • If you ever upgrade the core/queues module after doing these steps below, you must redo step 1, every time you upgrade/update core/queues module in FBX
  • If you are installing Asternic for the first time on a FreePBX queue version 2.10.0.7 or higher, follow the steps detailed in Asternic’s “INSTALL” file up until the patch fpbxmixmon.diff, skip that part and do the parts below instead, to get straight to the fix, once done, continue the “INSTALL” file instructions per usual
  • The recordings after doing this hack below, will still show up in both Asternic and also in ARI

NOTICE

  • I believe in the new recordings formatting, the FreePBX team has probably done some cleanup in their codes to streamline recordings.
  • USE THIS AT YOUR OWN RISK! While I take precautions to use FBX standards and not to invoke changes to any other dialplans, things can go wrong, so test test test
  • NOTE: Improvise if needed, e.g. directory location etc.

 

Step 1 – Modify the FreePBX coding

# nano /var/www/html/admin/modules/queues/functions.inc/dialplan.php

Locate anywhere that says sub-record-check and replace it with sub-record-check-asternic

This is because, we will need to override this context to fit to Asternic’s fancy.

 

Step 2 – Create a MODIFIED sub-record-check macro to support Asternic recording format and post recording script.

# nano /etc/asterisk/extensions_override_freepbx.conf

Paste this below into that file. Please be aware of the location of MONITOR_EXEC script to match the location of yours. All single lines below, so ensure that when copying/pasting.

[sub-record-check-asternic]
exten => s,1,GotoIf($["${BLINDTRANSFER}" = ""]?check)
exten => s,n,ResetCDR()
exten => s,n,GotoIf($["${REC_STATUS}" != "RECORDING"]?check)
exten => s,n,Set(AUDIOHOOK_INHERIT(MixMonitor)=yes)
exten => s,n,MixMonitor(${MIXMON_DIR}${YEAR}/${MONTH}/${DAY}/${CALLFILENAME}.${MIXMON_FORMAT},a,${MIXMON_POST})
exten => s,n(check),Set(__MON_FMT=${IF($["${MIXMON_FORMAT}"="wav49"]?WAV:${MIXMON_FORMAT})})
exten => s,n,GotoIf($["${REC_STATUS}"!="RECORDING"]?next)
exten => s,n,Set(CDR(recordingfile)=${CALLFILENAME}.${MON_FMT})
exten => s,n,Return()
exten => s,n(next),ExecIf($[!${LEN(${ARG1})}]?Return())
exten => s,n,GotoIf($["${REC_STATUS}"!=""]?${ARG1},1)
exten => s,n,Set(__REC_STATUS=INITIALIZED)
exten => s,n,ExecIf($["${REC_POLICY_MODE}"="" & "${ARG3}"!=""]?Set(__REC_POLICY_MODE=${ARG3}))
exten => s,n,Set(NOW=${EPOCH})
exten => s,n,Set(__DAY=${STRFTIME(${NOW},,%d)})
exten => s,n,Set(__MONTH=${STRFTIME(${NOW},,%m)})
exten => s,n,Set(__YEAR=${STRFTIME(${NOW},,%Y)})
exten => s,n,Set(__TIMESTR=${YEAR}${MONTH}${DAY}-${STRFTIME(${NOW},,%H%M%S)})
exten => s,n,Set(__FROMEXTEN=${IF($[${LEN(${AMPUSER})}]?${AMPUSER}:${IF($[${LEN(${REALCALLERIDNUM})}]?${REALCALLERIDNUM}:unknown)})})
;exten => s,n,Set(__CALLFILENAME=${ARG1}-${ARG2}-${FROMEXTEN}-${TIMESTR}-${UNIQUEID})  ;;;MODIFIED LINE 1 -- THIS WAS THE ORIGINAL VERSION, ITS COMMENTED SO IT WONT EXECUTE
exten => s,n,Set(__CALLFILENAME=q${ARG2}-${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}-${UNIQUEID}) ;;; MODIFIED LINE 2 -- THIS IS MY VERSION, COMPATIBLE WITH ASTERNIC
exten => s,n,Set(__MONITOR_EXEC=/usr/local/parselog/update_mix_mixmonitor.pl ^{UNIQUEID} ${MIXMON_DIR}${YEAR}/${MONTH}/${DAY}/${CALLFILENAME}.${MIXMON_FORMAT}) ;;; MODIFIED LINE 3 --THIS I ADDED

exten => s,n,Goto(${ARG1},1)

exten => recq,1,Set(AUDIOHOOK_INHERIT(MixMonitor)=yes)
exten => recq,n,Set(MONITOR_FILENAME=${MIXMON_DIR}${YEAR}/${MONTH}/${DAY}/${CALLFILENAME})
exten => recq,n,Set(__REC_STATUS=RECORDING)
exten => recq,n,Set(CDR(recordingfile)=${CALLFILENAME}.${MON_FMT})
exten => recq,n,Return()

exten => q,1,GosubIf($["${REC_POLICY_MODE}"="always"]?recq,1(${EXTEN},${ARG2},${FROMEXTEN}))
exten => q,n,Return()

Step 3 – Make any change in FreePBX and it should all work again Smile

- Click submit to anything and click Apply Conf

- Try to make calls and see ..

 

Additional stuff

Below is the parselog file I used that worked, be sure to find out AND CHANGE where your LAME app is in. In this case (Debian) lame was in /usr/local/bin/lame

A working parselog file. Click here. IT SHOULD BE THE SAME AS THE Original but yea…Please follow the configuration guide from Asternic for the parselog file.

Outbound call recording should work without any issues if you follow Asternic’s guide as it doesn’t interfere with FreePBX core coding through php, it uses the [macro-dialout-trunk-predial-hook] that doesn’t get directly modified in FreePBX gui.

 

Here’s my screenie of the before and after, notice before I hadn’t had recording, now with the above steps 1-3, it works again, yay

image

 

Bonus

If you got files that were not converted due to this issue above, here’s a dirty way how to get it working again on Asternic

1) Go to each directory containing the .wav file and run this code (For Debian 6 only, use on other OSes at your own risk)

# cd /var/spool/asterisk/monitor/2013/01/01/

# for i in `ls -l | awk {'print $9'}`; do uniqwav=`echo $i | cut -d - -f6 `;  uniqueid=`echo ${uniqwav//.wav/}`; /usr/local/parselog/update_mix_mixmonitor.pl $uniqueid `pwd`/$i; done