Enalean /
tuleap
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Copyright (c) STMicroelectronics, 2010. All Rights Reserved. |
||
| 4 | * |
||
| 5 | * This file is a part of Codendi. |
||
| 6 | * |
||
| 7 | * Codendi is free software; you can redistribute it and/or modify |
||
| 8 | * it under the terms of the GNU General Public License as published by |
||
| 9 | * the Free Software Foundation; either version 2 of the License, or |
||
| 10 | * (at your option) any later version. |
||
| 11 | * |
||
| 12 | * Codendi 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 General Public License for more details. |
||
| 16 | * |
||
| 17 | * You should have received a copy of the GNU General Public License |
||
| 18 | * along with Codendi. If not, see <http://www.gnu.org/licenses/>. |
||
| 19 | */ |
||
| 20 | |||
| 21 | require_once 'WebDAV_Request.class.php'; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * This class contains methods used in WebDAV plugin |
||
| 25 | */ |
||
| 26 | class WebDAVUtils { |
||
| 27 | |||
| 28 | protected static $instance; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Instance of docman plugin |
||
| 32 | * |
||
| 33 | * @var DocmanPlugin |
||
| 34 | */ |
||
| 35 | protected $docmanPlugin; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * We don't permit an explicit call of the constructor! (like $utils = new WebDAVUtils()) |
||
| 39 | * |
||
| 40 | * @return void |
||
|
0 ignored issues
–
show
|
|||
| 41 | */ |
||
| 42 | private function __construct() { |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * We don't permit cloning the singleton (like $webdavutils = clone $utils) |
||
| 47 | * |
||
| 48 | * @return void |
||
| 49 | */ |
||
| 50 | private function __clone() { |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Returns the instance of WebDAVUtils |
||
| 55 | * |
||
| 56 | * @return WebDAVUtils |
||
| 57 | */ |
||
| 58 | public static function getInstance() { |
||
| 59 | |||
| 60 | if (self::$instance === null) { |
||
| 61 | self::$instance = new self(); |
||
| 62 | } |
||
| 63 | return self::$instance; |
||
| 64 | |||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Replaces '/', '%' and '|' by their respective ASCII code |
||
| 69 | * |
||
| 70 | * @param String $name |
||
| 71 | * |
||
| 72 | * @return String |
||
| 73 | */ |
||
| 74 | function convertName($name) { |
||
| 75 | |||
| 76 | $name = str_replace('%', '%25', $name); |
||
| 77 | $name = str_replace('/', '%2F', $name); |
||
| 78 | $name = str_replace('|', '|', $name); |
||
| 79 | return $name; |
||
| 80 | |||
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Retrieves the converted HTML special characters |
||
| 85 | * |
||
| 86 | * @param String $name |
||
| 87 | * |
||
| 88 | * @return String |
||
| 89 | */ |
||
| 90 | function unconvertHTMLSpecialChars($name) { |
||
| 91 | return util_unconvert_htmlspecialchars($this->convertName($name)); |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Replaces ASCII codes of '/', '%' and '|' by the respective characters |
||
| 96 | * |
||
| 97 | * @param String $name |
||
| 98 | * |
||
| 99 | * @return String |
||
| 100 | */ |
||
| 101 | function retrieveName($name) { |
||
| 102 | |||
| 103 | $name = str_replace('%2F', '/', $name); |
||
| 104 | $name = str_replace('%25', '%', $name); |
||
| 105 | $name = str_replace('|', '|', $name); |
||
| 106 | return $name; |
||
| 107 | |||
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Tests if the user is Superuser, project admin or File release admin |
||
| 112 | * |
||
| 113 | * @param PFUser $user |
||
| 114 | * @param Integer $groupId |
||
| 115 | * |
||
| 116 | * @return Boolean |
||
| 117 | */ |
||
| 118 | function userIsAdmin($user, $groupId) { |
||
| 119 | |||
| 120 | // A refers to admin |
||
| 121 | // R2 refers to File release admin |
||
| 122 | return ($user->isSuperUser() || $user->isMember($groupId, 'A') || $user->isMember($groupId, 'R2')); |
||
| 123 | |||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Tests if the user is Superuser, or File release admin |
||
| 128 | * |
||
| 129 | * @param PFUser $user |
||
| 130 | * @param Integer $groupId |
||
| 131 | * |
||
| 132 | * @return Boolean |
||
| 133 | */ |
||
| 134 | function userCanWrite($user, $groupId) { |
||
| 135 | |||
| 136 | // R2 refers to File release admin |
||
| 137 | return $this->isWriteEnabled() && ($user->isSuperUser() || $user->isMember($groupId, 'R2')); |
||
| 138 | |||
| 139 | } |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Returns an instance of ProjectManager |
||
| 143 | * |
||
| 144 | * @return FRSProjectManager |
||
| 145 | */ |
||
| 146 | function getProjectManager() { |
||
| 147 | |||
| 148 | $pm = ProjectManager::instance(); |
||
| 149 | return $pm; |
||
| 150 | |||
| 151 | } |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Returns a FRSPackageFactory |
||
| 155 | * |
||
| 156 | * @return FRSPackageFactory |
||
| 157 | */ |
||
| 158 | function getPackageFactory() { |
||
| 159 | |||
| 160 | return new FRSPackageFactory(); |
||
| 161 | |||
| 162 | } |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Returns a FRSReleaseFactory |
||
| 166 | * |
||
| 167 | * @return FRSReleaseFactory |
||
| 168 | */ |
||
| 169 | function getReleaseFactory() { |
||
| 170 | |||
| 171 | return new FRSReleaseFactory(); |
||
| 172 | |||
| 173 | } |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Returns a FRSFileFactory |
||
| 177 | * |
||
| 178 | * @return FRSFileFactory |
||
| 179 | */ |
||
| 180 | function getFileFactory() { |
||
| 181 | |||
| 182 | return new FRSFileFactory(); |
||
| 183 | |||
| 184 | } |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Returns a PermissionsManager instance |
||
| 188 | * |
||
| 189 | * @return PermissionsManager |
||
| 190 | */ |
||
| 191 | function getPermissionsManager() { |
||
| 192 | |||
| 193 | $pm = & PermissionsManager::instance(); |
||
| 194 | return $pm; |
||
| 195 | |||
| 196 | } |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Returns event manager instance |
||
| 200 | * |
||
| 201 | * @return EventManager |
||
| 202 | */ |
||
| 203 | function getEventManager() { |
||
| 204 | return EventManager::instance(); |
||
| 205 | } |
||
| 206 | |||
| 207 | function getIncomingFileSize($name) { |
||
| 208 | return PHP_BigFile::getSize($GLOBALS['ftp_incoming_dir'].'/'.$name); |
||
| 209 | } |
||
| 210 | |||
| 211 | function getIncomingFileMd5Sum($file) { |
||
| 212 | return PHP_BigFile::getMd5Sum($file); |
||
| 213 | } |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Returns an instance of PermissionsManager |
||
| 217 | * |
||
| 218 | * @param Project $project Used project |
||
| 219 | * |
||
| 220 | * @return Docman_PermissionsManager |
||
| 221 | */ |
||
| 222 | function getDocmanPermissionsManager($project) { |
||
| 223 | return Docman_PermissionsManager::instance($project->getGroupId()); |
||
| 224 | } |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Returns a new instance of ItemFactory |
||
| 228 | * |
||
| 229 | * @return Docman_ItemFactory |
||
| 230 | */ |
||
| 231 | function getDocmanItemFactory() { |
||
| 232 | return new Docman_ItemFactory(); |
||
| 233 | } |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Returns a new instance of VersionFactory |
||
| 237 | * |
||
| 238 | * @return Docman_VersionFactory |
||
| 239 | */ |
||
| 240 | function getVersionFactory() { |
||
| 241 | return new Docman_VersionFactory(); |
||
| 242 | } |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Returns the file system root of docman |
||
| 246 | * |
||
| 247 | * @return String |
||
| 248 | */ |
||
| 249 | function getDocmanRoot() { |
||
| 250 | $pluginManager = PluginManager::instance(); |
||
| 251 | $p = $pluginManager->getPluginByName('docman'); |
||
| 252 | $info = $p->getPluginInfo(); |
||
| 253 | return $info->getPropertyValueForName('docman_root'); |
||
| 254 | } |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Returns a new instance of FileStorage |
||
| 258 | * |
||
| 259 | * @return Docman_FileStorage |
||
| 260 | */ |
||
| 261 | function getFileStorage() { |
||
| 262 | return new Docman_FileStorage($this->getDocmanRoot()); |
||
| 263 | } |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Tells if write acces is enabled or not for the WebDAV plugin |
||
| 267 | * |
||
| 268 | * @return Boolean |
||
| 269 | */ |
||
| 270 | function isWriteEnabled() { |
||
| 271 | $pluginManager = PluginManager::instance(); |
||
| 272 | $p = $pluginManager->getPluginByName('webdav'); |
||
| 273 | $info = $p->getPluginInfo(); |
||
| 274 | return $info->getPropertyValueForName('write_access_enabled'); |
||
| 275 | } |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Use Docman MVC model to perform webdav actions |
||
| 279 | * |
||
| 280 | * @param WebDAV_Request $request |
||
| 281 | */ |
||
| 282 | function processDocmanRequest(WebDAV_Request $request) { |
||
| 283 | if (!$this->docmanPlugin) { |
||
| 284 | $pluginMgr = PluginManager::instance(); |
||
| 285 | $this->docmanPlugin = $pluginMgr->getPluginByName('docman'); |
||
| 286 | if (!$this->docmanPlugin || ($this->docmanPlugin && !$pluginMgr->isPluginAvailable($this->docmanPlugin))) { |
||
| 287 | throw new WebDAVExceptionServerError($GLOBALS['Language']->getText('plugin_webdav_common', 'plugin_not_available')); |
||
| 288 | } |
||
| 289 | } |
||
| 290 | $GLOBALS['Response'] = new WebDAV_Response(); |
||
| 291 | $controller = new WebDAV_DocmanController($this->docmanPlugin, $request); |
||
| 292 | $controller->process(); |
||
| 293 | |||
| 294 | if ($GLOBALS['Response']->feedbackHasErrors()) { |
||
| 295 | //file_put_contents('/tmp/webdav.log', $GLOBALS['Response']->getRawFeedback()); |
||
| 296 | throw new WebDAVExceptionServerError($GLOBALS['Response']->getRawFeedback()); |
||
| 297 | } |
||
| 298 | } |
||
| 299 | } |
||
| 300 | |||
| 301 | ?> |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.