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 | $dirId = 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_directory.tpl'; |
||||
| 44 | $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('directory.php'));
|
||||
| 45 | $adminObject->addItemButton(\_AM_WGFILEMANAGER_ADD_DIRECTORY, 'directory.php?op=new'); |
||||
| 46 | $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
|
||||
| 47 | $GLOBALS['xoopsTpl']->assign('wgfilemanager_url', \WGFILEMANAGER_URL);
|
||||
| 48 | $GLOBALS['xoopsTpl']->assign('wgfilemanager_upload_url', \WGFILEMANAGER_UPLOAD_URL);
|
||||
| 49 | $directoryCount = $directoryHandler->getCountDirectory(); |
||||
| 50 | $GLOBALS['xoopsTpl']->assign('directory_count', $directoryCount);
|
||||
| 51 | // Table view directory |
||||
| 52 | if ($directoryCount > 0) {
|
||||
| 53 | $directoryAll = $directoryHandler->getAllDirectory($start, $limit); |
||||
| 54 | foreach (\array_keys($directoryAll) as $i) {
|
||||
| 55 | $directory = $directoryAll[$i]->getValuesDir(); |
||||
| 56 | $GLOBALS['xoopsTpl']->append('directory_list', $directory);
|
||||
| 57 | unset($directory); |
||||
| 58 | } |
||||
| 59 | // Display Navigation |
||||
| 60 | if ($directoryCount > $limit) {
|
||||
| 61 | require_once \XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||||
| 62 | $pagenav = new \XoopsPageNav($directoryCount, $limit, $start, 'start', 'op=list&limit=' . $limit); |
||||
| 63 | $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav());
|
||||
| 64 | } |
||||
| 65 | } else {
|
||||
| 66 | if (1 === Request::getInt('createbasic')) {
|
||||
| 67 | //creation of basic directory tried already once but failed |
||||
| 68 | echo \_MA_WGFILEMANAGER_DIRECTORY_BASIC_FAILED; |
||||
| 69 | die; |
||||
| 70 | } |
||||
| 71 | //create basic directory |
||||
| 72 | $directoryObj = $directoryHandler->create(); |
||||
| 73 | $directoryObj->setVar('parent_id', 0);
|
||||
| 74 | $directoryObj->setVar('name', \_MA_WGFILEMANAGER_DIRECTORY_BASICNAME);
|
||||
| 75 | $directoryObj->setVar('description', '');
|
||||
| 76 | $directoryObj->setVar('fullpath', '/');
|
||||
| 77 | $directoryObj->setVar('weight', 1);
|
||||
| 78 | $directoryObj->setVar('date_created', time());
|
||||
| 79 | $uidCurrent = \is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->uid() : 0; |
||||
| 80 | $directoryObj->setVar('submitter', $uidCurrent);
|
||||
| 81 | // Insert Data |
||||
| 82 | if ($directoryHandler->insert($directoryObj)) {
|
||||
| 83 | \redirect_header('directory.php?op=list&createbasic=1', 0);
|
||||
| 84 | } else {
|
||||
| 85 | throw new \Exception('Error saving basic directory');
|
||||
| 86 | } |
||||
| 87 | } |
||||
| 88 | break; |
||||
| 89 | case 'new': |
||||
| 90 | $templateMain = 'wgfilemanager_admin_directory.tpl'; |
||||
| 91 | $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('directory.php'));
|
||||
| 92 | $adminObject->addItemButton(\_AM_WGFILEMANAGER_LIST_DIRECTORY, 'directory.php', 'list'); |
||||
| 93 | $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
|
||||
| 94 | // Form Create |
||||
| 95 | $directoryObj = $directoryHandler->create(); |
||||
| 96 | $form = $directoryObj->getForm(); |
||||
| 97 | $GLOBALS['xoopsTpl']->assign('form', $form->render());
|
||||
| 98 | break; |
||||
| 99 | case 'clone': |
||||
| 100 | $templateMain = 'wgfilemanager_admin_directory.tpl'; |
||||
| 101 | $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('directory.php'));
|
||||
| 102 | $adminObject->addItemButton(\_AM_WGFILEMANAGER_LIST_DIRECTORY, 'directory.php', 'list'); |
||||
| 103 | $adminObject->addItemButton(\_AM_WGFILEMANAGER_ADD_DIRECTORY, 'directory.php?op=new'); |
||||
| 104 | $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
|
||||
| 105 | // Request source |
||||
| 106 | $dirIdSource = Request::getInt('id_source');
|
||||
| 107 | // Get Form |
||||
| 108 | $directoryObjSource = $directoryHandler->get($dirIdSource); |
||||
| 109 | $directoryObj = $directoryObjSource->xoopsClone(); |
||||
| 110 | $form = $directoryObj->getForm(); |
||||
| 111 | $GLOBALS['xoopsTpl']->assign('form', $form->render());
|
||||
| 112 | break; |
||||
| 113 | case 'save': |
||||
| 114 | // Security Check |
||||
| 115 | if (!$GLOBALS['xoopsSecurity']->check()) {
|
||||
| 116 | \redirect_header('directory.php', 3, \implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
|
||||
| 117 | } |
||||
| 118 | if ($dirId > 0) {
|
||||
| 119 | $directoryObj = $directoryHandler->get($dirId); |
||||
| 120 | } else {
|
||||
| 121 | $directoryObj = $directoryHandler->create(); |
||||
| 122 | } |
||||
| 123 | $dirParentId = Request::getInt('parent_id');
|
||||
| 124 | $dirParentIdOld = Request::getInt('parent_id_old');
|
||||
| 125 | $dirName = Request::getString('name');
|
||||
| 126 | $dirNameOld = Request::getString('name_old');
|
||||
| 127 | $dirDescription = Request::getText('description');
|
||||
| 128 | $dirWeight = Request::getInt('weight');
|
||||
| 129 | $moveDir = false; |
||||
| 130 | $renameDir = false; |
||||
| 131 | if ($dirId > 1) {
|
||||
| 132 | $moveDir = $dirParentId !== $dirParentIdOld; |
||||
| 133 | $renameDir = $dirName !== $dirNameOld; |
||||
| 134 | } |
||||
| 135 | // get full path |
||||
| 136 | $dirBasePath = '/'; |
||||
| 137 | $dirFullPath = $dirBasePath; |
||||
| 138 | if ($dirParentId > 0) {
|
||||
| 139 | $path = $directoryHandler->getFullPath($dirParentId); |
||||
| 140 | if ('' !== $path) {
|
||||
| 141 | $dirBasePath .= $path . '/'; |
||||
| 142 | } |
||||
| 143 | $dirFullPath = $dirBasePath . \mb_strtolower($dirName); |
||||
| 144 | } |
||||
| 145 | $dirFullPathOld = ''; |
||||
| 146 | if ($moveDir) {
|
||||
| 147 | $dirBasePathOld = '/'; |
||||
| 148 | if ($dirParentIdOld > 0) {
|
||||
| 149 | $dirBasePathOld .= $directoryHandler->getFullPath($dirParentIdOld); |
||||
| 150 | $dirBasePathOld .= '/'; |
||||
| 151 | } |
||||
| 152 | $dirFullPathOld = $dirBasePathOld . \mb_strtolower($dirNameOld); |
||||
| 153 | } |
||||
| 154 | //check whether directory exist |
||||
| 155 | $dirExists = $directoryHandler->existDirectory($dirFullPath); |
||||
| 156 | //if new or move dir or rename dir then check that folder doesn't exist |
||||
| 157 | if ((0 === $dirId || $moveDir || $renameDir) && $dirExists) {
|
||||
| 158 | $templateMain = 'wgfilemanager_admin_directory.tpl'; |
||||
| 159 | $directoryObj->setVar('parent_id', $dirParentId);
|
||||
| 160 | $directoryObj->setVar('name', $dirName);
|
||||
| 161 | $directoryObj->setVar('description', $dirDescription);
|
||||
| 162 | $directoryObj->setVar('weight', $dirWeight);
|
||||
| 163 | $form = $directoryObj->getForm(); |
||||
| 164 | $GLOBALS['xoopsTpl']->assign('form', $form->render());
|
||||
| 165 | $GLOBALS['xoopsTpl']->assign('error', \_MA_WGFILEMANAGER_DIRECTORY_ERROR_EXISTS);
|
||||
| 166 | } else {
|
||||
| 167 | // Set Vars |
||||
| 168 | $directoryObj->setVar('parent_id', $dirParentId);
|
||||
| 169 | $directoryObj->setVar('name', $dirName);
|
||||
| 170 | $directoryObj->setVar('description', $dirDescription);
|
||||
| 171 | $directoryObj->setVar('fullpath', $dirFullPath);
|
||||
| 172 | $directoryObj->setVar('weight', $dirWeight);
|
||||
| 173 | $directoryDate_createdObj = \DateTime::createFromFormat(\_SHORTDATESTRING, Request::getString('date_created'));
|
||||
| 174 | $directoryObj->setVar('date_created', $directoryDate_createdObj->getTimestamp());
|
||||
| 175 | $directoryObj->setVar('submitter', Request::getInt('submitter'));
|
||||
| 176 | // Insert Data |
||||
| 177 | if ($directoryHandler->insert($directoryObj)) {
|
||||
| 178 | if ($moveDir) {
|
||||
| 179 | $directoryHandler->moveDirectory($dirFullPathOld, $dirFullPath); |
||||
| 180 | } else if ($renameDir) {
|
||||
| 181 | $directoryHandler->renameDirectory($dirBasePath . $dirNameOld, $dirFullPath); |
||||
| 182 | } else if (!$dirExists) {
|
||||
| 183 | $directoryHandler->createDirectory($dirFullPath); |
||||
| 184 | } |
||||
| 185 | $newDirId = $directoryObj->getNewInsertedId(); |
||||
| 186 | $permId = isset($_REQUEST['id']) ? $dirId : $newDirId; |
||||
| 187 | $grouppermHandler = \xoops_getHandler('groupperm');
|
||||
| 188 | $mid = $GLOBALS['xoopsModule']->getVar('mid');
|
||||
| 189 | if ('directory' === $helper->getConfig('permission_type')) {
|
||||
| 190 | // Permission to view_directory |
||||
| 191 | $grouppermHandler->deleteByModule($mid, 'wgfilemanager_view_directory', $permId); |
||||
|
0 ignored issues
–
show
The method
deleteByModule() does not exist on XoopsObjectHandler. Did you maybe mean delete()?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||
| 192 | if (isset($_POST['groups_view_directory'])) {
|
||||
| 193 | foreach ($_POST['groups_view_directory'] as $onegroupId) {
|
||||
| 194 | $grouppermHandler->addRight('wgfilemanager_view_directory', $permId, $onegroupId, $mid);
|
||||
|
0 ignored issues
–
show
The method
addRight() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsGroupPermHandler or XoopsPersistableObjectHandler.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 195 | } |
||||
| 196 | } |
||||
| 197 | // Permission to submit_directory |
||||
| 198 | $grouppermHandler->deleteByModule($mid, 'wgfilemanager_submit_directory', $permId); |
||||
| 199 | if (isset($_POST['groups_submit_directory'])) {
|
||||
| 200 | foreach ($_POST['groups_submit_directory'] as $onegroupId) {
|
||||
| 201 | $grouppermHandler->addRight('wgfilemanager_submit_directory', $permId, $onegroupId, $mid);
|
||||
| 202 | } |
||||
| 203 | } |
||||
| 204 | // Permission to approve_directory |
||||
| 205 | $grouppermHandler->deleteByModule($mid, 'wgfilemanager_approve_directory', $permId); |
||||
| 206 | if (isset($_POST['groups_approve_directory'])) {
|
||||
| 207 | foreach ($_POST['groups_approve_directory'] as $onegroupId) {
|
||||
| 208 | $grouppermHandler->addRight('wgfilemanager_approve_directory', $permId, $onegroupId, $mid);
|
||||
| 209 | } |
||||
| 210 | } |
||||
| 211 | } |
||||
| 212 | \redirect_header('directory.php?op=list&start=' . $start . '&limit=' . $limit, 2, \_AM_WGFILEMANAGER_FORM_OK);
|
||||
| 213 | } |
||||
| 214 | $GLOBALS['xoopsTpl']->assign('error', $directoryObj->getHtmlErrors());
|
||||
| 215 | } |
||||
| 216 | break; |
||||
| 217 | case 'edit': |
||||
| 218 | $templateMain = 'wgfilemanager_admin_directory.tpl'; |
||||
| 219 | $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('directory.php'));
|
||||
| 220 | $adminObject->addItemButton(\_AM_WGFILEMANAGER_ADD_DIRECTORY, 'directory.php?op=new'); |
||||
| 221 | $adminObject->addItemButton(\_AM_WGFILEMANAGER_LIST_DIRECTORY, 'directory.php', 'list'); |
||||
| 222 | $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
|
||||
| 223 | // Get Form |
||||
| 224 | $directoryObj = $directoryHandler->get($dirId); |
||||
| 225 | $directoryObj->start = $start; |
||||
| 226 | $directoryObj->limit = $limit; |
||||
| 227 | $form = $directoryObj->getForm(); |
||||
| 228 | $GLOBALS['xoopsTpl']->assign('form', $form->render());
|
||||
| 229 | break; |
||||
| 230 | case 'delete': |
||||
| 231 | $templateMain = 'wgfilemanager_admin_directory.tpl'; |
||||
| 232 | $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('directory.php'));
|
||||
| 233 | $directoryObj = $directoryHandler->get($dirId); |
||||
| 234 | $dirName = $directoryObj->getVar('name');
|
||||
| 235 | if (isset($_REQUEST['ok']) && 1 == $_REQUEST['ok']) {
|
||||
| 236 | if (!$GLOBALS['xoopsSecurity']->check()) {
|
||||
| 237 | \redirect_header('directory.php', 3, \implode(', ', $GLOBALS['xoopsSecurity']->getErrors()));
|
||||
| 238 | } |
||||
| 239 | $dirFullPath = $directoryObj->getVar('fullpath');
|
||||
| 240 | if ($directoryHandler->delete($directoryObj)) {
|
||||
| 241 | if ($directoryHandler->deleteDirectory($dirFullPath)) {
|
||||
| 242 | if ($directoryHandler->deleteSubDirData($dirId)) {
|
||||
| 243 | \redirect_header('directory.php', 3, \_AM_WGFILEMANAGER_FORM_DELETE_OK);
|
||||
| 244 | } else {
|
||||
| 245 | \redirect_header('directory.php', 3, \_MA_WGFILEMANAGER_DIRECTORY_ERROR_DELETE_SUBDIRDATA);
|
||||
| 246 | } |
||||
| 247 | } else {
|
||||
| 248 | \redirect_header('directory.php', 3, \_MA_WGFILEMANAGER_DIRECTORY_ERROR_DELETE);
|
||||
| 249 | } |
||||
| 250 | |||||
| 251 | } else {
|
||||
| 252 | $GLOBALS['xoopsTpl']->assign('error', $directoryObj->getHtmlErrors());
|
||||
| 253 | } |
||||
| 254 | } else {
|
||||
| 255 | $confirmText = \sprintf(\_MA_WGFILEMANAGER_DIRECTORY_DELETE_SINGLE, $dirName); |
||||
| 256 | if ($directoryHandler->dirIsParent($dirId)) {
|
||||
| 257 | $confirmText = \sprintf(\_MA_WGFILEMANAGER_DIRECTORY_DELETE_ISPARENT, $dirName); |
||||
| 258 | } |
||||
| 259 | $customConfirm = new Common\Confirm( |
||||
| 260 | ['ok' => 1, 'id' => $dirId, 'start' => $start, 'limit' => $limit, 'op' => 'delete'], |
||||
| 261 | $_SERVER['REQUEST_URI'], |
||||
| 262 | $confirmText); |
||||
| 263 | $form = $customConfirm->getFormConfirm(); |
||||
| 264 | $GLOBALS['xoopsTpl']->assign('form', $form->render());
|
||||
| 265 | } |
||||
| 266 | break; |
||||
| 267 | } |
||||
| 268 | require __DIR__ . '/footer.php'; |
||||
| 269 |
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: