2016-07-18 16:39:37 +00:00
|
|
|
<?php
|
|
|
|
requirePHPLib('judger');
|
2022-03-17 04:00:03 +00:00
|
|
|
|
2022-10-07 09:29:26 +00:00
|
|
|
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
2022-10-06 12:28:43 +00:00
|
|
|
redirectToLogin();
|
2022-03-17 04:00:03 +00:00
|
|
|
}
|
|
|
|
|
2022-10-07 09:29:26 +00:00
|
|
|
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login'] && $_GET['type'] != 'attachment') {
|
2022-04-03 10:18:17 +00:00
|
|
|
become403Page();
|
|
|
|
}
|
|
|
|
|
2016-07-18 16:39:37 +00:00
|
|
|
switch ($_GET['type']) {
|
2022-09-20 05:10:25 +00:00
|
|
|
case 'attachment':
|
2016-07-18 16:39:37 +00:00
|
|
|
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
|
|
|
|
become404Page();
|
|
|
|
}
|
|
|
|
|
|
|
|
$visible = isProblemVisibleToUser($problem, $myUser);
|
|
|
|
if (!$visible && $myUser != null) {
|
2017-11-25 15:29:18 +00:00
|
|
|
$result = DB::query("select contest_id from contests_problems where problem_id = {$_GET['id']}");
|
|
|
|
while (list($contest_id) = DB::fetch($result, MYSQLI_NUM)) {
|
2016-07-18 16:39:37 +00:00
|
|
|
$contest = queryContest($contest_id);
|
|
|
|
genMoreContestInfo($contest);
|
|
|
|
if ($contest['cur_progress'] != CONTEST_NOT_STARTED && hasRegistered($myUser, $contest) && queryContestProblemRank($contest, $problem)) {
|
|
|
|
$visible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$visible) {
|
|
|
|
become404Page();
|
|
|
|
}
|
|
|
|
|
|
|
|
$id = $_GET['id'];
|
|
|
|
|
|
|
|
$file_name = "/var/uoj_data/$id/download.zip";
|
2022-09-20 05:10:25 +00:00
|
|
|
$download_name = "problem_{$id}_attachment.zip";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'problem':
|
|
|
|
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
|
|
|
|
become404Page();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isProblemVisibleToUser($problem, $myUser)) {
|
|
|
|
become404Page();
|
|
|
|
}
|
|
|
|
|
|
|
|
$id = $_GET['id'];
|
|
|
|
$file_name = "/var/uoj_data/$id.zip";
|
2016-07-18 16:39:37 +00:00
|
|
|
$download_name = "problem_$id.zip";
|
2022-09-20 05:10:25 +00:00
|
|
|
|
2016-07-18 16:39:37 +00:00
|
|
|
break;
|
2022-09-20 05:10:25 +00:00
|
|
|
|
|
|
|
case 'testcase':
|
|
|
|
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
|
|
|
|
become404Page();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isProblemVisibleToUser($problem, $myUser)) {
|
|
|
|
become404Page();
|
|
|
|
}
|
|
|
|
|
|
|
|
$id = $_GET['id'];
|
|
|
|
$problem_conf = getUOJConf("/var/uoj_data/$id/problem.conf");
|
|
|
|
|
|
|
|
if ($problem_conf == -1 || $problem_conf == -2) {
|
|
|
|
become404Page();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validateUInt($_GET['testcase_id'])) {
|
|
|
|
become404Page();
|
|
|
|
}
|
|
|
|
|
|
|
|
$testcase_id = $_GET['testcase_id'];
|
|
|
|
$testcase_group = isset($_GET['testcase_group']) && $_GET['testcase_group'] == 'extra' ? 'extra' : 'normal';
|
|
|
|
|
|
|
|
if ($testcase_group == 'extra') {
|
|
|
|
$n_ex_tests = getUOJConfVal($problem_conf, 'n_ex_tests', 0);
|
|
|
|
|
|
|
|
if ($testcase_id < 1 || $testcase_id > $n_ex_tests) {
|
|
|
|
become404Page();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($_GET['testcase_type']) {
|
|
|
|
case 'input':
|
|
|
|
$file_name = "/var/uoj_data/$id/" . getUOJProblemExtraInputFileName($problem_conf, $testcase_id);
|
|
|
|
$download_name = getUOJProblemExtraInputFileName($problem_conf, $testcase_id);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'output':
|
|
|
|
$file_name = "/var/uoj_data/$id/" . getUOJProblemExtraOutputFileName($problem_conf, $testcase_id);
|
|
|
|
$download_name = getUOJProblemExtraOutputFileName($problem_conf, $testcase_id);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
become404Page();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$n_tests = getUOJConfVal($problem_conf, 'n_tests', 10);
|
|
|
|
|
|
|
|
if ($testcase_id < 1 || $testcase_id > $n_tests) {
|
|
|
|
become404Page();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($_GET['testcase_type']) {
|
|
|
|
case 'input':
|
|
|
|
$file_name = "/var/uoj_data/$id/" . getUOJProblemInputFileName($problem_conf, $testcase_id);
|
|
|
|
$download_name = getUOJProblemInputFileName($problem_conf, $testcase_id);
|
|
|
|
break;
|
|
|
|
case 'output':
|
|
|
|
$file_name = "/var/uoj_data/$id/" . getUOJProblemOutputFileName($problem_conf, $testcase_id);
|
|
|
|
$download_name = getUOJProblemOutputFileName($problem_conf, $testcase_id);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
become404Page();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2016-07-18 16:39:37 +00:00
|
|
|
case 'testlib.h':
|
2019-07-16 02:43:02 +00:00
|
|
|
$file_name = "/opt/uoj/judger/uoj_judger/include/testlib.h";
|
2016-07-18 16:39:37 +00:00
|
|
|
$download_name = "testlib.h";
|
|
|
|
break;
|
2022-09-20 05:10:25 +00:00
|
|
|
|
2016-07-18 16:39:37 +00:00
|
|
|
default:
|
|
|
|
become404Page();
|
|
|
|
}
|
|
|
|
|
|
|
|
$finfo = finfo_open(FILEINFO_MIME);
|
|
|
|
$mimetype = finfo_file($finfo, $file_name);
|
|
|
|
if ($mimetype === false) {
|
|
|
|
become404Page();
|
|
|
|
}
|
|
|
|
finfo_close($finfo);
|
|
|
|
|
|
|
|
header("X-Sendfile: $file_name");
|
|
|
|
header("Content-type: $mimetype");
|
|
|
|
header("Content-Disposition: attachment; filename=$download_name");
|
2022-09-18 04:58:35 +00:00
|
|
|
?>
|