feat(cloudron): add tirreno package artifacts

- Add CloudronStack/output/CloudronPackages-Artifacts/tirreno/ directory and its contents
- Includes package manifest, Dockerfile, source code, documentation, and build artifacts
- Add tirreno-1761840148.tar.gz as a build artifact
- Add tirreno-cloudron-package-1761841304.tar.gz as the Cloudron package
- Include all necessary files for the tirreno Cloudron package

This adds the complete tirreno Cloudron package artifacts to the repository.
This commit is contained in:
2025-10-30 11:43:06 -05:00
parent 0ce353ea9d
commit 91d52d2de5
1692 changed files with 202851 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
<?php
/**
* Tirreno ~ Open source user analytics
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.tirreno.com Tirreno(tm)
*/
namespace Traits;
trait ApiKeys {
public function getCurrentOperatorApiKeyId(): ?int {
$key = $this->getCurrentOperatorApiKeyObject();
return $key ? $key->id : null;
}
public function getCurrentOperatorApiKeyString(): ?string {
$key = $this->getCurrentOperatorApiKeyObject();
return $key ? $key->key : null;
}
public function getCurrentOperatorEnrichmentKeyString(): ?string {
$key = $this->getCurrentOperatorApiKeyObject();
return $key ? $key->token : null;
}
public function getOperatorApiKeys(int $operatorId): array {
$model = new \Models\ApiKeys();
$apiKeys = $model->getKeys($operatorId);
$isOwner = true;
if (!$apiKeys) {
$coOwnerModel = new \Models\ApiKeyCoOwner();
$coOwnerModel->getCoOwnership($operatorId);
if ($coOwnerModel->loaded()) {
$isOwner = false;
$apiKeys[] = $model->getKeyById($coOwnerModel->api);
}
}
return [$isOwner, $apiKeys];
}
// returns \Models\ApiKeys; in test mode returns object
protected function getCurrentOperatorApiKeyObject(): object|null {
$currentOperator = $this->f3->get('CURRENT_USER');
if (!$currentOperator) {
return null;
}
$model = new \Models\ApiKeys();
//This key specified in the local configuration file and will not applied to the production environment
$testId = $this->f3->get('TEST_API_KEY_ID');
if (isset($testId) && $testId !== '') {
return (object) [
'id' => $testId,
'key' => $model->getKeyById($testId)->key,
'skip_blacklist_sync' => true,
'token' => $model->getKeyById($testId)->token,
];
}
$operatorId = $currentOperator->id;
$key = $model->getKey($operatorId);
if (!$key) { // Check if operator is co-owner of another API key when it has no own API key.
$coOwnerModel = new \Models\ApiKeyCoOwner();
$coOwnerModel->getCoOwnership($operatorId);
if ($coOwnerModel->loaded()) {
$key = $model->getKeyById($coOwnerModel->api);
}
}
return $key;
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* Tirreno ~ Open source user analytics
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.tirreno.com Tirreno(tm)
*/
namespace Traits;
trait DateRange {
public function getDatesRangeByGivenDates(string $startDate, string $endDate, int $offset): array {
return [
'endDate' => date('Y-m-d H:i:s', strtotime($endDate) + $offset),
'startDate' => date('Y-m-d H:i:s', strtotime($startDate) + $offset),
];
}
public function getDatesRange(array $request, int $offset = 0): ?array {
$dates = null;
$dateTo = $request['dateTo'] ?? null;
$dateFrom = $request['dateFrom'] ?? null;
$keepDates = $request['keepDates'] ?? null;
if ($dateTo && $dateFrom) {
$dates = $this->getDatesRangeByGivenDates($dateFrom, $dateTo, $offset);
$endDate = null;
$startDate = null;
if ($keepDates) {
$endDate = $dates['endDate'];
$startDate = $dates['startDate'];
}
$this->f3->set('SESSION.filterEndDate', $endDate);
$this->f3->set('SESSION.filterStartDate', $startDate);
}
return $dates;
}
public function getLatestNDatesRange(int $days, int $offset = 0): array {
return [
'endDate' => date('Y-m-d 23:59:59', time() + $offset),
'startDate' => date('Y-m-d 00:00:01', time() - ($days * 24 * 60 * 60) + $offset),
];
}
public function getResolution(array $request): string {
$resolution = $request['resolution'] ?? 'day';
return array_key_exists($resolution, \Utils\Constants::get('CHART_RESOLUTION')) ? $resolution : 'day';
}
}

View File

@@ -0,0 +1,114 @@
<?php
/**
* Tirreno ~ Open source user analytics
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.tirreno.com Tirreno(tm)
*/
namespace Traits;
trait Db {
public function connectToDb(bool $keepSessionInDb = true): bool {
try {
$db = $this->f3->get('API_DATABASE');
if (!$db) {
$url = \Utils\Variables::getDB();
if ($url === null) {
return false;
}
$db = $this->getDbConnection($url);
if ($keepSessionInDb) {
new \DB\SQL\Session($db, 'dshb_sessions');
}
$this->f3->set('API_DATABASE', $db);
}
return true;
} catch (\Exception $e) {
error_log('Failed to establish database connection: ' . $e->getMessage());
}
return false;
}
private function getDbConnection(string $url): ?\DB\SQL {
$urlComponents = parse_url($url);
$host = $urlComponents['host'];
$port = $urlComponents['port'];
$user = $urlComponents['user'];
$pass = $urlComponents['pass'];
$db = ltrim($urlComponents['path'], '/');
// Include port in DSN if it's set
$dsn = sprintf('pgsql:host=%s;port=%s;dbname=%s', $host, $port, $db);
$options = [
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
];
try {
return new \DB\SQL($dsn, $user, $pass, $options);
} catch (\Exception $e) {
throw new \Exception('Failed to establish database connection: ' . $e->getMessage());
}
}
private function getOperatorInfoFromF3(): \Models\Operator|false|null {
return $this->f3->get('CURRENT_USER');
}
private function getOperatorInfoFromDb(): \Models\Operator|false|null {
$model = new \Models\Operator();
$loggedInOperatorId = $this->f3->get('SESSION.active_user_id');
return $loggedInOperatorId ? $model->getOperatorById($loggedInOperatorId) : null;
}
public function getLoggedInOperator(): \Models\Operator|false|null {
$testId = $this->f3->get('TEST_API_KEY_ID');
if ($testId !== null) {
$keyModel = new \Models\ApiKeys();
$operatorModel = new \Models\Operator();
$loggedInOperatorId = $keyModel->getKeyById($testId)->creator;
return $operatorModel->getOperatorById($loggedInOperatorId);
}
$user = $this->getOperatorInfoFromF3();
if (!$user) {
$user = $this->getOperatorInfoFromDb();
}
return $user;
}
public function showForbiddenIfUnlogged(): void {
if (!boolval($this->getLoggedInOperator())) {
$this->f3->error(403);
}
}
public function redirectIfUnlogged(string $targetPage = '/'): void {
if (!boolval($this->getLoggedInOperator())) {
$this->f3->reroute($targetPage);
}
}
public function redirectIfLogged(): void {
if (boolval($this->getLoggedInOperator())) {
$this->f3->reroute('/');
}
}
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* Tirreno ~ Open source user analytics
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.tirreno.com Tirreno(tm)
*/
namespace Traits;
trait Debug {
public function e($value, bool $shouldExit = false): void {
\Utils\HotDebug::e($value, $shouldExit);
}
public function l(?string $title, string $message): void {
$title = $title ?? 'Custom Log Message';
\Utils\Logger::log($title, $message);
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* Tirreno ~ Open source user analytics
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.tirreno.com Tirreno(tm)
*/
namespace Traits\Enrichment;
trait Devices {
public function applyDeviceParams(array &$records): void {
$iters = count($records);
for ($i = 0; $i < $iters; ++$i) {
$r = $records[$i];
$device = $r['device'] ?? 'unknown';
$browserName = $r['browser_name'] ?? '';
$browserVersion = $r['browser_version'] ?? '';
$osName = $r['os_name'] ?? '';
$osVersion = $r['os_version'] ?? '';
//Display 'Bot' label instead of his full name
$r['os_name'] = $device === 'bot' ? 'Bot' : $osName;
$r['os'] = sprintf('%s %s', $osName, $osVersion);
$r['browser'] = sprintf('%s %s', $browserName, $browserVersion);
$r['device_name'] = $device;
$records[$i] = $r;
}
}
}

View File

@@ -0,0 +1,82 @@
<?php
/**
* Tirreno ~ Open source user analytics
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.tirreno.com Tirreno(tm)
*/
namespace Traits\Enrichment;
trait Emails {
private function calculateEmailReputation(array &$records, string $fieldName = 'reputation'): void {
$iters = count($records);
for ($i = 0; $i < $iters; ++$i) {
$r = $records[$i];
$reputation = 'none';
if ($r['data_breach'] !== null && $r['data_breach'] !== null) {
$reputationLevel = (int) ($r['data_breach']) + (int) (!$r['blockemails']);
$reputation = match ($reputationLevel) {
2 => 'high',
1 => 'medium',
0 => 'low',
default => 'none',
};
}
/*if (!$r['profiles'] && !$r['data_breach'] && $r['blockemails']) {
$reputation = 'low';
} elseif (!$r['profiles'] && $r['data_breach'] && !$reputation) {
$reputation = 'medium';
} elseif ($r['profiles'] && !$r['data_breach'] && !$reputation) {
$reputation = 'medium';
} elseif ($r['profiles'] && $r['data_breach'] && !$reputation) {
$reputation = 'high';
} else {
$reputation = 'none';
}*/
$r[$fieldName] = $reputation;
$records[$i] = $r;
}
}
private function calculateEmailReputationForContext(array &$records): void {
$iters = count($records);
for ($i = 0; $i < $iters; ++$i) {
$r = $records[$i];
//$r['profiles'] = $r['ee_profiles'] ?? 0;
$r['data_breach'] = $r['ee_data_breach'] ?? false;
$r['blockemails'] = $r['ee_blockemails'] ?? false;
//$r['disposable_domains'] = $r['ed_disposable_domains'] ?? false;
$records[$i] = $r;
}
$fieldName = 'ee_reputation';
$this->calculateEmailReputation($records, $fieldName);
for ($i = 0; $i < $iters; ++$i) {
$r = $records[$i];
//unset($r['profiles']);
unset($r['data_breach']);
unset($r['blockemails']);
//unset($r['disposable_domains']);
$records[$i] = $r;
}
}
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* Tirreno ~ Open source user analytics
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.tirreno.com Tirreno(tm)
*/
namespace Traits\Enrichment;
trait Ips {
private function calculateIpType(array &$records): void {
$iters = count($records);
for ($i = 0; $i < $iters; ++$i) {
$r = $records[$i];
$type = null;
if ($r['fraud_detected'] && !$type) {
$type = 'Blacklisted';
}
if ($r['blocklist'] && !$type) {
$type = 'Spam list';
}
if ($r['country_id'] === 0 && $r['checked'] && !$type) {
$type = 'Localhost';
}
if ($r['tor'] && !$type) {
$type = 'TOR';
}
if ($r['starlink'] && !$type) {
$type = 'Starlink';
}
if ($r['relay'] && !$type) {
$type = 'AppleRelay';
}
if ($r['vpn'] && !$type) {
$type = 'VPN';
}
if ($r['data_center'] && !$type) {
$type = 'Datacenter';
}
if (!$r['checked']) {
$type = 'Unknown';
}
if (!$type) {
$type = 'Residential';
}
unset($r['tor']);
unset($r['starlink']);
unset($r['relay']);
unset($r['vpn']);
unset($r['data_center']);
$r['ip_type'] = $type;
$records[$i] = $r;
}
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Tirreno ~ Open source user analytics
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.tirreno.com Tirreno(tm)
*/
namespace Traits\Enrichment;
trait TimeZones {
protected function translateTimeZone(array &$row, array $attributes = ['time', 'lastseen'], bool $useMilliseconds = false): void {
foreach ($attributes as $attribute) {
if (isset($row[$attribute]) && $row[$attribute] !== null) {
\Utils\TimeZones::localizeForActiveOperator($row[$attribute], $useMilliseconds);
}
}
}
protected function translateTimeZones(array &$rows, array $attributes = ['time', 'lastseen'], bool $useMilliseconds = false): void {
$rows = array_map(function ($row) use ($attributes, $useMilliseconds) {
$this->translateTimeZone($row, $attributes, $useMilliseconds);
return $row;
}, $rows);
}
}

View File

@@ -0,0 +1,93 @@
<?php
/**
* Tirreno ~ Open source user analytics
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.tirreno.com Tirreno(tm)
*/
namespace Traits;
trait Navigation {
protected $response;
public function beforeroute(): void {
$currentOperator = $this->f3->get('CURRENT_USER');
if ($currentOperator) {
$apiKey = $this->getCurrentOperatorApiKeyId();
$messages = \Utils\SystemMessages::get($apiKey);
$this->f3->set('SYSTEM_MESSAGES', $messages);
if (count($messages)) {
$m = $messages[0];
$doRedirect = $this->shouldRedirectToApiKeys($m);
if ($doRedirect) {
$this->f3->reroute('/api');
}
}
}
}
private function shouldRedirectToApiKeys($message): bool {
$route = $this->f3->get('PARAMS.0');
$allowedPages = [
'/api',
'/settings',
'/logbook',
];
$allowedPages = array_merge($allowedPages, $this->f3->get('EXTRA_ALLOWED_PAGES') ?? []);
$isPageAllowed = in_array($route, $allowedPages);
return !$isPageAllowed && ($message['id'] === \Utils\ErrorCodes::THERE_ARE_NO_EVENTS_YET);
}
public function isPostRequest(): bool {
return $this->f3->VERB === 'POST';
}
/**
* set a new view.
*/
/* TODO: make sure that setView() is not needed
public function setView(BaseView $view) {
$this->response = $view;
}*/
/**
* kick start the View, which creates the response
* based on our previously set content data.
* finally echo the response or overwrite this method
* and do something else with it.
*/
public function afterroute(): void {
if (!$this->response) {
trigger_error('No View has been set.');
}
$shouldPrintSqlToLog = $this->f3->get('PRINT_SQL_LOG_AFTER_EACH_SCRIPT_CALL');
if ($shouldPrintSqlToLog) {
$hive = $this->f3->hive();
$path = $hive['PATH'];
$log = $this->f3->get('API_DATABASE')->log();
if ($log) {
\Utils\Logger::logSql($path, $log);
}
}
echo $this->response->render();
}
}

View File

@@ -0,0 +1,3 @@
<?php
//