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();
function DBGetFullProblemData($contestnumber, $freeproblems = false) { $c = DBConnect(); DBExec($c, "begin work", "GetFullProblemData"); $r = DBExec($c, "select p.problemnumber as number, p.problemname as name, p.problemfullname as fullname, " . "p.problembasefilename as basefilename, p.fake as fake, " . "p.problemcolor as color, p.problemcolorname as colorname, " . "p.probleminputfilename as inputfilename, p.probleminputfile as inputoid, p.probleminputfilehash as inputhash " . " from problemtable as p " . "where p.contestnumber={$contestnumber} order by p.problemnumber", "DBGetFullProblemData(get problem)"); // and p.problemfullname !~ '(DEL)' $n = DBnlines($r); if ($n == 0) { LOGLevel("No problems defined in the database ({$contestnumber})", 1); } $cf = globalconf(); $a = array(); $ds = DIRECTORY_SEPARATOR; if ($ds == "") { $ds = "/"; } for ($i = 0; $i < $n; $i++) { $a[$i] = array_merge(array(), DBRow($r, $i)); if (strpos($a[$i]['fullname'], '(DEL)') !== false) { continue; } $nn = $a[$i]['number']; $ptmp = $_SESSION["locr"] . $ds . "private" . $ds . "problemtmp" . $ds . "contest" . $contestnumber . "-problem" . $nn; $ck = myshorthash(''); if (is_readable($ptmp . ".hash")) { $ck = trim(file_get_contents($ptmp . ".hash")); } if ($ck != $a[$i]['inputhash']) { @unlink($ptmp . ".name"); @unlink($ptmp . ".hash"); $a[$i]['basefilename'] = ''; $a[$i]['descfilename'] = ''; $a[$i]['fullname'] = ''; } if ($freeproblems && $a[$i]['fake'] != 't') { if (is_readable($ptmp . ".name")) { $a[$i]['descfilename'] = trim(file_get_contents($ptmp . ".name")); if ($a[$i]['descfilename'] != '') { $a[$i]['descoid'] = -1; } } else { @unlink($ptmp . ".name"); @unlink($ptmp . ".hash"); $randnum = session_id() . "_" . rand(); $dir = $ptmp . '-' . $randnum; @mkdir($dir, 0770, true); $failed = 0; if (($ret = DB_lo_export($contestnumber, $c, $a[$i]["inputoid"], $dir . $ds . "tmp.zip")) === false) { LogError("FreeProblems: Unable to read problem package from database (problem={$nn}, contest={$contestnumber})"); $failed = 1; } if (!$failed) { $zip = new ZipArchive(); if ($zip->open($dir . $ds . "tmp.zip") === true) { $zip->extractTo($dir); $zip->close(); if (($info = @parse_ini_file($dir . $ds . "description" . $ds . 'problem.info')) === false) { $failed = 2; } if (!$failed) { $descfile = ''; if (isset($info['descfile'])) { $descfile = trim(sanitizeText($info['descfile'])); } $basename = trim(sanitizeText($info['basename'])); $fullname = trim(sanitizeText($info['fullname'])); if ($basename == '' || $fullname == '') { $failed = 3; } } } else { $failed = 4; } if (!$failed) { @mkdir($ptmp); if ($descfile != '') { if (file_put_contents($ptmp . $ds . $descfile, encryptData(file_get_contents($dir . $ds . "description" . $ds . $descfile), $cf['key']), LOCK_EX) === FALSE) { $failed = 5; } if (!$failed) { file_put_contents($ptmp . ".name", $ptmp . $ds . $descfile); file_put_contents($ptmp . ".hash", $a[$i]['inputhash']); if (is_readable($ptmp . ".name")) { $a[$i]['descfilename'] = trim(file_get_contents($ptmp . ".name")); if ($a[$i]['descfilename'] != '') { $a[$i]['descoid'] = -1; } } } } else { @unlink($ptmp . ".name"); @unlink($ptmp . ".hash"); } if (!$failed) { DBExec($c, "update problemtable set problemfullname='{$fullname}', problembasefilename='{$basename}' where problemnumber={$nn} and contestnumber={$contestnumber}", "DBGetFullProblemData(free problem)"); $a[$i]['basefilename'] = $basename; $a[$i]['fullname'] = $fullname; } } } if ($failed) { $a[$i]['basefilename'] = ''; $a[$i]['descfilename'] = ''; @unlink($ptmp . ".name"); @unlink($ptmp . ".hash"); DBExec($c, "update problemtable set problemfullname='', problembasefilename='' where problemnumber={$nn} and contestnumber={$contestnumber}", "DBGetFullProblemData(unfree problem)"); if ($failed != 4) { LogError("Failed to unzip problem package (failcode={$failed}, problem={$nn}, contest={$contestnumber})"); if ($failed == 1) { $a[$i]['fullname'] = '(ERROR READING FROM DATABASE, OR DIRECTORY PERMISSION PROBLEM)'; } else { $a[$i]['fullname'] = '(PROBLEM PACKAGE SEEMS INVALID)'; } } else { if ($ret == 1) { $a[$i]['fullname'] = '(PROBABLY ENCRYPTED FILE)'; } if ($ret == 2) { $a[$i]['fullname'] = '(FILE IS NOT A ZIP)'; } } } cleardir($dir, false, true); } } } DBExec($c, "commit", "GetFullProblemData"); return $a; }