Issues (411)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

admin/categories.php (2 issues)

Labels
Severity
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * Wfdownloads module
14
 *
15
 * @copyright       XOOPS Project (https://xoops.org)
16
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
17
 * @package         wfdownload
18
 * @since           3.23
19
 * @author          Xoops Development Team
20
 */
21
22
use Xmf\Module\Admin;
23
use Xmf\Request;
24
use XoopsModules\Wfdownloads\{
25
    Helper,
26
    Utility,
27
    ObjectTree
28
};
29
/** @var Helper $helper */
30
/** @var Utility $utility */
31
32
$currentFile = basename(__FILE__);
33
require_once __DIR__ . '/admin_header.php';
34
35
$helper = Helper::getInstance();
36
37
// Check directories
38
if (!is_dir($helper->getConfig('uploaddir'))) {
39
    redirect_header('index.php', 4, _AM_WFDOWNLOADS_ERROR_UPLOADDIRNOTEXISTS);
40
}
41
if (!is_dir(XOOPS_ROOT_PATH . '/' . $helper->getConfig('mainimagedir'))) {
42
    redirect_header('index.php', 4, _AM_WFDOWNLOADS_ERROR_MAINIMAGEDIRNOTEXISTS);
43
}
44
if (!is_dir(XOOPS_ROOT_PATH . '/' . $helper->getConfig('screenshots'))) {
45
    redirect_header('index.php', 4, _AM_WFDOWNLOADS_ERROR_SCREENSHOTSDIRNOTEXISTS);
46
}
47
if (!is_dir(XOOPS_ROOT_PATH . '/' . $helper->getConfig('catimage'))) {
48
    redirect_header('index.php', 4, _AM_WFDOWNLOADS_ERROR_CATIMAGEDIRNOTEXISTS);
49
}
50
51
$op = Request::getString('op', 'categories.list');
52
switch ($op) {
53
    case 'category.move':
54
    case 'move':
55
        $ok = Request::getBool('ok', false, 'POST');
56
        if (false === $ok) {
57
            $cid = Request::getInt('cid', 0);
58
59
            Utility::getCpHeader();
60
61
            xoops_load('XoopsFormLoader');
62
            $sform = new XoopsThemeForm(_AM_WFDOWNLOADS_CCATEGORY_MOVE, 'move', xoops_getenv('SCRIPT_NAME'), 'post', true);
63
64
            $categoryObjs     = $helper->getHandler('Category')->getObjects();
65
            $categoryObjsTree = new ObjectTree($categoryObjs, 'cid', 'pid');
66
67
            if (Utility::checkVerXoops($GLOBALS['xoopsModule'], '2.5.9')) {
68
                $catSelect = $categoryObjsTree->makeSelectElement('target', 'title', '--', $this->getVar('target'), true, 0, '', _AM_WFDOWNLOADS_BMODIFY);
69
                $sform->addElement($catSelect);
70
            } else {
71
                $sform->addElement(new XoopsFormLabel(_AM_WFDOWNLOADS_BMODIFY, $categoryObjsTree->makeSelBox('target', 'title')));
72
            }
73
74
            $create_tray = new XoopsFormElementTray('', '');
75
            $create_tray->addElement(new XoopsFormHidden('source', $cid));
76
            $create_tray->addElement(new XoopsFormHidden('ok', 'true'));
77
            $create_tray->addElement(new XoopsFormHidden('op', 'category.move'));
78
            $butt_save = new XoopsFormButton('', '', _AM_WFDOWNLOADS_BMOVE, 'submit');
79
            $butt_save->setExtra('onclick="this.form.elements.op.value=\'category.move\'"');
80
            $create_tray->addElement($butt_save);
81
            $butt_cancel = new XoopsFormButton('', '', _AM_WFDOWNLOADS_BCANCEL, 'submit');
82
            $butt_cancel->setExtra('onclick="this.form.elements.op.value=\'cancel\'"');
83
            $create_tray->addElement($butt_cancel);
84
            $sform->addElement($create_tray);
85
            $sform->display();
86
            xoops_cp_footer();
87
        } else {
88
            $source = Request::getInt('source', 0, 'POST');
89
            $target = Request::getInt('target', 0, 'POST');
90
            if ($target == $source) {
91
                redirect_header($currentFile . "?op=category.move&amp;ok=0&amp;cid={$source}", 5, _AM_WFDOWNLOADS_CCATEGORY_MODIFY_FAILED);
92
            }
93
            if (!$target) {
94
                redirect_header($currentFile . "?op=category.move&amp;ok=0&amp;cid={$source}", 5, _AM_WFDOWNLOADS_CCATEGORY_MODIFY_FAILEDT);
95
            }
96
            $result = $helper->getHandler('Download')->updateAll('cid', $target, new Criteria('cid', $source), true);
97
            if (!$result) {
98
                $error = _AM_WFDOWNLOADS_DBERROR;
99
                trigger_error($error, E_USER_ERROR);
100
            }
101
            redirect_header($currentFile, 1, _AM_WFDOWNLOADS_CCATEGORY_MODIFY_MOVED);
102
        }
103
        break;
104
    case 'category.save':
105
    case 'addCat':
106
        $cid          = Request::getInt('cid', 0, 'POST');
107
        $pid          = Request::getInt('pid', 0, 'POST');
108
        $weight       = (isset($_POST['weight']) && $_POST['weight'] > 0) ? Request::getInt('weight', 0, 'POST') : 0;
109
        $down_groups  = $_POST['groups'] ?? [];
110
        $up_groups    = $_POST['up_groups'] ?? [];
111
        $spotlighthis = Request::getInt('lid', 0, 'POST');
112
        $spotlighttop = (isset($_POST['spotlighttop']) && (1 == $_POST['spotlighttop'])) ? 1 : 0;
113
114
        require_once XOOPS_ROOT_PATH . '/class/uploader.php';
115
        $allowedMimetypes = ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'];
116
        $imgUrl           = 'blank.png';
117
        $maxFileSize      = $helper->getConfig('maxfilesize');
118
        $maxImgWidth      = $helper->getConfig('maximgwidth');
119
        $maxImgHeight     = $helper->getConfig('maximgheight');
120
        $uploadDirectory  = XOOPS_ROOT_PATH . '/' . $helper->getConfig('catimage');
121
        $uploader         = new XoopsMediaUploader($uploadDirectory, $allowedMimetypes, $maxFileSize, $maxImgWidth, $maxImgHeight);
122
        if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
123
            $uploader->setTargetFileName('wfdownloads_' . uniqid(time(), true) . '--' . mb_strtolower($_FILES['uploadfile']['name']));
124
            $uploader->fetchMedia($_POST['xoops_upload_file'][0]);
125
            if (!$uploader->upload()) {
126
                $errors = $uploader->getErrors();
127
                redirect_header('<script>javascript:history.go(-1)</script>', 3, $errors);
128
            } else {
129
                $imgUrl = $uploader->getSavedFileName();
130
            }
131
        } else {
132
            $imgUrl = (isset($_POST['imgurl'])
133
                       && 'blank.png' !== $_POST['imgurl']) ? $myts->addSlashes($_POST['imgurl']) : '';
134
        }
135
136
        if (!$cid) {
137
            $categoryObj = $helper->getHandler('Category')->create();
138
        } else {
139
            $categoryObj = $helper->getHandler('Category')->get($cid);
140
            $childcats   = $helper->getHandler('Category')->getChildCats($categoryObj);
141
            if ($pid == $cid || array_key_exists($pid, $childcats)) {
142
                $categoryObj->setErrors(_AM_WFDOWNLOADS_CCATEGORY_CHILDASPARENT);
143
            }
144
        }
145
146
        $categoryObj->setVar('title', $_POST['title']);
147
        $categoryObj->setVar('pid', $pid);
148
        $categoryObj->setVar('weight', $weight);
149
        $categoryObj->setVar('imgurl', $imgUrl);
150
        $categoryObj->setVar('description', $_POST['description']);
151
        $categoryObj->setVar('summary', $_POST['summary']);
152
        $categoryObj->setVar('dohtml', isset($_POST['dohtml']));
153
        $categoryObj->setVar('dosmiley', isset($_POST['dosmiley']));
154
        $categoryObj->setVar('doxcode', isset($_POST['doxcode']));
155
        $categoryObj->setVar('doimage', isset($_POST['doimage']));
156
        $categoryObj->setVar('dobr', isset($_POST['dobr']));
157
        // Formulize module support (2006/05/04) jpc - start
158
        if (Utility::checkModule('formulize')) {
159
            $formulize_fid = Request::getInt('formulize_fid', 0, 'POST');
160
            $categoryObj->setVar('formulize_fid', $formulize_fid);
161
        }
162
        // Formulize module support (2006/05/04) jpc - end
163
        $categoryObj->setVar('spotlighthis', $spotlighthis);
164
        $categoryObj->setVar('spotlighttop', $spotlighttop);
165
166
        if (!$helper->getHandler('Category')->insert($categoryObj)) {
167
            echo $categoryObj->getHtmlErrors();
168
        }
169
        if (!$cid) {
170
            if (0 == $cid) {
171
                $newid = (int)$categoryObj->getVar('cid');
172
            }
173
            Utility::savePermissions($down_groups, $newid, 'WFDownCatPerm');
174
            Utility::savePermissions($up_groups, $newid, 'WFUpCatPerm');
175
            // Notify of new category
176
            $tags                  = [];
177
            $tags['CATEGORY_NAME'] = $_POST['title'];
178
            $tags['CATEGORY_URL']  = WFDOWNLOADS_URL . '/viewcat.php?cid=' . $newid;
0 ignored issues
show
The constant WFDOWNLOADS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
179
            /** @var \XoopsNotificationHandler $notificationHandler */
180
            $notificationHandler = xoops_getHandler('notification');
181
            $notificationHandler->triggerEvent('global', 0, 'new_category', $tags);
182
            $database_mess = _AM_WFDOWNLOADS_CCATEGORY_CREATED;
183
        } else {
184
            $database_mess = _AM_WFDOWNLOADS_CCATEGORY_MODIFIED;
185
            Utility::savePermissions($down_groups, $cid, 'WFDownCatPerm');
186
            Utility::savePermissions($up_groups, $cid, 'WFUpCatPerm');
187
        }
188
        redirect_header($currentFile, 1, $database_mess);
189
        break;
190
    case 'category.delete':
191
    case 'del':
192
        $cid              = Request::getInt('cid', 0);
193
        $ok               = Request::getBool('ok', false, 'POST');
194
        $categoryObjs     = $helper->getHandler('Category')->getObjects();
195
        $categoryObjsTree = new ObjectTree($categoryObjs, 'cid', 'pid');
196
        if (true === $ok) {
197
            // get all subcategories under the specified category
198
            $childCategoryObjs = $categoryObjsTree->getAllChild($cid);
199
            foreach ($childCategoryObjs as $childCategoryObj) {
200
                // get all category ids
201
                $cids[] = $childCategoryObj->getVar('cid');
202
            }
203
            $cids[] = $cid;
204
205
            $criteria = new Criteria('cid', '(' . implode(',', $cids) . ')', 'IN');
206
207
            //get list of downloads in these subcategories
208
            $downloads = $helper->getHandler('Download')->getList($criteria);
209
210
            $download_criteria = new Criteria('lid', '(' . implode(',', array_keys($downloads)) . ')', 'IN');
211
212
            // now for each download, delete the text data and vote data associated with the download
213
            $helper->getHandler('Rating')->deleteAll($download_criteria);
214
            $helper->getHandler('Report')->deleteAll($download_criteria);
215
            $helper->getHandler('Download')->deleteAll($download_criteria);
216
            foreach (array_keys($downloads) as $lid) {
217
                xoops_comment_delete($helper->getModule()->mid(), (int)$lid);
218
            }
219
220
            // all downloads for each category is deleted, now delete the category data
221
            $helper->getHandler('Category')->deleteAll($criteria);
222
            $error = _AM_WFDOWNLOADS_DBERROR;
223
224
            foreach ($cids as $cid) {
225
                xoops_groupperm_deletebymoditem($helper->getModule()->mid(), 'WFDownCatPerm', $cid);
226
                xoops_groupperm_deletebymoditem($helper->getModule()->mid(), 'WFUpCatPerm', $cid);
227
            }
228
229
            redirect_header($currentFile, 1, _AM_WFDOWNLOADS_CCATEGORY_DELETED);
230
        } else {
231
            Utility::getCpHeader();
232
            xoops_confirm(['op' => 'category.delete', 'cid' => $cid, 'ok' => true], $currentFile, _AM_WFDOWNLOADS_CCATEGORY_AREUSURE);
233
            xoops_cp_footer();
234
        }
235
        break;
236
    case 'category.add':
237
    case 'category.edit':
238
    case 'modCat':
239
        Utility::getCpHeader();
240
        $adminObject = Admin::getInstance();
241
        $adminObject->displayNavigation($currentFile);
242
243
        //$adminObject = \Xmf\Module\Admin::getInstance();
244
        $adminObject->addItemButton(_MI_WFDOWNLOADS_MENU_CATEGORIES, "{$currentFile}?op=categories.list", 'list');
245
        $adminObject->displayButton('left');
246
247
        if (Request::hasVar('cid', 'REQUEST')) {
248
            $categoryObj = $helper->getHandler('Category')->get($_REQUEST['cid']);
249
        } else {
250
            $categoryObj = $helper->getHandler('Category')->create();
251
        }
252
        /** @var  XoopsThemeForm $form */
253
        $form = $categoryObj->getForm();
0 ignored issues
show
The method getForm() does not exist on XoopsObject. It seems like you code against a sub-type of XoopsObject such as XoopsModules\Wfdownloads\Download or SystemSmilies or SystemBanner or XoopsModules\Wfdownloads\Mimetype or SystemBannerclient or XoopsModules\Wfdownloads\Review or ProfileCategory or SystemUserrank or XoopsModules\Wfdownloads\Mirror or XoopsModules\Wfdownloads\Category or SystemGroup or SystemBlock or SystemAvatar or SystemUsers. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

253
        /** @scrutinizer ignore-call */ 
254
        $form = $categoryObj->getForm();
Loading history...
254
        $form->display();
255
256
        require_once __DIR__ . '/admin_footer.php';
257
        break;
258
    case 'categories.list':
259
    case 'main':
260
    default:
261
        Utility::getCpHeader();
262
        $adminObject = Admin::getInstance();
263
        $adminObject->displayNavigation($currentFile);
264
265
        //$adminObject = \Xmf\Module\Admin::getInstance();
266
        $adminObject->addItemButton(_AM_WFDOWNLOADS_CCATEGORY_CREATENEW, "{$currentFile}?op=category.add", 'add');
267
        $adminObject->displayButton('left');
268
269
        $totalCategories = Utility::categoriesCount();
270
        if ($totalCategories > 0) {
271
            $sorted_categories = Utility::sortCategories();
272
            $GLOBALS['xoopsTpl']->assign('sorted_categories', $sorted_categories);
273
            //            $GLOBALS['xoopsTpl']->assign('securityToken', $GLOBALS['xoopsSecurity']->getTokenHTML());
274
            $GLOBALS['xoopsTpl']->display("db:{$helper->getModule()->dirname()}_am_categorieslist.tpl");
275
        } else {
276
            redirect_header("{$currentFile}?op=category.add", 1, _AM_WFDOWNLOADS_CCATEGORY_NOEXISTS);
277
        }
278
        require_once __DIR__ . '/admin_footer.php';
279
        break;
280
    case 'categories.reorder':
281
        if (!$GLOBALS['xoopsSecurity']->check()) {
282
            redirect_header($currentFile, 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
283
        }
284
285
        if (Request::hasVar('new_weights', 'POST') && count($_POST['new_weights']) > 0) {
286
            $new_weights = $_POST['new_weights'];
287
            $ids         = [];
288
            foreach ($new_weights as $cid => $new_weight) {
289
                $categoryObj = $helper->getHandler('Category')->get($cid);
290
                $categoryObj->setVar('weight', $new_weight);
291
                if (!$helper->getHandler('Category')->insert($categoryObj)) {
292
                    redirect_header($currentFile, 3, implode(',', $categoryObj->getErrors()));
293
                }
294
                unset($categoryObj);
295
            }
296
            redirect_header($currentFile, 1, _AM_WFDOWNLOADS_CATEGORIES_REORDERED);
297
        }
298
        break;
299
}
300