Skip to content

Commit 09c2dcc

Browse files
committed
Support for viewing and exporting packs
1 parent a1bc6fa commit 09c2dcc

File tree

8 files changed

+403
-21
lines changed

8 files changed

+403
-21
lines changed

app/Http/Controllers/Admin/PackController.php

Lines changed: 89 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
namespace Pterodactyl\Http\Controllers\Admin;
2525

2626
use Alert;
27+
use DB;
2728
use Log;
2829
use Storage;
2930

@@ -42,17 +43,7 @@ public function __construct()
4243
//
4344
}
4445

45-
public function list(Request $request, $id)
46-
{
47-
$option = Models\ServiceOptions::findOrFail($id);
48-
return view('admin.services.packs.index', [
49-
'packs' => Models\ServicePack::where('option', $option->id)->get(),
50-
'service' => Models\Service::findOrFail($option->parent_service),
51-
'option' => $option
52-
]);
53-
}
54-
55-
public function new(Request $request, $opt = null)
46+
protected function formatServices()
5647
{
5748
$options = Models\ServiceOptions::select(
5849
'services.name AS p_service',
@@ -72,8 +63,41 @@ public function new(Request $request, $opt = null)
7263
]]);
7364
}
7465

66+
return $array;
67+
}
68+
69+
public function listAll(Request $request)
70+
{
71+
//
72+
}
73+
74+
public function listByOption(Request $request, $id)
75+
{
76+
$option = Models\ServiceOptions::findOrFail($id);
77+
return view('admin.services.packs.byoption', [
78+
'packs' => Models\ServicePack::where('option', $option->id)->get(),
79+
'service' => Models\Service::findOrFail($option->parent_service),
80+
'option' => $option
81+
]);
82+
}
83+
84+
public function listByService(Request $request, $id)
85+
{
86+
return view('admin.services.packs.byservice', [
87+
'service' => Models\Service::findOrFail($id),
88+
'options' => Models\ServiceOptions::select(
89+
'service_options.id',
90+
'service_options.name',
91+
DB::raw('(SELECT COUNT(id) FROM service_packs WHERE service_packs.option = service_options.id) AS p_count')
92+
)->where('parent_service', $id)->get()
93+
]);
94+
}
95+
96+
public function new(Request $request, $opt = null)
97+
{
98+
7599
return view('admin.services.packs.new', [
76-
'services' => $array,
100+
'services' => $this->formatServices(),
77101
'packFor' => $opt,
78102
]);
79103
}
@@ -103,6 +127,58 @@ public function create(Request $request)
103127
public function edit(Request $request, $id)
104128
{
105129
$pack = Models\ServicePack::findOrFail($id);
106-
dd($pack, Storage::url('packs/' . $pack->uuid));
130+
$option = Models\ServiceOptions::select('id', 'parent_service', 'name')->where('id', $pack->option)->first();
131+
return view('admin.services.packs.edit', [
132+
'pack' => $pack,
133+
'services' => $this->formatServices(),
134+
'files' => Storage::files('packs/' . $pack->uuid),
135+
'service' => Models\Service::findOrFail($option->parent_service),
136+
'option' => $option
137+
]);
138+
}
139+
140+
public function export(Request $request, $id, $files = false)
141+
{
142+
$pack = Models\ServicePack::findOrFail($id);
143+
$json = [
144+
'name' => $pack->name,
145+
'version' => $pack->version,
146+
'description' => $pack->dscription,
147+
'selectable' => (bool) $pack->selectable,
148+
'visible' => (bool) $pack->visible,
149+
'build' => [
150+
'memory' => $pack->build_memory,
151+
'swap' => $pack->build_swap,
152+
'cpu' => $pack->build_cpu,
153+
'io' => $pack->build_io,
154+
'container' => $pack->build_container,
155+
'script' => $pack->build_script
156+
]
157+
];
158+
159+
$filename = tempnam(sys_get_temp_dir(), 'pterodactyl_');
160+
if ((bool) $files) {
161+
$zip = new \ZipArchive;
162+
if (!$zip->open($filename, \ZipArchive::CREATE)) {
163+
exit("cannot open <$filename>\n");
164+
}
165+
166+
$files = Storage::files('packs/' . $pack->uuid);
167+
foreach ($files as $file) {
168+
$zip->addFile(storage_path('app/' . $file), basename(storage_path('app/' . $file)));
169+
}
170+
171+
$zip->addFromString('import.json', json_encode($json, JSON_PRETTY_PRINT));
172+
$zip->close();
173+
174+
return response()->download($filename, 'pack-' . $pack->name . '.zip')->deleteFileAfterSend(true);
175+
} else {
176+
$fp = fopen($filename, 'a+');
177+
fwrite($fp, json_encode($json, JSON_PRETTY_PRINT));
178+
fclose($fp);
179+
return response()->download($filename, 'pack-' . $pack->name . '.json', [
180+
'Content-Type' => 'application/json'
181+
])->deleteFileAfterSend(true);
182+
}
107183
}
108184
}

app/Http/Routes/AdminRoutes.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,29 @@ public function map(Router $router) {
446446
$router->post('/new', [
447447
'uses' => 'Admin\PackController@create'
448448
]);
449-
$router->get('/for/{option}', [
450-
'as' => 'admin.services.packs.for',
451-
'uses' => 'Admin\PackController@list'
449+
$router->get('/', [
450+
'as' => 'admin.services.packs',
451+
'uses' => 'Admin\PackController@listAll'
452+
]);
453+
$router->get('/for/option/{option}', [
454+
'as' => 'admin.services.packs.option',
455+
'uses' => 'Admin\PackController@listByOption'
456+
]);
457+
$router->get('/for/service/{service}', [
458+
'as' => 'admin.services.packs.service',
459+
'uses' => 'Admin\PackController@listByService'
452460
]);
453461
$router->get('/edit/{pack}', [
454462
'as' => 'admin.services.packs.edit',
455463
'uses' => 'Admin\PackController@edit'
456464
]);
465+
$router->post('/edit/{pack}', [
466+
'uses' => 'Admin\PackController@update'
467+
]);
468+
$router->get('/edit/{pack}/export/{archive?}', [
469+
'as' => 'admin.services.packs.export',
470+
'uses' => 'Admin\PackController@export'
471+
]);
457472
});
458473

459474
}

