|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Pterodactyl - Panel |
|
4
|
|
|
* Copyright (c) 2015 - 2016 Dane Everitt <[email protected]> |
|
5
|
|
|
* Some Modifications (c) 2015 Dylan Seidt <[email protected]>. |
|
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
|
|
|
|
|
26
|
|
|
namespace Pterodactyl\Http\Controllers\Base; |
|
27
|
|
|
|
|
28
|
|
|
use Log; |
|
29
|
|
|
use Alert; |
|
30
|
|
|
use Pterodactyl\Models; |
|
31
|
|
|
use Illuminate\Http\Request; |
|
32
|
|
|
use Pterodactyl\Repositories\APIRepository; |
|
33
|
|
|
use Pterodactyl\Exceptions\DisplayException; |
|
34
|
|
|
use Pterodactyl\Http\Controllers\Controller; |
|
35
|
|
|
use Pterodactyl\Exceptions\DisplayValidationException; |
|
36
|
|
|
|
|
37
|
|
|
class APIController extends Controller |
|
38
|
|
|
{ |
|
39
|
|
|
public function index(Request $request) |
|
40
|
|
|
{ |
|
41
|
|
|
$keys = Models\APIKey::where('user', $request->user()->id)->get(); |
|
42
|
|
|
foreach ($keys as &$key) { |
|
43
|
|
|
$key->permissions = Models\APIPermission::where('key_id', $key->id)->get(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return view('base.api.index', [ |
|
47
|
|
|
'keys' => $keys, |
|
48
|
|
|
]); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function create(Request $request) |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
return view('base.api.new'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
View Code Duplication |
public function save(Request $request) |
|
|
|
|
|
|
57
|
|
|
{ |
|
58
|
|
|
try { |
|
59
|
|
|
$repo = new APIRepository($request->user()); |
|
60
|
|
|
$secret = $repo->create($request->except(['_token'])); |
|
61
|
|
|
Alert::success('An API Keypair has successfully been generated. The API secret for this public key is shown below and will not be shown again.<br /><br /><code>' . $secret . '</code>')->flash(); |
|
62
|
|
|
|
|
63
|
|
|
return redirect()->route('account.api'); |
|
64
|
|
|
} catch (DisplayValidationException $ex) { |
|
65
|
|
|
return redirect()->route('account.api.new')->withErrors(json_decode($ex->getMessage()))->withInput(); |
|
66
|
|
|
} catch (DisplayException $ex) { |
|
67
|
|
|
Alert::danger($ex->getMessage())->flash(); |
|
68
|
|
|
} catch (\Exception $ex) { |
|
69
|
|
|
Log::error($ex); |
|
70
|
|
|
Alert::danger('An unhandled exception occured while attempting to add this API key.')->flash(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return redirect()->route('account.api.new')->withInput(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
View Code Duplication |
public function revoke(Request $request, $key) |
|
|
|
|
|
|
77
|
|
|
{ |
|
78
|
|
|
try { |
|
79
|
|
|
$repo = new APIRepository($request->user()); |
|
80
|
|
|
$repo->revoke($key); |
|
81
|
|
|
|
|
82
|
|
|
return response('', 204); |
|
83
|
|
|
} catch (\Exception $ex) { |
|
84
|
|
|
return response()->json([ |
|
85
|
|
|
'error' => 'An error occured while attempting to remove this key.', |
|
86
|
|
|
], 503); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.