Login only once per UniFiController instance to avoid rate limiting
createVoucher() calls apiRequest() twice (cmd/hotspot + stat/voucher), which previously triggered two separate login requests in rapid succession. The UniFi controller was rate-limiting the second attempt with 403. Fix: $loggedIn flag ensures login() is a no-op after the first successful authentication, reusing the existing session cookie for all API calls. https://claude.ai/code/session_01UsuvFAmmeagtQa14QA4iaq
This commit is contained in:
parent
897392041a
commit
e0a999b27b
1 changed files with 6 additions and 0 deletions
|
|
@ -7,6 +7,7 @@ class UniFiController {
|
|||
private $cookieFile;
|
||||
private $csrfToken = null;
|
||||
private $sessionCookie = null;
|
||||
private $loggedIn = false;
|
||||
|
||||
public function __construct($controllerUrl, $username, $password, $siteId) {
|
||||
$this->controllerUrl = rtrim($controllerUrl, '/');
|
||||
|
|
@ -24,6 +25,10 @@ class UniFiController {
|
|||
|
||||
// Login zum Controller
|
||||
private function login() {
|
||||
if ($this->loggedIn) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt_array($ch, [
|
||||
|
|
@ -90,6 +95,7 @@ class UniFiController {
|
|||
$this->csrfToken = $this->readCsrfFromCookieFile();
|
||||
}
|
||||
|
||||
$this->loggedIn = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue