📜 ⬆️ ⬇️

Asterisk, or home telephony for (pro) moved users

This story began two long years ago, when, during a business trip to the USA, I was suddenly left without a mobile connection: I changed the phone with a fool before the trip, but it turned out to be “two-band” ... And roaming is not cheap ...
The result was the discovery of SIP-telephony.

And here several months ago, from articles on Habré, I find out that other people's uncles can and don’t pay for intercity if you need to call from somewhere in your hometown via the Internet! It is enough to put the VoIP server and configure it exactly as you need it!

And so, taking Asterisk in my hands, I began an operation to combat the excessive greed of OpSoSov ...
')


Note




Introduction


There was a 2-core server on ubuntu (10.04), which, in principle, fulfills my duties as a file archive, but in practice it is often idle.
It was necessary to simplify my life with telephone conversations.
In particular, the following tasks were set:

Having outlined a range of tasks, we proceed to the purchase of glands for this business.

Hardware


D-Link DVG-7111S - GTS-VoIP Adapter

image
I chose it for a relatively “cheap” cost - in Moscow it costs from 2,152 to 2,610 rubles, which is slightly cheaper than the Linxuses, who also need to be found.
In fact, it makes two SIP clients that connect to Asterisk from the city line and telephone.
Settings do here so Makar

The subtlety is one connected with CallerID - for its correct transmission, you need to miss one call, so that the adapter has managed to determine the number:
HOT LINE-> Ring count before FXO pick up = 1

If necessary, you can upgrade the firmware, but unlike routers and other DLink devices, this is a rather uncommon process ...

Sometimes the adapter beats the definition of the signal "Busy". To do this, you need to adjust the duration of these signals. Instructions on how to get them are available , but he hasn’t dealt with himself yet - it’s only the second day that this problem started after the equipment was changed to PBX.

For a call from Asterisk to a city number, the following format is used for Dial in Dialplan:
Dial (SIP / FXO channel number / telephone)
To call the phone:
Dial (SIP / FXS channel number)

To simplify life with marasmus from MGTS, I myself made it possible to dial all the numbers in Moscow with the same “8-code-7 digits”, and the server will deal with the dialing rules:

Below are two configuration options. The first option is for those who have a number in the 495 code, and the second - in 499. Both options allow you to call both phones in the 495 code, and in 499.

For rooms in code 495
; 495 -
exten => _8495XXXXXXX,1,Dial(SIP/701/${EXTEN:4})
exten => _8495XXXXXXX,n,Hangup()
; 499 -
exten => _8499XXXXXXX,1,Dial(SIP/701/${EXTEN:0}) ; - 499 , , - -, 8...
exten => _8499XXXXXXX,n,Hangup()

For numbers in 499 code
; 495 - ""
exten => _8495XXXXXXX,1,Dial(SIP/701/${EXTEN:0})
exten => _8495XXXXXXX,n,Hangup()
; 499 - ""
exten => _8499XXXXXXX,1,Dial(SIP/701/${EXTEN:1})
exten => _8499XXXXXXX,n,Hangup()


Phone

Initially, he used a Panasonic radio receiver connected to an adapter's FXS port as a telephone, but quickly became disillusioned: its clumsy display only dealt with the digital CallerID. Therefore, Siemens Gigaset C470 IP + Siemens Siemens Gigaset C47H handset was purchased .
image
For them, I laid out a total of five thousand and I do not regret: The main charm of the unit is that it supports simultaneous work with 6 tubes (basic + 5 additional).
“And what's the point? There is one line! ”You will say and ... You will be fundamentally wrong!
In addition to 6 handsets - the base station also supports 6 sip accounts! Each of which can be tied to your handset !!!
Those. - if you put a radio tube in each room in an apartment, then these will be completely different sip-users who can calmly talk at the same time!

A few words about the setting:
Whatever you say in the instructions - the dynamic allocation of the address on the phone does not occur. Therefore, there are two options - with a handset to drive the correct one or by briefly pressing the button on the base - to determine the current network and configure it.
The pin-code can be changed ONLY from the handset - there is no such item in the web panel: so it is better to change it right away, until it was done by some cunning hacker!

GSM adapter

