Skip to content

Commit 66882bc

Browse files
committed
add README file
1 parent e7caef7 commit 66882bc

File tree

5 files changed

+66
-30
lines changed

5 files changed

+66
-30
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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

api.php

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,28 @@
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
176
do{
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?
3220
if( !mkdir($uritoken) ){
3321
echo '{"status": "file-error"}';
3422
return;
3523
}
3624

25+
/*Language supported: c and python*/
3726
if($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
5444
exec($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

6855
if( file_exists($uritoken."output") )
6956
unlink($uritoken."output");

geraterandompath.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+

output

Lines changed: 0 additions & 6 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)