|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Pterodactyl - Panel |
|
4
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <[email protected]>. |
|
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
|
|
|
|
|
25
|
|
|
namespace Pterodactyl\Http\Controllers\Daemon; |
|
26
|
|
|
|
|
27
|
|
|
use Illuminate\Http\Request; |
|
28
|
|
|
use Pterodactyl\Models\Service; |
|
29
|
|
|
use Pterodactyl\Models\ServiceOption; |
|
30
|
|
|
use Pterodactyl\Http\Controllers\Controller; |
|
31
|
|
|
|
|
32
|
|
|
class ServiceController extends Controller |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* Returns a listing of all services currently on the system, |
|
36
|
|
|
* as well as the associated files and the file hashes for |
|
37
|
|
|
* caching purposes. |
|
38
|
|
|
* |
|
39
|
|
|
* @param \Illuminate\Http\Request $request |
|
40
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
41
|
|
|
*/ |
|
42
|
|
|
public function listServices(Request $request) |
|
|
|
|
|
|
43
|
|
|
{ |
|
44
|
|
|
$response = []; |
|
45
|
|
|
foreach (Service::all() as $service) { |
|
46
|
|
|
$response[$service->folder] = [ |
|
47
|
|
|
'main.json' => sha1($this->getConfiguration($service->id)->toJson()), |
|
48
|
|
|
'index.js' => sha1($service->index_file), |
|
49
|
|
|
]; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return response()->json($response); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Returns the contents of the requested file for the given service. |
|
57
|
|
|
* |
|
58
|
|
|
* @param \Illuminate\Http\Request $request |
|
59
|
|
|
* @param string $folder |
|
60
|
|
|
* @param string $file |
|
61
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\FileResponse |
|
62
|
|
|
*/ |
|
63
|
|
|
public function pull(Request $request, $folder, $file) |
|
|
|
|
|
|
64
|
|
|
{ |
|
65
|
|
|
$service = Service::where('folder', $folder)->firstOrFail(); |
|
66
|
|
|
|
|
67
|
|
|
if ($file === 'index.js') { |
|
68
|
|
|
return response($service->index_file)->header('Content-Type', 'text/plain'); |
|
|
|
|
|
|
69
|
|
|
} elseif ($file === 'main.json') { |
|
70
|
|
|
return response()->json($this->getConfiguration($service->id)); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return abort(404); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Returns a `main.json` file based on the configuration |
|
78
|
|
|
* of each service option. |
|
79
|
|
|
* |
|
80
|
|
|
* @param int $id |
|
81
|
|
|
* @return \Illuminate\Support\Collection |
|
82
|
|
|
*/ |
|
83
|
|
|
protected function getConfiguration($id) |
|
84
|
|
|
{ |
|
85
|
|
|
$options = ServiceOption::where('service_id', $id)->get(); |
|
86
|
|
|
|
|
87
|
|
|
return $options->mapWithKeys(function ($item) use ($options) { |
|
88
|
|
|
return [ |
|
89
|
|
|
$item->tag => array_filter([ |
|
90
|
|
|
'symlink' => $options->where('id', $item->config_from)->pluck('tag')->pop(), |
|
91
|
|
|
'startup' => json_decode($item->config_startup), |
|
92
|
|
|
'stop' => $item->config_stop, |
|
93
|
|
|
'configs' => json_decode($item->config_files), |
|
94
|
|
|
'log' => json_decode($item->config_logs), |
|
95
|
|
|
'query' => 'none', |
|
96
|
|
|
]), |
|
97
|
|
|
]; |
|
98
|
|
|
}); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.