Issues (167)

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.

class/Downloads.php (2 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Tdmdownloads;
6
7
use XoopsModules\Tag\FormTag;
8
9
/**
10
 * TDMDownload
11
 *
12
 * You may not change or alter any portion of this comment or credits
13
 * of supporting developers from this source code or any supporting source code
14
 * which is considered copyrighted (c) material of the original comment or credit authors.
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
 *
19
 * @copyright   Gregory Mage (Aka Mage)
20
 * @license     GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
21
 * @author      Gregory Mage (Aka Mage)
22
 */
23
24
/**
25
 * Class Downloads
26
 * @package XoopsModules\Tdmdownloads
27
 */
28
class Downloads extends \XoopsObject
29
{
30
    // constructor
31
    public function __construct()
32
    {
33
        $this->initVar('lid', \XOBJ_DTYPE_INT, null, false, 11);
34
        $this->initVar('cid', \XOBJ_DTYPE_INT, null, false, 5);
35
        $this->initVar('title', \XOBJ_DTYPE_TXTBOX, null, false);
36
        $this->initVar('url', \XOBJ_DTYPE_TXTBOX, null, false);
37
        $this->initVar('homepage', \XOBJ_DTYPE_TXTBOX, null, false);
38
        $this->initVar('version', \XOBJ_DTYPE_TXTBOX, null, false);
39
        $this->initVar('size', \XOBJ_DTYPE_TXTBOX, null, false);
40
        $this->initVar('platform', \XOBJ_DTYPE_TXTBOX, null, false);
41
        $this->initVar('description', \XOBJ_DTYPE_TXTAREA, null, false);
42
        // Pour autoriser le html
43
        $this->initVar('dohtml', \XOBJ_DTYPE_INT, 1, false);
44
        $this->initVar('logourl', \XOBJ_DTYPE_TXTBOX, null, false);
45
        $this->initVar('submitter', \XOBJ_DTYPE_INT, null, false, 11);
46
        $this->initVar('status', \XOBJ_DTYPE_INT, null, false, 2);
47
        $this->initVar('date', \XOBJ_DTYPE_INT, null, false, 10);
48
        $this->initVar('hits', \XOBJ_DTYPE_INT, null, false, 10);
49
        $this->initVar('rating', \XOBJ_DTYPE_OTHER, null, false, 10);
50
        $this->initVar('votes', \XOBJ_DTYPE_INT, null, false, 11);
51
        $this->initVar('comments', \XOBJ_DTYPE_INT, null, false, 11);
52
        $this->initVar('top', \XOBJ_DTYPE_INT, null, false, 2);
53
        $this->initVar('paypal', \XOBJ_DTYPE_TXTBOX, null, false);
54
        //pour les jointures:
55
        $this->initVar('cat_title', \XOBJ_DTYPE_TXTBOX, null, false);
56
        $this->initVar('cat_imgurl', \XOBJ_DTYPE_TXTBOX, null, false);
57
    }
58
59
    /**
60
     * @param null $db
61
     * @return int|string
62
     */
63
    public function getNewEnreg($db = null)
64
    {
65
        $newEnreg = 0;
66
        /** @var \XoopsMySQLDatabase $db */
67
        if (null !== $db) {
68
            $newEnreg = $db->getInsertId();
69
        }
70
        return $newEnreg;
71
    }
72
73
    /**
74
     * @param array $donnee
75
     * @param bool  $erreur
76
     * @param bool  $action
77
     * @return \XoopsThemeForm
78
     */
79
    public function getForm($donnee = [], $erreur = false, $action = false)
80
    {
81
        global $xoopsModule, $xoopsUser;
82
        $helper = Helper::getInstance();
83
        $utility       = new \XoopsModules\Tdmdownloads\Utility();
84
        $moduleDirName = \basename(\dirname(__DIR__));
85
        if (!$action) {
86
            $action = $_SERVER['REQUEST_URI'];
87
        }
88
        //permission pour uploader
89
        /** @var \XoopsGroupPermHandler $grouppermHandler */
90
        $grouppermHandler = \xoops_getHandler('groupperm');
91
        $groups           = \is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
92
        if ($xoopsUser) {
93
            $perm_upload = true;
94
            if (!$xoopsUser->isAdmin($xoopsModule->mid())) {
95
                $perm_upload = $grouppermHandler->checkRight('tdmdownloads_ac', 32, $groups, $xoopsModule->getVar('mid'));
96
            }
97
        } else {
98
            $perm_upload = $grouppermHandler->checkRight('tdmdownloads_ac', 32, $groups, $xoopsModule->getVar('mid'));
99
        }
100
        //nom du formulaire selon l'action (editer ou ajouter):
101
        $title = $this->isNew() ? \sprintf(_AM_TDMDOWNLOADS_FORMADD) : \sprintf(_AM_TDMDOWNLOADS_FORMEDIT);
102
        //création du formulaire
103
        $form = new \XoopsThemeForm($title, 'form', $action, 'post', true);
104
        $form->setExtra('enctype="multipart/form-data"');
105
        //titre
106
        $form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMTITLE, 'title', 50, 255, $this->getVar('title')), true);
107
        // fichier
108
        $fichier = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMFILE, '<br><br>');
