|
1
|
|
|
<?php |
|
2
|
|
|
namespace AOE\AoeIpauth\Domain\Service; |
|
3
|
|
|
|
|
4
|
|
|
/*************************************************************** |
|
5
|
|
|
* Copyright notice |
|
6
|
|
|
* |
|
7
|
|
|
* (c) 2019 AOE GmbH <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* All rights reserved |
|
10
|
|
|
* |
|
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
|
12
|
|
|
* free software; you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU General Public License as published by |
|
14
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
15
|
|
|
* (at your option) any later version. |
|
16
|
|
|
* |
|
17
|
|
|
* The GNU General Public License can be found at |
|
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
|
19
|
|
|
* |
|
20
|
|
|
* This script is distributed in the hope that it will be useful, |
|
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
23
|
|
|
* GNU General Public License for more details. |
|
24
|
|
|
* |
|
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
|
26
|
|
|
***************************************************************/ |
|
27
|
|
|
|
|
28
|
|
|
use AOE\AoeIpauth\Utility\EnableFieldsUtility; |
|
29
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
|
30
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Class IpService |
|
34
|
|
|
* |
|
35
|
|
|
* @package AOE\AoeIpauth\Domain\Service |
|
36
|
|
|
*/ |
|
37
|
|
|
class IpService implements \TYPO3\CMS\Core\SingletonInterface |
|
38
|
|
|
{ |
|
39
|
|
|
|
|
40
|
|
|
const TABLE = 'tx_aoeipauth_domain_model_ip'; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Returns all ip domain model records that belong to a given fe_user uid |
|
44
|
|
|
* |
|
45
|
|
|
* @param int $uid fe_users uid |
|
46
|
|
|
* @return array |
|
47
|
|
|
*/ |
|
48
|
|
|
public function findIpsByFeUserId($uid) |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->findIpsByField('fe_user', $uid); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Returns all ip domain model records that belong to a given fe_groups uid |
|
55
|
|
|
* |
|
56
|
|
|
* @param int $uid fe_groups uid |
|
57
|
|
|
* @return array |
|
58
|
|
|
*/ |
|
59
|
|
|
public function findIpsByFeGroupId($uid) |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->findIpsByField('fe_group', $uid); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Finds IPs from the table by a given field and field value |
|
66
|
|
|
* |
|
67
|
|
|
* @param string $field |
|
68
|
|
|
* @param int $value |
|
69
|
|
|
* @return array |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function findIpsByField($field, $value) |
|
72
|
|
|
{ |
|
73
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::TABLE); |
|
74
|
|
|
$queryBuilder->getRestrictions()->removeAll(); |
|
75
|
|
|
$ips = $queryBuilder->select('ip') |
|
76
|
|
|
->from(self::TABLE) |
|
77
|
|
|
->where( |
|
78
|
|
|
$queryBuilder->expr()->eq($field, (int)$value . ' ' . EnableFieldsUtility::enableFields(self::TABLE)) |
|
79
|
|
|
) |
|
80
|
|
|
->execute() |
|
81
|
|
|
->fetchAll(); |
|
82
|
|
|
|
|
83
|
|
|
if (empty($ips)) { |
|
84
|
|
|
return array(); |
|
85
|
|
|
} |
|
86
|
|
|
$finalIps = array(); |
|
87
|
|
|
foreach ($ips as $record) { |
|
88
|
|
|
$finalIps[] = $record['ip']; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return $finalIps; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|