Like many colleagues in the shop, I have a small network built at home. And, of course, there is a home server, a sort of springboard for testing new technologies. With regular periodicity in the quiet evenings under the monotonous mumbling of some podcast, I am visited with thoughts of picking up something new and interesting. The announcement of the provider to open the
sip-telephony service prompted me to go towards voip. An interesting and promising direction. It would seem that there is such a thing - I installed a softphone, or even better, an iron sip gateway and enjoy life. But unless it is that way which we have chosen, having gone on the way of the engineer, the system administrator, the programmer (it is necessary to underline). It will be much more interesting to set up your own VoIP server, hang up
voice mail on it and let them answer the calls in a beautiful female voice when no one can pick up the phone. Of course, the choice fell on
Asterisk .
Installation distribution
The home server is running
FreeBSD . All procedures and paths will apply to this operating system. Actually, with a little effort, everything perfectly adapts to any platform on which Asterisk can work.
Once before, I installed Asterisk from source. I do not remember what the problem was, that's not the point. There is nothing difficult in the assembly. This time I didn’t get bored and used the ports system.
')
cd /usr/ports/net/asterisk
make install clean
Left everything by default in the configurator. All gathered without further questions. As it should be, the configs are in
/ usr / local / etc / asterisk / . And as usual there were not a few of them. We, in fact, need only three of them.
Do not forget about the autorun daemon:
echo 'asterisk_enable=”YES”' >> /etc/rc.conf
Configuration
The provider provides sip telephony services. Gives a direct city number. According to the terms of reference, my server should automatically register with the provider’s server and, in the event of an incoming call from the provider, route it to an internal telephone. The internal telephone is a regular telephone connected via an iron sip gateway to our server. If no one picks up the phone, then we play the voice message and offer the caller to leave a voice message.
When calling from a “local” phone, we will use the prefix to access the provider (I stopped at 9, as the most familiar option). When dialing a number (in my case 777, we get into the voice mail menu). It was possible to make an exit “to the city” without a prefix, but my plans are to connect to sipnet.ru and use long-distance and international destinations through it. After all, if you face it, the service of my local provider is only useful, that the direct city number and cheap calls within the city.
Let's go back to the configuration.
All connections will be made using the SIP protocol. Everything related to the operation of Asterisk with sip is described in the file
/usr/local/etc/asterisk/sip.conf :
[general]
videosupport=no
useragent=boorhomepbx
register=<_username>:<_password>@<_server_address>/200
[100]
type=friend
host=dynamic
username=100
secret=
language=ru
nat=no
canreinvite=no
context=home
mailbox=200@default
disallow=all
allow=ulaw
allow=alaw
deny=0.0.0.0/0
permit=192.168.0.0/24
[ext-out]
type=peer
context= extrnl
username=username
secret=<_password>
host=server_address
dtmf=inband
nat=yes
canreinvite=no
insecure=invite,port
fromuser=<_username>
fromdomain=<_server_address>
authname=<_username>
authuser=<_username>
100 is a local phone
ext-out is a provider
_username - username to register with the provider
_password - password to register with the provider
_server address - the address of the provider's server
It is important to pay attention to the line:
register=<_username>:<_password>@<_server_address>/200
Here we tell the server to register with the provider and in case of an incoming call, send it (call) to 200 extensions.
Also (as a litnimax rightly recommended), it is worthwhile to get into the habit of using the deny / permit directives. Be careful, as they say, God protects.
Next you need to set up a dialplan so that the server knows what he needs to do with the incoming calls. Dialplan is configured in the
/usr/local/etc/asterisk/extensions.conf file:
[home]
exten => 777,1,VoiceMailMain(300)
exten => _9.,1,Dial(SIP/ext-out/${EXTEN:1},30,r)
[extrnl]
exten => 200,1,Dial(SIP/100,20,Ttr)
exten => 200,2,Playback(vm-nobodyavail)
exten => 200,3,Voicemail(200@default)
exten => 200,n,Hangup
Here we have two contexts: home and extrnl. The first one is used for “local” calls, the second one gets calls “outside” (the context option in sip.conf).
Home has only two lines. The first allows you to get into the voice mail menu when dialing 777 (let's deal with it later).
The second line is somewhat trickier. Here, when you try to dial a number with prefix 9, the first character (prefix) is automatically discarded, and the remaining number is unchanged to the provider.
In the extrnl prefix we describe extension 200. Recall the register option in sip.conf. Actually, here first of all we are trying to call the SIP / 100 subscriber - this is our local phone (
exten => 200,1, Dial (SIP / 100,20, Ttr) ), if nobody picks up the phone within 20 seconds we play the voice message (
exten => 200.2, Playback (vm-nobodyavail) ) and transfer the caller to voice mail (
exten => 200.3, Voicemail (200 @ default) ). The last action is "hang up".
It uses standard sound files from the distribution. They can be replaced with your own.
Next you need to deal with voice mail. The file
/usr/local/etc/asterisk/voicemail.conf is responsible for this:
[general]
format=wav49|gsm|wav
serveremail=asterisk
attach=yes
skipms=3000
maxsilence=10
silencethreshold=128
maxlogins=3
emaildateformat=%A, %d %B %Y at %H:%M:%S
mailcmd=/usr/sbin/sendmail –t
sendvoicemail=yes
[zonemessages]
eastern=America/New_York|'vm-received' Q 'digits/at' Imp
central=America/Chicago|'vm-received' Q 'digits/at' Imp
central24=America/Chicago|'vm-received' q 'digits/at' HN 'hours'
military=Zulu|'vm-received' q 'digits/at' HN 'hours' 'phonetic/z_p'
european=Europe/Copenhagen|'vm-received' adb 'digits/at' HM
[default]
; + e-mail
; = , _, , _
200 = 123, Incoming , email@me.com, attach=yes
Here in the section [general] we specify the options, the names speak for themselves. In [default] we describe the mailboxes of subscribers. We have one subscriber with the box 200. Remember the line
exten => 200,3, Voicemail (200 @ default) from extensions.conf ?
These are the minimum settings for which we will get a working system. Monitoring, debugging and server management can be performed via an interactive console, which is called by the asterisk –r command.
In general, the possibilities of Asterisk are truly endless. As I said, you can register with several voip providers and route calls to the most financially advantageous areas. You can automatically track the availability of certain areas. Purely ryushechek instead of the standard beeps when you call you can screw some beautiful melody. This can play into your hands when working as a freelancer from home.
If you go further, you can screw the cell phone. To do this, you need a sim card from a gsm provider (preferably with unlimited calls to your number and back) and a sip-gsm gateway. Iron or soft. From software I know only
www.sipgsm.ru . There is one huge, in my opinion, flaw - it works only under windows. And so he worked during the test period is quite stable. This is the question of how to get gsm on your asterisk. Well, then we set up the queue and please - you are always in touch. When an incoming call we call the first subscriber (home landline phone), if no one takes it, we try to call our cellular via gsm-gateway. With some imagination, you can get an opportunity to exit from your cell phone to the intercity at the rates of the sip provider. In general, here it is possible to do this, which is very scary. Everything is limited only by your imagination.
References:
Official project page
Asterisk in Russian
Materials in Russian
Asterisk Knowledge Base
Questions - Asterisk: Questions and Answers
ATS Company Blog Design
Asterisk - voip-info.org