109
        $url     = $this->isNew() ? 'http://' : $this->getVar('url');
110
        $formurl = new \XoopsFormText(_AM_TDMDOWNLOADS_FORMURL, 'url', 75, 255, $url);
111
        $fichier->addElement($formurl, false);
112
        if ($perm_upload) {
113
            $fichier->addElement(new \XoopsFormFile(_AM_TDMDOWNLOADS_FORMUPLOAD, 'attachedfile', $helper->getConfig('maxuploadsize')), false);
114
        }
115
        $form->addElement($fichier);
116
        //catégorie
117
        /** @var \XoopsModules\Tdmdownloads\CategoryHandler $categoryHandler */
118
        $categoryHandler = Helper::getInstance()->getHandler('Category');
119
        $categories      = $utility->getItemIds('tdmdownloads_submit', $moduleDirName);
120
        $criteria        = new \CriteriaCompo();
121
        $criteria->setSort('cat_weight ASC, cat_title');
122
        $criteria->setOrder('ASC');
123
        if ($xoopsUser) {
124
            if (!$xoopsUser->isAdmin($xoopsModule->mid())) {
125
                $criteria->add(new \Criteria('cat_cid', '(' . \implode(',', $categories) . ')', 'IN'));
126
            }
127
        } else {
128
            $criteria->add(new \Criteria('cat_cid', '(' . \implode(',', $categories) . ')', 'IN'));
129
        }
130
        $downloadscatArray = $categoryHandler->getAll($criteria);
131
        if (empty($downloadscatArray)) {
132
            \redirect_header('index.php', 2, \_NOPERM);
133
        }
134
        $mytree = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid');
135
        $form->addElement($mytree->makeSelectElement('cid', 'cat_title', '--', $this->getVar('cid'), true, 0, '', _AM_TDMDOWNLOADS_FORMINCAT), true);
0 ignored issues
show
It seems like $this->getVar('cid') can also be of type array and array; however, parameter $selected of XoopsObjectTree::makeSelectElement() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

135
        $form->addElement($mytree->makeSelectElement('cid', 'cat_title', '--', /** @scrutinizer ignore-type */ $this->getVar('cid'), true, 0, '', _AM_TDMDOWNLOADS_FORMINCAT), true);
Loading history...
136
        //affichage des champs
137
        /** @var \XoopsModules\Tdmdownloads\FieldHandler $fieldHandler */
138
        $fieldHandler = Helper::getInstance()->getHandler('Field');
139
        $criteria     = new \CriteriaCompo();
140
        $criteria->setSort('weight ASC, title');
141
        $criteria->setOrder('ASC');
142
        /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloads_field */
143
        $downloads_field = $fieldHandler->getAll($criteria);
