diff --git a/app/Http/Controllers/Admin/PackController.php b/app/Http/Controllers/Admin/PackController.php
index 9d2474395..5a7ecf49d 100644
--- a/app/Http/Controllers/Admin/PackController.php
+++ b/app/Http/Controllers/Admin/PackController.php
@@ -24,6 +24,7 @@
namespace Pterodactyl\Http\Controllers\Admin;
use Alert;
+use DB;
use Log;
use Storage;
@@ -42,17 +43,7 @@ class PackController extends Controller
//
}
- public function list(Request $request, $id)
- {
- $option = Models\ServiceOptions::findOrFail($id);
- return view('admin.services.packs.index', [
- 'packs' => Models\ServicePack::where('option', $option->id)->get(),
- 'service' => Models\Service::findOrFail($option->parent_service),
- 'option' => $option
- ]);
- }
-
- public function new(Request $request, $opt = null)
+ protected function formatServices()
{
$options = Models\ServiceOptions::select(
'services.name AS p_service',
@@ -72,8 +63,41 @@ class PackController extends Controller
]]);
}
+ return $array;
+ }
+
+ public function listAll(Request $request)
+ {
+ //
+ }
+
+ public function listByOption(Request $request, $id)
+ {
+ $option = Models\ServiceOptions::findOrFail($id);
+ return view('admin.services.packs.byoption', [
+ 'packs' => Models\ServicePack::where('option', $option->id)->get(),
+ 'service' => Models\Service::findOrFail($option->parent_service),
+ 'option' => $option
+ ]);
+ }
+
+ public function listByService(Request $request, $id)
+ {
+ return view('admin.services.packs.byservice', [
+ 'service' => Models\Service::findOrFail($id),
+ 'options' => Models\ServiceOptions::select(
+ 'service_options.id',
+ 'service_options.name',
+ DB::raw('(SELECT COUNT(id) FROM service_packs WHERE service_packs.option = service_options.id) AS p_count')
+ )->where('parent_service', $id)->get()
+ ]);
+ }
+
+ public function new(Request $request, $opt = null)
+ {
+
return view('admin.services.packs.new', [
- 'services' => $array,
+ 'services' => $this->formatServices(),
'packFor' => $opt,
]);
}
@@ -103,6 +127,58 @@ class PackController extends Controller
public function edit(Request $request, $id)
{
$pack = Models\ServicePack::findOrFail($id);
- dd($pack, Storage::url('packs/' . $pack->uuid));
+ $option = Models\ServiceOptions::select('id', 'parent_service', 'name')->where('id', $pack->option)->first();
+ return view('admin.services.packs.edit', [
+ 'pack' => $pack,
+ 'services' => $this->formatServices(),
+ 'files' => Storage::files('packs/' . $pack->uuid),
+ 'service' => Models\Service::findOrFail($option->parent_service),
+ 'option' => $option
+ ]);
+ }
+
+ public function export(Request $request, $id, $files = false)
+ {
+ $pack = Models\ServicePack::findOrFail($id);
+ $json = [
+ 'name' => $pack->name,
+ 'version' => $pack->version,
+ 'description' => $pack->dscription,
+ 'selectable' => (bool) $pack->selectable,
+ 'visible' => (bool) $pack->visible,
+ 'build' => [
+ 'memory' => $pack->build_memory,
+ 'swap' => $pack->build_swap,
+ 'cpu' => $pack->build_cpu,
+ 'io' => $pack->build_io,
+ 'container' => $pack->build_container,
+ 'script' => $pack->build_script
+ ]
+ ];
+
+ $filename = tempnam(sys_get_temp_dir(), 'pterodactyl_');
+ if ((bool) $files) {
+ $zip = new \ZipArchive;
+ if (!$zip->open($filename, \ZipArchive::CREATE)) {
+ exit("cannot open <$filename>\n");
+ }
+
+ $files = Storage::files('packs/' . $pack->uuid);
+ foreach ($files as $file) {
+ $zip->addFile(storage_path('app/' . $file), basename(storage_path('app/' . $file)));
+ }
+
+ $zip->addFromString('import.json', json_encode($json, JSON_PRETTY_PRINT));
+ $zip->close();
+
+ return response()->download($filename, 'pack-' . $pack->name . '.zip')->deleteFileAfterSend(true);
+ } else {
+ $fp = fopen($filename, 'a+');
+ fwrite($fp, json_encode($json, JSON_PRETTY_PRINT));
+ fclose($fp);
+ return response()->download($filename, 'pack-' . $pack->name . '.json', [
+ 'Content-Type' => 'application/json'
+ ])->deleteFileAfterSend(true);
+ }
}
}
diff --git a/app/Http/Routes/AdminRoutes.php b/app/Http/Routes/AdminRoutes.php
index 73679de69..d84de184c 100644
--- a/app/Http/Routes/AdminRoutes.php
+++ b/app/Http/Routes/AdminRoutes.php
@@ -446,14 +446,29 @@ class AdminRoutes {
$router->post('/new', [
'uses' => 'Admin\PackController@create'
]);
- $router->get('/for/{option}', [
- 'as' => 'admin.services.packs.for',
- 'uses' => 'Admin\PackController@list'
+ $router->get('/', [
+ 'as' => 'admin.services.packs',
+ 'uses' => 'Admin\PackController@listAll'
+ ]);
+ $router->get('/for/option/{option}', [
+ 'as' => 'admin.services.packs.option',
+ 'uses' => 'Admin\PackController@listByOption'
+ ]);
+ $router->get('/for/service/{service}', [
+ 'as' => 'admin.services.packs.service',
+ 'uses' => 'Admin\PackController@listByService'
]);
$router->get('/edit/{pack}', [
'as' => 'admin.services.packs.edit',
'uses' => 'Admin\PackController@edit'
]);
+ $router->post('/edit/{pack}', [
+ 'uses' => 'Admin\PackController@update'
+ ]);
+ $router->get('/edit/{pack}/export/{archive?}', [
+ 'as' => 'admin.services.packs.export',
+ 'uses' => 'Admin\PackController@export'
+ ]);
});
}
diff --git a/resources/views/admin/services/options/view.blade.php b/resources/views/admin/services/options/view.blade.php
index 414f8974a..d5de1a910 100644
--- a/resources/views/admin/services/options/view.blade.php
+++ b/resources/views/admin/services/options/view.blade.php
@@ -30,7 +30,6 @@
Services
{{ $service->name }}
{{ $option->name }}
- Service Packs
Warning! 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.
Settings
diff --git a/resources/views/admin/services/packs/index.blade.php b/resources/views/admin/services/packs/byoption.blade.php
similarity index 86%
rename from resources/views/admin/services/packs/index.blade.php
rename to resources/views/admin/services/packs/byoption.blade.php
index 2ec5ed0e4..6ec8f03e1 100644
--- a/resources/views/admin/services/packs/index.blade.php
+++ b/resources/views/admin/services/packs/byoption.blade.php
@@ -28,9 +28,9 @@
Service Packs
@@ -46,7 +46,7 @@
@foreach ($packs as $pack)
- {{ $pack->name }} |
+ {{ $pack->name }} |
{{ $pack->version }} |
{{ $pack->uuid }} |
@if($pack->selectable)@else@endif |
@@ -66,4 +66,9 @@
+
@endsection
diff --git a/resources/views/admin/services/packs/byservice.blade.php b/resources/views/admin/services/packs/byservice.blade.php
new file mode 100644
index 000000000..ddb538ac5
--- /dev/null
+++ b/resources/views/admin/services/packs/byservice.blade.php
@@ -0,0 +1,67 @@
+{{-- Copyright (c) 2015 - 2016 Dane Everitt --}}
+
+{{-- Permission is hereby granted, free of charge, to any person obtaining a copy --}}
+{{-- of this software and associated documentation files (the "Software"), to deal --}}
+{{-- in the Software without restriction, including without limitation the rights --}}
+{{-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --}}
+{{-- copies of the Software, and to permit persons to whom the Software is --}}
+{{-- furnished to do so, subject to the following conditions: --}}
+
+{{-- The above copyright notice and this permission notice shall be included in all --}}
+{{-- copies or substantial portions of the Software. --}}
+
+{{-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --}}
+{{-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --}}
+{{-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --}}
+{{-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --}}
+{{-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --}}
+{{-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --}}
+{{-- SOFTWARE. --}}
+@extends('layouts.admin')
+
+@section('title')
+ Service Packs for {{ $service->name }}
+@endsection
+
+@section('content')
+
+
+@endsection
diff --git a/resources/views/admin/services/packs/edit.blade.php b/resources/views/admin/services/packs/edit.blade.php
index e69de29bb..abc89fe99 100644
--- a/resources/views/admin/services/packs/edit.blade.php
+++ b/resources/views/admin/services/packs/edit.blade.php
@@ -0,0 +1,217 @@
+{{-- Copyright (c) 2015 - 2016 Dane Everitt --}}
+
+{{-- Permission is hereby granted, free of charge, to any person obtaining a copy --}}
+{{-- of this software and associated documentation files (the "Software"), to deal --}}
+{{-- in the Software without restriction, including without limitation the rights --}}
+{{-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --}}
+{{-- copies of the Software, and to permit persons to whom the Software is --}}
+{{-- furnished to do so, subject to the following conditions: --}}
+
+{{-- The above copyright notice and this permission notice shall be included in all --}}
+{{-- copies or substantial portions of the Software. --}}
+
+{{-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --}}
+{{-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --}}
+{{-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --}}
+{{-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --}}
+{{-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --}}
+{{-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --}}
+{{-- SOFTWARE. --}}
+@extends('layouts.admin')
+
+@section('title')
+ Add New Service Pack
+@endsection
+
+@section('content')
+
+
+
Manage Service Pack
+