http://pbx.domain.ru
<<VOIP CONFIG FILE>>Version:2.0003 <AUTOUPDATE CONFIG MODULE> DHCP Option :43 <<END OF FILE>>
http://pbx.domain.ru/f0F0052H000.cfg
is a common file for this phone model.http://pbx.domin.ru//mac.cfg
where mac = mac is the address of the phone. <?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