Skip to content

Commit aa3244a

Browse files
committedSep 12, 2011
Improve directory validation in admin checks
This commit brings the following improvements in check_paths_inc.php: - In addition to checking that a directory is valid, we now also verify that it is readable, this way admin will know if the error is caused e.g. by a symlink, or due to access rights - Print actual path instead of a text description in install check. The config option name is already displayed as part of the first line of the check's output, so repeating the information does not add any additional value. - Escape data printed in messages (path) with htmlspecialchars() as recommended by dhx - Added comments to clearly identify purpose of each check block
1 parent a903240 commit aa3244a

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed
 

‎admin/check/check_paths_inc.php

+26-3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
$t_path_config_names[] = 'absolute_path_default_upload_folder';
5050
}
5151

52+
# Build paths for all configs
5253
$t_paths = array();
5354
foreach( $t_path_config_names as $t_path_config_name ) {
5455
$t_new_path = array();
@@ -57,19 +58,39 @@
5758
$t_paths[$t_path_config_name] = $t_new_path;
5859
}
5960

61+
# Trailing directory separator
6062
foreach( $t_paths as $t_path_config_name => $t_path ) {
6163
check_print_test_row(
6264
$t_path_config_name . ' configuration option has a trailing directory separator',
6365
substr( $t_path['config_value'], -1, 1 ) == DIRECTORY_SEPARATOR,
64-
array( false => 'You must provide a trailing directory separator (' . DIRECTORY_SEPARATOR . ') to the end of the ' . $t_path_config_name . ' configuration value.' )
66+
array( false =>
67+
"You must provide a trailing directory separator (" . DIRECTORY_SEPARATOR .
68+
") to the end of '" . htmlspecialchars( $t_path['config_value'] ) . "'."
69+
) )
6570
);
6671
}
6772

73+
# Is a directory
6874
foreach( $t_paths as $t_path_config_name => $t_path ) {
6975
check_print_test_row(
7076
$t_path_config_name . ' configuration option points to a valid directory',
7177
is_dir( $t_path['config_value'] ),
72-
array( false => 'The path specified by the ' . $t_path_config_name . ' configuration option does not point to a valid and accessible directory.' )
78+
array( false =>
79+
"The path '" . htmlspecialchars( $t_path['config_value'] ) .
80+
"' is not a valid directory."
81+
)
82+
);
83+
}
84+
85+
# Is readable
86+
foreach( $t_paths as $t_path_config_name => $t_path ) {
87+
check_print_test_row(
88+
$t_path_config_name . ' configuration option points to an accessible directory',
89+
is_readable( $t_path['config_value'] ),
90+
array( false =>
91+
"The path '" . htmlspecialchars( $t_path['config_value'] ) .
92+
"' is not accessible."
93+
)
7394
);
7495
}
7596

@@ -80,7 +101,9 @@
80101
check_print_test_row(
81102
$t_path_config_name . ' configuration option points to a writable directory',
82103
is_writable( $t_path['config_value'] ),
83-
array( false => "The path specified by the $t_path_config_name configuration option ('" . $t_path['config_value'] . "') must be writable." )
104+
array( false =>
105+
"The path '" . htmlspecialchars( $t_path['config_value'] ) . "' must be writable."
106+
)
84107
);
85108
}
86109

0 commit comments

Comments
 (0)
Please sign in to comment.