|
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
|
|
|
* WF-Downloads module |
|
13
|
|
|
* |
|
14
|
|
|
* @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ |
|
15
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
|
16
|
|
|
* @package wfdownload |
|
17
|
|
|
* @since 3.23 |
|
18
|
|
|
* @author Xoops Development Team |
|
19
|
|
|
* @version svn:$id$ |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
//defined('XOOPS_ROOT_PATH') || die('XOOPS Root Path not defined'); |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
require_once dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Class DirectoryChecker |
|
28
|
|
|
* check status of a directory |
|
29
|
|
|
*/ |
|
30
|
|
|
class DirectoryChecker |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @param $path |
|
34
|
|
|
* @param int $mode |
|
35
|
|
|
* @param array $languageConstants |
|
36
|
|
|
* @param $redirectFile |
|
37
|
|
|
* |
|
38
|
|
|
* @return bool|string |
|
39
|
|
|
*/ |
|
40
|
|
|
public static function getDirectoryStatus($path, $mode = 0777, $languageConstants = array(), $redirectFile) |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
global $pathIcon16; |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
$languageConstants1 = array($languageConstants[5], $languageConstants[6]); |
|
45
|
|
|
$languageConstants2 = array($languageConstants[7], $languageConstants[8]); |
|
46
|
|
|
|
|
47
|
|
|
$myWords1 = urlencode(json_encode($languageConstants1)); |
|
48
|
|
|
$myWords2 = urlencode(json_encode($languageConstants2)); |
|
49
|
|
|
|
|
50
|
|
|
if (empty($path)) { |
|
51
|
|
|
return false; |
|
52
|
|
|
} |
|
53
|
|
|
if (!@is_dir($path)) { |
|
54
|
|
|
$path_status |
|
55
|
|
|
= "<img src='" . $pathIcon16 . "/0.png' >" . $path . ' ( ' . $languageConstants[1] . ' ) ' . "<a href=" . $_SERVER['PHP_SELF'] . "?op=dashboard&dircheck=createdir&path=$path&redirect=$redirectFile&languageConstants=$myWords1>" |
|
56
|
|
|
. $languageConstants[2] . '</a>'; |
|
57
|
|
|
} elseif (@is_writable($path)) { |
|
58
|
|
|
$path_status = "<img src='" . $pathIcon16 . "/1.png' >" . $path . ' ( ' . $languageConstants[0] . ' ) '; |
|
59
|
|
|
$currentMode = (substr(decoct(fileperms($path)), 2)); |
|
60
|
|
|
if ($currentMode != decoct($mode)) { |
|
61
|
|
|
$path_status = "<img src='" . $pathIcon16 . "/0.png' >" . $path . sprintf( |
|
62
|
|
|
$languageConstants[3], |
|
63
|
|
|
decoct($mode), |
|
64
|
|
|
$currentMode |
|
65
|
|
|
) . "<a href=" . $_SERVER['PHP_SELF'] . "?op=dashboard&dircheck=setperm&mode=$mode&path=$path&redirect=$redirectFile&languageConstants=$myWords2> " |
|
66
|
|
|
. $languageConstants[4] . '</a>'; |
|
67
|
|
|
} |
|
68
|
|
|
} else { |
|
69
|
|
|
$currentMode = (substr(decoct(fileperms($path)), 2)); |
|
70
|
|
|
$path_status = "<img src='" . $pathIcon16 . "/0.png' >" . $path . sprintf( |
|
71
|
|
|
$languageConstants[3], |
|
72
|
|
|
decoct($mode), |
|
73
|
|
|
$currentMode |
|
74
|
|
|
) . "<a href=" . $_SERVER['PHP_SELF'] . "?mode&path=$path&redirect=$redirectFile&languageConstants=$myWords2> " . $languageConstants[4] . '</a>'; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $path_status; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param $target |
|
82
|
|
|
* @param int $mode |
|
83
|
|
|
* |
|
84
|
|
|
* @return bool |
|
85
|
|
|
*/ |
|
86
|
|
|
public static function createDirectory($target, $mode = 0777) |
|
87
|
|
|
{ |
|
88
|
|
|
$target = str_replace("..", "", $target); |
|
89
|
|
|
// http://www.php.net/manual/en/function.mkdir.php |
|
90
|
|
|
/* |
|
|
|
|
|
|
91
|
|
|
$dirs = array(); |
|
92
|
|
|
|
|
93
|
|
|
while (realpath($target) === false && !empty($target)) { |
|
94
|
|
|
array_unshift($dirs, basename($target)); |
|
95
|
|
|
$target = dirname($target); |
|
96
|
|
|
}; |
|
97
|
|
|
$target = realpath($target); |
|
98
|
|
|
// this next test should handle bug on BSD with PHP < 5.3.0 |
|
99
|
|
|
if (!is_dir($target)) { |
|
100
|
|
|
array_unshift($dirs, basename($target)); |
|
101
|
|
|
$target = realpath(dirname($target)); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
*/ |
|
105
|
|
|
|
|
106
|
|
|
return is_dir($target) or (self::createDirectory(dirname($target), $mode) and mkdir($target, $mode)); |
|
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param $target |
|
111
|
|
|
* @param int $mode |
|
112
|
|
|
* |
|
113
|
|
|
* @return bool |
|
114
|
|
|
*/ |
|
115
|
|
|
public static function setDirectoryPermissions($target, $mode = 0777) |
|
116
|
|
|
{ |
|
117
|
|
|
$target = str_replace("..", "", $target); |
|
118
|
|
|
|
|
119
|
|
|
return @chmod($target, (int)$mode); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
$dircheck = (isset($_GET['dircheck'])) ? filter_input(INPUT_GET, 'dircheck', FILTER_SANITIZE_STRING) : ""; |
|
124
|
|
|
|
|
125
|
|
|
switch ($dircheck) { |
|
126
|
|
|
case "createdir": |
|
127
|
|
|
$languageConstants = array(); |
|
128
|
|
|
if (isset($_GET['path'])) { |
|
129
|
|
|
$path = filter_input(INPUT_GET, 'path', FILTER_SANITIZE_STRING); |
|
130
|
|
|
} |
|
131
|
|
|
if (isset($_GET['redirect'])) { |
|
132
|
|
|
$redirect = filter_input(INPUT_GET, 'redirect', FILTER_SANITIZE_STRING); |
|
133
|
|
|
} |
|
134
|
|
|
if (isset($_GET['languageConstants'])) { |
|
135
|
|
|
$languageConstants = json_decode($_GET['languageConstants']); |
|
136
|
|
|
} |
|
137
|
|
|
$result = DirectoryChecker::createDirectory($path); |
|
138
|
|
|
$msg = ($result) ? $languageConstants[0] : $languageConstants[1]; |
|
139
|
|
|
redirect_header($redirect, 2, $msg . ': ' . $path); |
|
140
|
|
|
exit(); |
|
141
|
|
|
break; |
|
142
|
|
|
case "setperm": |
|
143
|
|
|
$languageConstants = array(); |
|
144
|
|
|
if (isset($_GET['path'])) { |
|
145
|
|
|
$path = filter_input(INPUT_GET, 'path', FILTER_SANITIZE_STRING); |
|
146
|
|
|
} |
|
147
|
|
|
if (isset($_GET['mode'])) { |
|
148
|
|
|
$mode = filter_input(INPUT_GET, 'mode', FILTER_SANITIZE_STRING); |
|
149
|
|
|
} |
|
150
|
|
|
if (isset($_GET['redirect'])) { |
|
151
|
|
|
$redirect = filter_input(INPUT_GET, 'redirect', FILTER_SANITIZE_STRING); |
|
152
|
|
|
} |
|
153
|
|
|
if (isset($_GET['languageConstants'])) { |
|
154
|
|
|
$languageConstants = json_decode($_GET['languageConstants']); |
|
155
|
|
|
} |
|
156
|
|
|
$result = DirectoryChecker::setDirectoryPermissions($path, $mode); |
|
157
|
|
|
$msg = ($result) ? $languageConstants[0] : $languageConstants[1]; |
|
158
|
|
|
redirect_header($redirect, 2, $msg . ': ' . $path); |
|
159
|
|
|
exit(); |
|
160
|
|
|
break; |
|
161
|
|
|
} |
|
162
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.