1 | <?php |
||
27 | class File { |
||
28 | protected $fileId; |
||
29 | protected $owner; |
||
30 | protected $sharing; |
||
31 | protected $token; |
||
32 | protected $passwordProtected = false; |
||
33 | protected $ownerView; |
||
34 | protected $ownerViewFiles; |
||
35 | protected $path; |
||
36 | protected $pathFiles; |
||
37 | |||
38 | public function __construct($fileId, $shareOps = null, $token = ''){ |
||
39 | if (!$fileId){ |
||
40 | throw new \Exception('No valid file has been passed'); |
||
41 | } |
||
42 | |||
43 | $this->fileId = $fileId; |
||
44 | $this->sharing = $shareOps; |
||
45 | $this->token = $token; |
||
46 | |||
47 | if ($this->isPublicShare()) { |
||
48 | if (isset($this->sharing['uid_owner'])){ |
||
49 | $this->owner = $this->sharing['uid_owner']; |
||
50 | if (!\OC::$server->getUserManager()->userExists($this->sharing['uid_owner'])) { |
||
51 | throw new \Exception('Share owner' . $this->sharing['uid_owner'] . ' does not exist '); |
||
52 | } |
||
53 | |||
54 | \OC_Util::tearDownFS(); |
||
55 | \OC_Util::setupFS($this->sharing['uid_owner']); |
||
56 | } else { |
||
57 | throw new \Exception($this->fileId . ' is a broken share'); |
||
58 | } |
||
59 | } else { |
||
60 | $this->owner = \OC::$server->getUserSession()->getUser()->getUID(); |
||
61 | } |
||
62 | $this->initViews(); |
||
63 | } |
||
64 | |||
65 | |||
66 | public static function getByShareToken($token){ |
||
67 | $linkItem = \OCP\Share::getShareByToken($token, false); |
||
68 | if (is_array($linkItem) && isset($linkItem['uid_owner'])) { |
||
69 | // seems to be a valid share |
||
70 | $rootLinkItem = \OCP\Share::resolveReShare($linkItem); |
||
71 | } else { |
||
72 | throw new \Exception('This file was probably unshared'); |
||
73 | } |
||
74 | |||
75 | $file = new File($rootLinkItem['file_source'], $rootLinkItem, $token); |
||
76 | |||
77 | if (isset($linkItem['share_with']) && !empty($linkItem['share_with'])){ |
||
78 | $file->setPasswordProtected(true); |
||
79 | } |
||
80 | |||
81 | return $file; |
||
82 | } |
||
83 | |||
84 | public function getToken(){ |
||
87 | |||
88 | public function getFileId(){ |
||
91 | |||
92 | public function setToken($token){ |
||
95 | |||
96 | public function isPublicShare(){ |
||
99 | |||
100 | public function isPasswordProtected(){ |
||
103 | |||
104 | /** |
||
105 | * @param string $password |
||
106 | * @return boolean |
||
107 | */ |
||
108 | public function checkPassword($password){ |
||
109 | $shareId = $this->sharing['id']; |
||
110 | if (!$this->isPasswordProtected() |
||
111 | || (\OC::$server->getSession()->exists('public_link_authenticated') |
||
112 | && \OC::$server->getSession()->get('public_link_authenticated') === $shareId |
||
113 | ) |
||
114 | ){ |
||
115 | return true; |
||
116 | } |
||
117 | |||
118 | // Check Password |
||
119 | $newHash = ''; |
||
120 | if(\OC::$server->getHasher()->verify($password, $this->getPassword(), $newHash)) { |
||
121 | \OC::$server->getSession()->set('public_link_authenticated', $shareId); |
||
122 | |||
123 | /** |
||
124 | * FIXME: Migrate old hashes to new hash format |
||
125 | * Due to the fact that there is no reasonable functionality to update the password |
||
126 | * of an existing share no migration is yet performed there. |
||
127 | * The only possibility is to update the existing share which will result in a new |
||
128 | * share ID and is a major hack. |
||
129 | * |
||
130 | * In the future the migration should be performed once there is a proper method |
||
131 | * to update the share's password. (for example `$share->updatePassword($password)` |
||
132 | * |
||
133 | * @link https://github.com/owncloud/core/issues/10671 |
||
134 | */ |
||
135 | if(!empty($newHash)) { |
||
136 | |||
137 | } |
||
138 | |||
139 | return true; |
||
140 | } |
||
141 | return false; |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * @param boolean $value |
||
146 | */ |
||
147 | public function setPasswordProtected($value){ |
||
150 | |||
151 | public function getOwner(){ |
||
154 | |||
155 | public function getOwnerView($relativeToFiles = false){ |
||
158 | |||
159 | public function getPath($relativeToFiles = false){ |
||
162 | |||
163 | public function getPermissions(){ |
||
167 | |||
168 | protected function initViews(){ |
||
169 | $this->ownerView = new View('/' . $this->owner); |
||
170 | $this->ownerViewFiles = new View('/' . $this->owner . '/files'); |
||
184 | |||
185 | protected function getPassword(){ |
||
188 | } |
||
189 |