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:
@@ -0,0 +1,72 @@
|
||||
<?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\Grid\Users;
|
||||
|
||||
class Grid extends \Models\Grid\Base\Grid {
|
||||
public function __construct(int $apiKey) {
|
||||
parent::__construct();
|
||||
|
||||
$this->apiKey = $apiKey;
|
||||
$this->idsModel = new Ids($apiKey);
|
||||
$this->query = new Query($apiKey);
|
||||
}
|
||||
|
||||
public function getUsersByIpId(int $ipId): array {
|
||||
$params = [':ip_id' => $ipId];
|
||||
|
||||
return $this->getGrid($this->idsModel->getUsersIdsByIpId(), $params);
|
||||
}
|
||||
|
||||
public function getUsersByIspId(int $ispId): array {
|
||||
$params = [':isp_id' => $ispId];
|
||||
|
||||
return $this->getGrid($this->idsModel->getUsersIdsByIspId(), $params);
|
||||
}
|
||||
|
||||
public function getUsersByDomainId(int $domainId): array {
|
||||
$params = [':domain_id' => $domainId];
|
||||
|
||||
return $this->getGrid($this->idsModel->getUsersIdsByDomainId(), $params);
|
||||
}
|
||||
|
||||
public function getUsersByCountryId(int $countryId): array {
|
||||
$params = [':country_id' => $countryId];
|
||||
|
||||
return $this->getGrid($this->idsModel->getUsersIdsByCountryId(), $params);
|
||||
}
|
||||
|
||||
public function getUsersByDeviceId(int $deviceId): array {
|
||||
$params = [':device_id' => $deviceId];
|
||||
|
||||
return $this->getGrid($this->idsModel->getUsersIdsByDeviceId(), $params);
|
||||
}
|
||||
|
||||
public function getUsersByResourceId(int $resourceId): array {
|
||||
$params = [':resource_id' => $resourceId];
|
||||
|
||||
return $this->getGrid($this->idsModel->getUsersIdsByResourceId(), $params);
|
||||
}
|
||||
|
||||
public function getAllUsers(): array {
|
||||
return $this->getGrid();
|
||||
}
|
||||
|
||||
protected function convertTimeToUserTimezone(array &$result): void {
|
||||
$fields = ['time', 'lastseen', 'latest_decision', 'created', 'score_updated_at'];
|
||||
|
||||
$this->translateTimeZones($result, $fields);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?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\Grid\Users;
|
||||
|
||||
class Ids extends \Models\Grid\Base\Ids {
|
||||
public function getUsersIdsByIpId(): string {
|
||||
return (
|
||||
'SELECT DISTINCT
|
||||
event.account AS itemid
|
||||
FROM event
|
||||
WHERE
|
||||
event.ip = :ip_id AND
|
||||
event.key = :api_key'
|
||||
);
|
||||
}
|
||||
|
||||
public function getUsersIdsByIspId(): string {
|
||||
return (
|
||||
'SELECT DISTINCT
|
||||
event.account AS itemid
|
||||
FROM event_ip
|
||||
INNER JOIN event
|
||||
ON (event_ip.id = event.ip)
|
||||
WHERE
|
||||
event_ip.isp = :isp_id AND
|
||||
event_ip.key = :api_key'
|
||||
);
|
||||
}
|
||||
|
||||
public function getUsersIdsByDomainId(): string {
|
||||
return (
|
||||
'SELECT DISTINCT
|
||||
event_email.account_id AS itemid
|
||||
FROM event_domain
|
||||
INNER JOIN event_email
|
||||
ON event_domain.id = event_email.domain
|
||||
WHERE
|
||||
event_domain.id = :domain_id AND
|
||||
event_domain.key = :api_key'
|
||||
);
|
||||
}
|
||||
|
||||
public function getUsersIdsByCountryId(): string {
|
||||
return (
|
||||
'SELECT DISTINCT
|
||||
event.account AS itemid
|
||||
FROM event_ip
|
||||
INNER JOIN event
|
||||
ON (event_ip.id = event.ip)
|
||||
WHERE
|
||||
event_ip.country = :country_id AND
|
||||
event_ip.key = :api_key'
|
||||
);
|
||||
}
|
||||
|
||||
public function getUsersIdsByDeviceId(): string {
|
||||
return (
|
||||
'SELECT DISTINCT
|
||||
event.account AS itemid
|
||||
FROM event
|
||||
INNER JOIN event_device
|
||||
ON (event_device.id = event.device)
|
||||
WHERE
|
||||
event_device.user_agent = :device_id AND
|
||||
event.key = :api_key'
|
||||
);
|
||||
}
|
||||
|
||||
public function getUsersIdsByResourceId(): string {
|
||||
return (
|
||||
'SELECT DISTINCT
|
||||
event.account AS itemid
|
||||
FROM event
|
||||
WHERE
|
||||
event.url = :resource_id AND
|
||||
event.key = :api_key'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
<?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\Grid\Users;
|
||||
|
||||
class Query extends \Models\Grid\Base\Query {
|
||||
protected $defaultOrder = 'event_account.id DESC';
|
||||
protected $dateRangeField = 'event_account.lastseen';
|
||||
|
||||
protected $allowedColumns = ['score', 'accounttitle', 'firstname', 'lastname', 'created', 'lastseen', 'fraud', 'id'];
|
||||
|
||||
public function getData(): array {
|
||||
$queryParams = $this->getQueryParams();
|
||||
|
||||
$query = (
|
||||
"SELECT
|
||||
TEXT(date_trunc('day', event_account.created)::date) AS created_day,
|
||||
|
||||
event_account.id,
|
||||
event_account.is_important,
|
||||
event_account.id AS accountid,
|
||||
event_account.userid AS accounttitle,
|
||||
event_account.score,
|
||||
event_account.score_updated_at,
|
||||
event_account.created,
|
||||
event_account.fraud,
|
||||
event_account.reviewed,
|
||||
event_account.firstname,
|
||||
event_account.lastname,
|
||||
event_account.lastseen,
|
||||
event_account.total_visit,
|
||||
event_account.total_ip,
|
||||
event_account.total_device,
|
||||
event_account.total_country,
|
||||
event_account.latest_decision,
|
||||
event_account.added_to_review,
|
||||
|
||||
event_email.email,
|
||||
event_email.blockemails
|
||||
|
||||
FROM
|
||||
event_account
|
||||
|
||||
LEFT JOIN event_email
|
||||
ON (event_account.lastemail = event_email.id)
|
||||
|
||||
WHERE
|
||||
event_account.key = :api_key
|
||||
%s"
|
||||
);
|
||||
|
||||
$this->applySearch($query, $queryParams);
|
||||
$this->applyRules($query, $queryParams);
|
||||
$this->applyScore($query, $queryParams);
|
||||
$this->applyOrder($query);
|
||||
$this->applyLimit($query, $queryParams);
|
||||
|
||||
return [$query, $queryParams];
|
||||
}
|
||||
|
||||
public function getTotal(): array {
|
||||
$queryParams = $this->getQueryParams();
|
||||
|
||||
$query = (
|
||||
'SELECT
|
||||
COUNT (event_account.id)
|
||||
|
||||
FROM
|
||||
event_account
|
||||
|
||||
LEFT JOIN event_email
|
||||
ON (event_account.lastemail = event_email.id)
|
||||
|
||||
WHERE
|
||||
event_account.key = :api_key
|
||||
%s'
|
||||
);
|
||||
|
||||
$this->applySearch($query, $queryParams);
|
||||
$this->applyRules($query, $queryParams);
|
||||
$this->applyScore($query, $queryParams);
|
||||
|
||||
return [$query, $queryParams];
|
||||
}
|
||||
|
||||
private function applySearch(string &$query, array &$queryParams): void {
|
||||
$this->applyDateRange($query, $queryParams);
|
||||
|
||||
$search = $this->f3->get('REQUEST.search');
|
||||
$searchConditions = $this->injectIdQuery('event_account.id', $queryParams);
|
||||
|
||||
if (is_array($search) && isset($search['value']) && is_string($search['value']) && $search['value'] !== '') {
|
||||
$searchConditions .= (
|
||||
" AND
|
||||
(
|
||||
LOWER(REPLACE(
|
||||
COALESCE(event_account.firstname, '') ||
|
||||
COALESCE(event_account.lastname, '') ||
|
||||
COALESCE(event_account.firstname, ''),
|
||||
' ', '')) LIKE LOWER(REPLACE(:search_value, ' ', '')) OR
|
||||
LOWER(event_email.email) LIKE LOWER(:search_value) OR
|
||||
LOWER(event_account.userid) LIKE LOWER(:search_value) OR
|
||||
|
||||
TO_CHAR(event_account.created::timestamp without time zone, 'dd/mm/yyyy hh24:mi:ss') LIKE :search_value
|
||||
)"
|
||||
);
|
||||
|
||||
$queryParams[':search_value'] = '%' . $search['value'] . '%';
|
||||
}
|
||||
|
||||
//Add search and ids into request
|
||||
$query = sprintf($query, $searchConditions);
|
||||
}
|
||||
|
||||
private function applyRules(string &$query, array &$queryParams): void {
|
||||
$ruleUids = $this->f3->get('REQUEST.ruleUids');
|
||||
if ($ruleUids === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$uids = [];
|
||||
foreach ($ruleUids as $ruleUid) {
|
||||
$uids[] = ['uid' => $ruleUid];
|
||||
}
|
||||
|
||||
$query .= ' AND score_details @> (:rules_uids)::jsonb';
|
||||
$queryParams[':rules_uids'] = json_encode($uids);
|
||||
}
|
||||
|
||||
private function applyScore(string &$query, array &$queryParams): void {
|
||||
$scoresRanges = $this->f3->get('REQUEST.scoresRange');
|
||||
if ($scoresRanges === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$clauses = [];
|
||||
foreach ($scoresRanges as $key => $scoreBase) {
|
||||
$clauses[] = sprintf('event_account.score >= :score_base_%s AND event_account.score <= :score_base_%s + 10', $key, $key);
|
||||
$queryParams[':score_base_' . $key] = intval($scoreBase);
|
||||
}
|
||||
|
||||
$query .= ' AND (' . implode(' OR ', $clauses) . ')';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user