public function getView(Request $request, $uuid, $id)
 {
     $server = Models\Server::getByUUID($uuid);
     $this->authorize('view-subuser', $server);
     $subuser = Models\Subuser::select('subusers.*', 'users.email as a_userEmail')->join('users', 'users.id', '=', 'subusers.user_id')->where(DB::raw('md5(subusers.id)'), $id)->where('subusers.server_id', $server->id)->first();
     if (!$subuser) {
         abort(404);
     }
     $permissions = [];
     $modelPermissions = Models\Permission::select('permission')->where('user_id', $subuser->user_id)->where('server_id', $server->id)->get();
     foreach ($modelPermissions as &$perm) {
         $permissions[$perm->permission] = true;
     }
     return view('server.users.view', ['server' => $server, 'node' => Models\Node::find($server->node), 'subuser' => $subuser, 'permissions' => $permissions]);
 }
Beispiel #2
0
 /**
  * Deletes a user on the panel, returns the number of records deleted.
  *
  * @param  integer $id
  * @return integer
  */
 public function delete($id)
 {
     if (Models\Server::where('owner', $id)->count() > 0) {
         throw new DisplayException('Cannot delete a user with active servers attached to thier account.');
     }
     DB::beginTransaction();
     try {
         Models\Permission::where('user_id', $id)->delete();
         Models\Subuser::where('user_id', $id)->delete();
         Models\User::destroy($id);
         DB::commit();
         return true;
     } catch (\Exception $ex) {
         DB::rollBack();
         throw $ex;
     }
 }
Beispiel #3
0
 public function deleteServer($id, $force)
 {
     $server = Models\Server::findOrFail($id);
     $node = Models\Node::findOrFail($server->node);
     DB::beginTransaction();
     try {
         // Delete Allocations
         Models\Allocation::where('assigned_to', $server->id)->update(['assigned_to' => null]);
         // Remove Variables
         Models\ServerVariables::where('server_id', $server->id)->delete();
         // Remove SubUsers
         Models\Subuser::where('server_id', $server->id)->delete();
         // Remove Permissions
         Models\Permission::where('server_id', $server->id)->delete();
         // Remove Downloads
         Models\Download::where('server', $server->uuid)->delete();
         $client = Models\Node::guzzleRequest($server->node);
         $client->request('DELETE', '/servers', ['headers' => ['X-Access-Token' => $node->daemonSecret, 'X-Access-Server' => $server->uuid]]);
         $server->delete();
         DB::commit();
         return true;
     } catch (\GuzzleHttp\Exception\TransferException $ex) {
         if ($force === 'force') {
             $server->delete();
             DB::commit();
             return true;
         } else {
             DB::rollBack();
             throw new DisplayException('An error occured while attempting to delete the server on the daemon.', $ex);
         }
     } catch (\Exception $ex) {
         DB::rollBack();
         throw $ex;
     }
 }
 /**
  * Updates permissions for a given subuser.
  * @param  integer $id  The ID of the subuser row in MySQL. (Not the user ID)
  * @param  array  $data
  * @throws DisplayValidationException
  * @throws DisplayException
  * @return void
  */
 public function update($id, array $data)
 {
     $validator = Validator::make($data, ['permissions' => 'required|array', 'user' => 'required|exists:users,id', 'server' => 'required|exists:servers,id']);
     if ($validator->fails()) {
         throw new DisplayValidationException(json_encode($validator->all()));
     }
     $subuser = Models\Subuser::findOrFail($id);
     $server = Models\Server::findOrFail($data['server']);
     DB::beginTransaction();
     try {
         Models\Permission::where('user_id', $subuser->user_id)->where('server_id', $subuser->server_id)->delete();
         $daemonPermissions = $this->coreDaemonPermissions;
         foreach ($data['permissions'] as $permission) {
             if (array_key_exists($permission, $this->permissions)) {
                 // Build the daemon permissions array for sending.
                 if (!is_null($this->permissions[$permission])) {
                     array_push($daemonPermissions, $this->permissions[$permission]);
                 }
                 $model = new Models\Permission();
                 $model->fill(['user_id' => $data['user'], 'server_id' => $data['server'], 'permission' => $permission]);
                 $model->save();
             }
         }
         // Contact Daemon
         // We contact even if they don't have any daemon permissions to overwrite
         // if they did have them previously.
         $node = Models\Node::getByID($server->node);
         $client = Models\Node::guzzleRequest($server->node);
         $res = $client->request('PATCH', '/server', ['headers' => ['X-Access-Server' => $server->uuid, 'X-Access-Token' => $node->daemonSecret], 'json' => ['keys' => [$subuser->daemonSecret => $daemonPermissions]]]);
         DB::commit();
         return true;
     } catch (\GuzzleHttp\Exception\TransferException $ex) {
         DB::rollBack();
         throw new DisplayException('There was an error attempting to connect to the daemon to update permissions.', $ex);
     } catch (\Exception $ex) {
         DB::rollBack();
         throw $ex;
     }
     return false;
 }