Skip to content

Commit 745c735

Browse files
committed
Add initial basic API changes
New route is `/api/me`
1 parent 126df09 commit 745c735

File tree

17 files changed

+587
-40
lines changed

17 files changed

+587
-40
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
namespace Pterodactyl\Http\Controllers\API\User;
25+
26+
use Auth;
27+
use Dingo;
28+
use Pterodactyl\Models;
29+
use Illuminate\Http\Request;
30+
31+
use Pterodactyl\Http\Controllers\API\BaseController;
32+
33+
class InfoController extends BaseController
34+
{
35+
public function me(Request $request)
36+
{
37+
$servers = Models\Server::getUserServers();
38+
$response = [];
39+
40+
foreach($servers as &$server) {
41+
$response = array_merge($response, [[
42+
'id' => $server->uuidShort,
43+
'uuid' => $server->uuid,
44+
'name' => $server->name,
45+
'node' => $server->nodeName,
46+
'ip' => [
47+
'set' => $server->ip,
48+
'alias' => $server->ip_alias
49+
],
50+
'port' => $server->port,
51+
'service' => $server->a_serviceName,
52+
'option' => $server->a_serviceOptionName
53+
]]);
54+
}
55+
56+
return $response;
57+
}
58+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
namespace Pterodactyl\Http\Controllers\API\User;
25+
26+
use Pterodactyl\Models;
27+
use Illuminate\Http\Request;
28+
29+
class PowerController extends BaseController
30+
{
31+
public function __constructor()
32+
{
33+
}
34+
35+
public function pass(Request $request, $uuid)
36+
{
37+
//$server = Models\Server::where('id', $id)->where();
38+
}
39+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
5+
* Some Modifications (c) 2015 Dylan Seidt <dylan.seidt@gmail.com>
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
*/
25+
namespace Pterodactyl\Http\Controllers\Base;
26+
27+
use Alert;
28+
29+
use Pterodactyl\Models;
30+
31+
use Pterodactyl\Exceptions\DisplayException;
32+
use Pterodactyl\Http\Controllers\Controller;
33+
34+
use Illuminate\Http\Request;
35+
36+
class APIController extends Controller
37+
{
38+
public function index(Request $request)
39+
{
40+
$keys = Models\APIKey::where('user', $request->user()->id)->get();
41+
foreach($keys as &$key) {
42+
$key->permissions = Models\APIPermission::where('key_id', $key->id)->get();
43+
}
44+
45+
return view('base.api.index', [
46+
'keys' => $keys
47+
]);
48+
49+
}
50+
51+
public function new(Request $request)
52+
{
53+
return view('base.api.new');
54+
}
55+
56+
public function save(Request $request)
57+
{
58+
59+
}
60+
}

app/Http/Middleware/APISecretToken.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
*/
2424
namespace Pterodactyl\Http\Middleware;
2525

26+
use Auth;
2627
use Crypt;
28+
use Config;
2729
use IPTools\IP;
2830
use IPTools\Range;
2931

3032
use Pterodactyl\Models\APIKey;
3133
use Pterodactyl\Models\APIPermission;
34+
use Pterodactyl\Models\User;
3235
use Pterodactyl\Services\APILogService;
3336

3437
use Illuminate\Http\Request;
@@ -51,7 +54,7 @@ class APISecretToken extends Authorization
5154

5255
public function __construct()
5356
{
54-
//
57+
Config::set('session.driver', 'array');
5558
}
5659

5760
public function getAuthorizationMethod()
@@ -90,14 +93,11 @@ public function authenticate(Request $request, Route $route)
9093
}
9194
}
9295

93-
foreach(APIPermission::where('key_id', $key->id)->get() as &$row) {
94-
if ($row->permission === '*' || $row->permission === $request->route()->getName()) {
95-
$this->permissionAllowed = true;
96-
continue;
97-
}
98-
}
99-
100-
if (!$this->permissionAllowed) {
96+
$permission = APIPermission::where('key_id', $key->id)
97+
->where('permission', $request->route()->getName())
98+
->orWhere('permission', '*')
99+
->first();
100+
if (!$permission) {
101101
APILogService::log($request, 'You do not have permission to access this resource.');
102102
throw new AccessDeniedHttpException('You do not have permission to access this resource.');
103103
}
@@ -118,7 +118,7 @@ public function authenticate(Request $request, Route $route)
118118

119119
// Log the Route Access
120120
APILogService::log($request, null, true);
121-
return true;
121+
return Auth::loginUsingId($key->user);
122122

123123
}
124124

