From b7666bdb05855c53b1e437dfda65b0c4d5bb826f Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Mon, 18 Jan 2016 01:24:33 -0500 Subject: [PATCH] Basic initial subuser management --- .../Controllers/Server/SubuserController.php | 77 ++++++++ app/Http/Routes/ServerRoutes.php | 15 ++ app/Repositories/SubuserRepository.php | 78 ++++++++ resources/views/layouts/master.blade.php | 2 + resources/views/server/index.blade.php | 6 +- resources/views/server/users/index.blade.php | 38 ++++ resources/views/server/users/view.blade.php | 166 ++++++++++++++++++ 7 files changed, 381 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/Server/SubuserController.php create mode 100644 app/Repositories/SubuserRepository.php create mode 100644 resources/views/server/users/index.blade.php create mode 100644 resources/views/server/users/view.blade.php diff --git a/app/Http/Controllers/Server/SubuserController.php b/app/Http/Controllers/Server/SubuserController.php new file mode 100644 index 000000000..c3757658a --- /dev/null +++ b/app/Http/Controllers/Server/SubuserController.php @@ -0,0 +1,77 @@ +authorize('list-subusers', $server); + + return view('server.users.index', [ + 'server' => $server, + 'node' => Models\Node::find($server->node), + 'subusers' => Models\Subuser::select('subusers.*', 'users.email as a_userEmail') + ->join('users', 'users.id', '=', 'subusers.user_id') + ->where('server_id', $server->id) + ->get() + ]); + + } + + 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, + ]); + } + + public function postView(Request $request, $uuid, $id) + { + // + } + +} diff --git a/app/Http/Routes/ServerRoutes.php b/app/Http/Routes/ServerRoutes.php index a00ec390b..f29264afa 100644 --- a/app/Http/Routes/ServerRoutes.php +++ b/app/Http/Routes/ServerRoutes.php @@ -52,6 +52,21 @@ class ServerRoutes { 'uses' => 'Server\AjaxController@postSaveFile' ]); + // Sub-User Routes + $router->get('users', [ + 'as' => 'server.subusers', + 'uses' => 'Server\SubuserController@getIndex' + ]); + + $router->get('users/view/{id}', [ + 'as' => 'server.subusers.view', + 'uses' => 'Server\SubuserController@getView' + ]); + + $router->post('users/view/{id}', [ + 'uses' => 'Server\SubuserController@postView' + ]); + // Assorted AJAX Routes $router->group(['prefix' => 'ajax'], function ($server) use ($router) { // Returns Server Status diff --git a/app/Repositories/SubuserRepository.php b/app/Repositories/SubuserRepository.php new file mode 100644 index 000000000..e5a0162aa --- /dev/null +++ b/app/Repositories/SubuserRepository.php @@ -0,0 +1,78 @@ + 's:power:start', + 'power-stop' => 's:power:stop', + 'power-restart' => 's:power:restart', + 'power-kill' => 's:power:kill', + + // Commands + 'send-command' => 's:command', + + // File Manager + 'list-files' => 's:files:get', + 'edit-file' => 's:files:read', + 'save-file' => 's:files:post', + 'create-file' => 's:files:post', + 'download-file' => null, + 'upload-file' => 's:files:upload', + 'delete-file' => 's:files:delete', + + // Subusers + 'list-subusers' => null, + 'view-subuser' => null, + 'edit-subuser' => null, + 'create-subuser' => null, + 'delete-subuser' => null, + + // Management + 'set-connection' => null, + 'view-sftp' => null, + 'reset-sftp' => 's:set-password' + ]; + + public function __construct() + { + // + } + + /** + * 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' + ]); + + if ($validator->fails()) { + throw new DisplayValidationException(json_encode($validator->all())); + } + + // @TODO the thing. + + } diff --git a/resources/views/layouts/master.blade.php b/resources/views/layouts/master.blade.php index 470f0de82..7ed559721 100644 --- a/resources/views/layouts/master.blade.php +++ b/resources/views/layouts/master.blade.php @@ -10,10 +10,12 @@ + + +@endsection diff --git a/resources/views/server/users/view.blade.php b/resources/views/server/users/view.blade.php new file mode 100644 index 000000000..b36479c70 --- /dev/null +++ b/resources/views/server/users/view.blade.php @@ -0,0 +1,166 @@ +@extends('layouts.master') + +@section('title') + Manage Subuser: {{ $subuser->a_userEmail }} +@endsection + +@section('content') +
+

Manage Subuser {{ $subuser->a_userEmail }}


+ @can('edit-subuser', $server) +
+ @endcan +
+
+

Power Management


+
+
+
+
+
+
+
+
+
+
+
+
+

File Management


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

Subuser Management


+
+
+
+
+
+
+
+
+
+
+
+
+

Server Management


+
+
+
+
+
+
+
+
+ @can('edit-subuser', $server) +
+
+
+ {!! csrf_field() !!} + +
+
+
+
+ @endcan +
+ +@endsection