2626
2727use DB ;
2828use Log ;
29+ use Hash ;
2930use Alert ;
3031use Carbon ;
3132use Validator ;
@@ -107,21 +108,6 @@ public function postNew(Request $request)
107108 return redirect ()->route ('admin.nodes.new ' )->withInput ();
108109 }
109110
110- public function getView (Request $ request , $ id )
111- {
112- $ node = Models \Node::with (
113- 'servers.user ' , 'servers.service ' ,
114- 'servers.allocations ' , 'location '
115- )->findOrFail ($ id );
116- $ node ->setRelation ('allocations ' , $ node ->allocations ()->with ('server ' )->paginate (40 ));
117-
118- return view ('admin.nodes.view ' , [
119- 'node ' => $ node ,
120- 'stats ' => Models \Server::select (DB ::raw ('SUM(memory) as memory, SUM(disk) as disk ' ))->where ('node_id ' , $ node ->id )->first (),
121- 'locations ' => Models \Location::all (),
122- ]);
123- }
124-
125111 /**
126112 * Shows the index overview page for a specific node.
127113 *
@@ -221,36 +207,35 @@ public function viewServers(Request $request, $id)
221207 ]);
222208 }
223209
224- public function postView (Request $ request , $ id )
210+ /**
211+ * Updates settings for a node.
212+ *
213+ * @param Request $request
214+ * @param integer $node
215+ * @return \Illuminate\Http\RedirectResponse
216+ */
217+ public function updateSettings (Request $ request , $ id )
225218 {
219+ $ repo = new NodeRepository ;
220+
226221 try {
227- $ node = new NodeRepository ;
228- $ node ->update ($ id , $ request ->only ([
229- 'name ' , 'location_id ' , 'public ' ,
230- 'fqdn ' , 'scheme ' , 'memory ' ,
231- 'memory_overallocate ' , 'disk ' ,
232- 'disk_overallocate ' , 'upload_size ' ,
222+ $ repo ->update ($ id , $ request ->intersect ([
223+ 'name ' , 'location_id ' , 'public ' , 'fqdn ' , 'scheme ' , 'memory ' ,
224+ 'memory_overallocate ' , 'disk ' , 'disk_overallocate ' , 'upload_size ' ,
233225 'daemonSFTP ' , 'daemonListen ' , 'reset_secret ' ,
234226 ]));
235- Alert::success ('Successfully update this node \'s information. If you changed any daemon settings you will need to restart it now. ' )->flash ();
236227
237- return redirect ()->route ('admin.nodes.view ' , [
238- 'id ' => $ id ,
239- 'tab ' => 'tab_settings ' ,
240- ]);
241- } catch (DisplayValidationException $ e ) {
242- return redirect ()->route ('admin.nodes.view ' , $ id )->withErrors (json_decode ($ e ->getMessage ()))->withInput ();
243- } catch (DisplayException $ e ) {
244- Alert::danger ($ e ->getMessage ())->flash ();
245- } catch (\Exception $ e ) {
246- Log::error ($ e );
228+ Alert::success ('Successfully updated this node \'s information. If you changed any daemon settings you will need to restart it now. ' )->flash ();
229+ } catch (DisplayValidationException $ ex ) {
230+ return redirect ()->route ('admin.nodes.view.settings ' , $ id )->withErrors (json_decode ($ ex ->getMessage ()))->withInput ();
231+ } catch (DisplayException $ ex ) {
232+ Alert::danger ($ ex ->getMessage ())->flash ();
233+ } catch (\Exception $ ex ) {
234+ Log::error ($ ex );
247235 Alert::danger ('An unhandled exception occured while attempting to edit this node. Please try again. ' )->flash ();
248236 }
249237
250- return redirect ()->route ('admin.nodes.view ' , [
251- 'id ' => $ id ,
252- 'tab ' => 'tab_settings ' ,
253- ])->withInput ();
238+ return redirect ()->route ('admin.nodes.view.settings ' , $ id )->withInput ();
254239 }
255240
256241 /**
@@ -259,7 +244,7 @@ public function postView(Request $request, $id)
259244 * @param Request $request
260245 * @param integer $node
261246 * @param integer $allocation [description]
262- * @return mixed
247+ * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
263248 */
264249 public function allocationRemoveSingle (Request $ request , $ node , $ allocation )
265250 {
@@ -278,7 +263,7 @@ public function allocationRemoveSingle(Request $request, $node, $allocation)
278263 *
279264 * @param Request $request
280265 * @param integer $node
281- * @return mixed
266+ * @return \Illuminate\Http\RedirectResponse
282267 */
283268 public function allocationRemoveBlock (Request $ request , $ node )
284269 {
@@ -297,7 +282,8 @@ public function allocationRemoveBlock(Request $request, $node)
297282 *
298283 * @param Request $request
299284 * @param integer $node
300- * @return mixed
285+ * @return \Illuminate\Http\Response
286+ * @throws \Exception
301287 */
302288 public function allocationSetAlias (Request $ request , $ node )
303289 {
@@ -342,51 +328,48 @@ public function createAllocation(Request $request, $node)
342328 return redirect ()->route ('admin.nodes.view.allocation ' , $ node );
343329 }
344330
345- public function getAllocationsJson (Request $ request , $ id )
331+ /**
332+ * Deletes a node from the system.
333+ *
334+ * @param Request $request
335+ * @param integer $id
336+ * @return \Illuminate\Http\RedirectResponse
337+ */
338+ public function delete (Request $ request , $ id )
346339 {
347- $ allocations = Models \Allocation::select ('ip ' )->where ('node_id ' , $ id )->groupBy ('ip ' )->get ();
348-
349- return response ()->json ($ allocations );
350- }
340+ $ repo = new NodeRepository ;
351341
352- public function deleteNode (Request $ request , $ id )
353- {
354342 try {
355- $ repo = new NodeRepository ;
356343 $ repo ->delete ($ id );
357344 Alert::success ('Successfully deleted the requested node from the panel. ' )->flash ();
358345
359346 return redirect ()->route ('admin.nodes ' );
360- } catch (DisplayException $ e ) {
361- Alert::danger ($ e ->getMessage ())->flash ();
362- } catch (\Exception $ e ) {
363- Log::error ($ e );
347+ } catch (DisplayException $ ex ) {
348+ Alert::danger ($ ex ->getMessage ())->flash ();
349+ } catch (\Exception $ ex ) {
350+ Log::error ($ ex );
364351 Alert::danger ('An unhandled exception occured while attempting to delete this node. Please try again. ' )->flash ();
365352 }
366353
367- return redirect ()->route ('admin.nodes.view ' , [
368- 'id ' => $ id ,
369- 'tab ' => 'tab_delete ' ,
370- ]);
354+ return redirect ()->route ('admin.nodes.view ' , $ id );
371355 }
372356
373- public function getConfigurationToken (Request $ request , $ id )
357+ /**
358+ * Returns the configuration token to auto-deploy a node.
359+ *
360+ * @param Request $request
361+ * @param integer $id
362+ * @return \Illuminate\Http\JsonResponse
363+ */
364+ public function setToken (Request $ request , $ id )
374365 {
375- // Check if Node exists. Will lead to 404 if not.
376- Models \Node::findOrFail ($ id );
377-
378- // Create a token
379- $ token = new Models \NodeConfigurationToken ();
380- $ token ->node = $ id ;
381- $ token ->token = str_random (32 );
382- $ token ->expires_at = Carbon::now ()->addMinutes (5 ); // Expire in 5 Minutes
383- $ token ->save ();
384-
385- $ token_response = [
386- 'token ' => $ token ->token ,
387- 'expires_at ' => $ token ->expires_at ->toDateTimeString (),
388- ];
389-
390- return response ()->json ($ token_response , 200 );
366+ $ node = Models \Node::findOrFail ($ id );
367+
368+ $ t = Models \NodeConfigurationToken::create ([
369+ 'node_id ' => $ id ,
370+ 'token ' => str_random (32 ),
371+ ]);
372+
373+ return response ()->json (['token ' => $ t ->token ]);
391374 }
392375}
0 commit comments