📜 ⬆️ ⬇️

Automation. Configuring Voip Phones Fanvil

The network has a lot of scattered information on automating the process of setting up phones, but there are very few complete tutorials. Here, using the example of the Fanvil F52 phone, I want to show one of the options for how to fully automate the configuration and registration of Fanvil phones.

This will require:


I will not touch the Asterisk settings. The only thing is to modify the sippeers table by adding the mac field (we will write the mac addresses of the phones into it).

Information about where to get the configuration, we will transmit using DHCP options.
')
By default, DHCP option 66 (receiving configs via TFTP) is activated on the phone.
TFTP we need ONLY in order to change the boot parameter of the phone at the first boot, telling it to use DHCP option 43 in the future.

On the DHCP server, we configure two parameters:

option 66 where we specify the address of the TFTP server: pbx.domain.ru
option 43 where we specify the web address of the configuration server http://pbx.domain.ru

On the TFTP server, we edit the f0F0052H000.cfg file (the file name is a unique phone model number, you can find out by looking at the TFTP server log) .

 <<VOIP CONFIG FILE>>Version:2.0003 <AUTOUPDATE CONFIG MODULE> DHCP Option :43 <<END OF FILE>> 

Now, when you first turn on the phone on the network, it will download f0F0052H000.cfg from the TFTP server, apply it, and reboot. That's it, now this TFTP phone is no longer needed. From now on, it will request configuration files from the server received via option 43.

During the download, the phone requests two files:

http://pbx.domain.ru/f0F0052H000.cfg is a common file for this phone model.

Static file with all settings except SIP settings.

http://pbx.domin.ru//mac.cfg where mac = mac is the address of the phone.

The second request processes the php-script index.php, which connects to the database, receives the necessary settings for a particular phone and gives them to it. Or, if the phone is new, it registers it in the database. Thus, the procedure for setting up the phone from the beginning to the end is fully automated.

 <?php $pbx = 'pbx.domain.ru'; $host = 'localhost'; $dbname = 'asterisk'; $dbuser = 'asterisk'; $dbpassword = 'password; $mac= substr(split('\.', $_SERVER["REQUEST_URI"])[0],1); if (strlen($mac) != 12 ) { print "goodbye"; //   mac-  12   . exit; } $db = pg_connect("host=$host dbname=$dbname user=$dbuser password=$dbpassword") or die('Could not connect: ' . pg_last_error()); function print_conf($name,$secret,$pbx) { header('Content-Type:application/txt'); echo "<<VOIP CONFIG FILE>> <SIP CONFIG MODULE> --SIP Line List-- : SIP1 Phone Number :$name SIP1 Display Name :$name SIP1 Sip Name :$name SIP1 Register Addr :$pbx SIP1 Register User :$name SIP1 Register Pswd :$secret SIP1 Enable Reg :1 SIP1 DTMF Mode :2 SIP1 VoiceCodecMap :G711A,G711U,G722,G729 SIP2 line attachmen:1 <PHONE CONFIG MODULE> LCD Title :$name <<END OF FILE>> "; } function query_sql($db,$mac,$pbx) { $result = pg_query($db, "SELECT name,secret FROM sippeers WHERE mac = '$mac';"); if (!$result) { // -    return 2; } if ( pg_num_rows($result) == 0 ){ //        MAC- return 1; }else { //     while ( $row = pg_fetch_row($result)){ $name = $row[0]; $secret = $row[1]; } print_conf($name,$secret,$pbx); } } //          function update_sql($db,$mac) { $result = pg_query($db, "SELECT name,secret FROM sippeers WHERE mac IS NULL;"); if ( pg_num_rows($result) == 0 ){ return 2; } else { $result = pg_query($db,"UPDATE sippeers SET mac = '$mac' WHERE id IN (SELECT id FROM sippeers WHERE mac IS NULL LIMIT 1);"); if ($res) { return 0; } } } if (query_sql($db,$mac,$pbx) == 1) { //  ,          if (update_sql($db,$mac,$pbx) == 0) { //    query_sql($db,$mac,$pbx); //       } } pg_close($db); ?> 

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


All Articles