|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* @author Roeland Jago Douma <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* @license GNU AGPL version 3 or any later version |
|
7
|
|
|
* |
|
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
10
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
11
|
|
|
* License, or (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU Affero General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20
|
|
|
* |
|
21
|
|
|
*/ |
|
22
|
|
|
namespace OC\Core\Controller; |
|
23
|
|
|
|
|
24
|
|
|
use OC\CapabilitiesManager; |
|
25
|
|
|
use OC\Security\Bruteforce\Throttler; |
|
26
|
|
|
use OCP\AppFramework\Http\DataResponse; |
|
27
|
|
|
use OCP\IRequest; |
|
28
|
|
|
use OCP\IUserManager; |
|
29
|
|
|
use OCP\IUserSession; |
|
30
|
|
|
|
|
31
|
|
|
class OCSController extends \OCP\AppFramework\OCSController { |
|
32
|
|
|
|
|
33
|
|
|
/** @var CapabilitiesManager */ |
|
34
|
|
|
private $capabilitiesManager; |
|
35
|
|
|
|
|
36
|
|
|
/** @var IUserSession */ |
|
37
|
|
|
private $userSession; |
|
38
|
|
|
|
|
39
|
|
|
/** @var IUserManager */ |
|
40
|
|
|
private $userManager; |
|
41
|
|
|
|
|
42
|
|
|
/** @var Throttler */ |
|
43
|
|
|
private $throttler; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* OCSController constructor. |
|
47
|
|
|
* |
|
48
|
|
|
* @param string $appName |
|
49
|
|
|
* @param IRequest $request |
|
50
|
|
|
* @param CapabilitiesManager $capabilitiesManager |
|
51
|
|
|
* @param IUserSession $userSession |
|
52
|
|
|
* @param IUserManager $userManager |
|
53
|
|
|
* @param Throttler $throttler |
|
54
|
|
|
*/ |
|
55
|
|
|
public function __construct($appName, |
|
56
|
|
|
IRequest $request, |
|
57
|
|
|
CapabilitiesManager $capabilitiesManager, |
|
58
|
|
|
IUserSession $userSession, |
|
59
|
|
|
IUserManager $userManager, |
|
60
|
|
|
Throttler $throttler) { |
|
61
|
|
|
parent::__construct($appName, $request); |
|
62
|
|
|
|
|
63
|
|
|
$this->capabilitiesManager = $capabilitiesManager; |
|
64
|
|
|
$this->userSession = $userSession; |
|
65
|
|
|
$this->userManager = $userManager; |
|
66
|
|
|
$this->throttler = $throttler; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @PublicPage |
|
71
|
|
|
* |
|
72
|
|
|
* @return DataResponse |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getConfig() { |
|
75
|
|
|
$data = [ |
|
76
|
|
|
'version' => '1.7', |
|
77
|
|
|
'website' => 'Nextcloud', |
|
78
|
|
|
'host' => $this->request->getServerHost(), |
|
79
|
|
|
'contact' => '', |
|
80
|
|
|
'ssl' => 'false', |
|
81
|
|
|
]; |
|
82
|
|
|
|
|
83
|
|
|
return new DataResponse($data); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @NoAdminRequired |
|
88
|
|
|
* @return DataResponse |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getCapabilities() { |
|
91
|
|
|
$result = []; |
|
92
|
|
|
list($major, $minor, $micro) = \OCP\Util::getVersion(); |
|
93
|
|
|
$result['version'] = array( |
|
94
|
|
|
'major' => $major, |
|
95
|
|
|
'minor' => $minor, |
|
96
|
|
|
'micro' => $micro, |
|
97
|
|
|
'string' => \OC_Util::getVersionString(), |
|
98
|
|
|
'edition' => '', |
|
99
|
|
|
); |
|
100
|
|
|
|
|
101
|
|
|
$result['capabilities'] = $this->capabilitiesManager->getCapabilities(); |
|
102
|
|
|
|
|
103
|
|
|
return new DataResponse($result); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @NoAdminRequired |
|
108
|
|
|
* @return DataResponse |
|
109
|
|
|
*/ |
|
110
|
|
|
public function getCurrentUser() { |
|
111
|
|
|
$userObject = $this->userSession->getUser(); |
|
112
|
|
|
$data = [ |
|
113
|
|
|
'id' => $userObject->getUID(), |
|
114
|
|
|
'display-name' => $userObject->getDisplayName(), |
|
115
|
|
|
'email' => $userObject->getEMailAddress(), |
|
116
|
|
|
]; |
|
117
|
|
|
return new DataResponse($data); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @PublicPage |
|
122
|
|
|
* |
|
123
|
|
|
* @param string $login |
|
124
|
|
|
* @param string $password |
|
125
|
|
|
* @return DataResponse |
|
126
|
|
|
*/ |
|
127
|
|
|
public function personCheck($login = '', $password = '') { |
|
128
|
|
|
if ($login !== '' && $password !== '') { |
|
129
|
|
|
$this->throttler->sleepDelay($this->request->getRemoteAddress()); |
|
130
|
|
|
if ($this->userManager->checkPassword($login, $password)) { |
|
131
|
|
|
return new DataResponse([ |
|
132
|
|
|
'person' => [ |
|
133
|
|
|
'personid' => $login |
|
134
|
|
|
] |
|
135
|
|
|
]); |
|
136
|
|
|
} |
|
137
|
|
|
$this->throttler->registerAttempt('login', $this->request->getRemoteAddress()); |
|
138
|
|
|
return new DataResponse(null, 102); |
|
|
|
|
|
|
139
|
|
|
} |
|
140
|
|
|
return new DataResponse(null, 101); |
|
|
|
|
|
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: