-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.php
62 lines (58 loc) · 1.29 KB
/
compile.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
<?php
include 'path.php';
$CC="g++";
$out="a.exe";
$code=rawurldecode($_POST["code"]);
$input=rawurldecode($_POST["input"]); // we use raw decoding in order to save our plus signs, which would be converted to spaces with usual decoding
$filename_code="main.cpp";
$filename_in="input.txt";
$filename_error="error.txt";
$executable="a.exe";
$command=$CC." -lm ".$filename_code;
$command_error=$command." 2>".$filename_error;
$file_code=fopen($filename_code,"w+");
fwrite($file_code,$code);
fclose($file_code);
$file_in=fopen($filename_in,"w+");
fwrite($file_in,$input);
fclose($file_in);
exec("cacls $executable /g everyone:f");
exec("cacls $filename_error /g everyone:f");
shell_exec($command_error);
$error=file_get_contents($filename_error);
if(trim($error)=="")
{
if(trim($input)=="")
{
$output=shell_exec($out);
}
else
{
$out=$out." < ".$filename_in;
$output=shell_exec($out);
}
echo "$output";
}
else if(!strpos($error,"error"))
{
echo "<pre>$error</pre>";
if(trim($input) == "")
{
$output = shell_exec($out);
}
else
{
$out = $out." < ".$filename_in;
$output = shell_exec($out);
}
echo "$output";
}
else
{
echo "<pre>$error</pre>";
}
exec("del $filename_code");
exec("del *.o");
exec("del *.txt");
exec("del $executable");
?>