Sindbad~EG File Manager
<?php
$OutputDir = "otter/projects/";
$InputDir = "otter/projects/";
$ExampleDir = "examples/";
$OtterDir = "otter"; // Otter or Otter-lambda executable file location.
// up one to research, two to michaelbeeson, three to public_html, then down to Otter-Lambda.
$ExecuteLocation = "$OtterDir/otter-lambda"; // as it's called on sequoia
$TimeLimitScript = "$OtterDir/TimedExec"; // TimedExec <seconds> otter-lambda < infile > outfile
$TimeLimit = 120; // in seconds
$inputfile = "";
$outputfile = "";
function writeRed($errmsg)
{ echo "<P> <em><font color=\"#FF0000\">";
echo $errmsg;
echo "</font></em></P>";
}
function GenerateFileName()
{ // Each time this function is called it generates a unique new name.
$name = "otter-".time();
return $name;
}
function RunOtterByText($text)
{
global $InputDir, $OutputDir, $inputfile, $outputfile;
$Filename = GenerateFileName();
$inputfile = $InputDir.$Filename.".in";
$outputfile = $OutputDir.$Filename.".out";
file_write($inputfile,$text); // $OtterInput comes from the HTML form.
return RunOtterByFile($inputfile,$outputfile);
}
function RunOtterByFile($infile,$outfile)
{
global $ExecuteLocation;
global $TimeLimitScript;
global $TimeLimit;
$Execute = $ExecuteLocation." < ".$infile." > ".$outfile;
$TimedExecute = "$TimeLimitScript $TimeLimit $Execute";
// echo htmlspecialchars("About to run $TimedExecute"); echo "<br>";
exec($TimedExecute,$output,$execval);
$rval = file_read($outfile);
if($execval == 137)
writeRed("Time limit ($TimeLimit seconds) exceeded. This is a production web server whose main job is delivering HTML pages, so there has to be a time limit on otter-lambda jobs.");
return $rval;
}
function file_write($filename, $data)
{ // echo("Trying to open $filename");
$fh = fopen($filename, "wt");
if ( !$fh ) {
echo "ERROR: Could not open file $filename for writing.<BR>";
exit();
}
$bytes_written = fwrite($fh, $data);
fclose($fh);
$bytes_written;
}
function file_read($filename, $use_include_path = 0)
{
$successful = 0;
// echo "Entering file_read $filename<br>";
$file = fopen($filename, "rt", $use_include_path);
if ($file) {
while ( !feof($file) ) {
$line = fgets($file,4096);
if ( strstr($line,"PROOF") )
echo "<B><font color=#0000ff>";
echo htmlspecialchars($line);
echo "<br>";
if ( strstr($line,"end of proof") )
echo "</B></font>";
}
$successful = 1;
fclose($file);
} else {
echo "ERROR: Could not open file $filename for reading.<BR>";
exit();
}
return $successful;
}
function print_last($inputf,$outputf)
{
echo "<HR><table width=\"700\" border=\"0\" align=\"center\">
<tr>
<td><a href=\"$inputf\">Download The Input File</a></td>
<td><a href=\"$outputf\">Download The Output File</a></td>
</tr>
</table><BR>";
}
?>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists