Issues (621)

Security Analysis    not enabled

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/Common/DirectoryChecker.php (1 issue)

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
2
3
namespace XoopsModules\Smallworld\Common;
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
 * Smallworld module
17
 *
18
 * @copyright       XOOPS Project (https://xoops.org)
19
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
20
 * @author          Xoops Development Team
21
 */
22
23
use Xmf\Request;
24
use XoopsModules\Smallworld;
25
use XoopsModules\Smallworld\Constants;
26
27
//defined('XOOPS_ROOT_PATH') || die('XOOPS root path not defined');
28
29
require_once dirname(dirname(dirname(dirname(__DIR__)))) . '/mainfile.php';
30
$moduleDirName      = basename(dirname(dirname(__DIR__)));
31
$moduleDirNameUpper = mb_strtoupper($moduleDirName);
32
xoops_loadLanguage('directorychecker', $moduleDirName);
33
34
/**
35
 * Class DirectoryChecker
36
 * check status of a directory
37
 */
38
class DirectoryChecker
39
{
40
    /**
41
     * @param     $path
42
     * @param int $mode
43
     * @param     $redirectFile
44
     *
45
     * @return bool|string
46
     */
47
    public static function getDirectoryStatus($path, $mode = 0777, $redirectFile = null)
48
    {
49
        global $pathIcon16;
50
51
        if (empty($path)) {
52
            return false;
53
        }
54
        if (null === $redirectFile) {
55
            $redirectFile = $_SERVER['SCRIPT_NAME'];
56
        }
57
        $moduleDirName      = basename(dirname(dirname(__DIR__)));
58
        $moduleDirNameUpper = mb_strtoupper($moduleDirName);
59
        if (!@is_dir($path)) {
60
            $path_status = "<img src='$pathIcon16/0.png' >";
61
            $path_status .= "$path (" . constant('CO_' . $moduleDirNameUpper . '_' . 'DC_NOTAVAILABLE') . ') ';
62
            $path_status .= "<form action='" . $_SERVER['SCRIPT_NAME'] . "' method='post'>";
63
            $path_status .= "<input type='hidden' name='op' value='createdir'>";
64
            $path_status .= "<input type='hidden' name='path' value='$path'>";
65
            $path_status .= "<input type='hidden' name='redirect' value='$redirectFile'>";
66
            $path_status .= "<button class='submit' onClick='this.form.submit();'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'DC_CREATETHEDIR') . '</button>';
67
            $path_status .= '</form>';
68
        } elseif (@is_writable($path)) {
69
            $path_status = "<img src='$pathIcon16/1.png' >";
70
            $path_status .= "$path (" . constant('CO_' . $moduleDirNameUpper . '_' . 'DC_AVAILABLE') . ') ';
71
            $currentMode = mb_substr(decoct(fileperms($path)), 2);
72
            if ($currentMode != decoct($mode)) {
73
                $path_status = "<img src='$pathIcon16/0.png' >";
74
                $path_status .= $path . sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'DC_NOTWRITABLE'), decoct($mode), $currentMode);
75
                $path_status .= "<form action='" . $_SERVER['SCRIPT_NAME'] . "' method='post'>";
76
                $path_status .= "<input type='hidden' name='op' value='setdirperm'>";
77
                $path_status .= "<input type='hidden' name='mode' value='$mode'>";
78
                $path_status .= "<input type='hidden' name='path' value='$path'>";
79
                $path_status .= "<input type='hidden' name='redirect' value='$redirectFile'>";
80
                $path_status .= "<button class='submit' onClick='this.form.submit();'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'DC_SETMPERM') . '</button>';
81
                $path_status .= '</form>';
82
            }
83
        } else {
84
            $currentMode = mb_substr(decoct(fileperms($path)), 2);
85
            $path_status = "<img src='$pathIcon16/0.png' >";
86
            $path_status .= $path . sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'DC_NOTWRITABLE'), decoct($mode), $currentMode);
87
            $path_status .= "<form action='" . $_SERVER['SCRIPT_NAME'] . "' method='post'>";
88
            $path_status .= "<input type='hidden' name='op' value='setdirperm'>";
89
            $path_status .= "<input type='hidden' name='mode' value='$mode'>";
90
            $path_status .= "<input type='hidden' name='path' value='$path'>";
91
            $path_status .= "<input type='hidden' name='redirect' value='$redirectFile'>";
92
            $path_status .= "<button class='submit' onClick='this.form.submit();'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'DC_SETMPERM') . '</button>';
93
            $path_status .= '</form>';
94
        }
95
96
        return $path_status;
97
    }
98
99
    /**
100
     * @param     $target
101
     * @param int $mode
102
     *
103
     * @return bool
104
     */
105
    public static function createDirectory($target, $mode = 0777)
106
    {
107
        $target = str_replace('..', '', $target);
108
109
        // http://www.php.net/manual/en/function.mkdir.php
110
        return is_dir($target) || (self::createDirectory(dirname($target), $mode) && !mkdir($target, $mode) && !is_dir($target));
111
    }
112
113
    /**
114
     * @param     $target
115
     * @param int $mode
116
     *
117
     * @return bool
118
     */
119
    public static function setDirectoryPermissions($target, $mode = 0777)
120
    {
121
        $target = str_replace('..', '', $target);
122
123
        return @chmod($target, (int)$mode);
124
    }
125
126
    /**
127
     * @param   $dir_path
128
     *
129
     * @return bool
130
     */
131
    public static function dirExists($dir_path)
132
    {
133
        return is_dir($dir_path);
134
    }
135
}
136
137
$op = Request::getString('op', '', 'POST');
138
switch ($op) {
139
    case 'createdir':
140
        if (\Xmf\Request::hasVar('path', 'POST')) {
141
            $path = $_POST['path'];
142
        }
143
        if (\Xmf\Request::hasVar('redirect', 'POST')) {
144
            $redirect = $_POST['redirect'];
145
        }
146
        $msg = DirectoryChecker::createDirectory($path) ? constant('CO_' . $moduleDirNameUpper . '_' . 'DC_DIRCREATED') : constant('CO_' . $moduleDirNameUpper . '_' . 'DC_DIRNOTCREATED');
147
        redirect_header($redirect, Constants::REDIRECT_DELAY_MEDIUM, $msg . ': ' . $path);
148
        break;
149 View Code Duplication
    case 'setdirperm':
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
150
        if (\Xmf\Request::hasVar('path', 'POST')) {
151
            $path = $_POST['path'];
152
        }
153
        if (\Xmf\Request::hasVar('redirect', 'POST')) {
154
            $redirect = $_POST['redirect'];
155
        }
156
        if (\Xmf\Request::hasVar('mode', 'POST')) {
157
            $mode = $_POST['mode'];
158
        }
159
        $msg = DirectoryChecker::setDirectoryPermissions($path, $mode) ? constant('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMSET') : constant('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMNOTSET');
160
        redirect_header($redirect, Constants::REDIRECT_DELAY_MEDIUM, $msg . ': ' . $path);
161
        break;
162
}
163