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\Ips;
|
||||
|
||||
class Grid extends \Models\Grid\Base\Grid {
|
||||
use \Traits\Enrichment\Ips;
|
||||
|
||||
public function __construct(int $apiKey) {
|
||||
parent::__construct();
|
||||
|
||||
$this->apiKey = $apiKey;
|
||||
$this->idsModel = new Ids($apiKey);
|
||||
$this->query = new Query($apiKey);
|
||||
}
|
||||
|
||||
public function getIpsByUserId(int $userId): array {
|
||||
$params = [':account_id' => $userId];
|
||||
|
||||
return $this->getGrid($this->idsModel->getIpsIdsByUserId(), $params);
|
||||
}
|
||||
|
||||
public function getIpsByIspId(int $ispId): array {
|
||||
$params = [':isp_id' => $ispId];
|
||||
|
||||
return $this->getGrid($this->idsModel->getIpsIdsByIspId(), $params);
|
||||
}
|
||||
|
||||
public function getIpsByDomainId($domainId) {
|
||||
$params = [':domain_id' => $domainId];
|
||||
|
||||
return $this->getGrid($this->idsModel->getIpsIdsByDomainId(), $params);
|
||||
}
|
||||
|
||||
public function getIpsByCountryId(int $countryId): array {
|
||||
$params = [':country_id' => $countryId];
|
||||
|
||||
return $this->getGrid($this->idsModel->getIpsIdsByCountryId(), $params);
|
||||
}
|
||||
|
||||
public function getIpsByDeviceId(int $deviceId): array {
|
||||
$params = [':device_id' => $deviceId];
|
||||
|
||||
return $this->getGrid($this->idsModel->getIpsIdsByDeviceId(), $params);
|
||||
}
|
||||
|
||||
public function getIpsByResourceId(int $resourceId): array {
|
||||
$params = [':resource_id' => $resourceId];
|
||||
|
||||
return $this->getGrid($this->idsModel->getIpsIdsByResourceId(), $params);
|
||||
}
|
||||
|
||||
public function getAllIps() {
|
||||
return $this->getGrid();
|
||||
}
|
||||
|
||||
protected function calculateCustomParams(array &$result): void {
|
||||
$this->calculateIpType($result);
|
||||
}
|
||||
}
|
||||
@@ -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\Grid\Ips;
|
||||
|
||||
class Ids extends \Models\Grid\Base\Ids {
|
||||
public function getIpsIdsByUserId(): string {
|
||||
return (
|
||||
'SELECT DISTINCT
|
||||
event.ip AS itemid
|
||||
FROM event
|
||||
WHERE
|
||||
event.key = :api_key
|
||||
AND event.account = :account_id'
|
||||
);
|
||||
}
|
||||
|
||||
public function getIpsIdsByIspId(): string {
|
||||
return (
|
||||
'SELECT DISTINCT
|
||||
event_ip.id AS itemid
|
||||
FROM event_ip
|
||||
WHERE
|
||||
event_ip.key = :api_key
|
||||
AND event_ip.isp = :isp_id'
|
||||
);
|
||||
}
|
||||
|
||||
public function getIpsIdsByDomainId(): string {
|
||||
return (
|
||||
'SELECT DISTINCT
|
||||
event.ip AS itemid
|
||||
FROM event
|
||||
LEFT JOIN event_email
|
||||
ON (event.email = event_email.id)
|
||||
WHERE
|
||||
event_email.key = :api_key
|
||||
AND event_email.domain = :domain_id'
|
||||
);
|
||||
}
|
||||
|
||||
public function getIpsIdsByCountryId(): string {
|
||||
return (
|
||||
'SELECT DISTINCT
|
||||
event_ip.id AS itemid
|
||||
FROM event_ip
|
||||
WHERE
|
||||
event_ip.key = :api_key AND
|
||||
event_ip.country = :country_id'
|
||||
);
|
||||
}
|
||||
|
||||
public function getIpsIdsByDeviceId(): string {
|
||||
return (
|
||||
'SELECT DISTINCT
|
||||
event.ip AS itemid
|
||||
FROM event
|
||||
INNER JOIN event_device
|
||||
ON (event.device = event_device.id)
|
||||
WHERE
|
||||
event_device.user_agent = :device_id AND
|
||||
event_device.key = :api_key'
|
||||
);
|
||||
}
|
||||
|
||||
public function getIpsIdsByResourceId(): string {
|
||||
return (
|
||||
'SELECT DISTINCT
|
||||
event.ip AS itemid
|
||||
FROM event
|
||||
WHERE
|
||||
event.url = :resource_id AND
|
||||
event.key = :api_key'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
<?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\Ips;
|
||||
|
||||
class Query extends \Models\Grid\Base\Query {
|
||||
protected $defaultOrder = 'event_ip.lastseen DESC';
|
||||
protected $dateRangeField = 'event_ip.lastseen';
|
||||
|
||||
protected $allowedColumns = ['ip', 'full_country', 'asn', 'netname', 'ip_type', 'total_visit', 'total_account', 'lastseen', 'id'];
|
||||
|
||||
public function getData(): array {
|
||||
$queryParams = $this->getQueryParams();
|
||||
|
||||
$query = (
|
||||
'SELECT
|
||||
event_ip.id,
|
||||
event_ip.ip,
|
||||
event_ip.fraud_detected,
|
||||
event_ip.alert_list,
|
||||
event_ip.data_center,
|
||||
event_ip.vpn,
|
||||
event_ip.tor,
|
||||
event_ip.relay,
|
||||
event_ip.blocklist,
|
||||
event_ip.starlink,
|
||||
event_ip.shared AS total_account,
|
||||
event_ip.total_visit,
|
||||
event_ip.checked,
|
||||
|
||||
event_ip.lastseen AS lastseen,
|
||||
|
||||
event_isp.name AS netname,
|
||||
event_isp.description,
|
||||
event_isp.asn,
|
||||
|
||||
countries.id AS country_id,
|
||||
countries.iso AS country_iso,
|
||||
countries.value AS full_country
|
||||
|
||||
FROM
|
||||
event_ip
|
||||
|
||||
LEFT JOIN countries
|
||||
ON (event_ip.country = countries.id)
|
||||
|
||||
LEFT JOIN event_isp
|
||||
ON (event_ip.isp = event_isp.id)
|
||||
|
||||
WHERE
|
||||
event_ip.key = :api_key
|
||||
%s'
|
||||
);
|
||||
|
||||
$this->applySearch($query, $queryParams);
|
||||
$this->applyIpTypes($query);
|
||||
$this->applyOrder($query);
|
||||
$this->applyLimit($query, $queryParams);
|
||||
|
||||
return [$query, $queryParams];
|
||||
}
|
||||
|
||||
public function getTotal(): array {
|
||||
$queryParams = $this->getQueryParams();
|
||||
|
||||
$query = (
|
||||
'SELECT
|
||||
COUNT (DISTINCT event_ip.ip)
|
||||
|
||||
FROM
|
||||
event_ip
|
||||
|
||||
LEFT JOIN countries
|
||||
ON (event_ip.country = countries.id)
|
||||
|
||||
LEFT JOIN event_isp
|
||||
ON (event_ip.isp = event_isp.id)
|
||||
|
||||
WHERE
|
||||
event_ip.key = :api_key
|
||||
%s'
|
||||
);
|
||||
|
||||
$this->applySearch($query, $queryParams);
|
||||
$this->applyIpTypes($query);
|
||||
|
||||
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_ip.id', $queryParams);
|
||||
|
||||
if (is_array($search) && isset($search['value']) && is_string($search['value']) && $search['value'] !== '') {
|
||||
$searchConditions .= (
|
||||
' AND
|
||||
(
|
||||
TEXT(event_ip.ip) LIKE LOWER(:search_value)
|
||||
OR LOWER(event_isp.asn::text) LIKE LOWER(:search_value)
|
||||
OR LOWER(event_isp.name) LIKE LOWER(:search_value)
|
||||
OR LOWER(countries.value) LIKE LOWER(:search_value)
|
||||
OR LOWER(countries.iso) LIKE LOWER(:search_value)
|
||||
)'
|
||||
);
|
||||
|
||||
$queryParams[':search_value'] = '%' . $search['value'] . '%';
|
||||
}
|
||||
|
||||
//Add search and ids into request
|
||||
$query = sprintf($query, $searchConditions);
|
||||
}
|
||||
|
||||
private function applyIpTypes(string &$query): void {
|
||||
$ipTypeIds = $this->f3->get('REQUEST.ipTypeIds');
|
||||
if ($ipTypeIds === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($ipTypeIds as $ipTypeId) {
|
||||
switch ($ipTypeId) {
|
||||
case 0:
|
||||
$query .= ' AND fraud_detected IS TRUE ';
|
||||
break;
|
||||
case 1:
|
||||
$query .= ' AND blocklist IS TRUE ';
|
||||
break;
|
||||
case 2:
|
||||
$query .= ' AND countries.id = 0 AND event_ip.checked IS TRUE ';
|
||||
break;
|
||||
case 3:
|
||||
$query .= ' AND tor IS TRUE ';
|
||||
break;
|
||||
case 4:
|
||||
$query .= ' AND starlink IS TRUE ';
|
||||
break;
|
||||
case 5:
|
||||
$query .= ' AND relay IS TRUE ';
|
||||
break;
|
||||
case 6:
|
||||
$query .= ' AND vpn IS TRUE ';
|
||||
break;
|
||||
case 7:
|
||||
$query .= ' AND data_center IS TRUE ';
|
||||
break;
|
||||
case 8:
|
||||
$query .= ' AND (event_ip.checked IS FALSE OR event_ip.checked IS NULL) ';
|
||||
break;
|
||||
case 9:
|
||||
$query .= ' AND (tor IS FALSE AND vpn IS FALSE AND relay IS FALSE AND data_center IS FALSE AND event_ip.checked IS TRUE) ';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user