This repository was archived by the owner on Aug 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrouter.php
More file actions
executable file
·64 lines (49 loc) · 1.52 KB
/
router.php
File metadata and controls
executable file
·64 lines (49 loc) · 1.52 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
if ( !isset($request[0]) )
response(array(
'error' => 'No or invalid API version provided',
'desc' => 'Should be the first path of the url. ex http://api.crew.dreamhack.se/1 for version 1',
'no' => E_USER_ERROR,
));
$apiversion = $request[0];
array_shift($request);
$request = array_filter($request);
// Find all api versions
$versions = scandir('api/');
foreach($versions as $key => $line) {
if ( substr($line,0,1) == '.' )
unset($versions[$key]);
if ( !is_file("api/$line/router.php") )
unset($versions[$key]);
}
sort($versions);
// Check auths, if trying to access a api
if ( is_numeric($apiversion) ) {
foreach($versions as $key => $line ) {
if ( is_numeric($line) )
continue;
if ( !is_file("api/$line/check.php") )
continue;
if ( $uid = include("api/$line/check.php") ) {
$_SESSION['id'] = $uid;
break;
}
}
}
// Check if the api version exists
if ( !is_dir('api/'.$apiversion) || !is_file("api/$apiversion/router.php") ) {
header('HTTP/1.0 501 Not Implemented');
response(array(
'error' => 'The API version "'.$apiversion.'" does not exist',
'desc' => 'Available versions is: '.implode($versions,', '),
'available' => $versions,
'no' => E_USER_ERROR,
));
}
require( "api/$apiversion/router.php" );
// Throw an error message if the router does not work
response(array(
'error' => 'API request failed',
'no' => E_USER_ERROR,
));
?>