app/Http/Routes/APIRoutes.php

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,130 +32,137 @@ class APIRoutes
3232
public function map(Router $router) {
3333

3434
$api = app('Dingo\Api\Routing\Router');
35-
$api->version('v1', ['middleware' => 'api.auth'], function ($api) {
35+
$api->version('v1', ['prefix' => 'api/me', 'middleware' => 'api.auth'], function ($api) {
36+
$api->get('/', [
37+
'as' => 'api.user',
38+
'uses' => 'Pterodactyl\Http\Controllers\API\User\InfoController@me'
39+
]);
40+
});
41+
42+
$api->version('v1', ['prefix' => 'api', 'middleware' => 'api.auth'], function ($api) {
3643

3744
/**
3845
* User Routes
3946
*/
4047
$api->get('users', [
41-
'as' => 'api.users.list',
48+
'as' => 'api.admin.users.list',
4249
'uses' => 'Pterodactyl\Http\Controllers\API\UserController@list'
4350
]);
4451

4552
$api->post('users', [
46-
'as' => 'api.users.create',
53+
'as' => 'api.admin.users.create',
4754
'uses' => 'Pterodactyl\Http\Controllers\API\UserController@create'
4855
]);
4956

5057
$api->get('users/{id}', [
51-
'as' => 'api.users.view',
58+
'as' => 'api.admin.users.view',
5259
'uses' => 'Pterodactyl\Http\Controllers\API\UserController@view'
5360
]);
5461

5562
$api->patch('users/{id}', [
56-
'as' => 'api.users.update',
63+
'as' => 'api.admin.users.update',
5764
'uses' => 'Pterodactyl\Http\Controllers\API\UserController@update'
5865
]);
5966

6067
$api->delete('users/{id}', [
61-
'as' => 'api.users.delete',
68+
'as' => 'api.admin.users.delete',
6269
'uses' => 'Pterodactyl\Http\Controllers\API\UserController@delete'
6370
]);
6471

6572
/**
6673
* Server Routes
6774
*/
6875
$api->get('servers', [
69-
'as' => 'api.servers.list',
76+
'as' => 'api.admin.servers.list',
7077
'uses' => 'Pterodactyl\Http\Controllers\API\ServerController@list'
7178
]);
7279

7380
$api->post('servers', [
74-
'as' => 'api.servers.create',
81+
'as' => 'api.admin.servers.create',
7582
'uses' => 'Pterodactyl\Http\Controllers\API\ServerController@create'
7683
]);
7784

7885
$api->get('servers/{id}', [
79-
'as' => 'api.servers.view',
86+
'as' => 'api.admin.servers.view',
8087
'uses' => 'Pterodactyl\Http\Controllers\API\ServerController@view'
8188
]);
8289

8390
$api->patch('servers/{id}/config', [
84-
'as' => 'api.servers.config',
91+
'as' => 'api.admin.servers.config',
8592
'uses' => 'Pterodactyl\Http\Controllers\API\ServerController@config'
8693
]);
8794

8895
$api->patch('servers/{id}/build', [
89-
'as' => 'api.servers.build',
96+
'as' => 'api.admin.servers.build',
9097
'uses' => 'Pterodactyl\Http\Controllers\API\ServerController@build'
9198
]);
9299

93100
$api->post('servers/{id}/suspend', [
94-
'as' => 'api.servers.suspend',
101+
'as' => 'api.admin.servers.suspend',
95102
'uses' => 'Pterodactyl\Http\Controllers\API\ServerController@suspend'
96103
]);
97104

98105
$api->post('servers/{id}/unsuspend', [
99-
'as' => 'api.servers.unsuspend',
106+
'as' => 'api.admin.servers.unsuspend',
100107
'uses' => 'Pterodactyl\Http\Controllers\API\ServerController@unsuspend'
101108
]);
102109

103110
$api->delete('servers/{id}/{force?}', [
104-
'as' => 'api.servers.delete',
111+
'as' => 'api.admin.servers.delete',
105112
'uses' => 'Pterodactyl\Http\Controllers\API\ServerController@delete'
106113
]);
107114

108115
/**
109116
* Node Routes
110117
*/
111118
$api->get('nodes', [
112-
'as' => 'api.nodes.list',
119+
'as' => 'api.admin.nodes.list',
113120
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@list'
114121
]);
115122

116123
$api->post('nodes', [
117-
'as' => 'api.nodes.create',
124+
'as' => 'api.admin.nodes.create',
118125
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@create'
119126
]);
120127

121128
$api->get('nodes/allocations', [
122-
'as' => 'api.nodes.allocations',
129+
'as' => 'api.admin.nodes.allocations',
123130
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@allocations'
124131
]);
125132

126133
$api->get('nodes/{id}', [
127-
'as' => 'api.nodes.view',
134+
'as' => 'api.admin.nodes.view',
128135
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@view'
129136
]);
130137

131138
$api->get('nodes/{id}/config', [
132-
'as' => 'api.nodes.view',
139+
'as' => 'api.admin.nodes.view',
133140
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@config'
134141
]);
135142

136143
$api->delete('nodes/{id}', [
137-
'as' => 'api.nodes.delete',
144+
'as' => 'api.admin.nodes.delete',
138145
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@delete'
139146
]);
140147

141148
/**
142149
* Location Routes
143150
*/
144151
$api->get('locations', [
145-
'as' => 'api.locations.list',
152+
'as' => 'api.admin.locations.list',
146153
'uses' => 'Pterodactyl\Http\Controllers\API\LocationController@list'
147154
]);
148155

149156
/**
150157
* Service Routes
151158
*/
152159
$api->get('services', [
153-
'as' => 'api.services.list',
160+
'as' => 'api.admin.services.list',
154161
'uses' => 'Pterodactyl\Http\Controllers\API\ServiceController@list'
155162
]);
156163

157164
$api->get('services/{id}', [
158-
'as' => 'api.services.view',
165+
'as' => 'api.admin.services.view',
159166
'uses' => 'Pterodactyl\Http\Controllers\API\ServiceController@view'
160167
]);
161168

0 commit comments

Comments
 (0)