$count=$db->query("select count(id) as c from out_line_settings")->fetch(PDO::FETCH_OBJ)->c;
if($count!=0){
$sql = "SELECT out_line_settings.id, out_line_settings.hrn, sip_conf.host, sip_conf.port, sip_conf.name,sip_conf.username FROM out_line_settings LEFT JOIN sip_conf ON sip_conf.outline_id=out_line_settings.id WHERE out_line_settings.type = 'SIP'"; // Вывод внешних линий
$result = $db->query($sql);
while ($arr = $result->fetch(PDO::FETCH_OBJ)) {
$status = 0;
if (exec('/usr/sbin/asterisk -rx "sip show registry" | grep "' . $arr->host . ':' . $arr->port . '" | grep "' . $arr->username . '" | grep "Registered"') != "")
$status = $status + 1;
if (exec('/usr/sbin/asterisk -rx "sip show peers" | grep "' . $arr->name . '/' . $arr->username . '"') != "")
$status = $status + 1;
$db->query("UPDATE out_line_settings SET line_status=" . $status . " WHERE id=" . $arr->id);
}
}
$timeout=$db->query("SELECT timeout from general_config")->fetch(PDO::FETCH_OBJ)->timeout;
$timezone=$db->query("SELECT curtz from general_config")->fetch(PDO::FETCH_OBJ)->curtz;
date_default_timezone_set($timezone);
$sql="select login,ip,id from web_users where (now() - online) > interval '".($timeout*60)."' AND session_id!=''";
$res=$db->query($sql);
while($arru=$res->fetch(PDO::FETCH_OBJ)){
$db->query("BEGIN");
$db->query("UPDATE web_users SET online='1970-01-01 00:00:00.000000', session_id='' WHERE ((now() - online) > interval '".($timeout*60)."' AND session_id != '')");
$db->query("INSERT INTO events (event_date,event_time,ip_client,user_id,user_login,event_type,event_place,event_note,event_status,title) VALUES
('" . date("Y-m-d") . "','" . date("H:i:s") . "','" . $arru->ip . "'," .$arru->id . ",'" . $arru->login . "',1,'0','<tr><td>окончание мониторинга внешней линии, выход по таймауту web</td></tr>',1,'')");
$db->query("COMMIT");
$sql="select login from web_users where (now() - online) > interval '".($timeout*60)."' AND session_id != ''";
$res=$db->query($sql);
break;
}