diff options
Diffstat (limited to 'src/private/autojudging.php')
| -rwxr-xr-x | src/private/autojudging.php | 115 |
1 files changed, 79 insertions, 36 deletions
diff --git a/src/private/autojudging.php b/src/private/autojudging.php index 2a8b1ed..e44aaeb 100755 --- a/src/private/autojudging.php +++ b/src/private/autojudging.php @@ -1,7 +1,7 @@ <?php //////////////////////////////////////////////////////////////////////////////// //BOCA Online Contest Administrator -// Copyright (C) 2003-2013 by BOCA Development Team (bocasystem@gmail.com) +// Copyright (C) 2003-2017 by BOCA Development Team (bocasystem@gmail.com) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -15,7 +15,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. //////////////////////////////////////////////////////////////////////////////// -// Last modified 29/aug/2017 by cassio@ime.usp.br $ds = DIRECTORY_SEPARATOR; if($ds=="") $ds = "/"; @@ -157,6 +156,8 @@ while(42) { DBExec($c, "commit", "Autojudging(exportcommit)"); continue; } + cleardir($dir . $ds . "problemdatalocal"); + cleardir($dir . $ds . "problemdata"); if(is_readable($cache . $ds . $run["inputoid"] . "." . $run["inputname"])) { DBExec($c, "commit", "Autojudging(exportcommit)"); echo "Getting problem package file from local cache: " . $cache . $ds . $run["inputoid"] . "." . $run["inputname"] . "\n"; @@ -164,6 +165,25 @@ while(42) { file_put_contents($dir . $ds . $run["inputname"], decryptData($s,$key)); $basename=$basenames[$run['inputoid']. "." . $run["inputname"]]; } else { + $flocal = '/root/icpc-latam-packages/' . trim($run["problemname"]) . ".zip"; //cassiopc: HARDCODED FOR ICPC 2017 + if(!is_readable($flocal)) $flocal = '/root/icpc-latam-packages/' . trim($run["problemname"]) . ".ZIP"; + if(!is_readable($flocal)) $flocal = ''; + if($flocal != '') { + echo "Getting problem package file from local version: " . $flocal . "\n"; + $zip = new ZipArchive; + if ($zip->open($flocal) === true) { + $zip->extractTo($dir . $ds . "problemdatalocal"); + $zip->close(); + } else { + DBExec($c, "rollback work", "Autojudging(zipfailed)"); + echo "Failed to unzip the package file -- please check the problem package (maybe it is encrypted?)\n"; + DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file is invalid (1)"); + cleardir($dir . $ds . "problemdata"); + continue; + } + } + + @unlink($dir . $ds . $run["inputname"]); echo "Downloading problem package file from db into: " . $dir . $ds . $run["inputname"] . "\n"; if(DB_lo_export($contest,$c, $run["inputoid"], $dir . $ds . $run["inputname"]) === false) { DBExec($c, "rollback work", "Autojudging(rollback-input)"); @@ -176,7 +196,7 @@ while(42) { @chmod($dir . $ds . $run["inputname"], 0600); @chown($dir . $ds . $run["inputname"],"root"); - echo "Problem package downloaded -- running init scripts to obtain limits and other information\n"; + echo "Problem package obtained -- running init scripts to obtain limits and other information\n"; $zip = new ZipArchive; if ($zip->open($dir . $ds . $run["inputname"]) === true) { $zip->extractTo($dir . $ds . "problemdata"); @@ -187,12 +207,15 @@ while(42) { cleardir($dir . $ds . "problemdata"); continue; } - if(($info=@parse_ini_file($dir . $ds . "problemdata" . $ds . "description" . $ds . 'problem.info'))===false) { - echo "Problem content missing (description/problem.info) -- please check the problem package\n"; - DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file is invalid (2)"); - cleardir($dir . $ds . "problemdata"); - continue; - } + if(($info=@parse_ini_file($dir . $ds . "problemdatalocal" . $ds . "description" . $ds . 'problem.info'))===false) { + if(($info=@parse_ini_file($dir . $ds . "problemdata" . $ds . "description" . $ds . 'problem.info'))===false) { + echo "Problem content missing (description/problem.info) -- please check the problem package\n"; + DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file is invalid (2)"); + cleardir($dir . $ds . "problemdata"); + cleardir($dir . $ds . "problemdatalocal"); + continue; + } + } else echo "Problem info obtained from local package file\n"; if(isset($info['descfile'])) $descfile=trim(sanitizeFilename($info['descfile'])); $basename=trim(sanitizeFilename($info['basename'])); @@ -201,6 +224,7 @@ while(42) { echo "Problem content missing (description/problem.info) -- please check the problem package\n"; DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file is invalid (3)"); cleardir($dir . $ds . "problemdata"); + cleardir($dir . $ds . "problemdatalocal"); continue; } $basenames[$run['inputoid']. "." . $run["inputname"]]=$basename; @@ -208,11 +232,18 @@ while(42) { echo "Problem content missing (limits) -- please check the problem package\n"; DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file is invalid (4)"); cleardir($dir . $ds . "problemdata"); + cleardir($dir . $ds . "problemdatalocal"); continue; } - chdir($dir . $ds . "problemdata" . $ds . "limits"); + $pd = 'problemdata'; + if(is_dir($dir . $ds . "problemdatalocal" . $ds . "limits")) { + echo "Obtaining limits from local package file\n"; + $pd = 'problemdatalocal'; + } + chdir($dir . $ds . $pd . $ds . "limits"); $limits[$basename]=array(); - foreach(glob($dir . $ds . "problemdata" . $ds . "limits" .$ds . '*') as $file) { + $cont=false; + foreach(glob($dir . $ds . $pd . $ds . "limits" .$ds . '*') as $file) { chmod($file,0700); $ex = escapeshellcmd($file); $ex .= " >stdout 2>stderr"; @@ -223,38 +254,50 @@ while(42) { if($retval != 0) { echo "Error running script -- please check the problem package\n"; DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file is invalid (5)"); - cleardir($dir . $ds . "problemdata"); - continue; + $cont=true; + break; } $limits[$basename][basename($file)] = file('stdout',FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); } - $cont=false; - foreach(glob($dir . $ds . "problemdata" . $ds . "tests" .$ds . '*') as $file) { - chdir($dir . $ds . "problemdata" . $ds . "tests"); - chmod($file,0700); - $ex = escapeshellcmd($file); - $ex .= " >stdout 2>stderr"; - @unlink('stdout'); - @unlink('stderr'); - echo "Executing TEST SCRIPT " . $ex . " at " . getcwd() . "\n"; - if(system($ex, $retval)===false) $retval=-1; - if($retval != 0) { - echo "Error running test script -- please check the problem package or your installation\n"; - echo "=====stderr======\n"; - echo file_get_contents('stderr'); - echo "\n=====stdout======\n"; - echo file_get_contents('stdout'); - echo "\n===========\n"; - DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: internal test script failed (" . $file . ")"); - $cont=true; - break; + if(!$cont) { + $pd = 'problemdata'; + if(is_dir($dir . $ds . "problemdatalocal" . $ds . "tests")) { + echo "Running test scripts from local package file\n"; + $pd = 'problemdatalocal'; } + foreach(glob($dir . $ds . $pd . $ds . "tests" .$ds . '*') as $file) { + chdir($dir . $ds . $pd . $ds . "tests"); + chmod($file,0700); + $ex = escapeshellcmd($file); + $ex .= " >stdout 2>stderr"; + @unlink('stdout'); + @unlink('stderr'); + echo "Executing TEST SCRIPT " . $ex . " at " . getcwd() . "\n"; + if(system($ex, $retval)===false) $retval=-1; + if($retval != 0) { + echo "Error running test script -- please check the problem package or your installation\n"; + echo "=====stderr======\n"; + echo file_get_contents('stderr'); + echo "\n=====stdout======\n"; + echo file_get_contents('stdout'); + echo "\n===========\n"; + DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: internal test script failed (" . $file . ")"); + $cont=true; + break; + } + } + } + if(is_dir($dir . $ds . "problemdatalocal" . $ds . "output")) { + echo "Using scripts and inputs/outputs from local package file\n"; + @copy($flocal, $dir . $ds . $run["inputname"]); } + $s = file_get_contents($dir . $ds . $run["inputname"]); cleardir($dir . $ds . "problemdata"); - if($cont) + cleardir($dir . $ds . "problemdatalocal"); + if($cont) { + echo "Aborting judging because of issues in the package\n"; continue; - - $s = file_get_contents($dir . $ds . $run["inputname"]); + } file_put_contents($cache . $ds . $run["inputoid"] . "." . $run["inputname"], encryptData($s,$key)); } |