-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
39 lines (39 loc) · 1.25 KB
/
api.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
<?php
// $_GET is the array of the GET request received from the client
if($_GET["mode"] == "size") {
try {
$size = shell_exec("/var/www/html/tiripode/venv/bin/python /var/www/html/tiripode/query.py --" . $_GET['mode'] . " 2>&1");
header('Content-type:application/json;charset=utf-8');
echo("$size");
}
catch (exception $e) {
echo("$e");
}
}
elseif($_GET["mode"] == "parse") {
try {
// TODO sanitise with [a-z0-9]
$parse = shell_exec("/var/www/html/tiripode/venv/bin/python /var/www/html/tiripode/query.py --parse " . $_GET['word'] . " 2>&1");
header('Content-type:application/json;charset=utf-8');
echo("$parse");
}
catch (exception $e) {
echo("$e");
}
}
elseif($_GET["mode"] == "lookup") {
try {
// TODO sanitise with [a-z0-9]
$lookup = shell_exec("/var/www/html/tiripode/venv/bin/python /var/www/html/tiripode/query.py --lookup " . $_GET['word'] . " 2>&1");
header('Content-type:application/json;charset=utf-8');
echo("$lookup");
}
catch (exception $e) {
echo("$e");
}
}
else{
$error = "{\"error\": \"please choose mode=size/parse\"}";
header('Content-type:application/json;charset=utf-8');
echo("$error");
}