Код: Выделить всё
$ip = gg('Mikrotik_IP');
$login = gg('Mikrotik_login');
$password = gg('Mikrotik_password');
$API = new routeros_api();
if ($API->connect($ip, $login, $password)) {
// Получить все объекты класса
$objects = getObjectsByClass('WiFiDevice');
// WIFI клиенты ведущей точки
$ARRAYm = $API->comm('/interface/wireless/registration-table/print');
// WIFI клиенты ведомых точек
$ARRAYc = $API->comm('/caps-man/registration-table/print');
// Объединяем массивы
$ARRAY = array_merge($ARRAYm,$ARRAYc);
//print_r($ARRAY);
// перебор объектов класса WiFiDevice
foreach ($objects as $obj) {
$obj=getObject($obj['TITLE']);
$f=0;
// перебор массива роутера
foreach ($ARRAY as $i => $arr) {
if ($obj->getProperty('MAC') == $arr['mac-address']) {
$obj->setProperty('lastActive' , date("Y-m-d H:i:s",time()));
// Вызов метода Found
if (!$obj->getProperty('online')) {
$j=$obj->getProperty('holdCycles');
if (!$j) { $j=1; }
$obj->setProperty('online', $j);
$j=0; //свободна
$obj->callMethod('Found');
}
// удаляем элемент массива
unset($ARRAY[$i]);
$f=1;
// break;
}
}
// если MAC этого объекта в массиве роутера нет
// Уменьшить свойство online. Когда достигнет нуля, вызвать метод Lost
if (!$f) {
$j=$obj->getProperty('online');
if ($j) {
$j=$j-1;
$obj->setProperty('online', $j);
// Вызов метода Lost
if (!$j) { $obj->callMethod('Lost'); }
}
$j=0; //свободна
}
}
// перебор оставщихся MAC адресов массива роутера
foreach ($ARRAY as $arr) {
// Создание нового объекта
addClassObject('WiFiDevice', 'wifi_'.$arr['mac-address']);
$obj=getObject('wifi_'.$arr['mac-address']);
$obj->setProperty('MAC', $arr['mac-address']);
$obj->setProperty('name', 'Неизвестный девайс');
$obj->setProperty('lastActive' , date("Y-m-d H:i:s",time()));
$obj->setProperty('notify' , '20');
$obj->setProperty('online', '1');
$obj->setProperty('holdCycles', '2');
$obj->callMethod('Found');
}
/*
// список выданных адресов
$ARRAY = $API->comm('/ip/dhcp-server/lease/print');
print_r($ARRAY);
// о системе
$ARRAY = $API->comm('/system/resource/print');
print_r($ARRAY);
*/
$API->disconnect();
// echo ('ok');
} else { echo 'error'; }
setTimeOut('getWiFiclientsTimer',"runScript('getWiFiclients');",10);
14:04:41 0.13466100 Geturl to 192.168.1.3:80/objects/?job=11343877 (source runScheduledJobs) finished with error:
Operation timed out after 60001 milliseconds with 0 bytes received
{"url":"HTTP:\/\/192.168.1.3:80\/objects\/?job=11343877","content_type":null,"http_code":0,"header_size":0,"request_size":166,"filetime":-1,"ssl_verify_result":0,"redirect_count":0,"total_time":59.055497,"namelookup_time":5.4e-5,"connect_time":0.000215,"pretransfer_time":0.000316,"size_upload":0,"size_download":0,"speed_download":0,"speed_upload":0,"download_content_length":-1,"upload_content_length":-1,"starttransfer_time":0,"redirect_time":0,"redirect_url":"","primary_ip":"192.168.1.3","certinfo":[],"primary_port":80,"local_ip":"192.168.1.3","local_port":60613}
14:04:15 0.72500800 Closing socket.
14:03:46 0.92444200 Closing socket.
14:03:38 0.11998000 Error executing job WiFiclientsTimer (11343805): (/var/www/***/lib/common.class.php)
14:03:38 0.11968800 Geturl to 192.168.1.3:80/objects/?job=11343805 (source runScheduledJobs) finished with error:
Operation timed out after 60001 milliseconds with 0 bytes received
{"url":"HTTP:\/\/192.168.1.3:80\/objects\/?job=11343805","content_type":null,"http_code":0,"header_size":0,"request_size":166,"filetime":-1,"ssl_verify_result":0,"redirect_count":0,"total_time":59.051764,"namelookup_time":6.1e-5,"connect_time":0.000202,"pretransfer_time":0.000303,"size_upload":0,"size_download":0,"speed_download":0,"speed_upload":0,"download_content_length":-1,"upload_content_length":-1,"starttransfer_time":0,"redirect_time":0,"redirect_url":"","primary_ip":"192.168.1.3","certinfo":[],"primary_port":80,"local_ip":"192.168.1.3","local_port":60587}