144
        foreach (\array_keys($downloads_field) as $i) {
145
            /** @var \XoopsModules\Tdmdownloads\Field[] $downloads_field */
146
            if (1 == $downloads_field[$i]->getVar('status_def')) {
147
                if (1 == $downloads_field[$i]->getVar('fid')) {
148
                    //page d'accueil
149
                    if (1 == $downloads_field[$i]->getVar('status')) {
150
                        $form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMHOMEPAGE, 'homepage', 50, 255, $this->getVar('homepage')));
151
                    } else {
152
                        $form->addElement(new \XoopsFormHidden('homepage', ''));
153
                    }
154
                }
155
                if (2 == $downloads_field[$i]->getVar('fid')) {
156
                    //version
157
                    if (1 == $downloads_field[$i]->getVar('status')) {
158
                        $form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMVERSION, 'version', 10, 255, $this->getVar('version')));
159
                    } else {
160
                        $form->addElement(new \XoopsFormHidden('version', ''));
161
                    }
162
                }
163
                if (3 == $downloads_field[$i]->getVar('fid')) {
164
                    //taille du fichier
165
                    if (1 == $downloads_field[$i]->getVar('status')) {
166
                        $size_value_arr = \explode(' ', $this->getVar('size'));
167
                        $aff_size       = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMSIZE_WHEN_SUBMIT, '');
168
                        $aff_size->addElement(new \XoopsFormText('', 'sizeValue', 13, 13, $size_value_arr[0]));
169
                        if (!\array_key_exists(1, $size_value_arr)) {
170
                            $size_value_arr[1] = 'K';
171
                        }
172
                        $type      = new \XoopsFormSelect('', 'sizeType', $size_value_arr[1]);
173
                        $typeArray = [
174
                            'B' => _AM_TDMDOWNLOADS_BYTES,
175
                            'K' => _AM_TDMDOWNLOADS_KBYTES,
176
                            'M' => _AM_TDMDOWNLOADS_MBYTES,
177
                            'G' => _AM_TDMDOWNLOADS_GBYTES,
178
                            'T' => _AM_TDMDOWNLOADS_TBYTES,
179
                        ];
180
                        $type->addOptionArray($typeArray);
181
                        $aff_size->addElement($type);
182
                        $form->addElement($aff_size);
183
                    } else {
184
                        $form->addElement(new \XoopsFormHidden('size', ''));
185
                        $form->addElement(new \XoopsFormHidden('type_size', ''));
186
                    }
187
                }
188
                if (4 == $downloads_field[$i]->getVar('fid')) {
189
                    //plateforme
190
                    if (1 == $downloads_field[$i]->getVar('status')) {
191
                        $platformselect = new \XoopsFormSelect(_AM_TDMDOWNLOADS_FORMPLATFORM, 'platform', \explode('|', $this->getVar('platform')), 5, true);
192
                        $platformArray  = \explode('|', $helper->getConfig('platform'));
193
                        foreach ($platformArray as $platform) {
194
                            $platformselect->addOption((string)$platform, $platform);
195
                        }
196
                        $form->addElement($platformselect, false);
197
                    } else {
198
                        $form->addElement(new \XoopsFormHidden('platform', ''));
199
                    }
200
                }
