Issues (175)

Security Analysis    no request data  

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

  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  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.
  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.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
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/Tree.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php namespace Xoopsmodules\instruction;
2
3
// Автор: andrey3761
4
// Вывод древообразного списка страниц в панели администрирования
5
6
//defined('XOOPS_ROOT_PATH') || exit('Restricted access');
7
define('INST_DIRNAME', basename(dirname(__DIR__)));
8
9
include_once $GLOBALS['xoops']->path('include/common.php');
10
// Подключаем трей
11
include_once $GLOBALS['xoops']->path('class/tree.php');
12
13
// Наследник класса XoopsObjectTree
14
15
/**
16
 * Class Tree
17
 * @package Xoopsmodules\instruction
18
 */
19
class Tree extends \XoopsObjectTree
20
{
21
    //    public function __construct()
22
    //    {
23
    //    }
24
25
    /**
26
     * @param        $key
27
     * @param        $ret
28
     * @param        $prefix_orig
29
     * @param        $objInsinstr
30
     * @param string $class
31
     * @param string $prefix_curr
32
     */
33
    public function _makePagesAdminOptions($key, &$ret, $prefix_orig, $objInsinstr, $class = 'odd', $prefix_curr = '')
34
    {
35
        $pathIcon16    = \Xmf\Module\Admin::iconUrl('', 16);
36
        if ($key > 0) {
37
38
            //
39
            $class = ('even' === $class) ? 'odd' : 'even';
40
            // ID инструкции ( Можно сделать статической )
41
            $instrid = $objInsinstr->getVar('instrid');
42
43
            // ID страницы
44
            $pageid = $this->tree[$key]['obj']->getVar('pageid');
45
            // Название страницы
46
            $pagetitle = $this->tree[$key]['obj']->getVar('title');
47
            // Вес
48
            $pageweight = $this->tree[$key]['obj']->getVar('weight');
49
            // Статус
50
            $pagestatus = $this->tree[$key]['obj']->getVar('status');
51
            // Тип страницы
52
            $pagetype = $this->tree[$key]['obj']->getVar('type');
53
54
            // Дочернии страницы
55
            $page_childs = $this->getAllChild($pageid);
56
            // Число дочерних страниц
57
            $num_childs = count($page_childs);
58
59
            // Действие - удаление
60
            $act_del = ($num_childs > 0) ? '<img src="../assets/images/icons/16/application_key.png" alt="' . _AM_INSTR_NODELPAGE . '" title="' . _AM_INSTR_NODELPAGE . '" >' : '<a href="instr.php?op=delpage&pageid='
61
                                                                                                                                                                      . $pageid
62
                                                                                                                                                                      . '"><img src="'. $pathIcon16 . '/delete.png" alt="'
63
                                                                                                                                                                      . _AM_INSTRUCTION_DEL
64
                                                                                                                                                                      . '" title="'
65
                                                                                                                                                                      . _AM_INSTRUCTION_DEL
66
                                                                                                                                                                      . '"></a>';
67
            //
68
            $page_link = '<a name="pageid_' . $pageid . '" ' . ($pagetype ? 'href="' . XOOPS_URL . '/modules/' . INST_DIRNAME . '/page.php?id=' . $pageid . '#pagetext"' : '') . '>' . $pagetitle . '</a>';
69
70
            $ret .= '<tr class="' . $class . '">
71
      <td>' . $prefix_curr . ' ' . $page_link . '</td>
72
      <td align="center" width="50">
73
        <input type="text" name="weights[]" size="2" value="' . $pageweight . '" >
74
        <input type="hidden" name="pageids[]" value="' . $pageid . '" >
75
      </td>
76
      <td align="center" width="180">';
77
            // Просмотре без кэша
78
            $ret .= ' <a href="' . XOOPS_URL . '/modules/' . INST_DIRNAME . '/page.php?id=' . $pageid . '&amp;nocache=1"><img src="../assets/images/icons/16/database_black.png" alt="' . _AM_INSTR_DISPLAY_NOCACHE . '" title="' . _AM_INSTR_DISPLAY_NOCACHE . '" ></a> ';
79
            // Добавить подстраницу
80
            $ret .= ' <a href="instr.php?op=editpage&instrid=' . $instrid . '&pid=' . $pageid . '"><img src="'. $pathIcon16 . '/add.png" alt="' . _AM_INSTRUCTION_ADDSUBPAGE . '" title="' . _AM_INSTRUCTION_ADDSUBPAGE . '" ></a> ';
81
82
            if ($pagestatus) {
83
                $ret .= ' <img src="../assets/images/icons/16/lock.png" alt="' . _AM_INSTRUCTION_LOCK . '" title="' . _AM_INSTRUCTION_LOCK . '"> ';
84
            } else {
85
                $ret .= ' <img src="../assets/images/icons/16/lock_open.png" alt="' . _AM_INSTRUCTION_UNLOCK . '" title="' . _AM_INSTRUCTION_UNLOCK . '"> ';
86
            }
87
88
            $ret .= ' <a href="instr.php?op=editpage&pageid=' . $pageid . '"><img src="'. $pathIcon16 . '/edit.png" alt="' . _AM_INSTRUCTION_EDIT . '" title="' . _AM_INSTRUCTION_EDIT . '"></a> ' . $act_del . '
89
      </td>
90
    </tr>';
91
92
            // Устанавливаем префикс
93
            $prefix_curr .= $prefix_orig;
94
        }
95
96 View Code Duplication
        if (isset($this->tree[$key]['child']) && !empty($this->tree[$key]['child'])) {
97
            foreach ($this->tree[$key]['child'] as $childkey) {
98
                $this->_makePagesAdminOptions($childkey, $ret, $prefix_orig, $objInsinstr, $class, $prefix_curr);
99
            }
100
        }
101
    }
102
103
    /**
104
     * @param        $objInsinstr
105
     * @param string $prefix
106
     * @param int    $key
107
     * @return string
108
     */
109
    public function makePagesAdmin(&$objInsinstr, $prefix = '-', $key = 0)
110
    {
111
        $ret = '<form name="inspages" action="instr.php" method="post">
112
  <table width="100%" cellspacing="1" class="outer">
113
    <tr>
114
      <th align="center" colspan="3">' . sprintf(_AM_INSTRUCTION_LISTPAGESININSTR, $objInsinstr->getVar('title')) . '</th>
115
    </tr>
116
    <tr>
117
      <td class="head" align="center">' . _AM_INSTRUCTION_TITLE . '</td>
118
      <td class="head" align="center" width="50">' . _AM_INSTRUCTION_WEIGHT . '</td>
119
      <td class="head" align="center" width="180">' . _AM_INSTRUCTION_ACTION . '</td>
120
    </tr>';
121
122
        // Выводим все страницы
123
        $this->_makePagesAdminOptions($key, $ret, $prefix, $objInsinstr);
124
125
        $ret .= '<tr class="foot">
126
      <td><a href="instr.php?op=editpage&instrid=' . $objInsinstr->getVar('instrid') . '"><img src="'. $pathIcon16 . '/add.png" alt="' . _AM_INSTRUCTION_ADDPAGE . '" title="' . _AM_INSTRUCTION_ADDPAGE . '"></a></td>
0 ignored issues
show
The variable $pathIcon16 does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
127
      <td colspan="2">
128
        <input type="hidden" name="instrid" value="' . $objInsinstr->getVar('instrid') . '" >
129
        <input type="hidden" name="op" value="updpage" >
130
        <input type="submit" value="' . _SUBMIT . '" >
131
      </td>
132
    </tr>
133
  </table>
134
</form>';
135
136
        return $ret;
137
    }
138
139
    // ==================================
140
    // === Дерево категорий в админке ===
141
    // ==================================
142
143
    /**
144
     * @param        $key
145
     * @param        $ret
146
     * @param        $prefix_orig
147
     * @param array  $cidinstrids
148
     * @param string $class
149
     * @param string $prefix_curr
150
     */
151
    public function _makeCatsAdminOptions($key, &$ret, $prefix_orig, $cidinstrids = [], &$class = 'odd', $prefix_curr = '')
152
    {
153
        $pathIcon16    = \Xmf\Module\Admin::iconUrl('', 16);
154
        if ($key > 0) {
155
156
            //
157
            $class = ('even' === $class) ? 'odd' : 'even';
158
159
            // ID категории
160
            $catid = $this->tree[$key]['obj']->getVar('cid');
161
            // Название категории
162
            $cattitle = $this->tree[$key]['obj']->getVar('title');
163
            // Вес
164
            $catweight = $this->tree[$key]['obj']->getVar('weight');
165
            // Статус
166
            $pagestatus = $this->tree[$key]['obj']->getVar('status');
0 ignored issues
show
$pagestatus is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
167
168
            // Дочернии категории
169
            $cat_childs = $this->getAllChild($catid);
170
            // Число дочерних категорий
171
            $num_childs = count($cat_childs);
172
            // Число инструкций
173
            $num_instrs = isset($cidinstrids[$catid]) ? $cidinstrids[$catid] : 0;
174
175
            // Действие - удаление
176
            $act_del = (($num_instrs > 0) || ($num_childs > 0)) ? '<img src="'. $pathIcon16 . '/delete.png" alt="' . _AM_INSTR_NODELCAT . '" title="' . _AM_INSTR_NODELCAT . '" >' : '<a href="cat.php?op=delcat&cid='
177
                                                                                                                                                                                           . $catid
178
                                                                                                                                                                                           . '"><img src="'. $pathIcon16 . '/delete.png" alt="'
179
                                                                                                                                                                                           . _AM_INSTRUCTION_DEL
180
                                                                                                                                                                                           . '" title="'
181
                                                                                                                                                                                           . _AM_INSTRUCTION_DEL
182
                                                                                                                                                                                           . '" ></a>';
183
            // Действие - просмотр
184
            $act_view = ($num_instrs > 0) ? '<a href="instr.php?cid=' . $catid . '"><img src="'. $pathIcon16 . '/view.png" alt="' . _AM_INSTR_VIEWINSTR . '" title="' . _AM_INSTR_VIEWINSTR . '" ></a>' : '<img src="../assets/images/icons/16/document_protect.png" alt="'
185
                                                                                                                                                                                                             . _AM_INSTR_NOVIEWINSTR
186
                                                                                                                                                                                                             . '" title="'
187
                                                                                                                                                                                                             . _AM_INSTR_NOVIEWINSTR
188
                                                                                                                                                                                                             . '" >';
189
190
            $ret .= '<tr class="' . $class . '">
191
      <td>' . $prefix_curr . ' <a href="' . XOOPS_URL . '/modules/' . INST_DIRNAME . '/index.php?cid=' . $catid . '">' . $cattitle . '</a></td>
192
      <td align="center" width="50">' . $catweight . '</td>
193
      <td align="center" width="100">' . $num_instrs . '</td>
194
      <td align="center" width="150">
195
        ' . $act_view . '
196
        <a href="cat.php?op=editcat&cid=' . $catid . '"><img src="'. $pathIcon16 . '/edit.png" alt="' . _AM_INSTRUCTION_EDIT . '" title="' . _AM_INSTRUCTION_EDIT . '"></a>
197
        ' . $act_del . '
198
      </td>
199
    </tr>';
200
201
            // Устанавливаем префикс
202
            $prefix_curr .= $prefix_orig;
203
        }
204
205 View Code Duplication
        if (isset($this->tree[$key]['child']) && !empty($this->tree[$key]['child'])) {
206
            foreach ($this->tree[$key]['child'] as $childkey) {
207
                $this->_makeCatsAdminOptions($childkey, $ret, $prefix_orig, $cidinstrids, $class, $prefix_curr);
208
            }
209
        }
210
    }
211
212
    /**
213
     * @param string $prefix
214
     * @param array  $cidinstrids
215
     * @param int    $key
216
     * @return string
217
     */
218
    public function makeCatsAdmin($prefix = '-', $cidinstrids = [], $key = 0)
219
    {
220
        $ret = '<table width="100%" cellspacing="1" class="outer">
221
    <tr>
222
      <th align="center" colspan="4">' . _AM_INSTR_LISTALLCATS . '</th>
223
    </tr>
224
    <tr>
225
      <td class="head">' . _AM_INSTRUCTION_TITLE . '</td>
226
      <td class="head" align="center" width="50">' . _AM_INSTRUCTION_WEIGHT . '</td>
227
	  <td class="head" align="center" width="100">' . _AM_INSTR_INSTRS . '</td>
228
      <td class="head" align="center" width="150">' . _AM_INSTRUCTION_ACTION . '</td>
229
    </tr>';
230
231
        // Выводим все страницы
232
        $this->_makeCatsAdminOptions($key, $ret, $prefix, $cidinstrids);
233
234
        $ret .= '</table>';
235
236
        return $ret;
237
    }
238
239
    // ======================================
240
    // Список страниц на стороне пользователя
241
    // ======================================
242
243
    /**
244
     * @param       $key
245
     * @param       $ret
246
     * @param int   $currpageid
247
     * @param array $lastpageids
248
     * @param int   $level
249
     */
250
    public function _makePagesUserTree($key, &$ret, $currpageid = 0, &$lastpageids = [], $level = 0)
251
    {
252
253
        // Сохраняем значение предыдущей страницы
254
        //static $stat_prevpages;
255
256
        if ($key > 0) {
257
258
            // ID страницы
259
            $pageid = $this->tree[$key]['obj']->getVar('pageid');
260
            // Название страницы
261
            $pagetitle = $this->tree[$key]['obj']->getVar('title');
262
            // Тип страницы
263
            $pagetype = $this->tree[$key]['obj']->getVar('type');
264
265
            // Дочернии категории
266
            $page_childs = $this->getAllChild($pageid);
267
            // Число дочерних страниц
268
            $num_childs = count($page_childs);
269
270
            // Генерируем класс
271
            // InstrTreeNode InstrTreeIsRoot InstrTreeExpandClosed InstrTreeIsLast
272
            $class = [];
273
            // Данный класс должен быть у любого узла
274
            $class[] = 'InstrTreeNode';
275
            // Если узел нулевого уровня, добавляем InstrTreeIsRoot
276
            if (0 === $level) {
277
                $class[] = 'InstrTreeIsRoot';
278
            }
279
            // Тип узла InstrTreeExpandClosed|InstrTreeExpandLeaf
280
            // Если у узла нет потомков - InstrTreeExpandLeaf
281
            if (0 == $num_childs) {
282
                $class[] = 'InstrTreeExpandLeaf';
283
                // Если у искомого элемента есть потомки - открываем список
284
            } elseif ($currpageid == $pageid) {
285
                $class[] = 'InstrTreeExpandOpen';
286
                // Если искомый элемент есть в потомках текущего, то ставим класс InstrTreeExpandOpen
287
            } elseif (array_key_exists($currpageid, $page_childs)) {
288
                $class[] = 'InstrTreeExpandOpen';
289
                //
290
            } else {
291
                $class[] = 'InstrTreeExpandClosed';
292
            }
293
294
            // Данный класс нужно добавлять последнему узлу в каждом уровне
295
296
            if (isset($lastpageids[$level]) && ($pageid == $lastpageids[$level])) {
297
                $class[] = 'InstrTreeIsLast';
298
            }
299
300
            //$class[] = 'InstrTreeIsLast';
301
302
            // Test
303
            //$ret .= '<div id="' . $pageid . '">';
304
305
            // Создаём запись
306
            $ret .= '<li class="' . implode(' ', $class) . '">';
307
            //
308
            $ret .= '<div class="InstrTreeExpand"></div>';
309
            //
310
            $ret .= '<div class="InstrTreeContent">';
311
312
            // Если это лист дерева
313
            if (0 == $pagetype) {
314
                $ret .= '<span class="InstrTreeEmptyPage">' . $pagetitle . '</span>';
315
                //
316
            } elseif ($currpageid == $pageid) {
317
                $ret .= $pagetitle;
318
                //
319
            } else {
320
                $ret .= '<a href="' . XOOPS_URL . '/modules/' . INST_DIRNAME . '/page.php?id=' . $pageid . '#pagetext">' . $pagetitle . '</a>';
321
            }
322
323
            $ret .= '</div>';
324
325
            // Если есть потомки
326
            if ($num_childs > 0) {
327
                $ret .= '<ul class="InstrTreeContainer">';
328
            }
329
330
            // Инкримент уровня
331
            $level++;
332
        }
333
334
        // Рекурсия
335 View Code Duplication
        if (isset($this->tree[$key]['child']) && !empty($this->tree[$key]['child'])) {
336
            foreach ($this->tree[$key]['child'] as $childkey) {
337
                $this->_makePagesUserTree($childkey, $ret, $currpageid, $lastpageids, $level);
338
            }
339
        }
340
341
        // Test
342
        if ($key > 0) {
343
            // Если есть потомки
344
            if ($num_childs > 0) {
0 ignored issues
show
The variable $num_childs does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
345
                $ret .= '</ul>';
346
            }
347
            // Конец текущей записи
348
            $ret .= '</li>';
349
        }
350
    }
351
352
    // Находим предыдущую и следующую страницы.
353
    // Находим последнии страницы на каждом уровне.
354
    /**
355
     * @param       $key
356
     * @param int   $currpageid
357
     * @param array $prevpages
358
     * @param array $nextpages
359
     * @param array $lastpageids
360
     * @param int   $level
361
     */
362
    public function _makePagesUserCalc($key, $currpageid = 0, &$prevpages = [], &$nextpages = [], &$lastpageids = [], $level = 0)
363
    {
364
365
        // Сохраняем значение предыдущей страницы
366
        static $stat_prevpages;
367
368
        if ($key > 0) {
369
            // ID страницы
370
            $pageid = $this->tree[$key]['obj']->getVar('pageid');
371
            // Название страницы
372
            $pagetitle = $this->tree[$key]['obj']->getVar('title');
373
            // Тип страницы
374
            $pagetype = $this->tree[$key]['obj']->getVar('type');
375
376
            // Если мы передали ID текущей страницы, то находить предыдудую и следующую страницы
377
            // Не находить предыдущие и следующие для "Пустой страницы"
378
            if ($currpageid && $pagetype) {
379
                // Если элемент равен текущей странице
380
                if (null !== $stat_prevpages && ($currpageid == $pageid)) {
381
                    // Забиваем массив предыдущей страницы
382
                    $prevpages['pageid'] = $stat_prevpages['pageid'];
383
                    $prevpages['title']  = $stat_prevpages['title'];
384
385
                    // Если предыдущий равен текущей странице
386
                } elseif (null !== $stat_prevpages && ($currpageid == $stat_prevpages['pageid'])) {
387
                    // Забиваем массив следующей страницы
388
                    $nextpages['pageid'] = $pageid;
389
                    $nextpages['title']  = $pagetitle;
390
                }
391
                // Заносим текущие данные в массив предыдущей страницы
392
                $stat_prevpages['pageid'] = $pageid;
393
                $stat_prevpages['title']  = $pagetitle;
394
            }
395
396
            // Заносим текущую страницу в массив "последних страний"
397
            $lastpageids[$level] = $pageid;
398
399
            // Инкримент уровня
400
            $level++;
401
        }
402
403
        // Рекурсия
404 View Code Duplication
        if (isset($this->tree[$key]['child']) && !empty($this->tree[$key]['child'])) {
405
            foreach ($this->tree[$key]['child'] as $childkey) {
406
                $this->_makePagesUserCalc($childkey, $currpageid, $prevpages, $nextpages, $lastpageids, $level);
407
            }
408
        }
409
    }
410
411
    //
412
413
    /**
414
     * @param int   $currpageid
415
     * @param array $prevpages
416
     * @param array $nextpages
417
     * @param int   $key
418
     * @return string
419
     */
420
    public function makePagesUser($currpageid = 0, &$prevpages = [], &$nextpages = [], $key = 0)
421
    {
422
423
        // Массив последней страницы на каждом уровне
424
        // level => pageid
425
        $lastpageids = [];
426
427
        // Расчёт
428
        $this->_makePagesUserCalc($key, $currpageid, $prevpages, $nextpages, $lastpageids);
429
430
        $ret = '<div onclick="instr_tree_toggle(arguments[0])">
431
<div>' . _MD_INSTRUCTION_LISTPAGES . '</div>
432
<div><ul class="InstrTreeContainer">';
433
434
        // Генерируем дерево
435
        $this->_makePagesUserTree($key, $ret, $currpageid, $lastpageids);
436
437
        $ret .= '</ul>
438
</div>
439
</div>';
440
441
        return $ret;
442
    }
443
}
444