ggoffy /
wgfilemanager
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.
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | /* |
||
| 6 | You may not change or alter any portion of this comment or credits |
||
| 7 | of supporting developers from this source code or any supporting source code |
||
| 8 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful, |
||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 13 | */ |
||
| 14 | |||
| 15 | /** |
||
| 16 | * wgFileManager module for xoops |
||
| 17 | * |
||
| 18 | * @copyright 2021 XOOPS Project (https://xoops.org) |
||
| 19 | * @license GPL 2.0 or later |
||
| 20 | * @package wgfilemanager |
||
| 21 | * @author Goffy - Wedega - Email:[email protected] - Website:https://xoops.wedega.com |
||
| 22 | */ |
||
| 23 | |||
| 24 | use Xmf\Request; |
||
|
0 ignored issues
–
show
|
|||
| 25 | use XoopsModules\Wgfilemanager; |
||
| 26 | use XoopsModules\Wgfilemanager\Constants; |
||
| 27 | use XoopsModules\Wgfilemanager\Common; |
||
| 28 | |||
| 29 | require __DIR__ . '/header.php'; |
||
| 30 | // Get all request values |
||
| 31 | $op = Request::getCmd('op', 'list');
|
||
| 32 | $fileId = Request::getInt('id');
|
||
| 33 | $start = Request::getInt('start');
|
||
| 34 | $limit = Request::getInt('limit', $helper->getConfig('adminpager'));
|
||
| 35 | $GLOBALS['xoopsTpl']->assign('start', $start);
|
||
| 36 | $GLOBALS['xoopsTpl']->assign('limit', $limit);
|
||
| 37 | |||
| 38 | switch ($op) {
|
||
| 39 | case 'list': |
||
| 40 | default: |
||
| 41 | // Define Stylesheet |
||
| 42 | $GLOBALS['xoTheme']->addStylesheet($style, null); |
||
| 43 | $templateMain = 'wgfilemanager_admin_file.tpl'; |
||
| 44 | $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('file.php'));
|
||
| 45 | $adminObject->addItemButton(\_AM_WGFILEMANAGER_ADD_FILE, 'file.php?op=new'); |
||
| 46 | $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
|
||
| 47 | $fileCount = $fileHandler->getCountFile(); |
||
| 48 | $fileAll = $fileHandler->getAllFile($start, $limit); |
||
| 49 | $GLOBALS['xoopsTpl']->assign('file_count', $fileCount);
|
||
| 50 | $GLOBALS['xoopsTpl']->assign('wgfilemanager_url', \WGFILEMANAGER_URL);
|
||
| 51 | $GLOBALS['xoopsTpl']->assign('wgfilemanager_upload_url', \WGFILEMANAGER_UPLOAD_URL);
|
||
| 52 | // Table view file |
||
| 53 | if ($fileCount > 0) {
|
||
| 54 | foreach (\array_keys($fileAll) as $i) {
|
||
| 55 | $file = $fileAll[$i]->getValuesFile(); |
||
| 56 | $GLOBALS['xoopsTpl']->append('file_list', $file);
|
||
| 57 | unset($file); |
||
| 58 | } |
||
| 59 | // Display Navigation |
||
| 60 | if ($fileCount > $limit) {
|
||
| 61 | require_once \XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
| 62 | $pagenav = new \XoopsPageNav($fileCount, $limit, $start, 'start', 'op=list&limit=' . $limit); |
||
| 63 | $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav());
|
||
| 64 | } |
||
| 65 | } else {
|
||
| 66 | $GLOBALS['xoopsTpl']->assign('error', \_AM_WGFILEMANAGER_THEREARENT_FILE);
|
||
| 67 | } |
||
| 68 | break; |
||
| 69 | case 'new': |
||
| 70 | $templateMain = 'wgfilemanager_admin_file.tpl'; |
||
| 71 | $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('file.php'));
|
||
| 72 | $adminObject->addItemButton(\_AM_WGFILEMANAGER_LIST_FILE, 'file.php', 'list'); |
||
| 73 | $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
|
||
| 74 | // Form Create |
||
| 75 | $fileObj = $fileHandler->create(); |
||
| 76 | $form = $fileObj->getForm(); |
||
| 77 | $GLOBALS['xoopsTpl']->assign('form', $form->render());
|
||
| 78 | break; |
||
| 79 | case 'save': |
||
| 80 | // Security Check |
||
| 81 | if (!$GLOBALS['xoopsSecurity']->check()) {
|
||
| 82 | \redirect_header('file.php', 3, \implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
|
||
| 83 | } |
||
| 84 | if ($fileId > 0) {
|
||
| 85 | $fileObj = $fileHandler->get($fileId); |
||
| 86 | } else {
|
||
| 87 | $fileObj = $fileHandler->create(); |
||
| 88 | } |
||
| 89 | $fileHandlename = (int)$helper->getConfig('file_handlename');
|
||
| 90 | // Set Vars |
||
| 91 | $directoryId = Request::getInt('directory_id');
|
||
| 92 | $directoryIdOld = Request::getInt('directory_id_old');
|
||
| 93 | $fileObj->setVar('directory_id', $directoryId);
|
||
| 94 | // get full path of current directory |
||
| 95 | $dirBasePath = '/'; |
||
| 96 | if ($directoryId > 0) {
|
||
| 97 | $dirBasePath .= $directoryHandler->getFullPath($directoryId); |
||
| 98 | $dirBasePath .= '/'; |
||
| 99 | } |
||
| 100 | $repoPath = \WGFILEMANAGER_REPO_PATH . $dirBasePath; |
||
| 101 | $uploaderErrors = ''; |
||
| 102 | if (0 == $fileId) {
|
||
| 103 | //upload new file |
||
| 104 | require_once \XOOPS_ROOT_PATH . '/class/uploader.php'; |
||
| 105 | $filename = $_FILES['fil_name']['name']; |
||
| 106 | $fileMimetype = $_FILES['fil_name']['type']; |
||
| 107 | $fileSize = $_FILES['fil_name']['size']; |
||
| 108 | $fileNewName = substr($filename, 0, (strlen($filename)) - (strlen(strrchr($filename, '.')))); |
||
| 109 | $extension = \str_replace($fileNewName, '', $filename); |
||
| 110 | if (Constants::FILE_HANDLENAME_UNIQUE === $fileHandlename) {
|
||
| 111 | $fileNewName = \preg_replace("/[^a-zA-Z0-9]+/", '', $fileNewName);
|
||
| 112 | } |
||
| 113 | //check for new files, whether file already exists |
||
| 114 | if (Constants::FILE_HANDLENAME_ORIGINAL === $fileHandlename && file_exists($repoPath . $fileNewName . $extension)) {
|
||
| 115 | \redirect_header('file.php?op=list', 5, \_MA_WGFILEMANAGER_FILE_ERROR_EXISTS);
|
||
| 116 | } |
||
| 117 | $allowedMimeTypes = $mimetypeHandler->getMimetypeArray(); |
||
| 118 | $uploader = new \XoopsMediaUploader($repoPath, $allowedMimeTypes, $helper->getConfig('maxsize_file'), null, null);
|
||
| 119 | if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
|
||
| 120 | if (Constants::FILE_HANDLENAME_UNIQUE === $fileHandlename) {
|
||
| 121 | $uploader->setPrefix($fileNewName . '_'); |
||
| 122 | } |
||
| 123 | $uploader->fetchMedia($_POST['xoops_upload_file'][0]); |
||
| 124 | if ($uploader->upload()) {
|
||
| 125 | $fileObj->setVar('name', $uploader->getSavedFileName());
|
||
| 126 | } else {
|
||
| 127 | $uploaderErrors .= '<br>' . $uploader->getErrors(); |
||
| 128 | } |
||
| 129 | } else {
|
||
| 130 | if ($filename > '') {
|
||
| 131 | $uploaderErrors .= '<br>' . $uploader->getErrors(); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | if ('' !== $uploaderErrors) {
|
||
| 135 | \redirect_header('file.php?op=edit&file_id=' . $fileId, 5, $uploaderErrors);
|
||
| 136 | } |
||
| 137 | } else {
|
||
| 138 | //handle existing |
||
| 139 | $fileName = Request::getString('fil_name');
|
||
| 140 | $fileNameOld = Request::getString('fil_name_old');
|
||
| 141 | $movefile = $directoryIdOld !== $directoryId; |
||
| 142 | $renameFile = $fileName !== $fileNameOld; |
||
| 143 | if ($directoryIdOld !== $directoryId) {
|
||
| 144 | //move and rename file |
||
| 145 | $dirBasePathOld = '/'; |
||
| 146 | $dirBasePathOld .= $directoryHandler->getFullPath($directoryIdOld); |
||
| 147 | $dirBasePathOld .= '/'; |
||
| 148 | |||
| 149 | $fileHandler->renameFile($dirBasePathOld . $fileNameOld, $dirBasePath . $fileName); |
||
| 150 | } else {
|
||
| 151 | if ($fileName !== $fileNameOld) {
|
||
| 152 | //rename file |
||
| 153 | $fileHandler->renameFile($dirBasePath . $fileNameOld, $dirBasePath . $fileName); |
||
| 154 | } |
||
| 155 | } |
||
| 156 | $fileObj->setVar('name', $fileName);
|
||
| 157 | } |
||
| 158 | $fileObj->setVar('description', Request::getText('description'));
|
||
| 159 | $fileObj->setVar('ip', Request::getString('ip'));
|
||
| 160 | $fileObj->setVar('status', Request::getInt('status'));
|
||
| 161 | $fileDate_createdObj = \DateTime::createFromFormat(\_SHORTDATESTRING, Request::getString('date_created'));
|
||
| 162 | $fileObj->setVar('date_created', $fileDate_createdObj->getTimestamp());
|
||
| 163 | $fileObj->setVar('submitter', Request::getInt('submitter'));
|
||
| 164 | // Insert Data |
||
| 165 | if ($fileHandler->insert($fileObj)) {
|
||
| 166 | $newFileId = $fileId > 0 ? $fileId : $fileObj->getNewInsertedId(); |
||
| 167 | unset($fileObj); |
||
| 168 | $fileObj = $fileHandler->get($newFileId); |
||
| 169 | $fileSaved = $repoPath . $fileObj->getVar('name');
|
||
| 170 | $fileObj->setVar('mimetype', \mime_content_type($fileSaved));
|
||
| 171 | $fileObj->setVar('mtime', \filemtime($fileSaved));
|
||
| 172 | $fileObj->setVar('ctime', \filectime($fileSaved));
|
||
| 173 | $fileObj->setVar('size', \filesize($fileSaved));
|
||
| 174 | $fileHandler->insert($fileObj); |
||
| 175 | \redirect_header('file.php?op=list&start=' . $start . '&limit=' . $limit, 2, \_AM_WGFILEMANAGER_FORM_OK);
|
||
| 176 | } |
||
| 177 | // Get Form |
||
| 178 | $GLOBALS['xoopsTpl']->assign('error', $fileObj->getHtmlErrors());
|
||
| 179 | $form = $fileObj->getForm(); |
||
| 180 | $GLOBALS['xoopsTpl']->assign('form', $form->render());
|
||
| 181 | break; |
||
| 182 | case 'edit': |
||
| 183 | $templateMain = 'wgfilemanager_admin_file.tpl'; |
||
| 184 | $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('file.php'));
|
||
| 185 | $adminObject->addItemButton(\_AM_WGFILEMANAGER_ADD_FILE, 'file.php?op=new'); |
||
| 186 | $adminObject->addItemButton(\_AM_WGFILEMANAGER_LIST_FILE, 'file.php', 'list'); |
||
| 187 | $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
|
||
| 188 | // Get Form |
||
| 189 | $fileObj = $fileHandler->get($fileId); |
||
| 190 | $fileObj->start = $start; |
||
| 191 | $fileObj->limit = $limit; |
||
| 192 | $form = $fileObj->getForm(); |
||
| 193 | $GLOBALS['xoopsTpl']->assign('form', $form->render());
|
||
| 194 | break; |
||
| 195 | case 'delete': |
||
| 196 | $templateMain = 'wgfilemanager_admin_file.tpl'; |
||
| 197 | $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('file.php'));
|
||
| 198 | $fileObj = $fileHandler->get($fileId); |
||
| 199 | $fileName = $fileObj->getVar('name');
|
||
| 200 | if (isset($_REQUEST['ok']) && 1 == $_REQUEST['ok']) {
|
||
| 201 | if (!$GLOBALS['xoopsSecurity']->check()) {
|
||
| 202 | \redirect_header('file.php', 3, \implode(', ', $GLOBALS['xoopsSecurity']->getErrors()));
|
||
| 203 | } |
||
| 204 | if ($fileHandler->delete($fileObj)) {
|
||
| 205 | \redirect_header('file.php', 3, \_AM_WGFILEMANAGER_FORM_DELETE_OK);
|
||
| 206 | } else {
|
||
| 207 | $GLOBALS['xoopsTpl']->assign('error', $fileObj->getHtmlErrors());
|
||
| 208 | } |
||
| 209 | } else {
|
||
| 210 | $customConfirm = new Common\Confirm( |
||
| 211 | ['ok' => 1, 'id' => $fileId, 'start' => $start, 'limit' => $limit, 'op' => 'delete'], |
||
| 212 | $_SERVER['REQUEST_URI'], |
||
| 213 | \sprintf(\_AM_WGFILEMANAGER_FORM_SURE_DELETE, $fileName)); |
||
| 214 | $form = $customConfirm->getFormConfirm(); |
||
| 215 | $GLOBALS['xoopsTpl']->assign('form', $form->render());
|
||
| 216 | } |
||
| 217 | break; |
||
| 218 | } |
||
| 219 | require __DIR__ . '/footer.php'; |
||
| 220 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: