forked from boxysean/ucpccc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
confirm.php
168 lines (140 loc) · 5.25 KB
/
confirm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
include("config.php");
include("common.php");
?>
<html>
<head>
<?php print "<title>$g_pagetitle - Confirmation</title>\n"; ?>
</head>
<body>
<div align="center">
<h1>Submission Confirmation</h1>
</div>
<?php navigation("confirm"); ?>
<hr>
<div align="center">
<?php
// if team is logged in, we get the ID from the session
$team = $_SESSION["teamid"];
$problem = $_POST["problem"];
$language = $_POST["language"];
$source = $_FILES["source"]["name"];
$tempfile = $_FILES["source"]["tmp_name"];
$time = date("h:i");
// authenticate the team
if (isset($_SESSION["teamid"]) && $_SESSION["password"] == $g_teams[$team])
{
if ($source && $language)
{
$tssubmit = $tsstart = $tsend = time();
// get the contest time from the config file
if ($fp = fopen($g_configfile, "r"))
{
flock($fp, LOCK_SH);
// discard title and contact
fgets($fp); fgets($fp);
// next two lines are date and time
$cdate = trim(fgets($fp));
$ctime = trim(fgets($fp));
list($tsstart, $tsend) = contesttime($cdate, $ctime);
fclose($fp);
}
// check contest start and end time
if ($tsstart <= $tssubmit && $tssubmit < $tsend)
{
// create the team directory if necessary
$teamdir = $g_submitpath.$team;
if (!file_exists($teamdir))
{
mkdir($teamdir);
chmod($teamdir, 0770);
// make team "output" and "diff" directories for judge
// mkdir($teamdir . "/output");
// chmod($teamdir . "/output", 0777);
// mkdir($teamdir . "/diff");
// chmod($teamdir . "/diff", 0777);
//system("cp ".$teamdir."/../input/*.in $teamdir");
}
// find the next available filename for this team/problem
$number = 1;
do {
$shortfile = sprintf("P%s_%02d%s", $problem, $number,
$g_extension[$language]);
$teamfile = $teamdir . "/" . $shortfile;
//print "Trying file $teamfile.<br>\n";
$number++;
} while (file_exists($teamfile));
$error = false;
if (move_uploaded_file($tempfile, $teamfile))
{
chmod($teamfile, 0666);
// remember the team's preferred language
$_SESSION["language"] = $language;
// write the submission to log file
if ($fp = fopen($g_submitfile, "a"))
{
flock($fp, LOCK_EX);
$tdelta = intervaltostr($tssubmit - $tsstart);
fputs($fp, "$tdelta,$team,$problem,$language,$shortfile\n");
fclose($fp);
print "<table border=\"0\">\n";
print "<tr align=\"center\"><th colspan=\"2\">We are pleased to confirm your submission:</th></tr>\n";
print "<tr><td>Team:</td><td>$team</td></tr>\n";
print "<tr><td>Problem:</td><td>$problem</td></tr>\n";
print "<tr><td>Language:</td><td>$language</td></tr>\n";
print "<tr><td>Source:</td><td>$source</td></tr>\n";
print "<tr><td>Time:</td><td>$tdelta</td></tr>\n";
print "</table>\n";
print "<p><i>Note: Do not refresh this page unless you intend to submit the same file again!</i></p>\n";
// log the submitter's ip, for security tracking
if ($g_logIPs && ($gp = fopen($g_iplogfile, "a")))
{
flock($gp, LOCK_EX);
$ip=$_SERVER['REMOTE_ADDR'];
fputs($gp, "$tdelta,$team,$problem,$language,$shortfile;$ip\n");
fclose($gp);
}
}
else
{
$error = true;
}
}
// couldn't move the uploaded file for some reason?
else
{
$error = true;
}
if ($error)
{
print "<p>Something bad happened, and I don't know what.<br>\n";
print "Please try your submission again.</p>\n";
}
}
// submission out of time range
else
{
print "<p>Sorry $team, the contest is not running!</p>\n";
}
}
else
{
print "<p>Sorry $team, you must have screwed something up!<br>\n";
if ($language)
print "(Check that you selected the right source file.)<br>\n";
else
print "(Make sure you select the right langauge.)<br>\n";
print "<p>Unable to confirm your submission.</p>\n";
}
}
// authentication failed!
else
{
print "<p><i>You must be logged in to submit and view runs.</i></p>\n";
print "<p>Unable to confirm your submission.</p>\n";
}
?>
</div>
<?php footer(); ?>
</body>
</html>