Hi,
ich versuche mich gerade daran, dass Unifi Modul so zu erstellen, dass es etwas einfacher wird … also z.B. nicht alles Variablen angelegt werden oder andere Dinge Möglich sind. Die API von denen ist jetzt nicht so kompliziert.
Was ich aber ums verr… nicht hinbekomme, ist das Login (welches funktioniert) dann für einen weiteren Aufruf zu verwenden. Ich versuche jetzt schon seit Stunden den Code im alten Modul, welche ja von „the art of wlan“ kommt anzupassen - aber das Login Thema killt mich.
Evtl. kann mir jemand einen Tipp geben.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://192.168.1.1/api/auth/login');
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$User."&password=".$Password);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/unifi_cookie");
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/unifi_cookie");
curl_setopt($ch, CURLOPT_COOKIEJAR, "unifi_cookie");
$answer1 = curl_exec($ch);
if (curl_error($ch)) {
echo curl_error($ch);
}
var_dump ($answer1);
curl_close ($ch);
unset($ch);
//another request preserving the session
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://192.168.1.1/proxy/network/api/s/default/stat/health');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/unifi_cookie");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
//curl_setopt($ch, CURLOPT_POSTFIELDS, "");
$answer = curl_exec($ch);
if (curl_error($ch)) {
echo curl_error($ch);
}
var_dump ($answer);