Then I took the path of least resistance and bought the MTS modem Huawei E1550.
Why mts?
Firstly - 770 rubles, not 1500 for "not broken"
Secondly, the Bee and Megi have voice functions AT ALL.
Thirdly, I needed a modem under A-Mobile's Ashanovsky tariff, which didn’t have to be reflashed on the MTS network.
Who does not know - A-Mobile allows you to make 15 minutes of free calls per day to another A-Mobile, after which - a nominal fee of 90 kopecks per minute. I needed it as a backup channel to the home network and tariff, IMHO, the most enjoyable!
Device settings are dreary , but nothing complicated.

+ now on Habrapish has received a message from Angel2S2 :
“By the way, about the unlock of huawei modems ... If you're interested, you can look at me - angel2s2.blogspot.com/2010/07/huawei.html . I broke E160G and E1550 from a megaphone and mts, you can also call :) „
MB will help someone!

Uchkuduk two modem ...

A few more words complement ...
I put the second modem on the system for incoming AlloIncognito and then he came in the most ... P-c which: the modems themselves swapped acrobats in the circus! When disconnecting one - the second strove to move to its ports, etc. etc.

And since Dialplans are fundamentally different for them - it was necessary to somehow decide ...
The solution is quite reasonable for Linux: a fixed “link” can be assigned to the port!
Those. - we set for modem 1 - ports are not ttyUSB1 and 2, but hv0 and hi0 (HuaweiVois and HuaweiInfo)!
How?
We disconnect both modems from the computer, we insert the first one.
We give the command dmesg from the root in the terminal
In response, a lot of everything falls out, but at the end - the cherished lines:
[291015.913221] option 1-2:1.0: GSM modem (1-port) converter detected
[291015.913364] usb 1-2: GSM modem (1-port) converter now attached to ttyUSB0
[291015.913926] option 1-2:1.1: GSM modem (1-port) converter detected
[291015.914026] usb 1-2: GSM modem (1-port) converter now attached to ttyUSB1
[291015.916678] option 1-2:1.2: GSM modem (1-port) converter detected
[291015.916812] usb 1-2: GSM modem (1-port) converter now attached to ttyUSB2

“Who is who?”:
After the option comes the port ID.
1-2 - the first USB host, the second device
: 1.1 is the first port on this device.
The next line - infa on how the port has become this our internal.
We are interested in the pre-last and last - 1 and 2 in this case.
1 - port for voice, 2 - for data.
Now open the file /etc/udev/rules.d/huawei.rules from under the root for editing - here the rules for all Huawei devices in the system are written. Most likely it will be empty.
We drive in the lines:
KERNEL=="ttyUSB[0-9]*", ID=="1-2:1.1", NAME="%k", SYMLINK+="hv0", GROUP="root", MODE="0666"
KERNEL=="ttyUSB[0-9]*", ID=="1-2:1.2", NAME="%k", SYMLINK+="hi0", GROUP="root", MODE="0666"

“All devices on this particular port are now also called hv0, and this one is hi0! Save, Amen! ”
We repeat the process starting from plugging in for the second modem - two more lines will appear in the file, in which there are already ports from the second modem and hv1 and hi1 ... You can add the third and the hundred and thirty-fifth one ...

Now if you pull out the modems and insert, then using the command ls -1 / dev / hv * or ls -1 / dev / hi * will ALWAYS give the necessary device, the main thing is not to confuse the connector on your computer!

/etc/asterisk/datacard.conf is also changing - instead of faceless
audio=/dev/ttyUSB1 ; tty for audio connection
data=/dev/ttyUSB2 ; tty for AT commands

Appear
audio=/dev/hv0 ; tty for audio connection
data=/dev/hi0 ; tty for AT commands

Now we restart Asterisk and hurray - there will be no more confusion!
On this with iron for now.

SIP operators


In principle, with the existing equipment, we already have a city + mobile line, but I want additional opportunities, and I need to call somehow through the intercity!

Multiphone

Multiphone is a service from Moscow Megaphone. The point is that this is not just Internet telephony! This is Internet telephony, tied to your Megaphone number!
Translated into Russian: if someone calls your number, both the cellular and SIP client will work with the appropriate settings!
The Asterisk setting for this case was pretty well described on Habré , I can only add instructions on how to attach SEVERAL Multifonov to the server - some moments are controversial and did not work for me due to incompatibility with codecs, but perhaps this is a bug of my config ?!
UPD. Native instruction of the Multiphone on setting up in Asterisk

