From e0a999b27bf8b44de32b190ec6232546a8ba4852 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 22 Apr 2026 05:52:45 +0000 Subject: [PATCH] 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 --- includes/UniFiController.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/includes/UniFiController.php b/includes/UniFiController.php index 90dce55..d0da04b 100644 --- a/includes/UniFiController.php +++ b/includes/UniFiController.php @@ -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; }