从源辞典

查阅生活点点滴滴

Asterisk and /etc/hosts

October 11th, 2013 by congyuan

During recent network down because of fire at Singtel Bukit Panjang exchange, my home’s Asterisk server was also down. I search over internet and found it was a long time “bug” for Asterisk since many years ago and it was still not fixed.

The problem:

If the Asterisk server has SIP trunk to outside SIP providers, during the Internet outage, the SIP phones on LAN failed to register with the Asterisk server which is on the same network.

The reason:

The Asterisk uses synchronized DNS lookup. During Internet outrage, DNS times out. Asterisk will not respond to the local phones for SIP registration while waiting for DNS response.

The solution:

1. Use IP address for SIP trunk registration. However, for some SIP providers like pFingo, it will fail.
2. Add static hostname to IP address mapping to /etc/hosts

I go with solution 2.

Now I got another problem to fix. Usually the SIP providers will not change their IP address. To make it more sophisticate, I add the following script to my cron job list to check if the IP address changes and update accordingly.

#!/bin/sh

hosts=( "sip.pfingo.com" "sipproxy1.starhub.com" )
hostfile="/etc/hosts"

for host in "${hosts[@]}"
do
newip=$(dig +short $host)
oldip=$(sed -n 's/\([0-9.]\) '$host'$/\1/p' $hostfile)

if [ ${#newip} -gt 15 ]; then
echo "DNS timeout : $host"
continue
fi

if [ "$newip" != "$oldip" ]; then
sed -i 's/'$oldip'/'$newip'/' $hostfile
echo "$host : $oldip -> $newip"
fi

done

Posted in asterisk | No Comments »

Starhub Digital Voice Global to work with Asterisk PBX

March 28th, 2013 by congyuan

I have been able to extract the SIP settings for my starhub digital voice global long time ago. Only recently I could make it to work with Asterisk.

Problems that I faced previously:
Asterisk is able to register successfully but were not able to make outgoing calls. Error is 403 Forbidden.

PhoneNumber = 6xxxxxxx (8 digits)
Username = 3xxxxxxx (8 digits)

Correct values when registering:

From: sip:6xxxxxxx@sipproxy1.starhub.com;
Authorization: Digest username=”3xxxxxxx”, realm=”Registered_Subscribers”, algorithm=MD5, uri=”sip: sipproxy1.starhub.com”,

and calling requires proxy-authorization:

From: “asterisk” sip:6xxxxxxx@sipproxy1.starhub.com;
Proxy-Authorization: Digest username=”3xxxxxxx”, realm=”Registered_Subscribers”, algorithm=MD5,

I set Asterisk to have debug on and found out that
1. Asterisk uses username as the phone number when register.
2. Asterisk send the phone number as the username for Proxy-Authorization as a result.

In the users.conf file, I tried to change the username= 6xxxxxxx to username=3xxxxxxx, but the line could not register. Because Asterisk will use the 3xxxxxxx as phone number, which will be rejected by starhub.

The correct way to make both register and call works is to have a separate register => in sip.conf, and disable registersip in users.conf.

The correct settings are as follows.

file: sip.conf

[general]
register => 6xxxxxxx:YOURPASSWORD:3xxxxxxx@sipproxy1.starhub.com~600

file: users.conf

[starhub]
type = friend
host = sipproxy1.starhub.com
username = 3xxxxxxx
secret = YOURPASSWORD
trunkname = starhub
context = DID_starhub
hasexten = no
hasiax = no
hassip = yes
registeriax = no
registersip = no
trunkstyle = voip
insecure = port,invite
fromuser = 6xxxxxxx
authuser = 3xxxxxxx
outboundproxy = sipproxy1.starhub.com
fromdomain = sipproxy1.starhub.com
nat = yes
canreinvite = yes
disallow = all
allow = ulaw,alaw,g729

Now configure the outbound calling rules.

file: extensions.conf

[CallingRule_Local]
exten = _[3689]XXXXXXX,1,Macro(trunkdial-failover-0.3,${starhub}/${EXTEN:0},,starhub,)
[CallingRule_Local1800]
exten = _1800XXXXXXX,1,Macro(trunkdial-failover-0.3,${starhub}/${EXTEN:0},,starhub,)
[CallingRule_LocalFree]
exten = _1XXX,1,Macro(trunkdial-failover-0.3,${starhub}/${EXTEN:0},,starhub,)
[DLPN_DialPlan1]
include = CallingRule_Local
include = CallingRule_Local1800
include = CallingRule_LocalFree
include = default

Now configure the incoming rules.
file: extensions.conf

[DID_starhub]
include = DID_starhub_default
[DID_starhub_default]
exten = s,1,Goto(ringroups-custom-1,s,1)
[ringroups-custom-1]
exten = s,1,NoOp(Home)
exten = s,n,Dial(SIP/6001,20,${DIALOPTIONS}i)
exten = s,n,Hangup

Note 1: Home is my ring group including extension 6001.
Note 2: Trunk, Outbound and Incoming rules, Ring groups can be created from GUI.
Note 3: Modify the registersip to no for [starhub] in users.conf after the section being generated from GUI.
Note 4: Manually add register => to sip.conf.

Posted in All Others, Singnet Fibre | 6 Comments »

Cisco SLM2008T SG200-08 smart switch settings for Singnet Fibre Internet and Mio TV

March 7th, 2012 by congyuan

It has been mentioned in many forum posts that Singnet uses the following VLAN for their services:

VLAN 10: Internet
VLAN 20: Mio TV/IPTV
VLAN 30: Mio Voice
VLAN 40: Management

The main purpose of using a managed switch with VLAN capability is to remove the 2Wire modem from the setup so a more powerful router can be used. In my case, I have a Zywall USG50 dual Wan router for my home internet. It has WAN VLAN function and I have been able to set it up VLAN 10 on the WAN port to surf internet, but not for the Mio TV.

Mio TV requires 802.1p set at 4 for VLAN 20.

This instruction covers the Internet and Moi TV, as I don’t subscribe the digital voice and still use the analogue line.

Port 1: ONT
Port 2: Mio TV STB
Port 3: Your own router

1. VLAN Management -> Create VLAN

VLAN ID VLAN Name Type
1 Default Default
10 internet Static
20 miotv Static
Create vlan
2. Port to VLAN
VLAN 10: 1(Tagged), 3(Untagged)
VLAN 20: 1(Tagged), 2(Untagged)
Port Vlan

3. Interface Settings
Entry No. Interface Mode PVID Frame Type Priority
1 g1 Trunk 1 Admit Tagged Only 0
2 g2 Access 20 Admit Untagged Only 4
3 g3 Access 10 Admit Untagged Only 0
Interface settings
Note: Mode can be set as Trunk instead of Access. It will not affect the internet nor miotv.

4. Quality of Service -> Qos Properties
Entry No. Interface Trust Mode
1 g1 trust all
2 g2 trust dot1p
3 g3 untrusted
Qos settings
Note: If you have other SIP devices (Gigaset A580IP, Linksys PAP2T etc) which has DSCP or 802.1p settings, please set the port g3 to untrusted, so those tags will be removed before sending out. If not, these packets with priority tags will be dropped by Singtel fibre. The other end will never receive the registration packets.

5. Save configuration

By now, you should be able to surf internet and watch miotv already.

Please post your comments if you get it to work or have problems.

Posted in Singnet Fibre | 15 Comments »

NEC PBX Call SMDR Logger

January 17th, 2011 by congyuan

This is a Windows program written in C# to retrieve phone call log via TCP/IP from the PBX system.

Requirement:
1. Windows with .NET framework 1.1 or above
2. PBX system which can output SMDR via TCP/IP

How to use: (eg. NEC Univerge SV8100)
1. Enable NEC SMDR Output
http://univergesv8000series.blogspot.com/2009/04/setup-smdr-output-via-ip-for-nec.html
At SV8100
PROG 10-12-01/02: confirm your IP address given for the CPU
PROG 35-01-01: Output Port Type (select: LAN)
PROG 10-20-05: SMDR Output (input: 60010)
PROG 14-01-06: SMDR Print-Out (checked)
Repeat for all the trunks necessary
Reboot SV8100

2. Download the windows program here
http://www.xucongyuan.com/nec-smdr-logger.zip
It contains 3 files:
InstallUtil.exe The utility program to install a service
NecSmdrLogger.exe The main program for SMDR logging
NecSmdrLogger.exe.config The configuration file

3. Unzip it to a folder and edit the NecSmdrLogger.exe.config

NecHost: The Ip address of the NEC PBX
NecPort: The port of SMDR output
workingDir: The directory where the program will be running, auto create if not exist
CallLogDir: The directory where all the call logs be stored, auto create if not exist
logFile: The log file of the program, auto create if not exist

4. Open a Command prompt, and type the following command to install it a service
cd to_where_the_files_are
InstallUtil NecSmdrLogger.exe

5. Right click on “My computer” and go to “Manage”.
Under “Services”, look for “NEC SMDR Logging”. Click “Start” to run it.

6. Set it to run Automatically every time the windows starts.
By default, it is installed as start automatically. Check it to make sure it is set.

Note:
This program can only be run as a service.
It automatically reconnects to PBX every 24 hours if no data received for that period.
Call logs will be stored into files by month.

DISCLAIMER:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Posted in All Others | 2 Comments »