Add initial pack creation and overview pages
This commit is contained in:
parent
2d90187c83
commit
50558db7c3
21 changed files with 944 additions and 487 deletions
|
@ -27,179 +27,124 @@ namespace Pterodactyl\Http\Controllers\Admin;
|
|||
use Log;
|
||||
use Alert;
|
||||
use Storage;
|
||||
use Pterodactyl\Models;
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Models\Pack;
|
||||
use Pterodactyl\Models\Service;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Repositories\ServiceRepository\Pack;
|
||||
use Pterodactyl\Repositories\PackRepository;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
|
||||
class PackController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
/**
|
||||
* Display listing of all packs on the system.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
//
|
||||
$packs = Pack::with('option')->withCount('servers');
|
||||
|
||||
if (! is_null($request->input('query'))) {
|
||||
$packs->search($request->input('query'));
|
||||
}
|
||||
|
||||
return view('admin.packs.index', ['packs' => $packs->paginate(50)]);
|
||||
}
|
||||
|
||||
public function listAll(Request $request)
|
||||
/**
|
||||
* Display new pack creation form.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function new(Request $request)
|
||||
{
|
||||
return view('admin.services.packs.index', ['services' => Models\Service::all()]);
|
||||
}
|
||||
|
||||
public function listByOption(Request $request, $id)
|
||||
{
|
||||
return view('admin.services.packs.byoption', [
|
||||
'option' => Models\ServiceOption::with('service', 'packs')->findOrFail($id),
|
||||
return view('admin.packs.new', [
|
||||
'services' => Service::with('options')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function listByService(Request $request, $id)
|
||||
/**
|
||||
* Display new pack creation modal for use with template upload.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function newTemplate(Request $request)
|
||||
{
|
||||
return view('admin.services.packs.byservice', [
|
||||
'service' => Models\Service::with('options', 'options.packs')->findOrFail($id),
|
||||
]);
|
||||
}
|
||||
|
||||
public function new(Request $request, $opt = null)
|
||||
{
|
||||
return view('admin.services.packs.new', [
|
||||
'services' => Models\Service::with('options')->get(),
|
||||
return view('admin.packs.modal', [
|
||||
'services' => Service::with('options')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(Request $request)
|
||||
{
|
||||
$repo = new PackRepository;
|
||||
|
||||
try {
|
||||
$repo = new Pack;
|
||||
$pack = $repo->create($request->only([
|
||||
'name', 'version', 'description',
|
||||
'option', 'selectable', 'visible',
|
||||
'file_upload',
|
||||
]));
|
||||
Alert::success('Successfully created new service!')->flash();
|
||||
|
||||
return redirect()->route('admin.services.packs.edit', $pack->id)->withInput();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.services.packs.new', $request->input('option'))->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An error occured while attempting to add a new service pack.')->flash();
|
||||
}
|
||||
|
||||
return redirect()->route('admin.services.packs.new', $request->input('option'))->withInput();
|
||||
}
|
||||
|
||||
public function edit(Request $request, $id)
|
||||
{
|
||||
$pack = Models\ServicePack::with('option.service')->findOrFail($id);
|
||||
|
||||
return view('admin.services.packs.edit', [
|
||||
'pack' => $pack,
|
||||
'services' => Models\Service::all()->load('options'),
|
||||
'files' => Storage::files('packs/' . $pack->uuid),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
if (! is_null($request->input('action_delete'))) {
|
||||
try {
|
||||
$repo = new Pack;
|
||||
$repo->delete($id);
|
||||
Alert::success('The requested service pack has been deleted from the system.')->flash();
|
||||
|
||||
return redirect()->route('admin.services.packs');
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An error occured while attempting to delete this pack.')->flash();
|
||||
}
|
||||
|
||||
return redirect()->route('admin.services.packs.edit', $id);
|
||||
} else {
|
||||
try {
|
||||
$repo = new Pack;
|
||||
$repo->update($id, $request->only([
|
||||
'name', 'version', 'description',
|
||||
'option', 'selectable', 'visible',
|
||||
if ($request->input('action') === 'from_template') {
|
||||
$pack = $repo->createWithTemplate($request->intersect(['option_id', 'file_upload']));
|
||||
} else {
|
||||
$pack = $repo->create($request->intersect([
|
||||
'name', 'description', 'version', 'option_id',
|
||||
'selectable', 'visible', 'locked', 'file_upload',
|
||||
]));
|
||||
Alert::success('Service pack has been successfully updated.')->flash();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.services.packs.edit', $id)->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An error occured while attempting to add edit this pack.')->flash();
|
||||
}
|
||||
Alert::success('Pack successfully created on the system.')->flash();
|
||||
|
||||
return redirect()->route('admin.services.packs.edit', $id);
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
];
|
||||
|
||||
$filename = tempnam(sys_get_temp_dir(), 'pterodactyl_');
|
||||
if ((bool) $files) {
|
||||
$zip = new \ZipArchive;
|
||||
if (! $zip->open($filename, \ZipArchive::CREATE)) {
|
||||
abort(503, 'Unable to open file for writing.');
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
public function uploadForm(Request $request, $for = null)
|
||||
{
|
||||
return view('admin.services.packs.upload', [
|
||||
'services' => Models\Service::all()->load('options'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function postUpload(Request $request)
|
||||
{
|
||||
try {
|
||||
$repo = new Pack;
|
||||
$pack = $repo->createWithTemplate($request->only(['option', 'file_upload']));
|
||||
Alert::success('Successfully created new service!')->flash();
|
||||
|
||||
return redirect()->route('admin.services.packs.edit', $pack->id)->withInput();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->back()->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
return redirect()->route('admin.packs.view', $pack->id);
|
||||
} catch(DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.packs.new')->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An error occured while attempting to add a new service pack.')->flash();
|
||||
Alert::danger('An error occured while attempting to add a new service pack. This error has been logged.')->flash();
|
||||
}
|
||||
|
||||
return redirect()->back();
|
||||
return redirect()->route('admin.packs.new')->withInput();
|
||||
}
|
||||
|
||||
|
||||
// public function export(Request $request, $id, $files = false)
|
||||
// {
|
||||
// $pack = Models\Pack::findOrFail($id);
|
||||
// $json = [
|
||||
// 'name' => $pack->name,
|
||||
// 'version' => $pack->version,
|
||||
// 'description' => $pack->dscription,
|
||||
// 'selectable' => (bool) $pack->selectable,
|
||||
// 'visible' => (bool) $pack->visible,
|
||||
// ];
|
||||
|
||||
// $filename = tempnam(sys_get_temp_dir(), 'pterodactyl_');
|
||||
// if ((bool) $files) {
|
||||
// $zip = new \ZipArchive;
|
||||
// if (! $zip->open($filename, \ZipArchive::CREATE)) {
|
||||
// abort(503, 'Unable to open file for writing.');
|
||||
// }
|
||||
|
||||
// $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);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue