Skip to content

Commit

Permalink
slashargument test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Feb 26, 2005
1 parent 2896553 commit 48283ff
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
33 changes: 23 additions & 10 deletions admin/health.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ function exists() {
if (!$this->is_enabled()) {
return true;
}
if ($this->status() == 0) {
if ($this->status() < 1) {
return true;
}
return false;
Expand All @@ -412,13 +412,16 @@ function severity() {
}
}
function description() {
global $CFG;
$desc = 'Slasharguments are needed for relative linking in uploaded resources:<ul>';
if (!$this->is_enabled()) {
$desc .= '<li>slasharguments are <strong>disabled</strong> in Moodle configuration</li>';
} else {
$desc .= '<li>slasharguments are enabled in Moodle configuration</li>';
}
if ($this->status() == 0) {
if ($this->status() == -1) {
$desc .= '<li>can not run automatic test, you can verify it <a href="'.$CFG->wwwroot.'/file.php/testslasharguments" target="_blank">here</a></li>';
} else if ($this->status() == 0) {
$desc .= '<li>slashargument test <strong>failed</strong>, please check server configuration</li>';
} else {
$desc .= '<li>slashargument test passed</li>';
Expand All @@ -427,19 +430,24 @@ function description() {
return $desc;
}
function solution() {
global $CFG;
$enabled = $this->is_enabled();
$status = $this->status();
$solution = '';
if ($enabled and ($status == 0)) {
$solution .= 'Slasharguments are enabled, but the test failed. Please disable slasharguments in Moodle configuration or fix the server configuration.<hr />';
} else if ((!$enabled) and ($status == 0)) {
$solution .= 'Slasharguments are disabled and the test failed. You may try to fix the server configuration.<hr />';
} else if ($enabled and ($status == -1)) {
$solution .= 'Slasharguments are enabled, <a href="'.$CFG->wwwroot.'/file.php/testslasharguments">automatic testing</a> not possible.<hr />';
} else if ((!$enabled) and ($status == -1)) {
$solution .= 'Slasharguments are disabled, <a href="'.$CFG->wwwroot.'/file.php/testslasharguments">automatic testing</a> not possible.<hr />';
} else if ((!$enabled) and ($status > 0)) {
$solution .= 'Slasharguments are disabled though the iternal test is OK. You should enable slasharguments in Moodle configuration.';
} else if ($enabled and ($status > 0)) {
$solution .= 'Congratulations - everything seems OK now :-D';
}
if ($status ==0) {
if ($status < 1) {
$solution .= '<p>IIS:<ul><li>try to add <code>cgi.fix_pathinfo=1</code> to php.ini</li><li>do NOT enable AllowPathInfoForScriptMappings !!!</li><li>slasharguments may not work when using ISAPI and PHP 4.3.10 and older</li></ul></p>';
$solution .= '<p>Apache 1:<ul><li>try to add <code>cgi.fix_pathinfo=1</code> to php.ini</li></ul></p>';
$solution .= '<p>Apache 2:<ul><li>you must add <code>AcceptPathInfo on</code> to php.ini or .htaccess</li><li>try to add <code>cgi.fix_pathinfo=1</code> to php.ini</li></ul></p>';
Expand All @@ -452,14 +460,20 @@ function is_enabled() {
}
function status() {
global $CFG;
$handle = @fopen($CFG->wwwroot.'/file.php/test', "r");
$contents = trim(@fread($handle, 10));
$handle = @fopen($CFG->wwwroot.'/file.php?file=/testslasharguments', "r");
$contents = trim(@fread($handle, 7));
@fclose($handle);
if ($contents != 'test -1') {
return -1;
}
$handle = @fopen($CFG->wwwroot.'/file.php/testslasharguments', "r");
$contents = trim(@fread($handle, 6));
@fclose($handle);
switch ($contents) {
case '1': return 1;
case '2': return 2;
case 'test 1': return 1;
case 'test 2': return 2;
default: return 0;
}
}
}
}

Expand Down Expand Up @@ -488,8 +502,7 @@ function solution() {
TODO:
session.save_path -- it doesn't really matter because we are already IN a session, right?
slasharguments -- get_file_argument() in weblib.php
*/

?>
2 changes: 1 addition & 1 deletion file.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Syntax: file.php/courseid/dir/dir/dir/filename.ext
// file.php/courseid/dir (returns index.html from dir)
// Workaround: file.php?file=/courseid/dir/dir/dir/filename.ext
// Test: file.php/test
// Test: file.php/testslasharguments

require_once('config.php');
require_once('files/mimetypes.php');
Expand Down
12 changes: 8 additions & 4 deletions lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -802,15 +802,19 @@ function get_file_argument($scriptname) {

// first try normal parameter (compatible method == no relative links!)
$relativepath = optional_param('file', FALSE, PARAM_PATH);
if ($relativepath === '/testslasharguments') {
echo 'test -1: Incorrect use - try "file.php/testslasharguments" instead'; //indicate fopen/fread works for health center
die;
}

// then try extract file from PATH_INFO (slasharguments method)
if (!$relativepath and !empty($_SERVER['PATH_INFO'])) {
$path_info = $_SERVER['PATH_INFO'];
// check that PATH_INFO works == must not contain the script name
if (!strpos($path_info, $scriptname)) {
$relativepath = clean_param(rawurldecode($path_info), PARAM_PATH);
if ($relativepath === '/test') {
echo '1'; //indicate ok for health center
if ($relativepath === '/testslasharguments') {
echo 'test 1: Slasharguments test passed.'; //indicate ok for health center
die;
}
}
Expand All @@ -823,8 +827,8 @@ function get_file_argument($scriptname) {
if (!empty($arr[1])) {
$path_info = strip_querystring($arr[1]);
$relativepath = clean_param(rawurldecode($path_info), PARAM_PATH);
if ($relativepath === '/test') {
echo '2'; //indicate ok for health center
if ($relativepath === '/testslasharguments') {
echo 'test 2:Slasharguments test passed (compatibility hack).'; //indicate ok for health center
die;
}
}
Expand Down

0 comments on commit 48283ff

Please sign in to comment.