From dede2ab442f2c10e2761edad1040be769df41a8f Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 29 Jul 2026 16:38:41 +0530 Subject: [PATCH] fix(install): honor DO_NOT_TRACK for self-hosted install telemetry Skip the install/upgrade analytics ping when DO_NOT_TRACK is set. Co-authored-by: Cursor --- src/Appwrite/Platform/Tasks/Install.php | 60 +++-------- tests/unit/Platform/Tasks/InstallTest.php | 124 ---------------------- 2 files changed, 16 insertions(+), 168 deletions(-) delete mode 100644 tests/unit/Platform/Tasks/InstallTest.php diff --git a/src/Appwrite/Platform/Tasks/Install.php b/src/Appwrite/Platform/Tasks/Install.php index ee5a2af418..7bbdf87350 100644 --- a/src/Appwrite/Platform/Tasks/Install.php +++ b/src/Appwrite/Platform/Tasks/Install.php @@ -852,45 +852,18 @@ class Install extends Action return; } - $payload = $this->buildSelfHostedInstallPayload($input, $isUpgrade, $version, $account); - - if ($payload === null) { + // Opt out via DO_NOT_TRACK (https://donottrack.sh/) + $doNotTrack = \strtolower((string) System::getEnv('DO_NOT_TRACK', '')); + if (\in_array($doNotTrack, ['1', 'true', 'yes'], true)) { return; } - try { - $client = new Client(); - $client - ->setConnectTimeout(5000) - ->setTimeout(5000) - ->addHeader('Content-Type', 'application/json') - ->fetch(self::GROWTH_API_URL . '/analytics', Client::METHOD_POST, $payload); - } catch (\Throwable) { - // tracking shouldn't block installation - } - } - - /** - * Build the self-hosted install/upgrade analytics payload. - * - * Returns null when tracking must not happen (opt-out or non-production). - * - * @param array $input Resolved environment variables - * @param array $account Administrator account details - * @return array|null - */ - public function buildSelfHostedInstallPayload(array $input, bool $isUpgrade, string $version, array $account = []): ?array - { - if ($this->isTelemetryDisabled()) { - return null; - } - $appEnv = $input['_APP_ENV'] ?? 'development'; $domain = $input['_APP_DOMAIN'] ?? 'localhost'; /* local or test instance */ if ($appEnv !== 'production') { - return null; + return; } /* prod but local or test instance */ @@ -898,7 +871,7 @@ class Install extends Action || str_starts_with($domain, '127.') || str_starts_with($domain, '0.0.0.0') ) { - return null; + return; } $type = $isUpgrade ? 'upgrade' : 'install'; @@ -908,7 +881,7 @@ class Install extends Action $hostIp = @gethostbyname($domain); - return [ + $payload = [ 'action' => $type, 'account' => 'self-hosted', 'url' => 'https://' . $domain, @@ -927,18 +900,17 @@ class Install extends Action 'ram' => (int) round(((float) trim((string) \shell_exec('grep MemTotal /proc/meminfo | awk \'{print $2}\''))) / 1024), ]), ]; - } - /** - * Whether the operator opted out of install/upgrade telemetry. - * - * Honors DO_NOT_TRACK (https://donottrack.sh/). - */ - public function isTelemetryDisabled(): bool - { - $doNotTrack = \strtolower((string) System::getEnv('DO_NOT_TRACK', '')); - - return \in_array($doNotTrack, ['1', 'true', 'yes'], true); + try { + $client = new Client(); + $client + ->setConnectTimeout(5000) + ->setTimeout(5000) + ->addHeader('Content-Type', 'application/json') + ->fetch(self::GROWTH_API_URL . '/analytics', Client::METHOD_POST, $payload); + } catch (\Throwable) { + // tracking shouldn't block installation + } } /** diff --git a/tests/unit/Platform/Tasks/InstallTest.php b/tests/unit/Platform/Tasks/InstallTest.php deleted file mode 100644 index cb27fa349e..0000000000 --- a/tests/unit/Platform/Tasks/InstallTest.php +++ /dev/null @@ -1,124 +0,0 @@ -install = new Install(); - } - - protected function tearDown(): void - { - \putenv('DO_NOT_TRACK'); - } - - /** - * @return array - */ - private function productionInput(): array - { - return [ - '_APP_ENV' => 'production', - '_APP_DOMAIN' => 'example.com', - '_APP_DB_ADAPTER' => 'mariadb', - ]; - } - - /** - * @return array - */ - private function account(): array - { - return [ - 'name' => 'Jane Admin', - 'email' => 'jane@example.com', - ]; - } - - public function testPayloadIncludesAdminNameAndEmail(): void - { - $payload = $this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6', $this->account()); - - $this->assertIsArray($payload); - $this->assertSame('install', $payload['action']); - $this->assertSame('self-hosted', $payload['account']); - $this->assertSame('1.9.6', $payload['version']); - - $data = \json_decode($payload['data'], true); - $this->assertIsArray($data); - - $this->assertSame('Jane Admin', $data['name']); - $this->assertSame('jane@example.com', $data['email']); - $this->assertSame('example.com', $data['domain']); - $this->assertSame('mariadb', $data['database']); - $this->assertArrayHasKey('os', $data); - $this->assertArrayHasKey('arch', $data); - } - - public function testUpgradeActionIsReported(): void - { - $payload = $this->install->buildSelfHostedInstallPayload($this->productionInput(), true, '1.9.6', $this->account()); - - $this->assertIsArray($payload); - $this->assertSame('upgrade', $payload['action']); - $this->assertSame('self_hosted_upgrade', $payload['label']); - } - - public function testDoNotTrackDisablesTelemetry(): void - { - \putenv('DO_NOT_TRACK=1'); - - $this->assertTrue($this->install->isTelemetryDisabled()); - $this->assertNull($this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6', $this->account())); - } - - public function testDoNotTrackTrueValueDisablesTelemetry(): void - { - \putenv('DO_NOT_TRACK=true'); - - $this->assertTrue($this->install->isTelemetryDisabled()); - } - - public function testDoNotTrackYesValueDisablesTelemetry(): void - { - \putenv('DO_NOT_TRACK=yes'); - - $this->assertTrue($this->install->isTelemetryDisabled()); - $this->assertNull($this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6', $this->account())); - } - - public function testTelemetryEnabledByDefault(): void - { - $this->assertFalse($this->install->isTelemetryDisabled()); - } - - public function testNonProductionEnvironmentIsNotTracked(): void - { - $input = $this->productionInput(); - $input['_APP_ENV'] = 'development'; - - $this->assertNull($this->install->buildSelfHostedInstallPayload($input, false, '1.9.6', $this->account())); - } - - public function testLocalhostDomainIsNotTracked(): void - { - $input = $this->productionInput(); - $input['_APP_DOMAIN'] = 'localhost'; - - $this->assertNull($this->install->buildSelfHostedInstallPayload($input, false, '1.9.6', $this->account())); - } -}