resources/views/admin/services/options/view.blade.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
<li><a href="/admin/services">Services</a></li>
3131
<li><a href="{{ route('admin.services.service', $service->id) }}">{{ $service->name }}</a></li>
3232
<li class="active">{{ $option->name }}</li>
33-
<li><a href="{{ route('admin.services.packs.for', $option->id) }}">Service Packs</a></li>
3433
</ul>
3534
<div class="alert alert-warning"><strong>Warning!</strong> This page contains advanced settings that the panel and daemon use to control servers. Modifying information on this page is not recommended unless you are absolutely sure of what you are doing.</div>
3635
<h3>Settings</h3><hr />

resources/views/admin/services/packs/index.blade.php renamed to resources/views/admin/services/packs/byoption.blade.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
<ul class="breadcrumb">
2929
<li><a href="/admin">Admin Control</a></li>
3030
<li><a href="/admin/services">Services</a></li>
31-
<li><a href="{{ route('admin.services.service', $service->id) }}">{{ $service->name }}</a></li>
32-
<li><a href="{{ route('admin.services.option', [$service->id, $option->id]) }}">{{ $option->name }}</a></li>
33-
<li class="active">Service Packs</li>
31+
<li><a href="{{ route('admin.services.packs') }}">Packs</a></li>
32+
<li><a href="{{ route('admin.services.packs.service', $service->id) }}">{{ $service->name }}</a></li>
33+
<li class="active">{{ $option->name }}</li>
3434
</ul>
3535
<h3 class="nopad">Service Packs</h3><hr />
3636
<table class="table table-bordered table-hover">
@@ -46,7 +46,7 @@
4646
<tbody>
4747
@foreach ($packs as $pack)
4848
<tr>
49-
<td>{{ $pack->name }}</td>
49+
<td><a href="{{ route('admin.services.packs.edit', $pack->id) }}">{{ $pack->name }}</a></td>
5050
<td>{{ $pack->version }}</td>
5151
<td><code>{{ $pack->uuid }}</code></td>
5252
<td>@if($pack->selectable)<span class="label label-success"><i class="fa fa-check"></i></span>@else<span class="label label-default"><i class="fa fa-times"></i></span>@endif</td>
@@ -66,4 +66,9 @@
6666
</tbody>
6767
</table>
6868
</div>
69+
<script>
70+
$(document).ready(function () {
71+
$('#sidebar_links').find("a[href='/admin/services/packs']").addClass('active');
72+
});
73+
</script>
6974
@endsection
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{{-- Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com> --}}
2+
3+
{{-- Permission is hereby granted, free of charge, to any person obtaining a copy --}}
4+
{{-- of this software and associated documentation files (the "Software"), to deal --}}
5+
{{-- in the Software without restriction, including without limitation the rights --}}
6+
{{-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --}}
7+
{{-- copies of the Software, and to permit persons to whom the Software is --}}
8+
{{-- furnished to do so, subject to the following conditions: --}}
9+
10+
{{-- The above copyright notice and this permission notice shall be included in all --}}
11+
{{-- copies or substantial portions of the Software. --}}
12+
13+
{{-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --}}
14+
{{-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --}}
15+
{{-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --}}
16+
{{-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --}}
17+
{{-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --}}
18+
{{-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --}}
19+
{{-- SOFTWARE. --}}
20+
@extends('layouts.admin')
21+
22+
@section('title')
23+
Service Packs for {{ $service->name }}
24+
@endsection
25+
26+
@section('content')
27+
<div class="col-md-12">
28+
<ul class="breadcrumb">
29+
<li><a href="/admin">Admin Control</a></li>
30+
<li><a href="/admin/services">Services</a></li>
31+
<li><a href="{{ route('admin.services.packs') }}">Packs</a></li>
32+
<li class="active">{{ $service->name }}</li>
33+
</ul>
34+
<h3 class="nopad">Service Packs</h3><hr />
35+
<table class="table table-bordered table-hover">
36+
<thead>
37+
<tr>
38+
<th>Name</th>
39+
<th>Total Packs</th>
40+
</tr>
41+
</thead>
42+
<tbody>
43+
@foreach ($options as $option)
44+
<tr>
45+
<td><a href="{{ route('admin.services.packs.option', $option->id) }}">{{ $option->name }}</a></td>
46+
<td>{{ $option->p_count }}</td>
47+
</tr>
48+
@endforeach
49+
<tr>
50+
<td colspan="2">
51+
<a href="{{ route('admin.services.packs.new') }}">
52+
<button class="pull-right btn btn-xxs btn-primary"><i class="fa fa-plus"></i></button>
53+
</a>
54+
<a href="{{ route('admin.services.packs.new') }}">
55+
<button class="pull-right btn btn-xxs btn-default" style="margin-right:5px;"><i class="fa fa-upload"></i> Install from Template</button>
56+
</a>
57+
</td>
58+
</tr>
59+
</tbody>
60+
</table>
61+
</div>
62+
<script>
63+
$(document).ready(function () {
64+
$('#sidebar_links').find("a[href='/admin/services/packs']").addClass('active');
65+
});
66+
</script>
67+
@endsection

0 commit comments

Comments
 (0)