Example #1
0
 /**
  * List All Locations
  *
  * Lists all locations currently on the system.
  *
  * @Get("/locations")
  * @Versions({"v1"})
  * @Response(200)
  */
 public function list(Request $request)
 {
     $locations = Location::select('locations.*', DB::raw('GROUP_CONCAT(nodes.id) as nodes'))->join('nodes', 'locations.id', '=', 'nodes.location')->groupBy('locations.id')->get();
     foreach ($locations as &$location) {
         $location->nodes = explode(',', $location->nodes);
     }
     return $locations;
 }
 public function deleteLocation(Request $request, $id)
 {
     $model = Models\Location::select('locations.id', DB::raw('(SELECT COUNT(*) FROM nodes WHERE nodes.location = locations.id) as a_nodeCount'), DB::raw('(SELECT COUNT(*) FROM servers WHERE servers.node IN (SELECT nodes.id FROM nodes WHERE nodes.location = locations.id)) as a_serverCount'))->where('id', $id)->first();
     if (!$model) {
         return response()->json(['error' => 'No location with that ID exists on the system.'], 404);
     }
     if ($model->a_nodeCount > 0 || $model->a_serverCount > 0) {
         return response()->json(['error' => 'You cannot remove a location that is currently assigned to a node or server.'], 422);
     }
     $model->delete();
     return response('', 204);
 }
Example #3
0
 /**
  * Modifies a location based on the fields passed in $data.
  * @param  integer $id
  * @param  array   $data
  * @throws Pterodactyl\Exceptions\DisplayValidationException
  * @return boolean
  */
 public function edit($id, array $data)
 {
     $validator = Validator::make($data, ['short' => 'regex:/^[a-z0-9_.-]{1,10}$/i', 'long' => 'string|min:1|max:255']);
     // Run validator, throw catchable and displayable exception if it fails.
     // Exception includes a JSON result of failed validation rules.
     if ($validator->fails()) {
         throw new DisplayValidationException($validator->errors());
     }
     $location = Models\Location::findOrFail($id);
     if (isset($data['short'])) {
         $location->short = $data['short'];
     }
     if (isset($data['long'])) {
         $location->long = $data['long'];
     }
     return $location->save();
 }
Example #4
0
 public function getNew(Request $request)
 {
     return view('admin.servers.new', ['locations' => Models\Location::all(), 'services' => Models\Service::all()]);
 }
Example #5
0
 public function getView(Request $request, $id)
 {
     $node = Models\Node::findOrFail($id);
     $allocations = [];
     $alloc = Models\Allocation::select('ip', 'port', 'assigned_to')->where('node', $node->id)->orderBy('ip', 'asc')->orderBy('port', 'asc')->get();
     if ($alloc) {
         foreach ($alloc as &$alloc) {
             if (!array_key_exists($alloc->ip, $allocations)) {
                 $allocations[$alloc->ip] = [['port' => $alloc->port, 'assigned_to' => $alloc->assigned_to]];
             } else {
                 array_push($allocations[$alloc->ip], ['port' => $alloc->port, 'assigned_to' => $alloc->assigned_to]);
             }
         }
     }
     return view('admin.nodes.view', ['node' => $node, 'servers' => Models\Server::select('servers.*', 'users.email as a_ownerEmail', 'services.name as a_serviceName')->join('users', 'users.id', '=', 'servers.owner')->join('services', 'services.id', '=', 'servers.service')->where('node', $id)->paginate(10), 'stats' => Models\Server::select(DB::raw('SUM(memory) as memory, SUM(disk) as disk'))->where('node', $node->id)->first(), 'locations' => Models\Location::all(), 'allocations' => json_decode(json_encode($allocations), false)]);
 }