1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Teampass - a collaborative passwords manager. |
4
|
|
|
* --- |
5
|
|
|
* This library is distributed in the hope that it will be useful, |
6
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
7
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
8
|
|
|
* --- |
9
|
|
|
* |
10
|
|
|
* @project Teampass |
11
|
|
|
* @version API |
12
|
|
|
* |
13
|
|
|
* @file FolderControler.php |
14
|
|
|
* --- |
15
|
|
|
* |
16
|
|
|
* @author Nils Laumaillé ([email protected]) |
17
|
|
|
* |
18
|
|
|
* @copyright 2009-2023 Teampass.net |
19
|
|
|
* |
20
|
|
|
* @license https://spdx.org/licenses/GPL-3.0-only.html#licenseText GPL-3.0 |
21
|
|
|
* --- |
22
|
|
|
* |
23
|
|
|
* @see https://www.teampass.net |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
use TeampassClasses\SuperGlobal\SuperGlobal; |
27
|
|
|
|
28
|
|
|
class FolderController extends BaseController |
29
|
|
|
{ |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Get list of Folders |
33
|
|
|
* |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
|
|
public function listFoldersAction(array $userData) |
37
|
|
|
{ |
38
|
|
|
$superGlobal = new SuperGlobal(); |
39
|
|
|
$strErrorDesc = $responseData = $strErrorHeader = ''; |
40
|
|
|
$requestMethod = $superGlobal->get('REQUEST_METHOD', 'SERVER'); |
41
|
|
|
|
42
|
|
|
// get parameters |
43
|
|
|
//$arrQueryStringParams = $this->getQueryStringParams(); |
44
|
|
|
|
45
|
|
|
if (strtoupper($requestMethod) === 'GET') { |
46
|
|
|
if (empty($userData['folders_list'])) { |
47
|
|
|
$this->sendOutput("", ['HTTP/1.1 204 No Content']); |
48
|
|
|
} else { |
49
|
|
|
try { |
50
|
|
|
$folderModel = new FolderModel(); |
51
|
|
|
$arrFolders = $folderModel->getFoldersInfo(explode(",", $userData['folders_list'])); |
52
|
|
|
$responseData = json_encode($arrFolders); |
53
|
|
|
} catch (Error $e) { |
54
|
|
|
$strErrorDesc = $e->getMessage() . ' Something went wrong! Please contact support.'; |
55
|
|
|
$strErrorHeader = 'HTTP/1.1 500 Internal Server Error'; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} else { |
59
|
|
|
$strErrorDesc = 'Method not supported'; |
60
|
|
|
$strErrorHeader = 'HTTP/1.1 422 Unprocessable Entity'; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// send output |
64
|
|
|
if (empty($strErrorDesc) === true) { |
65
|
|
|
$this->sendOutput( |
66
|
|
|
$responseData, |
67
|
|
|
['Content-Type: application/json', 'HTTP/1.1 200 OK'] |
68
|
|
|
); |
69
|
|
|
} else { |
70
|
|
|
$this->sendOutput( |
71
|
|
|
json_encode(['error' => $strErrorDesc]), |
72
|
|
|
['Content-Type: application/json', $strErrorHeader] |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
//end listInFoldersAction() |
77
|
|
|
} |
78
|
|
|
|