Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

slashargument test fix

  • Loading branch information...
commit 48283ff6386201731c8418a8de59043cc368fe6b 1 parent 2896553
skodak authored
Showing with 32 additions and 15 deletions.
  1. +23 −10 admin/health.php
  2. +1 −1  file.php
  3. +8 −4 lib/weblib.php
View
33 admin/health.php
@@ -399,7 +399,7 @@ function exists() {
if (!$this->is_enabled()) {
return true;
}
- if ($this->status() == 0) {
+ if ($this->status() < 1) {
return true;
}
return false;
@@ -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>';
@@ -427,6 +430,7 @@ function description() {
return $desc;
}
function solution() {
+ global $CFG;
$enabled = $this->is_enabled();
$status = $this->status();
$solution = '';
@@ -434,12 +438,16 @@ function solution() {
$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>';
@@ -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;
- }
+ }
}
}
@@ -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
+
*/
?>
View
2  file.php
@@ -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');
View
12 lib/weblib.php
@@ -802,6 +802,10 @@ 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'])) {
@@ -809,8 +813,8 @@ function get_file_argument($scriptname) {
// 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;
}
}
@@ -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;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.