Passed
Push — master ( 81ba93...c6c854 )
by Michael
03:30
created

admin/admin.php (2 issues)

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
 * @copyright    XOOPS Project https://xoops.org/
14
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
15
 * @package
16
 * @since
17
 * @author       XOOPS Development Team, Kazumi Ono (AKA onokazu)
18
 */
19
20
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
21
22
if (\Xmf\Request::hasVar('fct', 'POST')) {
23
    $fct = trim($_POST['fct']);
24
}
25
if (\Xmf\Request::hasVar('fct', 'GET')) {
26
    $fct = trim($_GET['fct']);
27
}
28
if (empty($fct)) {
29
    $fct = 'preferences';
30
}
31
require_once dirname(dirname(dirname(__DIR__))) . '/mainfile.php';
32
require_once XOOPS_ROOT_PATH . '/include/cp_functions.php';
33
34
require_once XOOPS_ROOT_PATH . '/kernel/module.php';
35
36
$admintest = 0;
37
38
if (is_object($xoopsUser)) {
39
    $xoopsModule = XoopsModule::getByDirname('system');
40
    if (!$xoopsUser->isAdmin($xoopsModule->mid())) {
41
        redirect_header(XOOPS_URL . '/user.php', 3, _NOPERM);
42
    }
43
    $admintest = 1;
44
} else {
45
    redirect_header(XOOPS_URL . '/user.php', 3, _NOPERM);
46
}
47
48
// include system category definitions
49
require_once XOOPS_ROOT_PATH . '/modules/system/constants.php';
50
$error = false;
51
if (0 != $admintest) {
0 ignored issues
show
The condition 0 != $admintest is always true.
Loading history...
52
    if (isset($fct) && '' != $fct) {
53
        if (file_exists(XOOPS_ROOT_PATH . '/modules/system/admin/' . $fct . '/xoops_version.php')) {
54
            xoops_loadLanguage('admin', 'system');
55
            xoops_loadLanguage('admin/' . $fct, 'system');
56
57
            require_once XOOPS_ROOT_PATH . '/modules/system/admin/' . $fct . '/xoops_version.php';
58
            $grouppermHandler = xoops_getHandler('groupperm');
59
            $category       = !empty($modversion['category']) ? (int)$modversion['category'] : 0;
60
            unset($modversion);
61
            if ($category > 0) {
62
                $groups = &$xoopsUser->getGroups();
63
                if (in_array(XOOPS_GROUP_ADMIN, $groups)
64
                    || false !== $grouppermHandler->checkRight('system_admin', $category, $groups, $xoopsModule->getVar('mid'))) {
65
                    if (file_exists("../include/{$fct}.inc.php")) {
66
                        require_once __DIR__ . "/../include/{$fct}.inc.php";
67
                    } else {
68
                        $error = true;
69
                    }
70
                } else {
71
                    $error = true;
72
                }
73
            } elseif ('version' === $fct) {
74
                if (file_exists(XOOPS_ROOT_PATH . '/modules/system/admin/version/main.php')) {
75
                    require_once XOOPS_ROOT_PATH . '/modules/system/admin/version/main.php';
76
                } else {
77
                    $error = true;
78
                }
79
            } else {
80
                $error = true;
81
            }
82
        } else {
83
            $error = true;
84
        }
85
    } else {
86
        $error = true;
87
    }
88
}
89
90
if (false !== $error) {
91
    xoops_cp_header();
92
    echo '<h4>System Configuration</h4>';
93
    echo '<table class="outer" cellpadding="4" cellspacing="1">';
94
    echo '<tr>';
95
    $groups = &$xoopsUser->getGroups();
96
    $all_ok = false;
97
    if (!in_array(XOOPS_GROUP_ADMIN, $groups)) {
98
        $grouppermHandler = xoops_getHandler('groupperm');
99
        $ok_syscats     = &$grouppermHandler->getItemIds('system_admin', $groups);
100
    } else {
101
        $all_ok = true;
102
    }
103
    $admin_dir = XOOPS_ROOT_PATH . '/modules/system/admin';
104
    $handle    = opendir($admin_dir);
105
    $counter   = 0;
106
    $class     = 'even';
107
    while ($file = readdir($handle)) {
0 ignored issues
show
It seems like $handle can also be of type false; however, parameter $dir_handle of readdir() does only seem to accept resource, 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

107
    while ($file = readdir(/** @scrutinizer ignore-type */ $handle)) {
Loading history...
108
        if ('cvs' !== mb_strtolower($file) && !preg_match('/[.]/', $file) && is_dir($admin_dir . '/' . $file)) {
109
            require_once $admin_dir . '/' . $file . '/xoops_version.php';
110
            if ($modversion['hasAdmin']) {
111
                $category = isset($modversion['category']) ? (int)$modversion['category'] : 0;
112
                if (false !== $all_ok || in_array($modversion['category'], $ok_syscats)) {
113
                    echo "<td class='$class' align='center' valign='bottom' width='19%'>";
114
                    echo "<a href='" . XOOPS_URL . '/modules/system/admin.php?fct=' . $file . "'><b>" . trim($modversion['name']) . "</b></a>\n";
115
                    echo '</td>';
116
                    ++$counter;
117
                    $class = ('even' === $class) ? 'odd' : 'even';
118
                }
119
                if ($counter > 4) {
120
                    $counter = 0;
121
                    echo '</tr>';
122
                    echo '<tr>';
123
                }
124
            }
125
            unset($modversion);
126
        }
127
    }
128
    while ($counter < 5) {
129
        echo '<td class="' . $class . '">&nbsp;</td>';
130
        $class = ('even' === $class) ? 'odd' : 'even';
131
        ++$counter;
132
    }
133
    echo '</tr></table>';
134
    xoops_cp_footer();
135
}
136