A few words are common for all SIP-operators: if you are going ONLY to call from some SIP account, then register is not needed, but if you intend to accept ...
By the way, register with such a furious syntax - only for Megaphone: for the rest, it is more standard ...

Europhone

Euroset CIP-telephony service. In the black, the lion’s share of Russian cities is priced at 49 kopecks. There are incoming numbers in Moscow and a bunch of cities, so if you are not too lazy to drive in a number + your number in Europhone - you can receive incoming calls from there ...
Potentially, if the incoming city is not particularly needed, and you do not need to call very much, it may be more profitable than the monthly 155 rubles from MGTS "for the line" ...

For registration - you need to buy a telephony card from Euroset. Username-password - will be listed on the card, in the future, this account can be credited. There is no registration without a card.

pctel.ru

Calls to all Russian numbers - by ruble per minute.
I took it as an “add-on” to Europhone: calls to mobiles are cheaper in it, but I’m not talking about a ruble and a half for outgoing ones in the Multiphone! If you want to hide your number - the most it.

Sipnet

Nothing special, but many prefer it.

DID, or Direct Telephone Number


This service is that you can get a phone number in one of the cities of any country and receive calls to this number via Asterisk.
The advantage is that if you move often, it will allow you to always keep your number, minus - unlike 155 rubles per month at MGTS, the prices for Moscow numbers from operators start from 250 rubles, approximately. (For comparison, the number in the United States costs about $ 3.5 per month).

Go2baza

According to the people who used it, the direct Moscow number costs 250 rubles per month. Tariffs are not clearly defined, so I can neither confirm nor deny ... Approximately 250 per month for a room, plus the initial payment for the allocation of a number — 500 rubles for 499 or 3000 for 495 ... It’s worth paying more if MGTS becomes here in 499 to push all ?!
Plus, what is provided by as many as five incoming channels ... However, only when redirecting to phone numbers, and on SIP - only 2 (they overloaded in April). But the redirect to the phones is paid, and on the CIP - a freebie!
Well, then: a two-channel phone number - IMHO, very good! Most often, more and do not!

"Personal phone number" or "Number that is always with you"

MGTS bullshit. In fact - the Moscow number through SIP. In the time-based version of the subscription fee is not, the price per minute - the same 36 kopecks. Connection - 8340 rubles, and the Siemens 470 I was talking about comes in the kit.

Sponges rolled? Freebie? Cool?
Catch the machine: it works ONLY through ADSL from MGTS! As explained in the support, this is only for organizing a second phone number at home.
Potentially, it is obviously possible to tamp down with Asterisk, but I don’t need such a phone tied to the main line and I don’t need a gift, but I couldn’t find the happy owners of this service on the Internet.
Just keep in mind what it is, and if at home someone periodically hangs on the phone, you can connect, so that there is a backup line ...

gtalk2voip

Direct numbers in different countries.
Registration idiotic:
1. Go to gtalk2voip , in the corner there is a field for entering e-soap. Enter google soap.
2. Connect to Jabber on your Google account, see the invitation from the user service@gtalk2voip.com. Connect to the "conversation"
3. Further, this bot command MYPAGE get a page through which you can register numbers and replenish the balance.

ipkall

A company with a “non-print” name provides free phone numbers in the USA with redirect to SIP. If you don’t need it, don’t need to occupy it with registrations: what if someone needs it, and everything goes away in habraeffekt ?!
About this service I have an eternal scandal with a toad:
- s! Cool! US Toll Free! It is necessary, it is necessary, it is necessary!
- What for? - asks realist. - Are you a thread from the States calling?
- Because they do not call! Want Want want!
- Learn English, Wishlist! That call, and what do you say ?!
- Hyundai-hoh? Ay Widersein? Hows What would such a pyleglot like me say nothing ?! Ha!
- All the same - the meaning in it is zero now!
- So what? Halyaaaaava!

Alloincognito: "The Perfect 499"

Ideal 499 , tariff plan from Alyinkognito, without subscription fee for 499 ... Included is a SIM card from MegaFon, to which calls are received ...
Link threw bdmalex . According to him, he has been using it for a long time, there really is no subscription fee and, even that, in general, beyond my understanding, there is no payment for re-sending incoming calls to a mobile number !!!

Asterisk Dialplan Plans


With iron and operators, somehow, we figured out ...
Now a few tricks related to Asterisk:

Black list

