Revert " MDL-45044 filter_tex: properly escape excutable pathnames for Windows"

This reverts commit 07a50c2f29.
This commit is contained in:
Eloy Lafuente (stronk7) 2014-06-26 10:03:25 +02:00
parent 9d5a2e6f1c
commit 65684fa600
4 changed files with 22 additions and 45 deletions

View file

@ -108,16 +108,14 @@
fclose( $fh ); fclose( $fh );
// run latex on document // run latex on document
$pathlatex = escapeshellarg(trim($CFG->filter_tex_pathlatex, " '\"")); $command = "{$CFG->filter_tex_pathlatex} --interaction=nonstopmode --halt-on-error $tex";
$command = "{$pathlatex} --interaction=nonstopmode --halt-on-error $tex";
chdir( $this->temp_dir ); chdir( $this->temp_dir );
if ($this->execute($command, $log)) { // It allways False on Windows if ($this->execute($command, $log)) { // It allways False on Windows
// return false; // return false;
} }
// run dvips (.dvi to .ps) // run dvips (.dvi to .ps)
$pathdvips = escapeshellarg(trim($CFG->filter_tex_pathdvips, " '\"")); $command = "{$CFG->filter_tex_pathdvips} -E $dvi -o $ps";
$command = "{$pathdvips} -E $dvi -o $ps";
if ($this->execute($command, $log )) { if ($this->execute($command, $log )) {
return false; return false;
} }
@ -128,8 +126,7 @@
} else { } else {
$bg_opt = ""; $bg_opt = "";
} }
$pathconvert = escapeshellarg(trim($CFG->filter_tex_pathconvert, " '\"")); $command = "{$CFG->filter_tex_pathconvert} -density $density -trim $bg_opt $ps $img";
$command = "{$pathconvert} -density $density -trim $bg_opt $ps $img";
if ($this->execute($command, $log )) { if ($this->execute($command, $log )) {
return false; return false;
} }

View file

@ -116,13 +116,9 @@ function filter_tex_updatedcallback($name) {
return; return;
} }
$pathlatex = trim($CFG->filter_tex_pathlatex, " '\""); if (!(is_file($CFG->filter_tex_pathlatex) && is_executable($CFG->filter_tex_pathlatex) &&
$pathdvips = trim($CFG->filter_tex_pathdvips, " '\""); is_file($CFG->filter_tex_pathdvips) && is_executable($CFG->filter_tex_pathdvips) &&
$pathconvert = trim($CFG->filter_tex_pathconvert, " '\""); is_file($CFG->filter_tex_pathconvert) && is_executable($CFG->filter_tex_pathconvert))) {
if (!(is_file($pathlatex) && is_executable($pathlatex) &&
is_file($pathdvips) && is_executable($pathdvips) &&
is_file($pathconvert) && is_executable($pathconvert))) {
// LaTeX, dvips or convert are not available, and mimetex can only produce GIFs so... // LaTeX, dvips or convert are not available, and mimetex can only produce GIFs so...
set_config('filter_tex_convertformat', 'gif'); set_config('filter_tex_convertformat', 'gif');
} }

View file

@ -50,9 +50,9 @@ if ($ADMIN->fulltree) {
} else if (PHP_OS=='WINNT' or PHP_OS=='WIN32' or PHP_OS=='Windows') { } else if (PHP_OS=='WINNT' or PHP_OS=='WIN32' or PHP_OS=='Windows') {
// note: you need Ghostscript installed (standard), miktex (standard) // note: you need Ghostscript installed (standard), miktex (standard)
// and ImageMagick (install at c:\ImageMagick) // and ImageMagick (install at c:\ImageMagick)
$default_filter_tex_pathlatex = "c:\\texmf\\miktex\\bin\\latex.exe"; $default_filter_tex_pathlatex = "\"c:\\texmf\\miktex\\bin\\latex.exe\" ";
$default_filter_tex_pathdvips = "c:\\texmf\\miktex\\bin\\dvips.exe"; $default_filter_tex_pathdvips = "\"c:\\texmf\\miktex\\bin\\dvips.exe\" ";
$default_filter_tex_pathconvert = "c:\\imagemagick\\convert.exe"; $default_filter_tex_pathconvert = "\"c:\\imagemagick\\convert.exe\" ";
} else { } else {
$default_filter_tex_pathlatex = ''; $default_filter_tex_pathlatex = '';
@ -60,16 +60,6 @@ if ($ADMIN->fulltree) {
$default_filter_tex_pathconvert = ''; $default_filter_tex_pathconvert = '';
} }
$pathlatex = $CFG->filter_tex_pathlatex;
$pathdvips = $CFG->filter_tex_pathdvips;
$pathconvert = $CFG->filter_tex_pathconvert;
if (strrpos($pathlatex . $pathdvips . $pathconvert, '"') or
strrpos($pathlatex . $pathdvips . $pathconvert, "'")) {
set_config('filter_tex_pathlatex', trim($pathlatex, " '\""));
set_config('filter_tex_pathdvips', trim($pathdvips, " '\""));
set_config('filter_tex_pathconvert', trim($pathconvert, " '\""));
}
$items[] = new admin_setting_configexecutable('filter_tex_pathlatex', get_string('pathlatex', 'admin'), '', $default_filter_tex_pathlatex); $items[] = new admin_setting_configexecutable('filter_tex_pathlatex', get_string('pathlatex', 'admin'), '', $default_filter_tex_pathlatex);
$items[] = new admin_setting_configexecutable('filter_tex_pathdvips', get_string('pathdvips', 'admin'), '', $default_filter_tex_pathdvips); $items[] = new admin_setting_configexecutable('filter_tex_pathdvips', get_string('pathdvips', 'admin'), '', $default_filter_tex_pathdvips);
$items[] = new admin_setting_configexecutable('filter_tex_pathconvert', get_string('pathconvert', 'admin'), '', $default_filter_tex_pathconvert); $items[] = new admin_setting_configexecutable('filter_tex_pathconvert', get_string('pathconvert', 'admin'), '', $default_filter_tex_pathconvert);
@ -84,4 +74,4 @@ if ($ADMIN->fulltree) {
$item->set_updatedcallback('filter_tex_updatedcallback'); $item->set_updatedcallback('filter_tex_updatedcallback');
$settings->add($item); $settings->add($item);
} }
} }

