$value){
$post_array[$key] = stripslashes($value);
}
}
}
include("interfacetop.php");
undo_magic_quotes_on_post($_POST);
if ($my_test) {echo '
PARAMS
';}
foreach ($_POST as $key => $value){
if ($key != EXEC_KEY) {
$param .= $value . "\n";
if ($my_test){
echo "
$key : $value ";
}
}
}
$work_name = microtime(true) * 10000;
$work_dir = TMP_DIR ."/" .$work_name;
umask(0000); // remover permissoes de defeito do utilizador
// echo $work_name; echo $work_dir;
if ( mkdir($work_dir, 0777) ){
$descriptorspec =
array(0 => array("pipe", "r"), // stdin is a pipe the child reads from
1 => array("pipe", "w"), // stdout is a pipe the child writes to
2 => array("file", $work_dir . "/" . OUTPUT_ERROR_FILE, "a"));
// Uploader -- Begin 20-Jul-2012 26-Jul-2014 ...........................
if($filepresent){
if ($my_test)
echo "% UPLOADER TWO
";
$target_path = TMP_DIR . "/";
$target_path = $target_path. basename($_FILES['uploadedfile']['name']);
if ($my_test) echo '% target_path: '. $target_path. '
';
// Comment Begin........................................................
if ($_FILES["uploadedfile"]["error"] > 0){
echo "% Error: " . $_FILES["uploadedfile"]["error"] . "
";
}
else if ($my_test){
echo "% Uploaded: " . $_FILES["uploadedfile"]["name"] . "
";
echo '% — Type, size: ' . $_FILES["uploadedfile"]["type"]. ', '.
$_FILES["uploadedfile"]["size"]. ' bytes
';
echo '% — Stored in: '.
$_FILES["uploadedfile"]["tmp_name"]. "
";
}
$target_path = $_FILES['uploadedfile']['tmp_name'];
// Comment End .........................................................
if ($my_test) echo '% target_path: '. $target_path. '
';
if ($my_test) {
echo '% Printing the file: ...
';
$myfile = fopen($target_path, "r") or
exit("Unable to open file or file not given !");
while (!feof($myfile)) {
echo fgets($myfile);
}
fclose($myfile);
} // matches if mytest
if ($my_test)
echo "% End of upload
"; // Uploader -- End
/* Compor a string que corresponde a chamada do executavel. */
$exec_string = EXEC_DIR. "/". $_POST[EXEC_KEY]. " ".
$target_path. " ". $work_name; // § CAUTION
}
else{
/* Compor a string que corresponde a chamada do executavel. */
$exec_string = EXEC_DIR. "/". $_POST[EXEC_KEY]. " " . $work_name; // § CAUTION
}
$process = proc_open($exec_string, $descriptorspec, $pipes);
if ($my_test)
echo "% process: exec_string:
". $exec_string. "
";
if (is_resource($process)) {
/* Escrever para o stdin do executavel os parametros */
fwrite($pipes[0], $param); // #test: echo "% Params: " .$param;
fclose($pipes[0]);
}
// Admitimos que o executavel nao gera linhas com mais de 4095 caracteres
while (!feof($pipes[1])){
$buffer = fgets($pipes[1], 4096);
echo $buffer;
// echo htmlentities($buffer, ENT_NOQUOTES, "ISO8859-15");
}
fclose($pipes[1]);
// Close any pipes before calling proc_close in order to avoid a deadlock
$return_value = proc_close($process);
clearstatcache(); // Se ficheiro de output vazio, apagar
if ($my_test)
echo "% work_dir: ". $work_dir. "
";
if (file_exists($work_dir . "/" . OUTPUT_ERROR_FILE)){
$size = filesize($work_dir . "/" . OUTPUT_ERROR_FILE);
if ($size == 0) {
unlink($work_dir ."/" .OUTPUT_ERROR_FILE);
rmdir($work_dir);
}
} // Matches: if (is_resource($process)) (brace)
if (!$my_test){
if (file_exists($work_dir . "/" . OUTPUT_ERROR_FILE)){
unlink($work_dir ."/" .OUTPUT_ERROR_FILE);
rmdir($work_dir);
}
}
// 2014-07-28 MCasquilho (Veloza)
// $tmp_str = 'cd '. $work_dir. '; /usr/bin/gnuplot gnoload.dat';
//if ($my_test) echo "Executar:
". $tmp_str. "\n";
// exec ($tmp_str);
//Final Falta uma chaveta de fechar ?
// }
/*echo "\n"; // i.e., bottom
if ($my_test) echo "% TMP_URL+work_name: ". TMP_URL. "/". $work_name. "
";
echo "";
echo "". "Go back using your browser.".
"