-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompilare.php
More file actions
226 lines (202 loc) · 6.33 KB
/
compilare.php
File metadata and controls
226 lines (202 loc) · 6.33 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?php
#Folosim config.php
if (!isset($_SESSION)) {
session_start();
}
include __DIR__."/config.php";
include __DIR__."/navbar.php";
ini_set('display_errors', 0);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
?>
<html>
<head>
<link rel="stylesheet" href=<?php echo "$root2/style.css";?>>
<style>
select, textarea {
width: 100%;
resize: vertical;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
table {
border-collapse: collapse;
}
hr {
width: 100%;
}
#box {
width: 100%;
}
textarea {
height: 300px;
}
</style>
</head>
<body>
<?php
$title = 'Problema '.$bpwd;
echo "<h2>$title</h2><title>$title - RezProbleme</title>";
?>
<!--Cutia de text in care se trimite codul-->
<div id="box">
<b>Cerinta</b>
<div id="box_text">
<?php echo file_get_contents('cerinta.html'); ?>
</div>
</div>
<br />
<div id="box">
<b>Solutii trimise</b>
<div id="box_text">
<?php
$solutii = scandir("sol");
#Ordine numerica, nu lexicografica.
natsort($solutii);
#Mai intai primele solutii...
$solutii = array_reverse($solutii);
#Scadem fisierele/folderele: ".", "..", "num.txt", "date" si "corecte".
$oo = count($solutii) - 5;
$i = 0;
foreach($solutii as $solutie) {
if (!is_dir('sol/'.$solutie) && $solutie != 'num.txt') {
++$i;
$linie = file('sol/'.$solutie)[0];
echo "<a href=\"sol/$solutie\">".$solutie."</a><b> $linie</b>".'<br />';
#Am ajuns la ultima solutie?
if ($i < $oo)
echo '<hr />';
#Nu mai afisam <hr>!
}
}
#Lista tuturor solutiilor
?>
</div>
</div>
<br />
<div id="box">
<!--Titlul "ferestrei"-->
<b>Incarcare solutie</b>
<form method="post" name="cod">
<textarea name="solutie"></textarea>
<select method="post" name="lang">
<option value="cpp">C++</option>
<option value="c">C</option>
<option value="d">D</option>
<option value="py">Python</option>
<option value="bvm">BCCVM - Limbaj custom</option>
</select>
<br />
<button type="submit" class="button">Trimite!</input>
</form>
</div>
<br />
<div id="box" style="width:fit-content;
min-width:100px">
<b>I/O Standard</b><div id="box_text"><table border="1px solid">
<?php
#Fallback C++
$COMPILATOR = $_SERVER['cxx'];
$EXTENSIE = '.cpp';
#Alegem limbajul care va fi utilizat.
if (isset($_POST['lang'])) {
$num = file_get_contents('sol/num.txt');
++$num;
file_put_contents('sol/num.txt', @$num);
#Copie $num pt a fi folosit cu extensie.
$fn = $num;
#Limbajele/compilatoarele sunt definite in CONFIG.PHP !!
$INTERP = "";
$COMM = "//";
switch($_POST['lang']) {
case 'c':
$COMPILATOR = $_SERVER['cc'].' -o '.$fn;
$EXTENSIE = '.c';
break;
case 'cpp':
$COMPILATOR = $_SERVER['cxx'].' -o '.$fn;
$EXTENSIE = '.cpp';
break;
case 'd':
$COMPILATOR = $_SERVER['dc'].' -of='.$fn;
$EXTENSIE = '.d';
break;
case 'py':
$INTERP = "python";
$COMM = "#";
$EXTENSIE = '.py';
break;
case 'bvm':
$INTERP = "../../../eso/bccvm";
$COMM = ';;';
$EXTENSIE = '.bvm';
break;
}
$fn = './' . $fn;
#Mergem in directorul de solutii pt. problema.
mkdir('sol');
chdir('sol');
#Compilam pe server...
if ($INTERP != "") {
$fn = $fn.$EXTENSIE;
file_put_contents($fn, $_POST['solutie']);
} else {
file_put_contents($num.$EXTENSIE, $_POST['solutie']);
shell_exec($COMPILATOR.' '.$num.$EXTENSIE);
}
$date = scandir("date");
#Punctajul este un string definit ca "$corecte/$totale".
$corecte = 0;
$totale = 0;
if ($date) {
foreach ($date as $io) {
if (!is_dir($io)) {
$continut = file_get_contents('date/'.$io);
$corect = trim(file_get_contents('corect/'.$io));
#Stergem spatiile albe.
preg_replace('/[0-9][A-z] .', '', $corect);
echo '<tr>
<td>'.
htmlspecialchars($continut).
'</td>
<td>'.
htmlspecialchars($corect).
'</td>
<td>';
$timpInceput = floor(microtime(true) * 100);
/* comanda care va fi filtrata */
$command = $fn;
if ($INTERP != "")
$command = $INTERP.' '.$fn;
#Executam dintr-un pipe, in "wrap" (pentru a evita executarea de cod arbitrar).
$rez = trim(shell_exec('echo "'.$continut.'"|'.$root.'/wrap '.$command));
$timpFinal = floor(microtime(true) * 100) - $timpInceput;
echo htmlspecialchars($rez).'</td><td>';
++$totale;
if (!strcmp($rez, $corect) && $timpFinal <= 107) {
++$corecte;
echo '✅';
} else echo '❌';
echo '~'.$timpFinal.'ms</td></tr>';
#Afisam borderoul de evaluare.
}
}
}
if ($INTERP == "") {
#Stergem binarele rezultate dupa compilare.
unlink($fn);
}
$var = file_get_contents($num.$EXTENSIE);
$var = $COMM.' '.$corecte.'/'.$totale.', '.$_SESSION["nume"].PHP_EOL.$var;
file_put_contents($num.$EXTENSIE, $var);
#Adaugam rezolvarea la lista de pe profil
if ($_SESSION["nume"] != "Anonim")
symlink("../../../comp/".basename(realpath(".."))."/sol/$num$EXTENSIE",
"../../../profile/".$_SESSION["nume"]."/sol/$bpwd-$num$EXTENSIE");
#Ne intoarcem de unde am plecat.
chdir('..');
}
?>
</table></div></div>
</body>
</html>