1 | <?php |
||
2 | /** |
||
3 | * sysPass |
||
4 | * |
||
5 | * @author nuxsmin |
||
6 | * @link https://syspass.org |
||
7 | * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org |
||
8 | * |
||
9 | * This file is part of sysPass. |
||
10 | * |
||
11 | * sysPass is free software: you can redistribute it and/or modify |
||
12 | * it under the terms of the GNU General Public License as published by |
||
13 | * the Free Software Foundation, either version 3 of the License, or |
||
14 | * (at your option) any later version. |
||
15 | * |
||
16 | * sysPass is distributed in the hope that it will be useful, |
||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
19 | * GNU General Public License for more details. |
||
20 | * |
||
21 | * You should have received a copy of the GNU General Public License |
||
22 | * along with sysPass. If not, see <http://www.gnu.org/licenses/>. |
||
23 | */ |
||
24 | |||
25 | namespace SP\Services\Account; |
||
26 | |||
27 | defined('APP_ROOT') || die(); |
||
28 | |||
29 | use SP\Config\ConfigData; |
||
30 | use SP\DataModel\AccountSearchVData; |
||
31 | use SP\DataModel\ItemData; |
||
32 | use SP\Html\Html; |
||
33 | use SP\Services\PublicLink\PublicLinkService; |
||
34 | |||
35 | /** |
||
36 | * Class AccountSearchItem para contener los datos de cada cuenta en la búsqueda |
||
37 | * |
||
38 | * @package SP\Controller |
||
39 | */ |
||
40 | final class AccountSearchItem |
||
41 | { |
||
42 | /** |
||
43 | * @var bool |
||
44 | */ |
||
45 | public static $accountLink = false; |
||
46 | /** |
||
47 | * @var bool |
||
48 | */ |
||
49 | public static $topNavbar = false; |
||
50 | /** |
||
51 | * @var bool |
||
52 | */ |
||
53 | public static $optionalActions = false; |
||
54 | /** |
||
55 | * @var bool |
||
56 | */ |
||
57 | public static $showTags = false; |
||
58 | /** |
||
59 | * @var bool |
||
60 | */ |
||
61 | public static $requestEnabled = true; |
||
62 | /** |
||
63 | * @var bool |
||
64 | */ |
||
65 | public static $wikiEnabled = false; |
||
66 | /** |
||
67 | * @var bool |
||
68 | */ |
||
69 | public static $dokuWikiEnabled = false; |
||
70 | /** |
||
71 | * @var bool |
||
72 | */ |
||
73 | public static $publicLinkEnabled = false; |
||
74 | /** |
||
75 | * @var bool |
||
76 | */ |
||
77 | public static $isDemoMode = false; |
||
78 | |||
79 | /** |
||
80 | * @var AccountSearchVData |
||
81 | */ |
||
82 | protected $accountSearchVData; |
||
83 | /** |
||
84 | * @var string |
||
85 | */ |
||
86 | protected $color; |
||
87 | /** |
||
88 | * @var string |
||
89 | */ |
||
90 | protected $link; |
||
91 | /** |
||
92 | * @var bool |
||
93 | */ |
||
94 | protected $url_islink = false; |
||
95 | /** |
||
96 | * @var string |
||
97 | */ |
||
98 | protected $numFiles; |
||
99 | /** |
||
100 | * @var bool |
||
101 | */ |
||
102 | protected $favorite = false; |
||
103 | /** |
||
104 | * @var int |
||
105 | */ |
||
106 | protected $textMaxLength = 60; |
||
107 | /** |
||
108 | * @var ItemData[] |
||
109 | */ |
||
110 | protected $users; |
||
111 | /** |
||
112 | * @var ItemData[] |
||
113 | */ |
||
114 | protected $tags; |
||
115 | /** |
||
116 | * @var ItemData[] |
||
117 | */ |
||
118 | protected $userGroups; |
||
119 | /** |
||
120 | * @var ConfigData |
||
121 | */ |
||
122 | private $configData; |
||
123 | /** |
||
124 | * @var AccountAcl |
||
125 | */ |
||
126 | private $accountAcl; |
||
127 | |||
128 | /** |
||
129 | * AccountsSearchItem constructor. |
||
130 | * |
||
131 | * @param AccountSearchVData $accountSearchVData |
||
132 | * @param AccountAcl $accountAcl |
||
133 | * @param ConfigData $configData |
||
134 | */ |
||
135 | public function __construct(AccountSearchVData $accountSearchVData, AccountAcl $accountAcl, ConfigData $configData) |
||
136 | { |
||
137 | $this->accountSearchVData = $accountSearchVData; |
||
138 | $this->accountAcl = $accountAcl; |
||
139 | $this->configData = $configData; |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * @return boolean |
||
144 | */ |
||
145 | public function isFavorite() |
||
146 | { |
||
147 | return $this->favorite; |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * @param boolean $favorite |
||
152 | */ |
||
153 | public function setFavorite($favorite) |
||
154 | { |
||
155 | $this->favorite = $favorite; |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * @return boolean |
||
160 | */ |
||
161 | public function isShowRequest() |
||
162 | { |
||
163 | return (!$this->accountAcl->isShow() && self::$requestEnabled); |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * @return bool |
||
168 | */ |
||
169 | public function isShowCopyPass() |
||
170 | { |
||
171 | return ($this->accountAcl->isShowViewPass() && !$this->configData->isAccountPassToImage()); |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * @return bool |
||
176 | */ |
||
177 | public function isShowViewPass() |
||
178 | { |
||
179 | return $this->accountAcl->isShowViewPass(); |
||
180 | } |
||
181 | |||
182 | |||
183 | /** |
||
184 | * @return bool |
||
185 | */ |
||
186 | public function isShowOptional() |
||
187 | { |
||
188 | return ($this->accountAcl->isShow() && !self::$optionalActions); |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * @param int $textMaxLength |
||
193 | */ |
||
194 | public function setTextMaxLength($textMaxLength) |
||
195 | { |
||
196 | $this->textMaxLength = $textMaxLength; |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * @return string |
||
201 | */ |
||
202 | public function getShortUrl() |
||
203 | { |
||
204 | return Html::truncate($this->accountSearchVData->getUrl(), $this->textMaxLength); |
||
205 | } |
||
206 | |||
207 | /** |
||
208 | * @return boolean |
||
209 | */ |
||
210 | public function isUrlIslink() |
||
211 | { |
||
212 | return preg_match('#^https?://#i', $this->accountSearchVData->getUrl()); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
213 | } |
||
214 | |||
215 | /** |
||
216 | * @return string |
||
217 | */ |
||
218 | public function getShortLogin() |
||
219 | { |
||
220 | return Html::truncate($this->accountSearchVData->getLogin(), $this->textMaxLength); |
||
221 | } |
||
222 | |||
223 | /** |
||
224 | * @return string |
||
225 | */ |
||
226 | public function getShortClientName() |
||
227 | { |
||
228 | return Html::truncate($this->accountSearchVData->getClientName(), $this->textMaxLength / 3); |
||
229 | } |
||
230 | |||
231 | /** |
||
232 | * @return string |
||
233 | */ |
||
234 | public function getClientLink() |
||
235 | { |
||
236 | return self::$wikiEnabled ? $this->configData->getWikiSearchurl() . $this->accountSearchVData->getClientName() : null; |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * @return string |
||
241 | */ |
||
242 | public function getPublicLink() |
||
243 | { |
||
244 | return self::$publicLinkEnabled |
||
245 | && $this->accountSearchVData->getPublicLinkHash() !== null ? PublicLinkService::getLinkForHash($this->accountSearchVData->getPublicLinkHash()) : null; |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * @return string |
||
250 | */ |
||
251 | public function getColor() |
||
252 | { |
||
253 | return $this->color; |
||
254 | } |
||
255 | |||
256 | /** |
||
257 | * @param string $color |
||
258 | */ |
||
259 | public function setColor($color) |
||
260 | { |
||
261 | $this->color = $color; |
||
262 | } |
||
263 | |||
264 | /** |
||
265 | * @return string |
||
266 | */ |
||
267 | public function getLink() |
||
268 | { |
||
269 | return $this->link; |
||
270 | } |
||
271 | |||
272 | /** |
||
273 | * @param string $link |
||
274 | */ |
||
275 | public function setLink($link) |
||
276 | { |
||
277 | $this->link = $link; |
||
278 | } |
||
279 | |||
280 | /** |
||
281 | * @return array |
||
282 | */ |
||
283 | public function getAccesses() |
||
284 | { |
||
285 | $accesses = [ |
||
286 | '(G*) <em>' . $this->accountSearchVData->getUserGroupName() . '</em>', |
||
287 | '(U*) <em>' . $this->accountSearchVData->getUserLogin() . '</em>' |
||
288 | ]; |
||
289 | |||
290 | $userLabel = $this->accountSearchVData->getOtherUserEdit() === 1 ? 'U+' : 'U'; |
||
291 | $userGroupLabel = $this->accountSearchVData->getOtherUserGroupEdit() === 1 ? 'G+' : 'G'; |
||
292 | |||
293 | foreach ($this->userGroups as $group) { |
||
294 | $accesses[] = sprintf('(%s) <em>%s</em>', $userGroupLabel, $group->getName()); |
||
295 | } |
||
296 | |||
297 | foreach ($this->users as $user) { |
||
298 | $accesses[] = sprintf('(%s) <em>%s</em>', $userLabel, $user->login); |
||
299 | } |
||
300 | |||
301 | return $accesses; |
||
302 | } |
||
303 | |||
304 | /** |
||
305 | * @return string |
||
306 | */ |
||
307 | public function getNumFiles() |
||
308 | { |
||
309 | return $this->configData->isFilesEnabled() ? $this->accountSearchVData->getNumFiles() : 0; |
||
310 | } |
||
311 | |||
312 | /** |
||
313 | * @param string $numFiles |
||
314 | */ |
||
315 | public function setNumFiles($numFiles) |
||
316 | { |
||
317 | $this->numFiles = $numFiles; |
||
318 | } |
||
319 | |||
320 | /** |
||
321 | * @return boolean |
||
322 | */ |
||
323 | public function isShow() |
||
324 | { |
||
325 | return $this->accountAcl->isShow(); |
||
326 | } |
||
327 | |||
328 | /** |
||
329 | * @return boolean |
||
330 | */ |
||
331 | public function isShowView() |
||
332 | { |
||
333 | return $this->accountAcl->isShowView(); |
||
334 | } |
||
335 | |||
336 | /** |
||
337 | * @return boolean |
||
338 | */ |
||
339 | public function isShowEdit() |
||
340 | { |
||
341 | return $this->accountAcl->isShowEdit(); |
||
342 | } |
||
343 | |||
344 | /** |
||
345 | * @return boolean |
||
346 | */ |
||
347 | public function isShowCopy() |
||
348 | { |
||
349 | return $this->accountAcl->isShowCopy(); |
||
350 | } |
||
351 | |||
352 | /** |
||
353 | * @return boolean |
||
354 | */ |
||
355 | public function isShowDelete() |
||
356 | { |
||
357 | return $this->accountAcl->isShowDelete(); |
||
358 | } |
||
359 | |||
360 | /** |
||
361 | * @return AccountSearchVData |
||
362 | */ |
||
363 | public function getAccountSearchVData() |
||
364 | { |
||
365 | return $this->accountSearchVData; |
||
366 | } |
||
367 | |||
368 | /** |
||
369 | * @return string |
||
370 | */ |
||
371 | public function getShortNotes() |
||
372 | { |
||
373 | if ($this->accountSearchVData->getNotes()) { |
||
374 | return nl2br(Html::truncate($this->accountSearchVData->getNotes(), 300)); |
||
375 | } |
||
376 | |||
377 | return ''; |
||
378 | } |
||
379 | |||
380 | /** |
||
381 | * Develve si la clave ha caducado |
||
382 | * |
||
383 | * @return bool |
||
384 | */ |
||
385 | public function isPasswordExpired() |
||
386 | { |
||
387 | return $this->configData->isAccountExpireEnabled() |
||
388 | && $this->accountSearchVData->getPassDateChange() > 0 |
||
389 | && time() > $this->accountSearchVData->getPassDateChange(); |
||
390 | } |
||
391 | |||
392 | /** |
||
393 | * @param ItemData[] $userGroups |
||
394 | */ |
||
395 | public function setUserGroups(array $userGroups) |
||
396 | { |
||
397 | $this->userGroups = $userGroups; |
||
398 | } |
||
399 | |||
400 | /** |
||
401 | * @param ItemData[] $users |
||
402 | */ |
||
403 | public function setUsers(array $users) |
||
404 | { |
||
405 | $this->users = $users; |
||
406 | } |
||
407 | |||
408 | /** |
||
409 | * @return ItemData[] |
||
410 | */ |
||
411 | public function getTags() |
||
412 | { |
||
413 | return $this->tags; |
||
414 | } |
||
415 | |||
416 | /** |
||
417 | * @param ItemData[] $tags |
||
418 | */ |
||
419 | public function setTags(array $tags) |
||
420 | { |
||
421 | $this->tags = $tags; |
||
422 | } |
||
423 | |||
424 | /** |
||
425 | * @param $wikiFilter |
||
426 | * |
||
427 | * @return bool |
||
428 | */ |
||
429 | public function isWikiMatch($wikiFilter) |
||
430 | { |
||
431 | return preg_match('/^' . $wikiFilter . '/i', $this->accountSearchVData->getName()) === 1; |
||
432 | } |
||
433 | } |