diff options
| -rw-r--r-- | src/admin/run.php | 36 | ||||
| -rw-r--r-- | src/fcontest.php | 20 | ||||
| -rw-r--r-- | src/fproblem.php | 2 | ||||
| -rw-r--r-- | src/freport.php | 11 | ||||
| -rw-r--r-- | src/frun.php | 7 | ||||
| -rwxr-xr-x | src/private/autojudging.php | 1091 | ||||
| -rw-r--r-- | src/staff/header.php | 4 | ||||
| -rwxr-xr-x | src/staff/report/stat.php | 6 |
8 files changed, 598 insertions, 579 deletions
diff --git a/src/admin/run.php b/src/admin/run.php index 4ec0eca..b052393 100644 --- a/src/admin/run.php +++ b/src/admin/run.php @@ -15,7 +15,7 @@ // 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 05/aug/2012 by cassio@ime.usp.br +// Last modified 29/aug/2017 by cassio@ime.usp.br require 'header.php'; if(isset($_GET["order"]) && $_GET["order"] != "") { $order = myhtmlspecialchars($_GET["order"]); @@ -64,18 +64,18 @@ if(isset($_POST)) { if(isset($_POST["cbox_" . $run[$i]["number"] . "_" . $run[$i]["site"]]) && $_POST["cbox_" . $run[$i]["number"] . "_" . $run[$i]["site"]] != "") { if(isset($_POST["auto"]) && $_POST["auto"]=="Re-run autojudge for selected runs") { - if (DBGiveUpRunAutojudging($_SESSION["usertable"]["contestnumber"], - $run[$i]["site"], $run[$i]["number"])) - $nrenew++; - } + if (DBGiveUpRunAutojudging($_SESSION["usertable"]["contestnumber"], + $run[$i]["site"], $run[$i]["number"]), '', '', true) + $nrenew++; + } if(isset($_POST["open"]) && $_POST["open"]=="Open selected runs for rejudging") { - DBGiveUpRunAutojudging($_SESSION["usertable"]["contestnumber"], - $run[$i]["site"], $run[$i]["number"]); - if (DBChiefRunGiveUp($run[$i]["number"], $run[$i]["site"], - $_SESSION["usertable"]["contestnumber"])) - $nreopen++; + DBGiveUpRunAutojudging($_SESSION["usertable"]["contestnumber"], + $run[$i]["site"], $run[$i]["number"]); + if (DBChiefRunGiveUp($run[$i]["number"], $run[$i]["site"], + $_SESSION["usertable"]["contestnumber"])) + $nreopen++; } - } + } } if($nrenew > 0) { MSGError($nrenew . " runs renewed for autojudging."); @@ -87,7 +87,7 @@ if(isset($_POST)) { } } - +$us = DBAllUserNames($_SESSION["usertable"]["contestnumber"]); for ($i=0; $i<count($run); $i++) { if($run[$i]["answer1"] != 0 && $run[$i]["answer2"] != 0 && $run[$i]["status"] != "judged") { if($runphp == "runchief.php") @@ -105,8 +105,7 @@ for ($i=0; $i<count($run); $i++) { echo " <td nowrap>" . $run[$i]["site"] . "</td>\n"; if($runphp == "run.php") { if ($run[$i]["user"] != "") { - $u = DBUserInfo ($_SESSION["usertable"]["contestnumber"], $run[$i]["site"], $run[$i]["user"]); - echo " <td nowrap>" . $u["username"] . "</td>\n"; + echo " <td nowrap>" . $us[$run[$i]["site"] . '-' . $run[$i]["user"]] . "</td>\n"; } } echo " <td nowrap>" . dateconvminutes($run[$i]["timestamp"]) . "</td>\n"; @@ -124,18 +123,15 @@ for ($i=0; $i<count($run); $i++) { echo " <td nowrap bgcolor=\"#$color\">" . $run[$i]["status"] . "</td>\n"; if ($run[$i]["judge"] != "") { - $u = DBUserInfo ($_SESSION["usertable"]["contestnumber"], $run[$i]["judgesite"], $run[$i]["judge"]); - echo " <td nowrap>" . $u["username"] . " (" . $run[$i]["judgesite"] . ")"; + echo " <td nowrap>" . $us[$run[$i]["judgesite"] .'-'. $run[$i]["judge"]] . " (" . $run[$i]["judgesite"] . ")"; } else echo " <td> "; if ($run[$i]["judge1"] != "") { - $u = DBUserInfo ($_SESSION["usertable"]["contestnumber"], $run[$i]["judgesite1"], $run[$i]["judge1"]); - echo " [" . $u["username"] . " (" . $run[$i]["judgesite1"] . ")]"; + echo " [" . $us[$run[$i]["judgesite1"] .'-'. $run[$i]["judge1"]] . " (" . $run[$i]["judgesite1"] . ")]"; } if ($run[$i]["judge2"] != "") { - $u = DBUserInfo ($_SESSION["usertable"]["contestnumber"], $run[$i]["judgesite2"], $run[$i]["judge2"]); - echo " [" . $u["username"] . " (" . $run[$i]["judgesite2"] . ")]"; + echo " [" . $us[$run[$i]["judgesite2"] .'-'. $run[$i]["judge2"]] . " (" . $run[$i]["judgesite2"] . ")]"; } echo "</td>\n"; diff --git a/src/fcontest.php b/src/fcontest.php index 96576a6..045f28e 100644 --- a/src/fcontest.php +++ b/src/fcontest.php @@ -15,7 +15,7 @@ // 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 updated 26/jul/2017 by cassio@ime.usp.br +//Last updated 29/aug/2017 by cassio@ime.usp.br // function DBDropContestTable() { $c = DBConnect(); @@ -201,6 +201,24 @@ function DBFakeContest() { "'t', '$pass', NULL, NULL, '', NULL, NULL)", "DBFakeContest(insert system user)"); DBExec($c, "commit work"); } +function DBAllUserNames($contest,$site=-1) { + $sql = "select * from usertable where contestnumber=$contest "; + if($site > 0) $sql .= "and usersitenumber=$site "; + $c = DBConnect(); + $r = DBExec ($c, $sql, "DBAllUserNames(get users)"); + $n = DBnlines($r); + if ($n == 0) { + LOGError("Unable to find users in the database. SQL=(" . $sql . ")"); + MSGError("Unable to find users in the database!"); + } + + $a = array(); + for ($i=0;$i<$n;$i++) { + $tmp = DBRow($r,$i); + $a[$tmp['usersitenumber'] . '-' . $tmp['usernumber']] = $tmp['username']; + } + return $a; +} function DBAllUserInfo($contest,$site=-1) { $sql = "select * from usertable where contestnumber=$contest "; if($site > 0) $sql .= "and usersitenumber=$site "; diff --git a/src/fproblem.php b/src/fproblem.php index 88efcbb..a66f62c 100644 --- a/src/fproblem.php +++ b/src/fproblem.php @@ -290,7 +290,7 @@ function DBNewProblem($contestnumber, $param, $c=null) { if(isset($param['problemcolor']) && !isset($param['color'])) $param['color']=$param['problemcolor']; if(isset($param['probleminputfile']) && !isset($param['inputfilepath'])) $param['inputfilepath']=$param['probleminputfile']; if(isset($param['probleminputfilename']) && !isset($param['inputfilename'])) $param['inputfilename']=$param['probleminputfilename']; - $param['basename'] = sanitizeFilename($param['basename']); + if(isset($param['basename'])) $param['basename'] = sanitizeFilename($param['basename']); $ac=array('number','name'); $type['number']=1; diff --git a/src/freport.php b/src/freport.php index cded59b..6d990ca 100644 --- a/src/freport.php +++ b/src/freport.php @@ -15,7 +15,7 @@ // 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 05/aug/2012 by cassio@ime.usp.br +// Last modified 29/aug/2017 by cassio@ime.usp.br function DBRunReport($contest,$site) { $c = DBConnect(); @@ -50,7 +50,8 @@ function DBRunReport($contest,$site) { $xuserfull[$a['name']] = $a['fullname']; } ksort($xusername); - + $xcolor = array(); + $pr = DBGetProblems($contest); for($i=0; $i<count($pr); $i++) { $xproblem[$pr[$i]['problem']]=0; @@ -63,7 +64,11 @@ function DBRunReport($contest,$site) { $xanswer = array(); $xtimestamp = array(); $xtimestampyes = array(); - + $xpa = array(); + $xpl = array(); + $xla = array(); + $xup = array(); + $r = DBExec($c, $sql, "DBRunReport(get runs)"); $n = DBnlines($r); diff --git a/src/frun.php b/src/frun.php index eb5d33f..77677ad 100644 --- a/src/frun.php +++ b/src/frun.php @@ -15,7 +15,7 @@ // 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 26/jul/2017 by cassio@ime.usp.br +// Last modified 29/aug/2017 by cassio@ime.usp.br function DBDropRunTable() { $c = DBConnect(); @@ -498,7 +498,7 @@ function DBUpdateRunAutojudging($contest, $site, $number, $ip, $answer, $stdout, LOGLevel("Autojudging automatically answered a run (run=$number, site=$site, contest=$contest, retval=$retval, answer='$answer')", 3); return true; } -function DBGiveUpRunAutojudging($contest, $site, $number, $ip="", $ans="") { +function DBGiveUpRunAutojudging($contest, $site, $number, $ip="", $ans="", $fromadmin=false) { $c = DBConnect(); DBExec($c, "begin work", "DBGiveUpRunAutojudging(transaction)"); $sql = "select * from runtable as r " . @@ -514,14 +514,13 @@ function DBGiveUpRunAutojudging($contest, $site, $number, $ip="", $ans="") { $t = time(); $b = DBSiteInfo($contest, $site, $c); - if($b["siteautojudge"]=="t") { + if($fromadmin && $b["siteautojudge"]=="t") { if(DBUpdateRunO($contest, $site, $a["usernumber"], $site, $number, 7, $c)==false) { // 7 means contact staff DBExec($c, "rollback work", "DBGiveUpRunAutojudging(rollback auto)"); LOGError("Unable to automatically update a run answer (run=$number, site=$site, ". "contest=$contest, answer='$ans', retval=7)"); return false; } - LOGLevel("Autojudging automatically answered a run (run=$number, site=$site, contest=$contest, retval=7, answer='$ans')", 3); } if($ip=="") { diff --git a/src/private/autojudging.php b/src/private/autojudging.php index 6f913b7..d8580b5 100755 --- a/src/private/autojudging.php +++ b/src/private/autojudging.php @@ -15,33 +15,33 @@ // 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 19/Oct/2015 by cassio@ime.usp.br +// Last modified 29/aug/2017 by cassio@ime.usp.br $ds = DIRECTORY_SEPARATOR; if($ds=="") $ds = "/"; if(is_readable('/etc/boca.conf')) { - $pif=parse_ini_file('/etc/boca.conf'); - $bocadir = trim($pif['bocadir']) . $ds . 'src'; + $pif=parse_ini_file('/etc/boca.conf'); + $bocadir = trim($pif['bocadir']) . $ds . 'src'; } else { - $bocadir = getcwd(); + $bocadir = getcwd(); } if(is_readable($bocadir . $ds . '..' .$ds . 'db.php')) { - require_once($bocadir . $ds . '..' .$ds . 'db.php'); - require_once($bocadir . $ds . '..' .$ds . 'version.php'); + require_once($bocadir . $ds . '..' .$ds . 'db.php'); + require_once($bocadir . $ds . '..' .$ds . 'version.php'); } else { if(is_readable($bocadir . $ds . 'db.php')) { - require_once($bocadir . $ds . 'db.php'); - require_once($bocadir . $ds . 'version.php'); + require_once($bocadir . $ds . 'db.php'); + require_once($bocadir . $ds . 'version.php'); } else { - echo "unable to find db.php"; - exit; + echo "unable to find db.php"; + exit; } } if (getIP()!="UNKNOWN" || php_sapi_name()!=="cli") exit; if(system('test "`id -u`" -eq "0"',$retval)===false || $retval!=0) { - echo "Must be run as root\n"; - exit; + echo "Must be run as root\n"; + exit; } ini_set('memory_limit','600M'); @@ -65,11 +65,11 @@ if(file_exists($ds . 'bocajail' . $tmpdir)) { } if($ds=='/') { - system("find $basdir -user bocajail -delete >/dev/null 2>/dev/null"); - system("find $basdir -user nobody -delete >/dev/null 2>/dev/null"); - system("find $basdir -group users -exec chgrp root '{}' \\; 2>/dev/null"); - system("find $basdir -perm /1002 -type d > /tmp/boca.writabledirs.tmp 2>/dev/null"); - system('chmod 400 /tmp/boca.writabledirs.tmp 2>/dev/null'); + system("find $basdir -user bocajail -delete >/dev/null 2>/dev/null"); + system("find $basdir -user nobody -delete >/dev/null 2>/dev/null"); + system("find $basdir -group users -exec chgrp root '{}' \\; 2>/dev/null"); + system("find $basdir -perm /1002 -type d > /tmp/boca.writabledirs.tmp 2>/dev/null"); + system('chmod 400 /tmp/boca.writabledirs.tmp 2>/dev/null'); } umask(0022); @@ -85,550 +85,549 @@ $prevsleep=0; //$dodebug=1; while(42) { -if(($run = DBGetRunToAutojudging($activecontest["contestnumber"], $ip)) === false) { - if($prevsleep==0) - echo "Nothing to do. Sleeping..."; - else - echo "."; + if(($run = DBGetRunToAutojudging($activecontest["contestnumber"], $ip)) === false) { + if($prevsleep==0) + echo "Nothing to do. Sleeping..."; + else + echo "."; + flush(); + sleep(10); + $prevsleep=1; + continue; + } + if(!isset($dodebug)) { + if(isset($dir)) cleardir($dir); + if(isset($name)) unlink($name); + } + echo "\n"; flush(); - sleep(10); - $prevsleep=1; - continue; -} -if(!isset($dodebug)) { - if(isset($dir)) cleardir($dir); - if(isset($name)) unlink($name); -} -echo "\n"; -flush(); -$prevsleep=0; - -$number=$run["number"]; -$site=$run["site"]; -$contest=$run["contest"]; - -echo "Removing possible files from previous runs\n"; -$dirs=file('/tmp/boca.writabledirs.tmp'); -for($dir=0;$dir<count($dirs);$dir++) { - $dirn=trim($dirs[$dir]) . $ds; - if($dirn[0] != '/') continue; - system("find \"$dirn\" -user bocajail -delete >/dev/null 2>/dev/null"); - system("find \"$dirn\" -user nobody -delete >/dev/null 2>/dev/null"); -} + $prevsleep=0; + + $number=$run["number"]; + $site=$run["site"]; + $contest=$run["contest"]; + + echo "Removing possible files from previous runs\n"; + $dirs=file('/tmp/boca.writabledirs.tmp'); + for($dir=0;$dir<count($dirs);$dir++) { + $dirn=trim($dirs[$dir]) . $ds; + if($dirn[0] != '/') continue; + system("find \"$dirn\" -user bocajail -delete >/dev/null 2>/dev/null"); + system("find \"$dirn\" -user nobody -delete >/dev/null 2>/dev/null"); + } -echo "Entering directory $tmpdir (contest=$contest, site=$site, run=$number)\n"; -chdir($tmpdir); -for($i=0; $i<5; $i++) { - $name = tempnam($tmpdir, "boca"); - $dir = $name . ".d"; - if(@mkdir($dir, 0755)) break; - @unlink($name); - @rmdir($dir); -} -if($i>=5) { - echo "It was not possible to create a unique temporary directory\n"; - LogLevel("Autojudging: Unable to create temp directory (run=$number, site=$site, contest=$contest)",1); - DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem creating temp directory"); - continue; -} -chdir($dir); + echo "Entering directory $tmpdir (contest=$contest, site=$site, run=$number)\n"; + chdir($tmpdir); + for($i=0; $i<5; $i++) { + $name = tempnam($tmpdir, "boca"); + $dir = $name . ".d"; + if(@mkdir($dir, 0755)) break; + @unlink($name); + @rmdir($dir); + } + if($i>=5) { + echo "It was not possible to create a unique temporary directory\n"; + LogLevel("Autojudging: Unable to create temp directory (run=$number, site=$site, contest=$contest)",1); + DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem creating temp directory"); + continue; + } + chdir($dir); -echo "Using directory $dir (contest=$contest, site=$site, run=$number)\n"; + echo "Using directory $dir (contest=$contest, site=$site, run=$number)\n"; -if($run["sourceoid"]=="" || $run["sourcename"]=="") { - LogLevel("Autojudging: Source file not defined (run=$number, site=$site, contest=$contest)",1); - echo "Source file not defined (contest=$contest, site=$site, run=$number)\n"; - DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: source file not defined"); - continue; -} -if($run["inputoid"]=="" || $run["inputname"]=="") { - LogLevel("Autojudging: problem package not defined (run=$number, site=$site, contest=$contest)",1); - echo "Package file not defined (contest=$contest, site=$site, run=$number)\n"; - DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file not defined"); - continue; -} -$c = DBConnect(); -DBExec($c, "begin work", "Autojudging(exporttransaction)"); -if(DB_lo_export($contest,$c, $run["sourceoid"], $dir . $ds . $run["sourcename"]) === false) { - DBExec($c, "rollback work", "Autojudging(rollback-source)"); - LogLevel("Autojudging: Unable to export source file (run=$number, site=$site, contest=$contest)",1); - echo "Error exporting source file ${run["sourcename"]} (contest=$contest, site=$site, run=$number)\n"; - DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: unable to export source file"); - DBExec($c, "commit", "Autojudging(exportcommit)"); - continue; -} -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"; - $s = file_get_contents($cache . $ds . $run["inputoid"] . "." . $run["inputname"]); - file_put_contents($dir . $ds . $run["inputname"], decryptData($s,$key)); - $basename=$basenames[$run['inputoid']. "." . $run["inputname"]]; -} else { - 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)"); - LogLevel("Autojudging: Unable to export problem package file (run=$number, site=$site, contest=$contest)",1); - echo "Error exporting problem package file ${run["inputname"]} (contest=$contest, site=$site, run=$number)\n"; - DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: unable to export problem package file"); - DBExec($c, "commit", "Autojudging(exportcommit)"); - continue; - } - DBExec($c, "commit", "Autojudging(exportcommit)"); - @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"; - $zip = new ZipArchive; - if ($zip->open($dir . $ds . $run["inputname"]) === true) { - $zip->extractTo($dir . $ds . "problemdata"); - $zip->close(); - } else { - 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; - } - 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(isset($info['descfile'])) - $descfile=trim(sanitizeFilename($info['descfile'])); - $basename=trim(sanitizeFilename($info['basename'])); - $fullname=trim(sanitizeText($info['fullname'])); - if($basename=='') { - 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"); - continue; - } - $basenames[$run['inputoid']. "." . $run["inputname"]]=$basename; - if(!is_dir($dir . $ds . "problemdata" . $ds . "limits")) { - 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"); - continue; - } - chdir($dir . $ds . "problemdata" . $ds . "limits"); - $limits[$basename]=array(); - foreach(glob($dir . $ds . "problemdata" . $ds . "limits" .$ds . '*') as $file) { - chmod($file,0700); - $ex = escapeshellcmd($file); - $ex .= " >stdout 2>stderr"; - @unlink('stdout'); - @unlink('stderr'); - echo "Executing INIT SCRIPT " . $ex . " at " . getcwd() . "\n"; - if(system($ex, $retval)===false) $retval=-1; - 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; - } - $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($run["sourceoid"]=="" || $run["sourcename"]=="") { + LogLevel("Autojudging: Source file not defined (run=$number, site=$site, contest=$contest)",1); + echo "Source file not defined (contest=$contest, site=$site, run=$number)\n"; + DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: source file not defined"); + continue; + } + if($run["inputoid"]=="" || $run["inputname"]=="") { + LogLevel("Autojudging: problem package not defined (run=$number, site=$site, contest=$contest)",1); + echo "Package file not defined (contest=$contest, site=$site, run=$number)\n"; + DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file not defined"); + continue; + } + $c = DBConnect(); + DBExec($c, "begin work", "Autojudging(exporttransaction)"); + if(DB_lo_export($contest,$c, $run["sourceoid"], $dir . $ds . $run["sourcename"]) === false) { + DBExec($c, "rollback work", "Autojudging(rollback-source)"); + LogLevel("Autojudging: Unable to export source file (run=$number, site=$site, contest=$contest)",1); + echo "Error exporting source file ${run["sourcename"]} (contest=$contest, site=$site, run=$number)\n"; + DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: unable to export source file"); + DBExec($c, "commit", "Autojudging(exportcommit)"); + continue; + } + 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"; + $s = file_get_contents($cache . $ds . $run["inputoid"] . "." . $run["inputname"]); + file_put_contents($dir . $ds . $run["inputname"], decryptData($s,$key)); + $basename=$basenames[$run['inputoid']. "." . $run["inputname"]]; + } else { + 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)"); + LogLevel("Autojudging: Unable to export problem package file (run=$number, site=$site, contest=$contest)",1); + echo "Error exporting problem package file ${run["inputname"]} (contest=$contest, site=$site, run=$number)\n"; + DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: unable to export problem package file"); + continue; + } + DBExec($c, "commit", "Autojudging(exportcommit)"); + @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"; + $zip = new ZipArchive; + if ($zip->open($dir . $ds . $run["inputname"]) === true) { + $zip->extractTo($dir . $ds . "problemdata"); + $zip->close(); + } else { + 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; + } + 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(isset($info['descfile'])) + $descfile=trim(sanitizeFilename($info['descfile'])); + $basename=trim(sanitizeFilename($info['basename'])); + $fullname=trim(sanitizeText($info['fullname'])); + if($basename=='') { + 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"); + continue; + } + $basenames[$run['inputoid']. "." . $run["inputname"]]=$basename; + if(!is_dir($dir . $ds . "problemdata" . $ds . "limits")) { + 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"); + continue; + } + chdir($dir . $ds . "problemdata" . $ds . "limits"); + $limits[$basename]=array(); + foreach(glob($dir . $ds . "problemdata" . $ds . "limits" .$ds . '*') as $file) { + chmod($file,0700); + $ex = escapeshellcmd($file); + $ex .= " >stdout 2>stderr"; + @unlink('stdout'); + @unlink('stderr'); + echo "Executing INIT SCRIPT " . $ex . " at " . getcwd() . "\n"; + if(system($ex, $retval)===false) $retval=-1; + 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"); - if($cont) - continue; - - $s = file_get_contents($dir . $ds . $run["inputname"]); - file_put_contents($cache . $ds . $run["inputoid"] . "." . $run["inputname"], encryptData($s,$key)); -} - -if(!isset($limits[$basename][$run["extension"]][0]) || !is_numeric($limits[$basename][$run["extension"]][0]) || - !isset($limits[$basename][$run["extension"]][1]) || !is_numeric($limits[$basename][$run["extension"]][1]) || - !isset($limits[$basename][$run["extension"]][2]) || !is_numeric($limits[$basename][$run["extension"]][2]) || - !isset($limits[$basename][$run["extension"]][3]) || !is_numeric($limits[$basename][$run["extension"]][3]) ) { - echo "Failed to find proper limits information for the problem -- please check the problem package\n"; - DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file is invalid (6)"); continue; -} + } + $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; + } + } + cleardir($dir . $ds . "problemdata"); + if($cont) + continue; + + $s = file_get_contents($dir . $ds . $run["inputname"]); + file_put_contents($cache . $ds . $run["inputoid"] . "." . $run["inputname"], encryptData($s,$key)); + } -// COMPILATION -//# parameters are: -//# $1 source_file -//# $2 exe_file (default ../run.exe) -//# $3 timelimit (optional, limit to run all the repetitions, by default only one repetition) -//# $4 maximum allowed memory (in MBytes) - -$zip = new ZipArchive; -if ($zip->open($dir . $ds . $run["inputname"]) === true) { - $zip->extractTo($dir, array("compile" . $ds . $run["extension"])); - $zip->close(); -} else { - echo "Failed to unzip the package file -- please check the problem package\n"; - DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file is invalid (7)"); - continue; -} + if(!isset($limits[$basename][$run["extension"]][0]) || !is_numeric($limits[$basename][$run["extension"]][0]) || + !isset($limits[$basename][$run["extension"]][1]) || !is_numeric($limits[$basename][$run["extension"]][1]) || + !isset($limits[$basename][$run["extension"]][2]) || !is_numeric($limits[$basename][$run["extension"]][2]) || + !isset($limits[$basename][$run["extension"]][3]) || !is_numeric($limits[$basename][$run["extension"]][3]) ) { + echo "Failed to find proper limits information for the problem -- please check the problem package\n"; + DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file is invalid (6)"); + continue; + } -$script = $dir . $ds . 'compile' . $ds . $run["extension"]; -if(!is_file($script)) { - echo "Error (not found) compile script for ".$run["extension"]." -- please check the problem package\n"; - DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: compile script failed (".$run["extension"].")"); - continue; -} + // COMPILATION + //# parameters are: + //# $1 source_file + //# $2 exe_file (default ../run.exe) + //# $3 timelimit (optional, limit to run all the repetitions, by default only one repetition) + //# $4 maximum allowed memory (in MBytes) + + $zip = new ZipArchive; + if ($zip->open($dir . $ds . $run["inputname"]) === true) { + $zip->extractTo($dir, array("compile" . $ds . $run["extension"])); + $zip->close(); + } else { + echo "Failed to unzip the package file -- please check the problem package\n"; + DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file is invalid (7)"); + continue; + } + + $script = $dir . $ds . 'compile' . $ds . $run["extension"]; + if(!is_file($script)) { + echo "Error (not found) compile script for ".$run["extension"]." -- please check the problem package\n"; + DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: compile script failed (".$run["extension"].")"); + continue; + } -chdir($dir); -@unlink('allout'); -system('touch allout'); -@unlink('allerr'); -system('touch allerr'); - -chmod($script, 0700); -$ex = escapeshellcmd($script) ." ". - escapeshellarg($run["sourcename"])." ". - escapeshellarg($basename) . " ". - escapeshellarg(trim($limits[$basename][$run["extension"]][0]))." ". - escapeshellarg(trim($limits[$basename][$run["extension"]][2])); -$ex .= " >stdout 2>stderr"; -@unlink('stdout'); -@unlink('stderr'); -echo "Executing " . $ex . " at " . getcwd() . "\n"; -if(system($ex, $retval)===false) $retval=-1; - -if(is_readable('stdout')) { + chdir($dir); + @unlink('allout'); + system('touch allout'); + @unlink('allerr'); + system('touch allerr'); + + chmod($script, 0700); + $ex = escapeshellcmd($script) ." ". + escapeshellarg($run["sourcename"])." ". + escapeshellarg($basename) . " ". + escapeshellarg(trim($limits[$basename][$run["extension"]][0]))." ". + escapeshellarg(trim($limits[$basename][$run["extension"]][2])); + $ex .= " >stdout 2>stderr"; + @unlink('stdout'); + @unlink('stderr'); + echo "Executing " . $ex . " at " . getcwd() . "\n"; + if(system($ex, $retval)===false) $retval=-1; + + if(is_readable('stdout')) { system('/bin/echo ##### COMPILATION STDOUT: >> allerr'); - system('/bin/cat stdout >> allerr'); -} -if(is_readable('stderr')) { + system('/bin/cat stdout >> allerr'); + } + if(is_readable('stderr')) { system('/bin/echo ##### COMPILATION STDERR: >> allerr'); - system('/bin/cat stderr >> allerr'); -} + system('/bin/cat stderr >> allerr'); + } -if($retval != 0) { - list($retval,$answer) = exitmsg($retval); - $answer = "(WHILE COMPILING) " . $answer; -} else { -//# parameters are: -//# $1 exe_file -//# $2 input_file -//# $3 timelimit (limit to run all the repetitions, by default only one repetition) -//# $4 number_of_repetitions_to_run (optional, can be used for better tuning the timelimit) -//# $5 maximum allowed memory (in MBytes) -//# $6 maximum allowed output size (in KBytes) - - $zip = new ZipArchive; - $inputlist = array(); - $ninputlist = 0; - $outputlist = array(); - $noutputlist = 0; - if ($zip->open($dir . $ds . $run["inputname"]) === true) { - for($i = 0; $i < $zip->numFiles; $i++) { - $filename = $zip->getNameIndex($i); - $pos = strrpos(dirname($filename),"input"); - if($pos !== false && $pos==strlen(dirname($filename))-5) { - $inputlist[$ninputlist++] = 'input' . $ds . basename($filename); - $outputlist[$noutputlist++] = 'output' . $ds . basename($filename,'.link'); - } - } - if($ninputlist == 0) { - echo "WARN: There are NO input files in ZIP package -- should check the problem package?\n"; - DBGiveUpRunAutojudging($contest, $site, $number, $ip, "warning: problem package has no input files"); - continue; - } - $zip->extractTo($dir, array_merge(array("run" . $ds . $run["extension"]),array("compare" . $ds . $run["extension"]),$inputlist,$outputlist)); - $zip->close(); - if(chmod($dir . $ds . 'output', 0700)==false || chown($dir . $ds . 'output','root') == false) { - echo "Failed to chown/chdir the output folder -- please check the system and problem package\n"; - DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: chown/chmod failed for output (99)"); - continue; - } - if(chmod($dir . $ds . 'compare', 0700)==false || chown($dir . $ds . 'compare','root') == false) { - echo "Failed to chown/chdir the output folder -- please check the system and problem package\n"; - DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: chown/chmod failed for output (99)"); - continue; - } - } else { - echo "Failed to unzip the file (inputs) -- please check the problem package\n"; - DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file is invalid (8)"); - continue; - } - $retval = 0; - $script = $dir . $ds . 'run' . $ds . $run["extension"]; - if(!is_file($script)) { - echo "Failed to unzip the run script -- please check the problem package\n"; - DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file is invalid (9)"); - continue; + if($retval != 0) { + list($retval,$answer) = exitmsg($retval); + $answer = "(WHILE COMPILING) " . $answer; + } else { + //# parameters are: + //# $1 exe_file + //# $2 input_file + //# $3 timelimit (limit to run all the repetitions, by default only one repetition) + //# $4 number_of_repetitions_to_run (optional, can be used for better tuning the timelimit) + //# $5 maximum allowed memory (in MBytes) + //# $6 maximum allowed output size (in KBytes) + + $zip = new ZipArchive; + $inputlist = array(); + $ninputlist = 0; + $outputlist = array(); + $noutputlist = 0; + if ($zip->open($dir . $ds . $run["inputname"]) === true) { + for($i = 0; $i < $zip->numFiles; $i++) { + $filename = $zip->getNameIndex($i); + $pos = strrpos(dirname($filename),"input"); + if($pos !== false && $pos==strlen(dirname($filename))-5) { + $inputlist[$ninputlist++] = 'input' . $ds . basename($filename); + $outputlist[$noutputlist++] = 'output' . $ds . basename($filename,'.link'); } - chdir($dir); - chmod($script, 0700); - mkdir('team', 0755); - - $scriptcomp = $dir . $ds . 'compare' . $ds . $run["extension"]; - $answer='(Contact staff) nothing compared yet'; - chmod($scriptcomp, 0700); - - if($ninputlist == 0) { - echo "WARN: There are NO input files in ZIP package -- should check the problem package?\n"; - DBGiveUpRunAutojudging($contest, $site, $number, $ip, "warning: problem package has no input files"); - continue; + } + if($ninputlist == 0) { + echo "WARN: There are NO input files in ZIP package -- should check the problem package?\n"; + DBGiveUpRunAutojudging($contest, $site, $number, $ip, "warning: problem package has no input files"); + continue; + } + $zip->extractTo($dir, array_merge(array("run" . $ds . $run["extension"]),array("compare" . $ds . $run["extension"]),$inputlist,$outputlist)); + $zip->close(); + if(chmod($dir . $ds . 'output', 0700)==false || chown($dir . $ds . 'output','root') == false) { + echo "Failed to chown/chdir the output folder -- please check the system and problem package\n"; + DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: chown/chmod failed for output (99)"); + continue; + } + if(chmod($dir . $ds . 'compare', 0700)==false || chown($dir . $ds . 'compare','root') == false) { + echo "Failed to chown/chdir the output folder -- please check the system and problem package\n"; + DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: chown/chmod failed for output (99)"); + continue; + } + } else { + echo "Failed to unzip the file (inputs) -- please check the problem package\n"; + DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file is invalid (8)"); + continue; + } + $retval = 0; + $script = $dir . $ds . 'run' . $ds . $run["extension"]; + if(!is_file($script)) { + echo "Failed to unzip the run script -- please check the problem package\n"; + DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file is invalid (9)"); + continue; + } + chdir($dir); + chmod($script, 0700); + mkdir('team', 0755); + + $scriptcomp = $dir . $ds . 'compare' . $ds . $run["extension"]; + $answer='(Contact staff) nothing compared yet'; + chmod($scriptcomp, 0700); + + if($ninputlist == 0) { + echo "WARN: There are NO input files in ZIP package -- should check the problem package?\n"; + DBGiveUpRunAutojudging($contest, $site, $number, $ip, "warning: problem package has no input files"); + continue; + } else { + $errp=0; $ncor=0; $showcor=false; + foreach($inputlist as $file) { + $file = basename($file); + if(is_file($dir . $ds . "input" . $ds . $file)) { + $file1=basename($file,'.link'); + if($file != $file1) { + $fnam = trim(file_get_contents($dir . $ds . "input" . $ds . $file)); + echo "Input file $file is a link. Trying to read the linked file: ($fnam)\n"; + if(is_readable($fnam)) { + @unlink($dir . $ds . "input" . $ds . $file); + $file = basename($file,".link"); + @copy($fnam,$dir . $ds . "input" . $ds . $file); + } else { + echo "Failed to read input files from link indicated in the ZIP -- please check the problem package\n"; + DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file is invalid (11) or missing files on the autojudge"); + $errp=1; break; + } + } + + $ex = escapeshellcmd($script) ." ". + escapeshellarg($basename) . " ". + escapeshellarg($dir . $ds . "input" . $ds . $file)." ". + escapeshellarg(trim($limits[$basename][$run["extension"]][0]))." ". + escapeshellarg(trim($limits[$basename][$run["extension"]][1]))." ". + escapeshellarg(trim($limits[$basename][$run["extension"]][2]))." ". + escapeshellarg(trim($limits[$basename][$run["extension"]][3])); + $ex .= " >stdout 2>stderr"; + + chdir($dir); + if(file_exists($dir . $ds . 'tmp')) { + cleardir($dir . $ds . 'tmp'); + } + mkdir($dir . $ds . 'tmp', 0777); + @chown($dir . $ds . 'tmp',"nobody"); + if(is_readable($dir . $ds . $basename)) { + @copy($dir . $ds . $basename, $dir . $ds . 'tmp' . $ds . $basename); + @chown($dir . $ds . 'tmp' . $ds . $basename,"nobody"); + @chmod($dir . $ds . 'tmp' . $ds . $basename,0755); + } + if(is_readable($dir . $ds . 'run.jar')) { + @copy($dir . $ds . 'run.jar', $dir . $ds . 'tmp' . $ds . 'run.jar'); + @chown($dir . $ds . 'tmp' . $ds . 'run.jar',"nobody"); + @chmod($dir . $ds . 'tmp' . $ds . 'run.jar',0755); + } + if(is_readable($dir . $ds . 'run.exe')) { + @copy($dir . $ds . 'run.exe', $dir . $ds . 'tmp' . $ds . 'run.exe'); + @chown($dir . $ds . 'tmp' . $ds . 'run.exe',"nobody"); + @chmod($dir . $ds . 'tmp' . $ds . 'run.exe',0755); + } + chdir($dir . $ds . 'tmp'); + echo "Executing " . $ex . " at " . getcwd() . " for input " . $file . "\n"; + if(system($ex, $localretval)===false) $localretval=-1; + foreach (glob($dir . $ds . 'tmp' . $ds . '*') as $fne) { + @chown($fne,"nobody"); + @chmod($fne,0755); + } + if(is_readable('stderr0')) + system('/bin/cat stderr0 >> stderr'); + system('/bin/echo ##### STDERR FOR FILE ' . escapeshellarg($file) . ' >> ' . $dir . $ds . 'allerr'); + system('/bin/cat stderr >> ' . $dir . $ds . 'allerr'); + system('/bin/cat stdout > ' . $dir . $ds . 'team' . $ds . escapeshellarg($file)); + system('/bin/echo ##### STDOUT FOR FILE ' . escapeshellarg($file) . ' >> ' . $dir . $ds . 'allout'); + system('/bin/cat stdout >> ' . $dir . $ds . 'allout'); + chdir($dir); + if($localretval != 0) { + list($retval,$answer) = exitmsg($localretval); + $answer = "(WHILE RUNNING) " . $answer; + break; + } + if(is_file($dir . $ds . 'output' . $ds . $file)) { + @unlink($dir . $ds . 'compout'); + $ex = escapeshellcmd($scriptcomp) ." ". + escapeshellarg($dir . $ds . "team" . $ds . $file)." ". + escapeshellarg($dir . $ds . "output" . $ds . $file)." ". + escapeshellarg($dir . $ds . "input" . $ds . $file) . " >compout 2>&1"; + echo "Executing " . $ex . " at " . getcwd() . " for output file $file\n"; + if(system($ex, $localretval)===false) + $localretval = -1; + + $fp = fopen($dir . $ds . "allerr", "a+"); + fwrite($fp, "\n\n===OUTPUT OF COMPARING SCRIPT FOLLOWS FOR FILE " .$file ." (EMPTY MEANS NO DIFF)===\n"); + $dif = file($dir . $ds . "compout"); + $difi = 0; + for(; $difi < count($dif)-1 && $difi < 5000; $difi++) + fwrite($fp, $dif[$difi]); + if($difi >= 5000) fwrite($fp, "===OUTPUT OF COMPARING SCRIPT TOO LONG - TRUNCATED===\n"); + else fwrite($fp, "===OUTPUT OF COMPARING SCRIPT ENDS HERE===\n"); + $answertmp = ''; + if(count($dif) > 0) + $answertmp = substr(trim($dif[count($dif)-1]),0,200); + $answertmp = sanitizeText($answertmp); + fclose($fp); + foreach (glob($dir . $ds . '*') as $fne) { + @chown($fne,"nobody"); + @chmod($fne,0755); + } + // retval 5 (presentation) and retval 6 (wronganswer) are already compatible with the compare script + if($localretval < 4 || $localretval > 6) { + // contact staff + $retval = 7; + $answer='(Contact staff)' . $answertmp; + if($showcor) $answertmp .= ' (' . $ncor . '/' . $ninputlist . ' OKs)'; + break; + } + if($localretval == 6) { + $retval=$localretval; + $answer='(Wrong answer)'. $answertmp; + if($showcor) $answertmp .= ' (' . $ncor . '/' . $ninputlist . ' OKs)'; + break; + } + if($localretval == 5) { + $retval=$localretval; + $answer='(Presentation error)'. $answertmp; + if($showcor) $answertmp .= ' (' . $ncor . '/' . $ninputlist . ' OKs)'; + } else { + if($localretval != 4) { + $retval = 7; + $answer='(Contact staff)' . $answertmp; + if($showcor) $answertmp .= ' (' . $ncor . '/' . $ninputlist . ' OKs)'; + break; + } + $ncor++; + if($retval == 0 || $retval == 1) { + // YES! + $answer='(YES)' . $answertmp; + if($showcor) $answertmp .= ' (' . $ncor . '/' . $ninputlist . ' OKs)'; + $retval = 1; + } + } + } else { + echo "==> ERROR reading output file " . $dir . $ds . 'output' . $ds . $file . " - skipping it!\n"; + } + } else { - $errp=0; $ncor=0; $showcor=false; - foreach($inputlist as $file) { - $file = basename($file); - if(is_file($dir . $ds . "input" . $ds . $file)) { - $file1=basename($file,'.link'); - if($file != $file1) { - $fnam = trim(file_get_contents($dir . $ds . "input" . $ds . $file)); - echo "Input file $file is a link. Trying to read the linked file: ($fnam)\n"; - if(is_readable($fnam)) { - @unlink($dir . $ds . "input" . $ds . $file); - $file = basename($file,".link"); - @copy($fnam,$dir . $ds . "input" . $ds . $file); - } else { - echo "Failed to read input files from link indicated in the ZIP -- please check the problem package\n"; - DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file is invalid (11) or missing files on the autojudge"); - $errp=1; break; - } - } - - $ex = escapeshellcmd($script) ." ". - escapeshellarg($basename) . " ". - escapeshellarg($dir . $ds . "input" . $ds . $file)." ". - escapeshellarg(trim($limits[$basename][$run["extension"]][0]))." ". - escapeshellarg(trim($limits[$basename][$run["extension"]][1]))." ". - escapeshellarg(trim($limits[$basename][$run["extension"]][2]))." ". - escapeshellarg(trim($limits[$basename][$run["extension"]][3])); - $ex .= " >stdout 2>stderr"; - - chdir($dir); - if(file_exists($dir . $ds . 'tmp')) { - cleardir($dir . $ds . 'tmp'); - } - mkdir($dir . $ds . 'tmp', 0777); - @chown($dir . $ds . 'tmp',"nobody"); - if(is_readable($dir . $ds . $basename)) { - @copy($dir . $ds . $basename, $dir . $ds . 'tmp' . $ds . $basename); - @chown($dir . $ds . 'tmp' . $ds . $basename,"nobody"); - @chmod($dir . $ds . 'tmp' . $ds . $basename,0755); - } - if(is_readable($dir . $ds . 'run.jar')) { - @copy($dir . $ds . 'run.jar', $dir . $ds . 'tmp' . $ds . 'run.jar'); - @chown($dir . $ds . 'tmp' . $ds . 'run.jar',"nobody"); - @chmod($dir . $ds . 'tmp' . $ds . 'run.jar',0755); - } - if(is_readable($dir . $ds . 'run.exe')) { - @copy($dir . $ds . 'run.exe', $dir . $ds . 'tmp' . $ds . 'run.exe'); - @chown($dir . $ds . 'tmp' . $ds . 'run.exe',"nobody"); - @chmod($dir . $ds . 'tmp' . $ds . 'run.exe',0755); - } - chdir($dir . $ds . 'tmp'); - echo "Executing " . $ex . " at " . getcwd() . " for input " . $file . "\n"; - if(system($ex, $localretval)===false) $localretval=-1; - foreach (glob($dir . $ds . 'tmp' . $ds . '*') as $fne) { - @chown($fne,"nobody"); - @chmod($fne,0755); - } - if(is_readable('stderr0')) - system('/bin/cat stderr0 >> stderr'); - system('/bin/echo ##### STDERR FOR FILE ' . escapeshellarg($file) . ' >> ' . $dir . $ds . 'allerr'); - system('/bin/cat stderr >> ' . $dir . $ds . 'allerr'); - system('/bin/cat stdout > ' . $dir . $ds . 'team' . $ds . escapeshellarg($file)); - system('/bin/echo ##### STDOUT FOR FILE ' . escapeshellarg($file) . ' >> ' . $dir . $ds . 'allout'); - system('/bin/cat stdout >> ' . $dir . $ds . 'allout'); - chdir($dir); - if($localretval != 0) { - list($retval,$answer) = exitmsg($localretval); - $answer = "(WHILE RUNNING) " . $answer; - break; - } - if(is_file($dir . $ds . 'output' . $ds . $file)) { - @unlink($dir . $ds . 'compout'); - $ex = escapeshellcmd($scriptcomp) ." ". - escapeshellarg($dir . $ds . "team" . $ds . $file)." ". - escapeshellarg($dir . $ds . "output" . $ds . $file)." ". - escapeshellarg($dir . $ds . "input" . $ds . $file) . " >compout 2>&1"; - echo "Executing " . $ex . " at " . getcwd() . " for output file $file\n"; - if(system($ex, $localretval)===false) - $localretval = -1; - - $fp = fopen($dir . $ds . "allerr", "a+"); - fwrite($fp, "\n\n===OUTPUT OF COMPARING SCRIPT FOLLOWS FOR FILE " .$file ." (EMPTY MEANS NO DIFF)===\n"); - $dif = file($dir . $ds . "compout"); - $difi = 0; - for(; $difi < count($dif)-1 && $difi < 5000; $difi++) - fwrite($fp, $dif[$difi]); - if($difi >= 5000) fwrite($fp, "===OUTPUT OF COMPARING SCRIPT TOO LONG - TRUNCATED===\n"); - else fwrite($fp, "===OUTPUT OF COMPARING SCRIPT ENDS HERE===\n"); - $answertmp = ''; - if(count($dif) > 0) - $answertmp = substr(trim($dif[count($dif)-1]),0,200); - $answertmp = sanitizeText($answertmp); - fclose($fp); - foreach (glob($dir . $ds . '*') as $fne) { - @chown($fne,"nobody"); - @chmod($fne,0755); - } - // retval 5 (presentation) and retval 6 (wronganswer) are already compatible with the compare script - if($localretval < 4 || $localretval > 6) { - // contact staff - $retval = 7; - $answer='(Contact staff)' . $answertmp; - if($showcor) $answertmp .= ' (' . $ncor . '/' . $ninputlist . ' OKs)'; - break; - } - if($localretval == 6) { - $retval=$localretval; - $answer='(Wrong answer)'. $answertmp; - if($showcor) $answertmp .= ' (' . $ncor . '/' . $ninputlist . ' OKs)'; - break; - } - if($localretval == 5) { - $retval=$localretval; - $answer='(Presentation error)'. $answertmp; - if($showcor) $answertmp .= ' (' . $ncor . '/' . $ninputlist . ' OKs)'; - } else { - if($localretval != 4) { - $retval = 7; - $answer='(Contact staff)' . $answertmp; - if($showcor) $answertmp .= ' (' . $ncor . '/' . $ninputlist . ' OKs)'; - break; - } - $ncor++; - if($retval == 0 || $retval == 1) { - // YES! - $answer='(YES)' . $answertmp; - if($showcor) $answertmp .= ' (' . $ncor . '/' . $ninputlist . ' OKs)'; - $retval = 1; - } - } - } else { - echo "==> ERROR reading output file " . $dir . $ds . 'output' . $ds . $file . " - skipping it!\n"; - } - - } else { - echo "==> ERROR reading input file " . $dir . $ds . "input" . $ds . $file . " - skipping it!\n"; - } - } - if($errp==1) continue; - } -/* - if($retval==0) { - echo "Processing results\n"; - $zip = new ZipArchive; - if ($zip->open($dir . $ds . $run["inputname"]) === true) { - $zip->extractTo($dir, array_merge(array("compare" . $ds . $run["extension"]),$outputlist)); - $zip->close(); - } else { - echo "Failed to unzip the file (outputs) -- please check the problem package\n"; - DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file is invalid (12)"); - continue; - } - $script = $dir . $ds . 'compare' . $ds . $run["extension"]; - $retval = 0; - $answer='(Contact staff) nothing compared yet'; - chmod($script, 0700); - foreach($outputlist as $file) { - $file = basename($file); - if(is_file($dir . $ds . 'output' . $ds . $file)) { - @unlink($dir . $ds . 'compout'); - $ex = escapeshellcmd($script) ." ". - escapeshellarg($dir . $ds . "team" . $ds . $file)." ". - escapeshellarg($dir . $ds . "output" . $ds . $file)." ". - escapeshellarg($dir . $ds . "input" . $ds . $file) . " >compout"; - echo "Executing " . $ex . " at " . getcwd() . " for output file $file\n"; - if(system($ex, $localretval)===false) - $localretval = -1; - - $fp = fopen($dir . $ds . "allerr", "a+"); - fwrite($fp, "\n\n===OUTPUT OF COMPARING SCRIPT FOLLOWS FOR FILE " .$file ." (EMPTY MEANS NO DIFF)===\n"); - $dif = file($dir . $ds . "compout"); - $difi = 0; - for(; $difi < count($dif)-1 && $difi < 5000; $difi++) - fwrite($fp, $dif[$difi]); - if($difi >= 5000) fwrite($fp, "===OUTPUT OF COMPARING SCRIPT TOO LONG - TRUNCATED===\n"); - else fwrite($fp, "===OUTPUT OF COMPARING SCRIPT ENDS HERE===\n"); - $answertmp = trim($dif[count($dif)-1]); - fclose($fp); - foreach (glob($dir . $ds . '*') as $fne) { - @chown($fne,"nobody"); - @chmod($fne,0755); - } - // retval 5 (presentation) and retval 6 (wronganswer) are already compatible with the compare script - if($localretval < 4 || $localretval > 6) { - // contact staff - $retval = 7; - $answer='(Contact staff)' . $answertmp; - break; - } - if($localretval == 6) { - $retval=$localretval; - $answer='(Wrong answer)'. $answertmp; - break; - } - if($localretval == 5) { - $retval=$localretval; - $answer='(Presentation error)'. $answertmp; - } else { - if($localretval != 4) { - $retval = 7; - $answer='(Contact staff)' . $answertmp; - break; - } - if($retval == 0) { - // YES! - $answer='(YES)' . $answertmp; - $retval = 1; - } - } - } else { - echo "==> ERROR reading output file " . $dir . $ds . 'output' . $ds . $file . " - skipping it!\n"; - } - } + echo "==> ERROR reading input file " . $dir . $ds . "input" . $ds . $file . " - skipping it!\n"; } -*/ -} -if($retval >= 7 && $retval <= 9) { - $ans = file("allout"); - $anstmp = substr(trim(escape_string($ans[count($ans)-1])),0,100); - unset($ans); - $answer = "(probably runtime error - unusual code: $retval) " . $anstmp; - // runtime error - $retval = 3; -} -if($retval == 0 || $retval > 9) { - $ans = file("allout"); - $anstmp = substr(trim(escape_string($ans[count($ans)-1])),0,100); - unset($ans); - LogLevel("Autojudging: Script returned unusual code: $retval ($anstmp)". - "(run=$number, site=$site, contest=$contest)",1); - echo "Autojudging script returned unusual code $retval ($anstmp)". - "(contest=$contest, site=$site, run=$number)\n"; - $answer = "(check output files - unusual code: $retval) " . $anstmp; - // contact staff - $retval = 7; -} + } + if($errp==1) continue; + } + /* + if($retval==0) { + echo "Processing results\n"; + $zip = new ZipArchive; + if ($zip->open($dir . $ds . $run["inputname"]) === true) { + $zip->extractTo($dir, array_merge(array("compare" . $ds . $run["extension"]),$outputlist)); + $zip->close(); + } else { + echo "Failed to unzip the file (outputs) -- please check the problem package\n"; + DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file is invalid (12)"); + continue; + } + $script = $dir . $ds . 'compare' . $ds . $run["extension"]; + $retval = 0; + $answer='(Contact staff) nothing compared yet'; + chmod($script, 0700); + foreach($outputlist as $file) { + $file = basename($file); + if(is_file($dir . $ds . 'output' . $ds . $file)) { + @unlink($dir . $ds . 'compout'); + $ex = escapeshellcmd($script) ." ". + escapeshellarg($dir . $ds . "team" . $ds . $file)." ". + escapeshellarg($dir . $ds . "output" . $ds . $file)." ". + escapeshellarg($dir . $ds . "input" . $ds . $file) . " >compout"; + echo "Executing " . $ex . " at " . getcwd() . " for output file $file\n"; + if(system($ex, $localretval)===false) + $localretval = -1; + + $fp = fopen($dir . $ds . "allerr", "a+"); + fwrite($fp, "\n\n===OUTPUT OF COMPARING SCRIPT FOLLOWS FOR FILE " .$file ." (EMPTY MEANS NO DIFF)===\n"); + $dif = file($dir . $ds . "compout"); + $difi = 0; + for(; $difi < count($dif)-1 && $difi < 5000; $difi++) + fwrite($fp, $dif[$difi]); + if($difi >= 5000) fwrite($fp, "===OUTPUT OF COMPARING SCRIPT TOO LONG - TRUNCATED===\n"); + else fwrite($fp, "===OUTPUT OF COMPARING SCRIPT ENDS HERE===\n"); + $answertmp = trim($dif[count($dif)-1]); + fclose($fp); + foreach (glob($dir . $ds . '*') as $fne) { + @chown($fne,"nobody"); + @chmod($fne,0755); + } + // retval 5 (presentation) and retval 6 (wronganswer) are already compatible with the compare script + if($localretval < 4 || $localretval > 6) { + // contact staff + $retval = 7; + $answer='(Contact staff)' . $answertmp; + break; + } + if($localretval == 6) { + $retval=$localretval; + $answer='(Wrong answer)'. $answertmp; + break; + } + if($localretval == 5) { + $retval=$localretval; + $answer='(Presentation error)'. $answertmp; + } else { + if($localretval != 4) { + $retval = 7; + $answer='(Contact staff)' . $answertmp; + break; + } + if($retval == 0) { + // YES! + $answer='(YES)' . $answertmp; + $retval = 1; + } + } + } else { + echo "==> ERROR reading output file " . $dir . $ds . 'output' . $ds . $file . " - skipping it!\n"; + } + } + } + */ + } + if($retval >= 7 && $retval <= 9) { + $ans = file("allout"); + $anstmp = substr(trim(escape_string($ans[count($ans)-1])),0,100); + unset($ans); + $answer = "(probably runtime error - unusual code: $retval) " . $anstmp; + // runtime error + $retval = 3; + } + if($retval == 0 || $retval > 9) { + $ans = file("allout"); + $anstmp = substr(trim(escape_string($ans[count($ans)-1])),0,100); + unset($ans); + LogLevel("Autojudging: Script returned unusual code: $retval ($anstmp)". + "(run=$number, site=$site, contest=$contest)",1); + echo "Autojudging script returned unusual code $retval ($anstmp)". + "(contest=$contest, site=$site, run=$number)\n"; + $answer = "(check output files - unusual code: $retval) " . $anstmp; + // contact staff + $retval = 7; + } -echo "Sending results to server...\n"; -//echo "out==> "; system("tail -n1 ". $dir.$ds.'allout'); -//echo "err==> "; system("tail -n1 ". $dir.$ds.'allerr'); -$answer=substr($answer,0,200); -DBUpdateRunAutojudging($contest, $site, $number, $ip, $answer, $dir.$ds.'allout', $dir.$ds.'allerr', $retval); -LogLevel("Autojudging: answered '$answer' (run=$number, site=$site, contest=$contest)",3); -echo "Autojudging answered '$answer' (contest=$contest, site=$site, run=$number)\n"; + echo "Sending results to server...\n"; + //echo "out==> "; system("tail -n1 ". $dir.$ds.'allout'); + //echo "err==> "; system("tail -n1 ". $dir.$ds.'allerr'); + $answer=substr($answer,0,200); + DBUpdateRunAutojudging($contest, $site, $number, $ip, $answer, $dir.$ds.'allout', $dir.$ds.'allerr', $retval); + LogLevel("Autojudging: answered '$answer' (run=$number, site=$site, contest=$contest)",3); + echo "Autojudging answered '$answer' (contest=$contest, site=$site, run=$number)\n"; } ?> diff --git a/src/staff/header.php b/src/staff/header.php index 1f22259..650489c 100644 --- a/src/staff/header.php +++ b/src/staff/header.php @@ -15,7 +15,7 @@ // 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 05/aug/2012 by cassio@ime.usp.br +// Last modified 29/aug/2017 by cassio@ime.usp.br ob_start(); header ("Expires: " . gmdate("D, d M Y H:i:s") . " GMT"); header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); @@ -67,7 +67,7 @@ echo " <tr>\n"; echo " <td align=center width=\"20%\"><a class=menu style=\"font-weight:bold\" href=task.php>Tasks</a></td>\n"; //echo " <td align=center width=\"20%\"><a class=menu style=\"font-weight:bold\" href=task.php>Tasks ($nr)</a></td>\n"; echo " <td align=center width=\"20%\"><a class=menu style=\"font-weight:bold\" href=score.php>Score</a></td>\n"; -echo " <td align=center width=\"20%\"><a class=menu style=\"font-weight:bold\" href=run.php>Runs</a></td>\n"; +//echo " <td align=center width=\"20%\"><a class=menu style=\"font-weight:bold\" href=run.php>Runs</a></td>\n"; echo " <td align=center width=\"20%\"><a class=menu style=\"font-weight:bold\" href=option.php>Options</a></td>\n"; echo " <td align=center width=\"20%\"><a href=\"#\" class=menu style=\"font-weight:bold\" onClick=\"window.open('report/stat.php', ". diff --git a/src/staff/report/stat.php b/src/staff/report/stat.php index 8a706e4..f93662a 100755 --- a/src/staff/report/stat.php +++ b/src/staff/report/stat.php @@ -15,7 +15,7 @@ // 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 05/aug/2012 by cassio@ime.usp.br +// Last modified 29/aug/2017 by cassio@ime.usp.br require('header.php'); @@ -139,7 +139,9 @@ $str="All Runs by Language"; $str2="Accepted Runs by Language"; reset($d['language']); while (list($keya, $val) = each($d['language'])) { - $val = $d['languageyes'][$keya]; if($val=="") $val=0; + $val=0; + if(isset($d['languageyes'][$keya])) + $val = $d['languageyes'][$keya]; $str2 .= chr(1) . $keya . "(" . $val . ")" . chr(1) . $val; } |