Sometimes I really want something to stop calling a person: an ex-girlfriend, an idiot who is always mistaken with a number, advertising agents, polls, etc. etc.
To do this, there is a BLACKLIST () command in Asterisk. In fact, it checks CallerID with a list in its database, and if it returns 1, then you can safely send the caller to hell!
You can read about the “Simple” version here , but I wanted to make my life a little easier: well, I’m lazy to look at the number on the determinant, after which I’m trying to drive it in the right place!
Let Asterisk do it himself!

In Dialplan, when we call from the right context, we write (when I call from MGTS, I redirect to number 123 - replace it with what you have indicated!):
exten => 123,n,Set(_From=${CALLERID(name)}) ; name, num , CallerID !
exten => 123,n,GotoIf($[${BLACKLIST()}=1]?banned) ; - - - banned
exten => 123,n,Set(DB(ToMe/LastCaller)=${From}) ;
.....
; .
.....
exten => 123,n,Hangup()

; !
exten => 123,n(banned),Answer()
exten => 123,n,Playback(, )
exten => 123,n,Hangup()


And in the dialplan of the telephone:
; 20 -
exten => 20,1,Set(tmp=${DB(ToMe/LastCaller)})
exten => 20,n,Set(DB(blacklist/${tmp})=1)


Now, if after calling the spammer you pick up the phone and dial "20" - it will add it to the list of banned!
How to remove the number - shown in the instructions above.

Speed ​​dial

All of us have numbers that we most often call: relatives, work colleagues, acquaintances ...
To drive in every time 10 digits of the number is lazy! Therefore, you can create a notebook directly on your PBX!
In the dialplan for the phone:
exten => 1,1,Dial(SIP/701/8495......) ;
exten => 2,1,Dial(SIP/701/8495......) ;
exten => 3,1,Dial(SIP/701/8495......) ;
exten => 4,1,Dial(SIP/701/8499......) ;

Etc. etc.

In general, I wanted to make a voice menu, but for some reason, when I remove the radio tube, the processing of the number “s” does not happen ... So you can simply write to the “who is xy” button ...
If several handsets are bought, as in my case, each one may have its own context with its “short numbers”: parents do not need my friends on the phone in the room, and theirs are not necessary for me ...

Greetings from the time of day

You can add a bit of “humanity” to your ATSC, so that it gives out a different greeting, depending on the time of day (and, if desired, the day of the week, month, etc., etc.). For example, in the morning she can greet the caller with a yawn, and at night she can express everything that she thinks of a person who calls when all normal people are already sleeping.

;
exten => 1200,1,Background(hello_utro) ; ""
exten => 1200,n,Goto(123,naberite) ;

exten => 1201,1,Background(hello_den) ; ""
exten => 1201,n,Goto(123,naberite) ;

exten => 1202,1,Background(hello_vecher) ; ""
exten => 1202,n,Goto(123,naberite) ;

exten => 123,1,Verbose(" ")
exten => 123,n,Answer() ;
exten => 123,n,GotoIfTime(07:00-12:00|*|*|*?1200,1) ; 7 12
exten => 123,n,GotoIfTime(12:01-19:00|*|*|*?1201,1) ; - 12 19
exten => 123,n,GotoIfTime(19:01-22:00|*|*|*?1202,1) ; - 19 22
exten => 123,n,Background(hello_noch) ; - : ""

exten => 123,n(naberite),Verbose(" ") ; ...
...


Antibot

If you are often called by left people asking for “Masha, Sasha or Dasha,” or even some Barakobam in general, the following example is yours!
The general idea is that when you answer, you will receive a greeting in the style “Hello, you called the apartment. If you are sure that this is Ivanov's apartment - press 1, if Petrovs are 2, Sidorovs are 3! If none of the names does not match, or you call the organization - hang up: you did not get there! ”
Minus - will be wrapped and "useful" bots, like "You forgot to pay the phone and soon we will cut off you!", But here either-or ...

exten => 123,n,Answer()
...
exten => 123,n(naberite),Background(familie) ;
exten => 123,n,WaitExten() ;

exten => 1,1,Goto(normal,s,1) ; 1 - , ! 1 2, 3 . "normal" - , .

exten => i,1,Playback(invalid) ; —
exten => i,n,Hangup() ;

exten => t,1,Playback(bay) ; -
exten => t,n,Hangup() ;


Sly Callback

