Skip to content

Commit e7caef7

Browse files
committed
update project structure
1 parent 2accc94 commit e7caef7

File tree

5 files changed

+64
-25
lines changed

5 files changed

+64
-25
lines changed

AAA/code.c

Lines changed: 0 additions & 2 deletions
This file was deleted.

AAA/file.exe

-128 KB
Binary file not shown.

api.php

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,83 @@
11
<?php
22

3-
$token = "AAA";//$_POST["idtoken"];
3+
function generateRandomString($length = 10) {
4+
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
5+
6+
$charactersLength = strlen($characters);
7+
8+
$randomString = '';
9+
10+
for ($i = 0; $i < $length; $i++) {
11+
$randomString .= $characters[rand(0, $charactersLength - 1)];
12+
}
13+
14+
return $randomString;
15+
}
16+
17+
do{
18+
$token = "files_exec/".generateRandomString();
19+
20+
}while( is_dir($token) );
21+
22+
23+
//$_POST["idtoken"];
424
$code = $_POST['code'];
25+
$lang = isset($_POST['lang'])?$_POST['lang']:"c";
26+
527
//Creating folder
628
$uritoken= $token."/";
729

8-
unlink($uritoken."code.c");
9-
unlink($uritoken."file.exe");
10-
rmdir($token);
1130

1231

1332
if( !mkdir($uritoken) ){
1433
echo '{"status": "file-error"}';
1534
return;
1635
}
1736

37+
if($lang == "c"){
38+
39+
$namefile =$uritoken."code.c";
40+
$myfile = fopen($namefile, "w");
41+
fwrite($myfile, $code);
42+
fclose($myfile);
43+
$cmd = "gcc ".$namefile." -o ".$uritoken."file.exe 2> ".$uritoken."output";
1844

19-
$namefile =$uritoken."code.c";
20-
$myfile = fopen($namefile, "w");
21-
22-
fwrite($myfile, $code);
45+
}else if($lang == "py"){
46+
47+
$namefile =$uritoken."code.py";
48+
$myfile = fopen($namefile, "w");
49+
fwrite($myfile, $code);
50+
fclose($myfile);
51+
$cmd = "python ".$namefile;
52+
}
2353

24-
$cmd = "gcc ".$namefile." -o ".$uritoken."file.exe 2> output";
2554
exec($cmd, $result, $error);
2655

2756
if($error){
2857

2958
echo '{"status": "error"}';
30-
return;
59+
//return;
3160
}else{
3261

3362
echo '{"status": "noerror"}';
34-
return;
63+
//return;
3564
}
3665

66+
sleep(1);
67+
68+
if( file_exists($uritoken."output") )
69+
unlink($uritoken."output");
70+
71+
if( file_exists($uritoken."code.c") )
72+
unlink($uritoken."code.c");
73+
74+
if( file_exists($uritoken."code.py"))
75+
unlink($uritoken."code.py");
76+
77+
if( file_exists($uritoken."file.exe"))
78+
unlink($uritoken."file.exe");
79+
if(is_dir($token))
80+
rmdir($token);
3781

3882

3983
?>

index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
data: {code: "#include<stdio.h>\nint main(){ printf('teste');}"},
1010
//data: {code: "teste"},
1111
success: function(data) {
12-
13-
var json = JSON.parse(data);
14-
console.log(json);
12+
console.log(data);
13+
//var json = JSON.parse(data);
14+
//console.log(json);
1515

1616
},
1717

output

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
AAA/code.c: In function 'main':
2-
AAA/code.c:2:20: warning: character constant too long for its type
3-
int main(){ printf('teste');}
4-
^
5-
AAA/code.c:2:20: warning: passing argument 1 of 'printf' makes pointer from integer without a cast
6-
In file included from AAA/code.c:1:0:
7-
C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include/stdio.h:378:15: note: expected 'const char * __restrict__' but argument is of type 'int'
8-
int __cdecl printf(const char * __restrict__ _Format,...);
9-
^
1+
0lQSPhEvnV/code.c: In function 'main':
2+
0lQSPhEvnV/code.c:2:19: warning: character constant too long for its type
3+
int main(){ print('teste');}
4+
^
5+
C:\Users\hiper\AppData\Local\Temp\ccPh40Dn.o:code.c:(.text+0x13): undefined reference to `print'
6+
collect2.exe: error: ld returned 1 exit status

0 commit comments

Comments
 (0)