- Code: Select all
if ($is_webphone == 'Y') {
$stmt = "SELECT srvs.server_ip, srvs.server_description, count(vla.server_ip) as live_agents_count
FROM vicidial_live_agents vla RIGHT JOIN servers srvs ON vla.server_ip = srvs.server_ip
GROUP BY srvs.server_ip
ORDER BY live_agents_count ASC LIMIT 1";
$sql = mysql_to_mysqli($stmt, $link);
$row = mysqli_fetch_row($sql);
echo "<!-- SQL Statement: {$stmt} " . print_r($row, true) . " -->";
$new_server_ip = $row[0];
$domain_name = $row[1];
$conf_override = "context=default" . PHP_EOL;
$conf_override .= "transport=ws,wss,udp" . PHP_EOL;
$conf_override .= "encryption=yes" . PHP_EOL;
$conf_override .= "icesupport=yes" . PHP_EOL;
$conf_override .= "avpf=yes" . PHP_EOL;
$conf_override .= "nat=comedia" . PHP_EOL;
$conf_override .= "directmedia=no " . PHP_EOL;
$conf_override .= "dtlsenable=yes" . PHP_EOL;
$conf_override .= "dtlsverify=no " . PHP_EOL;
$conf_override .= "dtlscertfile=/etc/certbot/live/$domain_name/cert.pem" . PHP_EOL;
$conf_override .= "dtlsprivatekey=/etc/certbot/live/$domain_name/privkey.pem" . PHP_EOL;
$conf_override .= "dtlssetup=actpass" . PHP_EOL;
$stmt = "UPDATE phones SET active='Y', server_ip='$new_server_ip', conf_override='$conf_override' WHERE
extension='$phone_login' ";
mysql_to_mysqli($stmt, $link);
$stmt = "UPDATE servers SET rebuild_conf_files = 'Y' WHERE active_asterisk_server = 'Y' ";
mysql_to_mysqli($stmt, $link);
$stmt = "SELECT server_description FROM servers WHERE active_asterisk_server = 'Y' ";
$sql = mysql_to_mysqli($stmt, $link);
while ($row = mysqli_fetch_row($sql)) {
$domain_name = $row[0];
$url = "https://$domain_name/conf_rebuild_phones.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_USERAGENT, 'dialer_agent');
curl_exec($ch);
curl_close($ch);
}
echo "<!-- >> Phone {$phone_login} moved to server: {$domain_name} with ip: {$new_server_ip} -->";
}
So the above code works, but sometimes agents aren't able to register after logging in and "reg failed" shows on viciphone. Trying to login multiple times sometimes fixes the problem.
Can someone help me fix this.....
Thanks.