File tree Expand file tree Collapse file tree 5 files changed +66
-30
lines changed
Expand file tree Collapse file tree 5 files changed +66
-30
lines changed Original file line number Diff line number Diff line change 1+ #API Execute Code
2+
3+ API to execute code and return whether code result in error ou success.
4+
5+ ** request**
6+
7+ - Method: POST.
8+ - Params: code, lang.
9+
10+
11+ ** return:**
12+
13+ ``` json
14+
15+ {"status" : " error" };
16+
17+ ```
18+
19+ ``` json
20+
21+ {"status" : " noerror" }
22+
23+ ```
24+
25+
26+ ** Language supported**
27+
28+ - C
29+
30+ - Python
31+
32+ ** Requirements**
33+
34+ Interpreter or Compiler of languages.
35+
36+
37+ ** Examples**
38+
39+ Look sample.html
Original file line number Diff line number Diff line change 11<?php
22
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- }
3+ include "geraterandompath.php " ;
164
5+ //get a valid path
176do {
187 $ token = "files_exec/ " .generateRandomString ();
198
209}while ( is_dir ($ token ) );
2110
22-
23- //$_POST["idtoken"];
11+ //code sended
2412$ code = $ _POST ['code ' ];
13+ //lang of code
2514$ lang = isset ($ _POST ['lang ' ])?$ _POST ['lang ' ]:"c " ;
2615
27- //Creating folder
16+ //creating folders
2817$ uritoken = $ token ."/ " ;
2918
30-
31-
19+ //has dir?
3220if ( !mkdir ($ uritoken ) ){
3321 echo '{"status": "file-error"} ' ;
3422 return ;
3523}
3624
25+ /*Language supported: c and python*/
3726if ($ lang == "c " ){
3827
3928 $ namefile =$ uritoken ."code.c " ;
@@ -51,19 +40,17 @@ function generateRandomString($length = 10) {
5140 $ cmd = "python " .$ namefile ;
5241}
5342
43+ //executing code
5444exec ($ cmd , $ result , $ error );
5545
56- if ( $ error){
57-
46+ //has a error?
47+ if ( $ error ){
5848 echo '{"status": "error"} ' ;
59- //return;
6049}else {
61-
6250 echo '{"status": "noerror"} ' ;
63- //return;
6451}
6552
66- sleep ( 1 );
53+ //delete all file gerate
6754
6855if ( file_exists ($ uritoken ."output " ) )
6956 unlink ($ uritoken ."output " );
Original file line number Diff line number Diff line change 1+ <?php
2+
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+
Load Diff This file was deleted.
File renamed without changes.
You can’t perform that action at this time.
0 commit comments