yray писал(а): ↑Вс фев 14, 2021 10:58 pm
на последних прошивках не работает ?
В последних версиях DIGEST авторизация не работает.
Для исправления поправьте файл modules->keenetic_lan_devices->keenetic_lan_devices.class.php:
- добавьте метод:
private function checkAuth () {
$ch = curl_init('http://'.$this->config['API_URL'].'/auth ');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_HEADER, true);
$html = curl_exec($ch);
$headers = [];
$data = explode("\r",$html);
$headers['status'] = $data['0'];
array_shift($data);
foreach($data as $part){
$middle=explode(":",$part);
@$headers[trim($middle['0'])] = trim($middle['1']);
}
if($headers["status"] != "HTTP/1.1 200 OK"){
print $html;
$pass = hash('sha256', $headers["X-NDM-Challenge"].md5($this->config['ADMIN_USERNAME'].':'.$headers["X-NDM-Realm"].':'.$this->config['ADMIN_PASSWORD']));
$post = '{"login": "'. $this->config['ADMIN_USERNAME'] . '", "password": "' . $pass . '"}';
curl_setopt($ch, CURLOPT_HTTPHEADER, Array('Content-Type: application/json;charset=UTF-8'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$html = curl_exec($ch);
}
curl_close($ch);
}
- замените метод getAllDevicesInfo на:
private function getAllDevicesInfo()
{
try
{
if ($this->config['API_URL']=="") {return NULL;}
$this->checkAuth();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://'.$this->config['API_URL'].'/ci');
curl_setopt($ch, CURLOPT_POSTFIELDS, '<request id="0"><command name="show ip hotspot"></command></request>');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/xml']);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
if(curl_errno($ch)) {return NULL;}
if(strpos($data, "401 Authorization")>0)
{
DebMes("Ошибка авторизации на маршрутизаторе", 'keenetic_lan_devices');
return NULL;
}
$objectResult = new SimpleXMLElement($data);
$result = array();
foreach ($objectResult->children()->children() as $node) {
if ($node->mac=='' || $node->registered!="yes") {continue;}
$result[(string)$node->mac] = array();
$result[(string)$node->mac]["MAC"] = (string)$node->mac;
$result[(string)$node->mac]["STATUS"] = ((string)$node->link=='up' ? 1 : 0);
$result[(string)$node->mac]["STATUS_TXT"] = ((string)$node->link=='up' ? 'Online' : 'Offline');
$result[(string)$node->mac]["HOST_NAME"] = (string)$node->hostname;
$result[(string)$node->mac]["DEVICE_NAME"] = (string)$node->name;
$result[(string)$node->mac]["IP"] = (string)$node->ip;
$result[(string)$node->mac]["REGISTERED"] = (string)$node->registered;
}
//получаем статус подключения к интернету
curl_setopt($ch, CURLOPT_POSTFIELDS, '<request id="0"><command name="show internet status"></command></request>');
$data = curl_exec($ch);
if(curl_errno($ch)) {return $result;}
$objectResult = new SimpleXMLElement($data);
$gateWayMac = "11:11:11:11:11:11";
$result[$gateWayMac]["MAC"] = $gateWayMac;
$result[$gateWayMac]["STATUS"] = ((string)$objectResult->children()->children()->internet=='yes' ? 1 : 0);
$result[$gateWayMac]["STATUS_TXT"] = ((string)$objectResult->children()->children()->internet=='yes' ? 'Online' : 'Offline');
$result[$gateWayMac]["HOST_NAME"] = (string)$objectResult->children()->children()->gateway->interface;
$result[$gateWayMac]["DEVICE_NAME"] = "Интернет";
$result[$gateWayMac]["IP"] = (string)$objectResult->children()->children()->gateway->address;
$result[$gateWayMac]["REGISTERED"] = "yes";
curl_close($ch);
return $result;
}
catch (Exception $e) {
// код который может обработать исключение
//echo $e->getMessage();
return NULL;
}
}