201
            } else {
202
                $contenu        = '';
203
                $contenu_iddata = '';
204
                $fieldName      = 'champ' . $downloads_field[$i]->getVar('fid');
205
                /** @var \XoopsModules\Tdmdownloads\FielddataHandler $fielddataHandler */
206
                $fielddataHandler = Helper::getInstance()->getHandler('Fielddata');
207
                $criteria         = new \CriteriaCompo();
208
                $criteria->add(new \Criteria('lid', $this->getVar('lid')));
209
                $criteria->add(new \Criteria('fid', $downloads_field[$i]->getVar('fid')));
210
                $downloadsfielddata = $fielddataHandler->getAll($criteria);
211
                foreach (\array_keys($downloadsfielddata) as $j) {
212
                    /** @var \XoopsModules\Tdmdownloads\Fielddata[] $downloadsfielddata */
213
                    if ($erreur) {
214
                        $contenu = $donnee[$fieldName];
215
                    } else {
216
                        if (!$this->isNew()) {
217
                            $contenu = $downloadsfielddata[$j]->getVar('data');
218
                        }
219
                    }
220
                    $contenu_iddata = $downloadsfielddata[$j]->getVar('iddata');
221
                }
222
                $iddata = 'iddata' . $downloads_field[$i]->getVar('fid');
223
                if (!$this->isNew()) {
224
                    $form->addElement(new \XoopsFormHidden($iddata, $contenu_iddata));
225
                }
226
                if (1 == $downloads_field[$i]->getVar('status')) {
227
                    $form->addElement(new \XoopsFormText($downloads_field[$i]->getVar('title'), $fieldName, 50, 255, $contenu));
228
                } else {
229
                    $form->addElement(new \XoopsFormHidden($fieldName, ''));
230
                }
231
            }
232
        }
233
        //description
234
        $editorConfigs           = [];
235
        $editorConfigs['name']   = 'description';
236
        $editorConfigs['value']  = $this->getVar('description', 'e');
237
        $editorConfigs['rows']   = 20;
238
        $editorConfigs['cols']   = 100;
239
        $editorConfigs['width']  = '100%';
240
        $editorConfigs['height'] = '400px';
241
        $editorConfigs['editor'] = $helper->getConfig('editor');
242
        $form->addElement(new \XoopsFormEditor(_AM_TDMDOWNLOADS_FORMTEXTDOWNLOADS, 'description', $editorConfigs), true);
243
        //tag
244
        if (1 == $helper->getConfig('usetag') && \class_exists(FormTag::class)) {
245
            $tagId = $this->isNew() ? 0 : $this->getVar('lid');
246
            if ($erreur) {
247
                $tagId = $donnee['TAG'];
248
            }
249
            $form->addElement(new \XoopsModules\Tag\FormTag('tag', 60, 255, $tagId, 0));
250
        }
251
        //image
252
        if ($helper->getConfig('useshots')) {
253
            $uploaddir     = XOOPS_ROOT_PATH . '/uploads/' . $moduleDirName . '/images/shots/' . $this->getVar('logourl');
254
            $categoryImage = $this->getVar('logourl') ?: 'blank.gif';
255
            if (!\is_file($uploaddir)) {
256
                $categoryImage = 'blank.gif';
257
            }
258
            $uploadirectory = '/uploads/' . $moduleDirName . '/images/shots';
259
            $imgtray        = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMIMG, '<br>');
260
            $imgpath        = \sprintf(_AM_TDMDOWNLOADS_FORMPATH, $uploadirectory);
261
            $imageselect    = new \XoopsFormSelect($imgpath, 'logo_img', $categoryImage);
262
            $topics_array   = \XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . $uploadirectory);
263
            foreach ($topics_array as $image) {
264
                $imageselect->addOption($image, $image);
265
            }
266
            $imageselect->setExtra("onchange='showImgSelected(\"image3\", \"logo_img\", \"" . $uploadirectory . '", "", "' . XOOPS_URL . "\")'");
267
            $imgtray->addElement($imageselect, false);
268
            $imgtray->addElement(new \XoopsFormLabel('', "<br><img src='" . XOOPS_URL . '/' . $uploadirectory . '/' . $categoryImage . "' name='image3' id='image3' alt=''>"));
269
            $fileseltray = new \XoopsFormElementTray('', '<br>');
270
            if ($perm_upload) {
271
                $fileseltray->addElement(new \XoopsFormFile(_AM_TDMDOWNLOADS_FORMUPLOAD, 'attachedimage', $helper->getConfig('maxuploadsize')), false);
272
            }
273
            $imgtray->addElement($fileseltray);
274
            $form->addElement($imgtray);
275
        }
276
        // pour changer de poster et pour ne pas mettre à jour la date:
