commit | author | age
|
896879
|
1 |
<?php |
JK |
2 |
$base_proxy = 'http://www.ttss.krakow.pl/internetservice/services'; |
|
3 |
$method = [ |
|
4 |
'/lookup/autocomplete/json' => [ |
|
5 |
'query' => function() { return TRUE; }, |
|
6 |
], |
|
7 |
'/passageInfo/stopPassages/stop' => [ |
|
8 |
'stop' => 'ctype_alnum', |
|
9 |
'mode' => function($mode) { return in_array($mode, ['arrival', 'departure']); }, |
|
10 |
], |
|
11 |
'/routeInfo/routeStops' => [ |
|
12 |
'routeId' => 'ctype_alnum' |
|
13 |
], |
|
14 |
]; |
|
15 |
|
|
16 |
$path = $_SERVER['PATH_INFO']; |
|
17 |
|
|
18 |
if(!isset($method[$path])) { |
|
19 |
header('HTTP/1.1 403 Forbidden'); |
|
20 |
die('Forbidden'); |
|
21 |
} |
|
22 |
|
|
23 |
$parameters = []; |
|
24 |
|
|
25 |
foreach($method[$path] as $name => $filter) { |
|
26 |
if(!isset($_GET[$name])) { |
|
27 |
header('HTTP/1.1 403 Forbidden'); |
|
28 |
die('Parameter '.$name.' is required'); |
|
29 |
} |
|
30 |
|
|
31 |
if(!$filter($_GET[$name])) { |
|
32 |
header('HTTP/1.1 403 Forbidden'); |
|
33 |
die('Parameter '.$name.' has invalid value'); |
|
34 |
} |
|
35 |
|
|
36 |
$parameters[$name] = $_GET[$name]; |
|
37 |
} |
|
38 |
|
|
39 |
$result = @file_get_contents($base_proxy . $path . '?' . http_build_query($parameters)); |
|
40 |
if(!$result OR $http_response_header[0] != 'HTTP/1.1 200 OK') { |
|
41 |
header('HTTP/1.1 503 Service Unavailable'); |
|
42 |
if(isset($http_response_header[0])) { |
|
43 |
die($http_response_header[0]); |
|
44 |
} else { |
|
45 |
die('Unknown error'); |
|
46 |
} |
|
47 |
} |
|
48 |
|
|
49 |
header('Content-Type: application/json'); |
|
50 |
echo $result; |