Jetzt läuft es , der Vollständigkeit halber :
die Funktionierende unifi.php
<?
$username="ipsymcon";
$password="ipsymcon";
$baseurl="https://192.168.178.3:8443";
function Unifi_GetClients()
{
global $username;
global $password;
global $baseurl;
# init curl object and set session-wide options
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/unifi_cookie");
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/unifi_cookie");
curl_setopt($ch, CURLOPT_SSLVERSION, 1); //set TLSv1 (SSLv3 is no longer supported)
# authenticate against unifi controller
#curl_setopt($ch, CURLOPT_URL, "$baseurl/login");
curl_setopt($ch, CURLOPT_URL, "$baseurl/api/login");
curl_setopt($ch, CURLOPT_POST, 1);
#curl_setopt($ch, CURLOPT_POSTFIELDS, "login=login&username=$username&password=$password");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array("username" => $username, "password" => $password)).":");
curl_exec ($ch);
# client stats
curl_setopt($ch, CURLOPT_URL, "$baseurl/api/s/default/stat/sta");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "json={}");
$response = curl_exec ($ch);
# logout
curl_setopt($ch, CURLOPT_URL, "$baseurl/logout");
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, NULL);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_exec ($ch);
curl_close ($ch);
unset($ch);
if ($response !== false) {
return json_decode($response);
} else {
return 0;
}
}
/*
Todo!
function Unifi_AuthorizeDevice($mac, $minutes = 1440, $rateup = 512, $ratedown = 2048, $MBlimit = 150)
{
global $username;
global $password;
global $baseurl;
# init curl object and set session-wide options
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/unifi_cookie");
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/unifi_cookie");
curl_setopt($ch, CURLOPT_SSLVERSION, 1); //set TLSv1 (SSLv3 is no longer supported)
# authenticate against unifi controller
curl_setopt($ch, CURLOPT_URL, "$baseurl/login");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "login=login&username=$username&password=$password");
curl_exec ($ch);
# authorize a guest for $minutes with $rateup/$ratedown bandwidth limits and $MBlimit max transfer
curl_setopt($ch, CURLOPT_URL, "$baseurl/api/s/default/cmd/stamgr");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "json={'cmd':'authorize-guest', 'mac':'$mac', 'minutes':$minutes, 'up':$rateup, 'down':$ratedown, 'bytes':$MBlimit}");
$response = curl_exec ($ch);
# logout
curl_setopt($ch, CURLOPT_URL, "$baseurl/logout");
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, NULL);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_exec ($ch);
curl_close ($ch);
unset($ch);
if ($response !== false) {
return $response;
} else {
return 0;
}
}
*/
?>
meine unifi Abfrage :
<?
// V1.00 07.01.2015 - Erstes Release
// Mit diesem Skript können die Daten der an den Unifi APs angemeldeten Clients
// abgerufen werden.
//
// © by Kevin Heidrich 2015
// kevinheidrich@me.com
// Web: www.kh-solutions.de
//
//Vorgehensweise:
//
// - String Variable für die Ausgabe im Webfront anlegen und ID in der Config unten eintragen
$htmlBoxID = 40337 /*[Geräte\Unifi WLan\Content]*/; // bitte eine anlegen
// Optional können noch die nächsten Tabellen gepflegt werden.
//
// Eine Lockup Tabelle für nicht ermittelbare Gerätenamen pflegen
// Über den Parameter "PresentVarID" wird eine bool Variable mit dem aktuellen
// Verfügbarkeitsstatus befüllt. Evtl. sinnvoll für Anwesenheitserkennung über das
// Handy.
$macList = array(
array("Name" => "Sonos Play5", "MAC" => "b8:e9:37:22:3a:81"),
array("Name" => "iPhone Marcel", "MAC" => "70:3e:ac:07:c1:34", "PresentVarID" => 15995),
array("Name" => "iPhone Lilly", "MAC" => "88:1f:a1:c0:a3:14", "PresentVarID" => 28131),
);
// Eine weitere Lockup Tabelle für die Accesspoints und deren Alias.
$apList = array(
array("Name" => "Buero", "MAC" => "04:18:d6:10:1f:29"),
array("Name" => "Balkon", "MAC" => "04:18:d6:9a:62:5a"),
);
// ----------------------------------------------------------------------------------
// Ab hier dann bitte nichts mehr ändern
// ----------------------------------------------------------------------------------
include "unifi.php";
$clientList = Unifi_GetClients();
$scriptResult = "";
foreach($clientList->data as $client)
{
$scriptResult .= "<tr style='height:20px;font-size:12px;'>";
// Name über MACNummer rausfinden.
// Nicht alle Geräte senden anständig ihren Namen mit. Deswegen über Liste arbeiten
$clientName = "";
foreach($macList as $key => $entry)
if ($entry["MAC"] == $client->mac)
{
$clientName = $entry["Name"];
break;
}
// War nicht in Liste!
if ($clientName == "")
$clientName = $client->hostname;
$scriptResult .= "<td>".$clientName."</td>";
$scriptResult .= "<td style='text-align:center'>".$client->mac."</td>";
$scriptResult .= "<td style='text-align:center'>".$client->ip."</td>";
// Accesspoints übersetzen
$apName = "";
foreach($apList as $ap)
if ($ap["MAC"] == $client->ap_mac)
{
$apName = $ap["Name"];
break;
}
// War nicht in Liste!
if ($apName == "")
$apName = $client->ap_mac;
$scriptResult .= "<td style='text-align:center'>$apName</td>";
$scriptResult .= "<td style='text-align:center'>".$client->essid."</td>";
$scriptResult .= "<td style='text-align:center'><div style='width:100%;height:20px;overflow:hidden;'>";
// Pegelumwandlung - Entspricht leider nicht dem Wert in der Webconsole. Kein Plan wie die das berechnen
/* 100% -35 / 50% -65 / 1% -95 */
if ($client->signal <= -95)
$percent = 1;
else if ($client->signal >= -35)
$percent = 100;
else
$percent = round(($client->signal + 95) / 0.6);
if ($percent < 10)
$levelImg = "0";
else if ($percent <= 20)
$levelImg = "1";
else if ($percent <= 40)
$levelImg = "2";
else if ($percent <= 60)
$levelImg = "3";
else if ($percent <= 80)
$levelImg = "4";
else
$levelImg = "5";
$scriptResult .= "<img src='user/level/level$levelImg.png'> $percent% (Ch.".$client->channel.") ";
if ($client->radio_proto == "a")
$scriptResult .= "a";
else if ($client->radio_proto == "ac")
$scriptResult .= "ac";
else if ($client->radio_proto == "b")
$scriptResult .= "b";
else if ($client->radio_proto == "ng")
$scriptResult .= "n";
else if ($client->radio_proto == "g")
$scriptResult .= "g";
$scriptResult .= "</div></tr>";
}
// ------------------------------------------------
// Anwesenheitserkennung (Testinstallation)
// ------------------------------------------------
foreach($macList as $key => $entry)
{
$macList[$key]["Present"] = false;
}
foreach($clientList->data as $client)
{
// Name über MACNummer rausfinden.
// Nicht alle Geräte senden anständig ihren Namen mit. Deswegen über Liste arbeiten
$found = false;
foreach($macList as $key => $entry)
{
if ($entry["MAC"] == $client->mac)
$macList[$key]["Present"] = true;
}
}
foreach($macList as $key => $entry)
{
// Nur einen Wert setzen, wenn auch ein Target vorhanden ist
if (isset($entry["PresentVarID"]))
SetValue($entry["PresentVarID"],$entry["Present"]);
}
// ------------------------------------------------
// ------------------------------------------------
$htmlBox = "";
$htmlBox .= "<table style='width:100%;font-size:14px;'>";
$htmlBox .= "<tr><td style='text-align:left;font-size:12px;' colspan='10'>Letzte Aktualisierung: ".date("H:i:s d.m.Y")."</td></tr>";
$htmlBox .= "<tr style='height:1px;'><td style='background-color:#aaaaaa;' colspan='10'></td></tr>";
if ($scriptResult == "")
$htmlBox .= "<tr><td style=''>Keine Clients im WLAN</td></tr>";
else
{
$htmlBox .= "<tr><th>Name</th><th>MAC</th><th>IP</th><th>AP</th><th>WLAN</th><th>Pegel</th></tr>";
$htmlBox .= $scriptResult;
}
SetValue($htmlBoxID,$htmlBox);
?>
läuft bei Version 4.6.3 .