Blog

  • Asterisk Phone Inventory / Useragent List

    Create batch file with below and run the script. It will list down the Useragent, Contact & Username.

    asterisk -rx “sip show peers” | cut -f1 -d/ | grep -P ‘\d\d\d\d’ | grep -vP ‘(UNKNOWN|Unmonitored)’ |
    while read PEER
    do
    asterisk -rx “sip show peer ${PEER}” |
    grep -P “(Useragent|Contact|Username)”
    echo “====”
    done

  • Asterisk/FreePBX – How to restrict an extension to call certain extension only

    There may come a time that you want a public access phone that can only dial out a certain set of extensions. To accomplish this, a custom context needs to be created and applied to that extension.

    Here’s the scenario.
    Extension 312 is the public access phone. This should only be able to dial x530 & x555. All other calls needs to be terminated.

    Define the context in extensions_additional.conf

    [from-intercom]
    exten => 530,1,goto(from-internal,${EXTEN},1)
    exten => 555,1,goto(from-internal,${EXTEN},1)
    exten => _.,1,hangup()

    If FreePBX, go inside the extension and the context from from-internal->from-intercom. Apply the settings and you’re good to go.

  • Asterisk/FreePBX Blind Transfer Return Call to Origin

    Another customer of ours requested this feature. By default, with blind transfers if the internal destination doesn’t answer the call, it goes to vociemail or terminates if vociemail is not configured. This customer wanted to return the call to the originator so that they can direct the call elsewhere.

    You need to modify two places. They’re listed below.

    globals_custom.conf:
    TRANSFER_CONTEXT = custom-test_transfer

    extensions_custom.conf:
    [custom-test_transfer]
    exten => _X.,1,NOOP(entering custom-test_transfer)
    exten => _X.,n,set(timeoutd=25) ; set timeout in seconds
    exten => _X.,n,set(extLeng=${LEN(${EXTEN})})
    exten => _X.,n,noop(the extenlength is ${extLeng})
    exten => _x.,n,dial(local/${EXTEN}@from-internal,${timeoutd})
    exten => _X.,n,Gotoif($[“$\{DIALSTATUS}”=”ANSWER”]?hangup,callback)
    exten => _X.,n,Set(CALLERID(name)=RB:${CALLERID(name)})
    exten => _X.,n(callback),dial(local/${BLINDTRANSFER:4:${extLeng}}@from-internal)
    exten => _X.,n(hangup),hangup()
    exten => _*X.,1,dial(local/${EXTEN}@from-internal,15)
    exten => _*X.,n,hangup()

    Thanks to Alexander for fixing my earlier code. I am yet to test this on a live site 🙂

    extensions_custom.conf:
    [custom-test_transfer]
    exten => _X.,1,NoOp(Entering custom-test_transfer)
    exten => _X.,n,Set(timeoutd=25) ; set timeout in seconds
    exten => _X.,n,Set(extLeng=${LEN(${EXTEN})})
    exten => _X.,n,NoOp(The extenlength is ${extLeng})
    exten => _X.,n,Dial(Local/${EXTEN}@from-internal,${timeoutd})
    exten => _X.,n,Set(CALLERID(name)=RB:${CALLERID(name)})
    exten => _X.,n,Dial(Local/${BLINDTRANSFER:4:${extLeng}}@from-internal)
    exten => _X.,n,Hangup()

    Once setup, reload asterisk and test this out.

    There are several other scripts out there, but this is the one that worked correctly for me.

  • Common Issues with MOH – Asterisk/FreePBX

    When working with MOH (Music on Hold) files in Asterisk/FreePBX I’ve come across a few issues that can occur regularly mainly due to human error. Best way to identify the issue is to check CLI entries when putting on hold as they give distinct clues as to what the problem is.

    First one is that you get an error message stating cannot open or find the file. This is a permission issue. Make sure the MOH files are awned by asterisk user and has correct file permissions. This has happened to me more than one occasion when I’ve uploaded the file via SSH instead of the GUI or after doing a volume change using sox.

    Second one you’d get is something on the line of unknown stream or unsupported format. Which simply means that asterisk doesn’t have the required tools to play the file.
    With my customers, what I normally do is convert the files to wav files, on 8000 Hz, 16 bit, Mono settings using “Nero Wave Editor” and upload the files. This resolves many problems with different formats as well as reduces CPU load.

    Final issue can be rectified using one of my earlier post.  : http://www.asanka.me/?p=19

  • Asterisk/FreePBX add Listen/Whisper/Barge facilities to your PABX

    A few of our customers wanted a feature to listen to other calls. Asterisk/FreePBX already provides ChanSpy, but the problem with it is that you cannot select what extension to listen to. After some digging around, found a few sites with instructions to get this done.

    So here’s what I used to implement this. If you’re using this as it is, make sure that there are no feature codes using *222/*223 & *224.

    Add below snippet to extensions_custom.conf. Reload asterisk and you’re good to go. To listen on extension 123, simply dial *222123.

    [ext-local-custom]

    ;listen
    exten => _*222x.#,1,Macro(user-callerid,)
    exten => _*222x.#,n,Answer
    exten => _*222x.#,n,NoCDR
    exten => _*222x.#,n,Wait(1)
    exten => _*222x.#,n,ChanSpy(sip/${EXTEN:4},q)
    exten => _*222x.#,n,Hangup

    ;whisper
    exten => _*223x.#,1,Macro(user-callerid,)
    exten => _*223x.#,n,Answer
    exten => _*223x.#,n,NoCDR
    exten => _*223x.#,n,Wait(1)
    exten => _*223x.#,n,ChanSpy(sip/${EXTEN:4},qw)
    exten => _*223x.#,n,Hangup

    ;barge
    exten => _*224x.#,1,Macro(user-callerid,)
    exten => _*224x.#,n,Answer
    exten => _*224x.#,n,NoCDR
    exten => _*224x.#,n,Wait(1)
    exten => _*224x.#,n,ChanSpy(SIP/${EXTEN:4},qB)
    exten => _*224x.#,n,Hangup

     

    Now, say there are some extensions that you don’t want to be listened on (ex. a manager), there are few ways to do it. But the simplest method I found is using below context. This needs to be added before the above set.

    Here, no one should be able to listen/whisper/barge on extension 5205’s calls. What this code does is if someone tries to do be naughty, it will simply hangup the call.

    ;blockaccess
    exten => _*2225205,1,Macro(user-callerid,)
    exten => _*2225205,n,Hangup
    exten => _*2235205,1,Macro(user-callerid,)
    exten => _*2235205,n,Hangup
    exten => _*2245205,1,Macro(user-callerid,)
    exten => _*2245205,n,Hangup

  • A fix for new Asterisk MOH file not found issue

    The new Asterisk PBX system for some odd reason have an issue with MOH not working by default. Digging deeper I found out that there’s a mismatch in directory names where asterisk looks for these files.

    It looks like the GUI portion of asterisk uploads files to /var/lib/asterisk/mohmp3 but config files set to look in /var/lib/asterisk/moh. the easiest fix is as below.

    mv /var/lib/asterisk/mohmp3/*.* /var/lib/asterisk/moh/
    rm -f /var/lib/asterisk/mohmp3
    ln -s /var/lib/asterisk/moh /var/lib/asterisk/mohmp3

    This will move all content on mohmp3 directory to moh, delete mohmp3 folder and then create a symlink named mohmp3 targeting moh. Now you don’t have to mess about with editing any config files.

  • A sample QoS config for VOIP service on a Cisco router

    The config below is a sample for configuring QoS on a Cisco router. The below config is good for 10 simultaneous calls on G.711 codec. This QoS setting is geared towards SHDSL/EoC/Fibre services with guaranteed bandwidth.

    !
    class-map match-any VoIP
    match protocol h323
    match protocol rtcp
    match protocol rtp
    match protocol sip
    !
    policy-map VOIPQoS
    class VoIP
    priority 2000
    set dscp ef
    class class-default
    fair-queue
    !
    interface GigabitEthernet0/0
    service-policy output VOIPQoS
    !

  • Setting up NTP, Timezone and DST setting on a Cisco rotuer

    Simply use the following example to setup the router to get date time from a NTP server and show the current time according to the timezone and DST settings.

    The below example configures a NTP server, then sets the time zone for GMT+10 and sets the DST time frames.

    Router(config)#ntp server x.x.x.x
    Router(config)#clock timezone AEST 10 0
    Router(config)#clock summer-time AEDT recurring 1 Sun Oct 2:00 1 Sun Apr 3:00

  • Setting up a Cisco router for auto-provisioning of Cisco handsets

    Here is a sample config to setup auto-provisioning for Cisco handsets. This only covers the part of distributing the config files to the handsets and not the config file creation part.

    This assumes that VLAN100 is the VOICE VLAN and PCs are connecting via the PC port at the back of the phones.

    !
    ip dhcp pool VOICE
    network 192.168.100.0 255.255.255.0
    default-router 192.168.100.1
    dns-server 192.168.100.1
    option 66 ascii "http://auto.provisioning.url/"
    lease infinite
    !
    interface Vlan100
    description VoiceVLAN
    ip address 192.168.100.1 255.255.255.0
    ip nat inside
    ip virtual-reassembly in
    !
    interface FastEthernet3
    description ToVoiceSwitch
    switchport mode trunk
    switchport voice vlan 100
    !

  • Disabling inter-VLAN routing using ACLs

    While working on a customer’s router config he requested the following to be done.

    • 3 LAN subnets
    • IP’s must assigned by DHCP.
    • All 3 subnets must have access to internet.
    • Devices on each LAN should not be able to communicate with each other.

    As the customer had a Cisco 881 the easiest way this could be achieved is with VLANs.  Here’s how I did it.

    inter-vlan

    !
    ip dhcp pool LAN
    network 192.168.1.0 255.255.255.0
    dns-server 220.233.0.3 58.96.1.28 8.8.8.8
    default-router 192.168.1.1
    !
    ip dhcp pool LAN2
    network 192.168.2.0 255.255.255.0
    dns-server 220.233.0.3 58.96.1.28 8.8.8.8
    default-router 192.168.2.1
    !
    ip dhcp pool LAN3
    network 192.168.3.0 255.255.255.0
    dns-server 220.233.0.3 58.96.1.28 8.8.8.8
    default-router 192.168.3.1
    !
    interface FastEthernet0
    no ip address
    !
    interface FastEthernet1
    switchport access vlan 2
    no ip address
    !
    interface FastEthernet2
    switchport access vlan 3
    no ip address
    !
    interface FastEthernet3
    no ip address
    shutdown
    !
    interface FastEthernet4
    ip address 58.96.0.0 255.255.255.254
    ip nat outside
    ip virtual-reassembly in
    rate-limit output 9800000 1250000 2500000 conform-action transmit exceed-action drop
    duplex full
    speed 100
    !
    interface Vlan1
    ip address 192.168.1.1 255.255.255.0
    ip access-group 101 in
    ip nat inside
    ip virtual-reassembly in
    !
    interface Vlan2
    description LAN2
    ip address 192.168.2.1 255.255.255.0
    ip access-group 102 in
    ip nat inside
    ip virtual-reassembly in
    !
    interface Vlan3
    description LAN3
    ip address 192.168.3.1 255.255.255.0
    ip access-group 103 in
    ip nat inside
    ip virtual-reassembly in
    !
    ip nat inside source list 1 interface FastEthernet4 overload
    !
    access-list 1 permit 192.168.0.0 0.0.3.255
    access-list 1 permit any
    access-list 101 deny ip 192.168.1.0 0.0.0.255 192.168.2.0 0.0.0.255
    access-list 101 deny ip 192.168.1.0 0.0.0.255 192.168.3.0 0.0.0.255
    access-list 101 permit ip any any
    access-list 102 deny ip 192.168.2.0 0.0.0.255 192.168.1.0 0.0.0.255
    access-list 102 deny ip 192.168.2.0 0.0.0.255 192.168.3.0 0.0.0.255
    access-list 102 permit ip any any
    access-list 103 deny ip 192.168.3.0 0.0.0.255 192.168.1.0 0.0.0.255
    access-list 103 deny ip 192.168.3.0 0.0.0.255 192.168.2.0 0.0.0.255
    access-list 103 permit ip any any
    !