View file

@ -200,33 +200,27 @@
// first check if it is likely to work at all // first check if it is likely to work at all
$output .= "<h3>Checking executables</h3>\n"; $output .= "<h3>Checking executables</h3>\n";
$executables_exist = true; $executables_exist = true;
$pathlatex = trim($CFG->filter_tex_pathlatex, " '\""); if (is_file($CFG->filter_tex_pathlatex)) {
if (is_file($pathlatex)) { $output .= "latex executable ($CFG->filter_tex_pathlatex) is readable<br />\n";
$output .= "latex executable ($pathlatex) is readable<br />\n";
} }
else { else {
$executables_exist = false; $executables_exist = false;
$output .= "<b>Error:</b> latex executable ($pathlatex) is not readable<br />\n"; $output .= "<b>Error:</b> latex executable ($CFG->filter_tex_pathlatex) is not readable<br />\n";
} }
$pathlatex = escapeshellarg($pathlatex); if (is_file($CFG->filter_tex_pathdvips)) {
$pathdvips = trim($CFG->filter_tex_pathdvips, " '\""); $output .= "dvips executable ($CFG->filter_tex_pathdvips) is readable<br />\n";
if (is_file($pathdvips)) {
$output .= "dvips executable ($pathdvips) is readable<br />\n";
} }
else { else {
$executables_exist = false; $executables_exist = false;
$output .= "<b>Error:</b> dvips executable ($pathdvips) is not readable<br />\n"; $output .= "<b>Error:</b> dvips executable ($CFG->filter_tex_pathdvips) is not readable<br />\n";
} }
$pathdvips = escapeshellarg($pathdvips); if (is_file($CFG->filter_tex_pathconvert)) {
$pathconvert = trim($CFG->filter_tex_pathconvert, " '\""); $output .= "convert executable ($CFG->filter_tex_pathconvert) is readable<br />\n";
if (is_file($pathconvert)) {
$output .= "convert executable ($pathconvert) is readable<br />\n";
} }
else { else {
$executables_exist = false; $executables_exist = false;
$output .= "<b>Error:</b> convert executable ($pathconvert) is not readable<br />\n"; $output .= "<b>Error:</b> convert executable ($CFG->filter_tex_pathconvert) is not readable<br />\n";
} }
$pathconvert = escapeshellarg($pathconvert);
// knowing that it might work.. // knowing that it might work..
$md5 = md5($expression); $md5 = md5($expression);
@ -250,15 +244,15 @@
chdir($latex->temp_dir); chdir($latex->temp_dir);
// step 1: latex command // step 1: latex command
$cmd = "$pathlatex --interaction=nonstopmode --halt-on-error $tex"; $cmd = "$CFG->filter_tex_pathlatex --interaction=nonstopmode --halt-on-error $tex";
$output .= execute($cmd); $output .= execute($cmd);
// step 2: dvips command // step 2: dvips command
$cmd = "$pathdvips -E $dvi -o $ps"; $cmd = "$CFG->filter_tex_pathdvips -E $dvi -o $ps";
$output .= execute($cmd); $output .= execute($cmd);
// step 3: convert command // step 3: convert command
$cmd = "$pathconvert -density 240 -trim $ps $img "; $cmd = "$CFG->filter_tex_pathconvert -density 240 -trim $ps $img ";
$output .= execute($cmd); $output .= execute($cmd);
if (!$graphic) { if (!$graphic) {