I have a mobile phone with two SIM cards: one for talking, the second for A-Mobaylovskaya to communicate with my mini-PBX.
Well, the problem is that a couple of times by mistake I called from the wrong SIM card - 2.40 is not money, of course, but when you debug and call periodically to the server - it's unpleasant!
In this connection, I slightly redid the Callback script to fit my needs.

[incoming_mobile]
;
exten => s,1,GotoIf($["${CALLERID(num)}" = "+7916......."]?allow) ; - - !
exten => s,n,GotoIf($["${CALLERID(num)}" = "+7926........"]?callback) ; - !
exten => s,n(reject),Hangup() ; - , !
exten => s,n(allow),Verbose(" -")
exten => s,n,Goto (incoming_mobile,200,1) ;
exten => s,n,Hangup()
exten => s,n(callback),Verbose(" - !")
exten => s,n,System(/etc/asterisk/scripts/callback)
exten => s,n,Hangup()

exten => 200,1, .... ; , , , .
.....

exten => 601,1,Dial(Datacard/g1/+7916....) ; -
exten => 601,n,Hangup()


And this is / etc / asterisk / scripts / callback - do not forget to give it execution rights: I could not understand for half an hour why it did not work!
#!/bin/sh
sleep 10
echo "Channel: Local/601@incoming_mobile
MaxRetries: 1
RetryTime: 10
WaitTime: 20
Context: incoming_mobile
Extension: 200
Priority: 1
AlwaysDelete: Yes" >/var/spool/asterisk/tmp/tst.call
mv /var/spool/asterisk/tmp/tst.call /var/spool/asterisk/outgoing/tst.call


“I'm not all home!” Or “I'm in the house!”

This fragment is so elementary that it takes longer to describe why it is needed, than the extensions themselves!
So, you went somewhere for business, put your mobile phone in your pocket, combed it to the other end of the city and suddenly someone decided to call you at home! And “your call is important for us,” but you cannot answer ... Or can you?
; DID
...
exten => 123,n,Dial("sip/702",10) ; 10 - ...
exten => 123,n,Verbose(" - , !")
exten => 123,n,Dial("sip/702"&"Datacard/g1/+7916....",20) ; ...
exten => 123,n,Hangup()


The second piece - will be of interest to the owners of the Multiphone.
I, and many acquaintances, have a “disease”: forgetting a mobile phone in a pocket of trousers or a bag and stuffing this “vault” into a closet ... As a result, the choked phone squeals can hardly be heard, but the call could be important !!!
To combat this, I paralleled a radio tube to the Megaphone-Multiphone in my room.
It becomes stupid in 2.5 lines:
exten => 7926.......,1,Verbose(" !")
exten => 7926.......,n,Dial("SIP/702")
exten => 7926.......,n,Hangup()


Protection


Unlike home web ftp servers - home mini-PBX is a pretty serious threat to your well-being: bad radishes, having access to your telephone network, can be so interspersed so that a Beeline’s expense to a tourist for a connection in the amount of half a million can seem cheap!
I recommend reading the article about the protection of Asterisk , a note on Habré about the Cuban Epidemic ...
Well, simple tips:
1. If calls from the city line go only to landline numbers - block the dialing of any other numbers at the extension level.
2. To enter the intercity - create a separate context for the intercity, the entrance to which will be through the "password" - the number that must be entered.
3. For local phone accounts, type in a sip.conf for each local user its fixed IP address, in extreme cases, a local sub grid, the benefit is that SIP phones and adapters most often have the option to set a fixed IP.

Conclusion


This is only a small part of what can be done with Asterisk. Some more things I just could not remember - trite falling asleep on the go.
All this, if desired, the readers can be supplemented and corrected: write wishes in the comments!

Literature


O'Reilly, Asterisk: The Future of Telephony - Mast Hev! Bible!
Asterisk and Linux - IP Telephony Mission, Part 1
Asterisk and Linux - IP Telephony Mission, Part 2
Asterisk and Linux - IP Telephony Mission, Part 3
Making money on the stars
Asterisk Voice Menu

PS “Head bo-bo, in the mouth byak ....” - I will sleep off and add more about the protection of all this, a few words about NAT and some other examples.

PPS Some places in the dialplan "cut by the living" - may be a little buggy: write - I will clarify and correct!

Source: https://habr.com/ru/post/104026/


All Articles