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,188 @@
<?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 Models\UserDetails;
class Behaviour extends \Models\BaseSql {
protected $DB_TABLE_NAME = 'event';
public function getDayDetails(int $userId, array $dateRange, int $apiKey): array {
$params = [
':user_id' => $userId,
':api_key' => $apiKey,
':start_ts' => $dateRange['startDate'],
':end_ts' => $dateRange['endDate'],
':offset' => $dateRange['offset'],
':failed_login' => \Utils\Constants::get('ACCOUNT_LOGIN_FAIL_EVENT_TYPE_ID'),
':success_login' => \Utils\Constants::get('ACCOUNT_LOGIN_EVENT_TYPE_ID'),
':password_reset' => \Utils\Constants::get('ACCOUNT_PASSWORD_CHANGE_EVENT_TYPE_ID'),
':seconds_day' => 60 * 60 * 24,
':night_time_end' => 60 * 60 * 5,
];
$query = (
'SELECT
COUNT(CASE WHEN event.type = :failed_login THEN TRUE END) AS failed_login_cnt,
COUNT(CASE WHEN event.type = :password_reset THEN TRUE END) AS password_reset_cnt,
COUNT(CASE WHEN event.http_code > 400 THEN TRUE END) AS auth_error_cnt,
COUNT(CASE WHEN event.type IN (:failed_login, :success_login) THEN TRUE END) AS login_cnt,
COUNT(CASE WHEN
MOD(EXTRACT(EPOCH FROM event.time) + :offset, :seconds_day) < :night_time_end THEN TRUE END
) AS off_hours_login_cnt,
COUNT(DISTINCT event.device) AS device_cnt,
COUNT(DISTINCT event.ip) AS ip_cnt,
COUNT(DISTINCT event.session_id) AS session_cnt
FROM
event
WHERE
event.account = :user_id AND
event.key = :api_key AND
event.time > :start_ts AND
event.time < :end_ts'
);
$results = $this->execQuery($query, $params);
$result = $results[0] ?? [];
if ($result) {
$params = [
':user_id' => $userId,
':api_key' => $apiKey,
':start_ts' => $dateRange['startDate'],
':end_ts' => $dateRange['endDate'],
];
$query = (
'SELECT
percentile_disc(0.5) WITHIN GROUP (ORDER BY event_session.total_visit) AS median_event_cnt
FROM
event_session
WHERE
event_session.account_id = :user_id AND
event_session.key = :api_key AND
event_session.lastseen > :start_ts AND
event_session.lastseen < :end_ts'
);
$results = $this->execQuery($query, $params);
$result['median_event_cnt'] = $results[0]['median_event_cnt'] ?? 0;
}
return $result;
}
public function getWeekDetails(int $userId, array $dateRange, int $apiKey): array {
$params = [
':user_id' => $userId,
':api_key' => $apiKey,
':start_ts' => $dateRange['startDate'],
':end_ts' => $dateRange['endDate'],
':offset' => $dateRange['offset'],
':failed_login' => \Utils\Constants::get('ACCOUNT_LOGIN_FAIL_EVENT_TYPE_ID'),
':success_login' => \Utils\Constants::get('ACCOUNT_LOGIN_EVENT_TYPE_ID'),
':password_reset' => \Utils\Constants::get('ACCOUNT_PASSWORD_CHANGE_EVENT_TYPE_ID'),
':seconds_day' => 60 * 60 * 24,
':night_time_end' => 60 * 60 * 5,
];
$query = (
'WITH daily AS (
SELECT
EXTRACT(EPOCH FROM date_trunc(\'day\', event.time + :offset))::bigint AS ts,
COUNT(CASE WHEN event.type = :failed_login THEN TRUE END) AS failed_login_cnt,
COUNT(CASE WHEN event.type = :password_reset THEN TRUE END) AS password_reset_cnt,
COUNT(CASE WHEN event.http_code > 400 THEN TRUE END) AS auth_error_cnt,
COUNT(CASE WHEN event.type IN (:failed_login, :success_login) THEN TRUE END) AS login_cnt,
COUNT(CASE WHEN
MOD(EXTRACT(EPOCH FROM event.time + :offset), :seconds_day) < :night_time_end THEN TRUE END
) AS off_hours_login_cnt,
COUNT(DISTINCT event.device) AS device_cnt,
COUNT(DISTINCT event.ip) AS ip_cnt,
COUNT(DISTINCT event.session_id) AS session_cnt
FROM
event
WHERE
event.account = :user_id AND
event.key = :api_key AND
event.time > :start_ts AND
event.time < :end_ts
GROUP BY ts
ORDER BY ts
)
SELECT
percentile_disc(0.5) WITHIN GROUP (ORDER BY failed_login_cnt) AS failed_login_cnt,
percentile_disc(0.5) WITHIN GROUP (ORDER BY password_reset_cnt) AS password_reset_cnt,
percentile_disc(0.5) WITHIN GROUP (ORDER BY auth_error_cnt) AS auth_error_cnt,
percentile_disc(0.5) WITHIN GROUP (ORDER BY login_cnt) AS login_cnt,
percentile_disc(0.5) WITHIN GROUP (ORDER BY off_hours_login_cnt) AS off_hours_login_cnt,
percentile_disc(0.5) WITHIN GROUP (ORDER BY device_cnt) AS device_cnt,
percentile_disc(0.5) WITHIN GROUP (ORDER BY ip_cnt) AS ip_cnt,
percentile_disc(0.5) WITHIN GROUP (ORDER BY session_cnt) AS session_cnt
FROM daily'
);
$results = $this->execQuery($query, $params);
$result = $results[0] ?? [];
if ($result) {
$params = [
':user_id' => $userId,
':api_key' => $apiKey,
':start_ts' => $dateRange['startDate'],
':end_ts' => $dateRange['endDate'],
':offset' => $dateRange['offset'],
];
$query = (
'WITH daily AS (
SELECT
EXTRACT(EPOCH FROM date_trunc(\'day\', event_session.lastseen + :offset))::bigint AS ts,
percentile_disc(0.5) WITHIN GROUP (ORDER BY event_session.total_visit) AS median_event_cnt
FROM
event_session
WHERE
event_session.account_id = :user_id AND
event_session.key = :api_key AND
event_session.lastseen > :start_ts AND
event_session.lastseen < :end_ts
GROUP BY ts
ORDER BY ts
)
SELECT
percentile_disc(0.5) WITHIN GROUP (ORDER BY median_event_cnt) AS median_event_cnt
FROM daily'
);
$results = $this->execQuery($query, $params);
$result['median_event_cnt'] = $results[0]['median_event_cnt'] ?? 0;
}
return $result;
}
}

View File

@@ -0,0 +1,88 @@
<?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 Models\UserDetails;
class Id extends \Models\BaseSql implements \Interfaces\ApiKeyAccessAuthorizationInterface {
protected $DB_TABLE_NAME = 'event_account';
public function checkAccess(int $subjectId, int $apiKey): bool {
$params = [
':user_id' => $subjectId,
':api_key' => $apiKey,
];
$query = (
'SELECT
userid
FROM
event_account
WHERE
event_account.id = :user_id
AND event_account.key = :api_key'
);
$results = $this->execQuery($query, $params);
return count($results) > 0;
}
public function getDetails(int $userId, int $apiKey): array {
$params = [
':user_id' => $userId,
':api_key' => $apiKey,
];
$query = (
'SELECT
event_account.userid,
event_account.lastseen,
event_account.created,
event_account.firstname,
event_account.lastname,
event_account.score,
event_account.score_details,
event_account.is_important,
event_account.fraud,
event_account.reviewed,
event_account.latest_decision,
event_account.added_to_review,
event_email.email
FROM
event_account
LEFT JOIN event_email
ON (event_account.lastemail = event_email.id)
WHERE
event_account.id = :user_id
AND event_account.key = :api_key'
);
$results = $this->execQuery($query, $params);
$result = $results[0] ?? [];
$tsColumns = ['created', 'lastseen', 'score_updated_at', 'latest_decision', 'updated', 'added_to_review'];
\Utils\TimeZones::localizeTimestampsForActiveOperator($tsColumns, $result);
return $result;
}
}

View File

@@ -0,0 +1,80 @@
<?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 Models\UserDetails;
class Ip extends \Models\BaseSql {
use \Traits\Enrichment\Ips;
protected $DB_TABLE_NAME = 'event_ip';
public function getDetails(int $userId, int $apiKey): array {
$details = $this->getIpsDetails($userId, $apiKey);
$data = [];
if (count($details)) {
$data = [
'accountid' => $userId,
'withdc' => $details['data_center'],
'withar' => $details['relay'],
// 'withsl' => $details['starlink'],
'withvpn' => $details['vpn'],
'withtor' => $details['tor'],
'sharedips' => $details['shared'] > 1,
'fraud_detected' => $details['fraud_detected'],
'spamlist' => $details['blocklist'],
];
}
return $data;
}
private function getIpsDetails(int $userId, int $apiKey): array {
$params = [
':user_id' => $userId,
':api_key' => $apiKey,
];
$query = (
'SELECT
event.account AS accountid,
BOOL_OR(event_ip.data_center) AS data_center,
BOOL_OR(event_ip.relay) AS relay,
BOOL_OR(event_ip.starlink) AS starlink,
BOOL_OR(event_ip.vpn) AS vpn,
BOOL_OR(event_ip.tor) AS tor,
MAX(event_ip.shared) AS shared,
BOOL_OR(event_ip.fraud_detected) AS fraud_detected,
BOOL_OR(event_ip.blocklist) AS blocklist,
BOOL_OR(event_ip.checked) AS checked
FROM
event_ip
INNER JOIN event
ON (event_ip.id = event.ip)
WHERE
event_ip.key = :api_key AND
event.account = :user_id
GROUP BY event.account'
);
$results = $this->execQuery($query, $params);
return $results[0] ?? [];
}
}