-
Notifications
You must be signed in to change notification settings - Fork 21
/
routes.php
105 lines (81 loc) · 4.05 KB
/
routes.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
// just for testing
$app->get( 'test', function() {
return "Hello, world!";
});
// This is pretty kack but fideloper/TrustedProxy seems to not work on Lumen yet
if( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] ) {
$proto = 'https://';
} else if( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && strtolower( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) == 'https' ) {
$proto = 'https://';
} else {
$proto = 'http://';
}
$url = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $proto . $_SERVER['HTTP_X_FORWARDED_HOST'] : url( '', [], $proto == 'https://' );
// A proxy can optionally set HTTP_X_URL to add a prefix to the URL (http://www.example.com/prefix/).
if( isset($_SERVER['HTTP_X_URL'] ) ) {
if( substr( $url, -1 ) == '/' && substr( $_SERVER['HTTP_X_URL'], 0, 1 ) == '/' ) {
$url .= substr( $_SERVER['HTTP_X_URL'], 1 );
} else if( substr( $url, -1 ) != '/' && substr( $_SERVER['HTTP_X_URL'], 0, 1 ) != '/' ) {
$url .= '/' . $_SERVER['HTTP_X_URL'];
} else {
$url .= $_SERVER['HTTP_X_URL'];
}
}
// remove tailing slash
if( substr( $url, -1 ) == '/' ) {
$url = substr( $url, 0, -1 );
}
$app->get('/', function () use ($app,$url) {
return $app->make('view')->make('index')->with( [
'url' => $url,
'status' => json_decode( $app->call('\App\Http\Controllers\Status@show' )->content() )
]);
});
$app->get('api/status', 'Status@show');
$app->get('api/protocols/bgp', 'Protocols@bgp');
$app->get('api/protocol/{protocol}', 'Protocols@protocol');
$app->get('api/symbols', 'Symbols@all');
$app->get('api/symbols/tables', 'Symbols@tables');
$app->get('api/symbols/protocols', 'Symbols@protocols');
$app->get('api/routes/protocol/{protocol}', 'Routes@protocol' );
$app->get('api/routes/table/{table}', 'Routes@table' );
$app->get('api/routes/export/{protocol}', 'Routes@export' );
$app->get('api/routes/count/protocol/{protocol}', 'Routes@protocolCount' );
$app->get('api/routes/count/table/{table}', 'Routes@tableCount' );
$app->get('api/routes/count/export/{protocol}', 'Routes@exportCount' );
// Get wildcard large communities in protocol tabe of form ( x, y, * )
$app->get('api/routes/lc-zwild/protocol/{protocol}/{x}/{y}', 'Routes@protocolLargeCommunityWildXY' );
$throttle = env('THROTTLE_PER_MIN',20);
$app->group(['middleware' => 'throttle:' . $throttle,'namespace' => 'App\Http\Controllers'], function () use ($app) {
$app->get('api/route/{net}', 'Routes@lookupTable');
$app->get('api/route/{net}/table/{table}', 'Routes@lookupTable');
$app->get('api/route/{net}/protocol/{protocol}', 'Routes@lookupProtocol');
$app->get('api/route/{net}/export/{protocol}', 'Routes@lookupExport');
});
if( env('LOOKING_GLASS_ENABLED', false ) ) {
$app->group(['prefix' => 'lg', 'namespace' => 'App\Http\Controllers\LookingGlass'], function () use ($app,$url) {
$app->make('view')->share('url',$url);
$app->make('view')->share('status', json_decode( $app->call('\App\Http\Controllers\Status@show' )->content() ) );
$app->get('', function() use ($app,$url) {
return redirect( $url . '/lg/protocols/bgp' );
});
$app->get('protocols/bgp', 'Protocols\Bgp@summary' );
$app->get('routes/protocol/{protocol}', 'Routes@protocol' );
$app->get('routes/table/{table}', 'Routes@table' );
$app->get('routes/export/{protocol}', 'Routes@export' );
$app->get('route', 'Routes@getLookup' );
$app->get('route/{net}/protocol/{protocol}', 'Routes@lookupProtocol' );
$app->get('route/{net}/table/{table}', 'Routes@lookupTable' );
});
}