Skip to content

Commit e6d3e75

Browse files
committed
Add new daemon routes for pack handling
1 parent 95d0c64 commit e6d3e75

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 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+
25+
namespace Pterodactyl\Http\Controllers\Daemon;
26+
27+
use Storage;
28+
use Pterodactyl\Models;
29+
use Illuminate\Http\Request;
30+
use Pterodactyl\Http\Controllers\Controller;
31+
32+
class PackController extends Controller
33+
{
34+
/**
35+
* Controller Constructor.
36+
*/
37+
public function __construct()
38+
{
39+
//
40+
}
41+
42+
/**
43+
* Pulls an install pack archive from the system
44+
*
45+
* @param \Illuminate\Http\Request $request
46+
* @return \Illuminate\Http\Response
47+
*/
48+
public function pull(Request $request, $uuid)
49+
{
50+
$pack = Models\ServicePack::where('uuid', $uuid)->first();
51+
52+
if (!$pack) {
53+
return response()->json([ 'error' => 'No such pack.' ], 404);
54+
}
55+
56+
if (! Storage::exists('packs/' . $pack->uuid . '/archive.tar.gz')) {
57+
return response()->json([ 'error' => 'There is no archive available for this pack.' ], 503);
58+
}
59+
60+
return response()->download(storage_path('app/packs/' . $pack->uuid . '/archive.tar.gz'));
61+
}
62+
63+
/**
64+
* Returns the hash information for a pack.
65+
*
66+
* @param \Illuminate\Http\Request $request
67+
* @return \Illuminate\Http\Response
68+
*/
69+
public function hash(Request $request, $uuid)
70+
{
71+
$pack = Models\ServicePack::where('uuid', $uuid)->first();
72+
73+
if (!$pack) {
74+
return response()->json([ 'error' => 'No such pack.' ], 404);
75+
}
76+
77+
if (! Storage::exists('packs/' . $pack->uuid . '/archive.tar.gz')) {
78+
return response()->json([ 'error' => 'There is no archive available for this pack.' ], 503);
79+
}
80+
81+
return response()->json([
82+
'archive.tar.gz' => sha1_file(storage_path('app/packs/' . $pack->uuid . '/archive.tar.gz')),
83+
]);
84+
}
85+
86+
/**
87+
* Pulls an update pack archive from the system
88+
*
89+
* @param \Illuminate\Http\Request $request
90+
* @return \Illuminate\Http\Response
91+
*/
92+
public function pullUpdate(Request $request)
93+
{
94+
95+
}
96+
}

app/Http/Routes/DaemonRoutes.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ public function map(Router $router)
4040
'as' => 'remote.install',
4141
'uses' => 'Daemon\ServiceController@pull',
4242
]);
43+
44+
$router->get('packs/pull/{uuid}', [
45+
'as' => 'daemon.pack.pull',
46+
'uses' => 'Daemon\PackController@pull',
47+
]);
48+
$router->get('packs/pull/{uuid}/hash', [
49+
'as' => 'daemon.pack.hash',
50+
'uses' => 'Daemon\PackController@hash',
51+
]);
4352
});
4453
}
4554
}

0 commit comments

Comments
 (0)