|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016 Joas Schilling <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @license GNU AGPL version 3 or any later version |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
9
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
10
|
|
|
* License, or (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace OCA\WorkflowEngine\Check; |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
use OCP\IL10N; |
|
26
|
|
|
use OCP\IRequest; |
|
27
|
|
|
|
|
28
|
|
|
class RequestUserAgent extends AbstractStringCheck { |
|
29
|
|
|
|
|
30
|
|
|
/** @var IRequest */ |
|
31
|
|
|
protected $request; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param IL10N $l |
|
35
|
|
|
* @param IRequest $request |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(IL10N $l, IRequest $request) { |
|
38
|
|
|
parent::__construct($l); |
|
39
|
|
|
$this->request = $request; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param string $operator |
|
44
|
|
|
* @param string $value |
|
45
|
|
|
* @return bool |
|
46
|
|
|
*/ |
|
47
|
|
|
public function executeCheck($operator, $value) { |
|
48
|
|
|
$actualValue = $this->getActualValue(); |
|
49
|
|
|
if (in_array($operator, ['is', '!is'])) { |
|
50
|
|
|
switch ($value) { |
|
51
|
|
|
case 'android': |
|
52
|
|
|
$operator = $operator === 'is' ? 'matches' : '!matches'; |
|
53
|
|
|
$value = IRequest::USER_AGENT_CLIENT_ANDROID; |
|
54
|
|
|
break; |
|
55
|
|
|
case 'ios': |
|
56
|
|
|
$operator = $operator === 'is' ? 'matches' : '!matches'; |
|
57
|
|
|
$value = IRequest::USER_AGENT_CLIENT_IOS; |
|
58
|
|
|
break; |
|
59
|
|
|
case 'desktop': |
|
60
|
|
|
$operator = $operator === 'is' ? 'matches' : '!matches'; |
|
61
|
|
|
$value = IRequest::USER_AGENT_CLIENT_DESKTOP; |
|
62
|
|
|
break; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
return $this->executeStringCheck($operator, $value, $actualValue); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return string |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function getActualValue() { |
|
72
|
|
|
return (string) $this->request->getHeader('User-Agent'); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|