-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetFileInfoData.php
131 lines (116 loc) · 3.97 KB
/
getFileInfoData.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/**
* ownCloud files_sharding app
*
* @author Frederik Orellana
* @copyright 2014 Frederik Orellana
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
OCP\JSON::checkAppEnabled('files_sharding');
if(!OCA\FilesSharding\Lib::checkIP()){
http_response_code(401);
exit;
}
//$path = isset($_GET['path'])? urldecode($_GET['path']) : '';
// The superglobals $_GET and $_REQUEST are already decoded
$path = isset($_GET['path'])? $_GET['path'] : '';
$id = isset($_GET['id']) ? $_GET['id'] : null;
$owner = isset($_GET['owner']) ? $_GET['owner'] : '';
$user_id = isset($_GET['user_id']) ? $_GET['user_id'] : '';
$group = isset($_GET['group']) ? $_GET['group'] : '';
$group_dir_owner = $user_id;
function switchUser($myowner){
$myuser = \OC_User::getUser();
if($myowner && $myowner!==$myuser){
\OC_Util::teardownFS();
\OC_User::setUserId($myowner);
\OC_Util::setupFS($myowner);
return $myuser;
}
else{
return null;
}
}
$group_dir_owner = $owner;
if($owner && $owner!=$user_id){
switchUser($owner);
}
elseif($user_id){
switchUser($user_id);
\OCP\Util::writeLog('files_sharding', 'No id or owner: '.$user_id.':'.$owner.':'.$id, \OC_Log::WARN);
}
if(!empty($group) && !empty($group_dir_owner)){
\OC\Files\Filesystem::tearDown();
$groupDir = '/'.$group_dir_owner.'/user_group_admin/'.$group;
\OC\Files\Filesystem::init($group_dir_owner, $groupDir);
\OCP\Util::writeLog('files_sharding', 'Initialized group dir: '.$groupDir.' as '.\OC_User::getUser(), \OC_Log::WARN);
}
if($id){
$path = \OC\Files\Filesystem::getPath($id);
}
\OCP\Util::writeLog('files_sharding', 'Path: '.$path, \OC_Log::WARN);
try{
if(!empty($owner) && $owner!=$user_id){
$permissions = \OCA\FilesSharding\Lib::checkAccessRecursively($user_id, $id, $owner, $group, $path);
if(empty($permissions)){
\OCP\Util::writeLog('files_sharding', 'Not allowed '.$user_id.'/'.$owner.'-->'.$id.':'.$path.'-->'.$permissions, \OC_Log::WARN);
restoreUser($user_id);
//throw new Exception('Not allowed. '.$id);
}
else{
switchUser($owner);
}
}
if(!empty($group)){
$path = \OC\Files\Filesystem::normalizePath('/'.trim($group, '/').'/'.trim($path, '/'));
$fs = \OCP\Files::getStorage('user_group_admin');
\OCP\Util::writeLog('User_Group_Admin', 'DIR: '.$path, \OCP\Util::WARN);
$info = $fs->getFileInfo($path);
}
else{
$info = \OC\Files\Filesystem::getFileInfo($path);
}
}
catch(\Exception $e){
restoreUser($user_id);
OCP\JSON::encodedPrint('');
exit;
}
restoreUser($user_id);
if(empty($info) || !empty($id) && $info->getId()!=$id){
\OCP\Util::writeLog('files_sharding', 'File not found '.$owner.'-->'.$id.':'.$path, \OC_Log::WARN);
OCP\JSON::encodedPrint('');
exit;
}
$data = $info->getData();
if(!empty($permissions)){
$data['permissions'] = $permissions;
}
//$data['directory'] = $path;
$data['path'] = $info->getpath();
//$data['storage'] = $info->getStorage();
//\OCP\Util::writeLog('files_sharding', 'STORAGE: '.serialize($data['storage']), \OC_Log::WARN);
$data['internalPath'] = $info->getInternalPath();
\OCP\Util::writeLog('files_sharding', 'Returning file info for '.$owner.'-->'.$id.':'.$path.':'.$data['path'], \OC_Log::WARN);
OCP\JSON::encodedPrint($data);
function restoreUser($user_id){
// Not necessary for ws calls - which are one-off
return true;
// If not done, the user shared with will now be logged in as $owner
/*\OC_Util::teardownFS();
\OC_User::setUserId($user_id);
\OC_Util::setupFS($user_id);*/
}