Automation. Setting Up Voip Phones Fanvil
This will require:
- Asterisk with configured peers in realtime (in my case it is Posgresql)
- DHCP, TFTP and WEB servers
I will not touch on setting up Asterisk. The only thing is that you need to modify the sippeers table by adding the mac field (we will write the phone’s mac addresses into it).
Information about where to get the configuration, we will pass using DHCP options.
By default, DHCP option 66 is activated on the phone (receiving configs via TFTP).
We need TFTP ONLY in order to change the phone boot parameter at the first boot, instructing it to use DHCP option 43 in the future.
On the DHCP server, configure two parameters:
option 66 where we specify the TFTP server address: pbx.domain.ru
option 43 where we specify the address configuration server web
http://pbx.domain.ruon the TFTP server edit the file f0F0052H000.cfg(file name - a unique phone model number, you can find out by looking at the TFTP server log) .
<>Version:2.0003
DHCP Option :43
<>
Now, when you first turn on the phone on the network, it downloads f0F0052H000.cfg from the TFTP server, applies it, and reboots. That's it, now this TFTP phone is no longer needed. From this moment, it will request configuration files from the server received through option 43.
During the download, the phone requests two files:
http://pbx.domain.ru/f0F0052H000.cfg- a file common to this phone model. A static file with all settings except for SIP settings.
http://pbx.domin.ru//mac.cfgwhere mac = mac is the phone address. The second request is processed by 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, registers it in the database. Thus, the procedure for setting up the phone from start to finish is fully automated.
>
--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
LCD Title :$name
<>
";
}
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);
?>