-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
48 lines (36 loc) · 874 Bytes
/
index.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
<?php
include 'vendor/autoload.php';
function json($value)
{
header('Content-Type: application/json');
die(json_encode($value));
}
function error($message) {
json([
'status' => 'error',
'message' => $message
]);
}
chdir(sys_get_temp_dir());
$gpx = trim($_POST['gpx']);
if (empty($gpx)) {
error("No GPX input provided!");
}
$speed = trim($_POST['speed'] ?? '');
if (empty($speed)) {
$speed = 5;
}
if (!is_numeric($speed)) {
error("Invalid speed given.");
}
$reverse = (isset($_POST['reverse']) && $_POST['reverse'] == 'true') ? '--reverse' : '';
file_put_contents('input.gpx', $gpx);
$command = 'gips.rb --speed '.$speed.' '.$reverse.' input.gpx output.gpx';
exec($command);
$output = file_get_contents('output.gpx');
unlink('output.gpx');
unlink('input.gpx');
json([
'status' => 'success',
'gpx' => $output
]);