277
        if ($xoopsUser) {
278
            if ($xoopsUser->isAdmin($xoopsModule->mid())) {
279
                // auteur
280
                if ($this->isNew()) {
281
                    $submitter             = !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
282
                    $donnee['date_update'] = 0;
283
                } else {
284
                    $submitter = $this->getVar('submitter');
285
                    $v_date    = $this->getVar('date');
286
                }
287
                if ($erreur) {
288
                    $date_update = $donnee['date_update'];
289
                    $v_status    = $donnee['status'];
290
                    $submitter   = $donnee['submitter'];
291
                } else {
292
                    $date_update = 'N';
293
                    $v_status    = 1;
294
                }
295
                $form->addElement(new \XoopsFormSelectUser(_AM_TDMDOWNLOADS_FORMSUBMITTER, 'submitter', true, $submitter, 1, false), true);
296
                // date
297
                if (!$this->isNew()) {
298
                    $selection_date = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMDATEUPDATE);
299
                    $date           = new \XoopsFormRadio('', 'date_update', $date_update);
300
                    $options        = [
301
                        'N' => _AM_TDMDOWNLOADS_FORMDATEUPDATE_NO . ' (' . \formatTimestamp($v_date, 's') . ')',
302
                        'Y' => _AM_TDMDOWNLOADS_FORMDATEUPDATE_YES,
303
                    ];
304
                    $date->addOptionArray($options);
305
                    $selection_date->addElement($date);
306
                    $selection_date->addElement(new \XoopsFormTextDateSelect('', 'date', '', \time()));
307
                    $form->addElement($selection_date);
308
                }
309
                $status = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_FORMSTATUS, 'status', $v_status);
310
                $status->addOption(1, _AM_TDMDOWNLOADS_FORMSTATUS_OK);
311
                $form->addElement($status);
312
                //permissions pour télécharger
313
                if (2 == $helper->getConfig('permission_download')) {
314
                    /** @var \XoopsMemberHandler $memberHandler */
315
                    $memberHandler = \xoops_getHandler('member');
316
                    $group_list    = $memberHandler->getGroupList();
317
                    /** @var \XoopsGroupPermHandler $grouppermHandler */
318
                    $grouppermHandler = \xoops_getHandler('groupperm');
319
                    $full_list        = \array_keys($group_list);
320
                    global $xoopsModule;
321
                    if (!$this->isNew()) {
322
                        $item_ids_download               = $grouppermHandler->getGroupIds('tdmdownloads_download_item', $this->getVar('lid'), $xoopsModule->getVar('mid'));
323
                        $item_ids_downloa                = \array_values($item_ids_download);
0 ignored issues
show
The assignment to $item_ids_downloa is dead and can be removed.
Loading history...
324
                        $item_news_can_download_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_FORMPERMDOWNLOAD, 'item_download[]', $item_ids_download);
325
                    } else {
326
                        $item_news_can_download_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_FORMPERMDOWNLOAD, 'item_download[]', $full_list);
327
                    }
328
                    $item_news_can_download_checkbox->addOptionArray($group_list);
329
                    $form->addElement($item_news_can_download_checkbox);
330
                }
331
            }
332
        }
333
        //paypal
334
        if (true === $helper->getConfig('use_paypal')) {
335
            $form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMPAYPAL, 'paypal', 50, 255, $this->getVar('paypal')), false);
336
        } else {
337
            $form->addElement(new \XoopsFormHidden('paypal', ''));
338
        }
339
        // captcha
340
        $form->addElement(new \XoopsFormCaptcha(), true);
341
        // pour passer "lid" si on modifie la catégorie
342
        if (!$this->isNew()) {
343
            $form->addElement(new \XoopsFormHidden('lid', $this->getVar('lid')));
344
            $form->addElement(new \XoopsFormHidden('downloads_modified', true));
345
        }
346
        //pour enregistrer le formulaire
347
        $form->addElement(new \XoopsFormHidden('op', 'save_downloads'));
348
        //bouton d'envoi du formulaire
349
        $form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', 'submit', false));
350
        return $form;
351
    }
352
}
353