11<?php
22/**
33 * Pterodactyl - Panel
4- * Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
4+ * Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>.
55 *
66 * Permission is hereby granted, free of charge, to any person obtaining a copy
77 * of this software and associated documentation files (the "Software"), to deal
2121 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222 * SOFTWARE.
2323 */
24+
2425namespace Pterodactyl \Http \Controllers \Admin ;
2526
26- use Alert ;
2727use DB ;
2828use Log ;
29+ use Alert ;
2930use Storage ;
30-
3131use Pterodactyl \Models ;
32- use Pterodactyl \Repositories \ServiceRepository \Pack ;
32+ use Illuminate \Http \Request ;
33+ use Pterodactyl \Exceptions \DisplayException ;
3334use Pterodactyl \Http \Controllers \Controller ;
35+ use Pterodactyl \Repositories \ServiceRepository \Pack ;
3436use Pterodactyl \Exceptions \DisplayValidationException ;
35- use Pterodactyl \Exceptions \DisplayException ;
36-
37- use Illuminate \Http \Request ;
3837
3938class PackController extends Controller
4039{
@@ -52,14 +51,14 @@ protected function formatServices()
5251 )->join ('services ' , 'services.id ' , '= ' , 'service_options.parent_service ' )->get ();
5352
5453 $ array = [];
55- foreach ($ options as &$ option ) {
56- if (!array_key_exists ($ option ->p_service , $ array )) {
54+ foreach ($ options as &$ option ) {
55+ if (! array_key_exists ($ option ->p_service , $ array )) {
5756 $ array [$ option ->p_service ] = [];
5857 }
5958
6059 $ array [$ option ->p_service ] = array_merge ($ array [$ option ->p_service ], [[
6160 'id ' => $ option ->id ,
62- 'name ' => $ option ->name
61+ 'name ' => $ option ->name ,
6362 ]]);
6463 }
6564
@@ -69,17 +68,18 @@ protected function formatServices()
6968 public function listAll (Request $ request )
7069 {
7170 return view ('admin.services.packs.index ' , [
72- 'services ' => Models \Service::all ()
71+ 'services ' => Models \Service::all (),
7372 ]);
7473 }
7574
7675 public function listByOption (Request $ request , $ id )
7776 {
7877 $ option = Models \ServiceOptions::findOrFail ($ id );
78+
7979 return view ('admin.services.packs.byoption ' , [
8080 'packs ' => Models \ServicePack::where ('option ' , $ option ->id )->get (),
8181 'service ' => Models \Service::findOrFail ($ option ->parent_service ),
82- 'option ' => $ option
82+ 'option ' => $ option,
8383 ]);
8484 }
8585
@@ -91,7 +91,7 @@ public function listByService(Request $request, $id)
9191 'service_options.id ' ,
9292 'service_options.name ' ,
9393 DB ::raw ('(SELECT COUNT(id) FROM service_packs WHERE service_packs.option = service_options.id) AS p_count ' )
94- )->where ('parent_service ' , $ id )->get ()
94+ )->where ('parent_service ' , $ id )->get (),
9595 ]);
9696 }
9797
@@ -108,9 +108,10 @@ public function create(Request $request)
108108 try {
109109 $ repo = new Pack ;
110110 $ id = $ repo ->create ($ request ->except ([
111- '_token '
111+ '_token ' ,
112112 ]));
113113 Alert::success ('Successfully created new service! ' )->flash ();
114+
114115 return redirect ()->route ('admin.services.packs.edit ' , $ id )->withInput ();
115116 } catch (DisplayValidationException $ ex ) {
116117 return redirect ()->route ('admin.services.packs.new ' , $ request ->input ('option ' ))->withErrors (json_decode ($ ex ->getMessage ()))->withInput ();
@@ -120,42 +121,46 @@ public function create(Request $request)
120121 Log::error ($ ex );
121122 Alert::danger ('An error occured while attempting to add a new service pack. ' )->flash ();
122123 }
124+
123125 return redirect ()->route ('admin.services.packs.new ' , $ request ->input ('option ' ))->withInput ();
124126 }
125127
126128 public function edit (Request $ request , $ id )
127129 {
128130 $ pack = Models \ServicePack::findOrFail ($ id );
129131 $ option = Models \ServiceOptions::select ('id ' , 'parent_service ' , 'name ' )->where ('id ' , $ pack ->option )->first ();
132+
130133 return view ('admin.services.packs.edit ' , [
131134 'pack ' => $ pack ,
132135 'services ' => $ this ->formatServices (),
133136 'files ' => Storage::files ('packs/ ' . $ pack ->uuid ),
134137 'service ' => Models \Service::findOrFail ($ option ->parent_service ),
135- 'option ' => $ option
138+ 'option ' => $ option,
136139 ]);
137140 }
138141
139142 public function update (Request $ request , $ id )
140143 {
141- if (!is_null ($ request ->input ('action_delete ' ))) {
144+ if (! is_null ($ request ->input ('action_delete ' ))) {
142145 try {
143146 $ repo = new Pack ;
144147 $ repo ->delete ($ id );
145148 Alert::success ('The requested service pack has been deleted from the system. ' )->flash ();
149+
146150 return redirect ()->route ('admin.services.packs ' );
147151 } catch (DisplayException $ ex ) {
148152 Alert::danger ($ ex ->getMessage ())->flash ();
149153 } catch (\Exception $ ex ) {
150154 Log::error ($ ex );
151155 Alert::danger ('An error occured while attempting to delete this pack. ' )->flash ();
152156 }
157+
153158 return redirect ()->route ('admin.services.packs.edit ' , $ id );
154159 } else {
155160 try {
156161 $ repo = new Pack ;
157162 $ repo ->update ($ id , $ request ->except ([
158- '_token '
163+ '_token ' ,
159164 ]));
160165 Alert::success ('Service pack has been successfully updated. ' )->flash ();
161166 } catch (DisplayValidationException $ ex ) {
@@ -164,6 +169,7 @@ public function update(Request $request, $id)
164169 Log::error ($ ex );
165170 Alert::danger ('An error occured while attempting to add edit this pack. ' )->flash ();
166171 }
172+
167173 return redirect ()->route ('admin.services.packs.edit ' , $ id );
168174 }
169175 }
@@ -183,14 +189,14 @@ public function export(Request $request, $id, $files = false)
183189 'cpu ' => $ pack ->build_cpu ,
184190 'io ' => $ pack ->build_io ,
185191 'container ' => $ pack ->build_container ,
186- 'script ' => $ pack ->build_script
187- ]
192+ 'script ' => $ pack ->build_script ,
193+ ],
188194 ];
189195
190196 $ filename = tempnam (sys_get_temp_dir (), 'pterodactyl_ ' );
191197 if ((bool ) $ files ) {
192198 $ zip = new \ZipArchive ;
193- if (!$ zip ->open ($ filename , \ZipArchive::CREATE )) {
199+ if (! $ zip ->open ($ filename , \ZipArchive::CREATE )) {
194200 abort (503 , 'Unable to open file for writing. ' );
195201 }
196202
@@ -207,16 +213,18 @@ public function export(Request $request, $id, $files = false)
207213 $ fp = fopen ($ filename , 'a+ ' );
208214 fwrite ($ fp , json_encode ($ json , JSON_PRETTY_PRINT ));
209215 fclose ($ fp );
216+
210217 return response ()->download ($ filename , 'pack- ' . $ pack ->name . '.json ' , [
211- 'Content-Type ' => 'application/json '
218+ 'Content-Type ' => 'application/json ' ,
212219 ])->deleteFileAfterSend (true );
213220 }
214221 }
215222
216- public function uploadForm (Request $ request , $ for = null ) {
223+ public function uploadForm (Request $ request , $ for = null )
224+ {
217225 return view ('admin.services.packs.upload ' , [
218226 'services ' => $ this ->formatServices (),
219- 'for ' => $ for
227+ 'for ' => $ for,
220228 ]);
221229 }
222230
@@ -225,9 +233,10 @@ public function postUpload(Request $request)
225233 try {
226234 $ repo = new Pack ;
227235 $ id = $ repo ->createWithTemplate ($ request ->except ([
228- '_token '
236+ '_token ' ,
229237 ]));
230238 Alert::success ('Successfully created new service! ' )->flash ();
239+
231240 return redirect ()->route ('admin.services.packs.edit ' , $ id )->withInput ();
232241 } catch (DisplayValidationException $ ex ) {
233242 return redirect ()->back ()->withErrors (json_decode ($ ex ->getMessage ()))->withInput ();
@@ -237,6 +246,7 @@ public function postUpload(Request $request)
237246 Log::error ($ ex );
238247 Alert::danger ('An error occured while attempting to add a new service pack. ' )->flash ();
239248 }
249+
240250 return redirect ()->back ();
241251 }
242252}
0 commit comments