diff --git a/app/Policies/ServerPolicy.php b/app/Policies/ServerPolicy.php index 160d107f7..302ace0f4 100644 --- a/app/Policies/ServerPolicy.php +++ b/app/Policies/ServerPolicy.php @@ -434,6 +434,22 @@ class ServerPolicy return $user->permissions()->server($server)->permission('reset-sftp')->exists(); } + /** + * Check if user has permission to view the SFTP password for a server. + * + * @param Pterodactyl\Models\User $user + * @param Pterodactyl\Models\Server $server + * @return boolean + */ + public function viewSftpPassword(User $user, Server $server) + { + if ($this->isOwner($user, $server)) { + return true; + } + + return $user->permissions()->server($server)->permission('view-sftp-password')->exists(); + } + /** * Check if user has permission to view databases for a server. * diff --git a/app/Repositories/ServerRepository.php b/app/Repositories/ServerRepository.php index 06d97e353..a38b4e3a0 100644 --- a/app/Repositories/ServerRepository.php +++ b/app/Repositories/ServerRepository.php @@ -23,6 +23,7 @@ */ namespace Pterodactyl\Repositories; +use Crypt; use DB; use Debugbar; use Validator; @@ -804,7 +805,12 @@ class ServerRepository throw new DisplayValidationException(json_encode($validator->errors())); } + DB::beginTransaction(); + $server->sftp_password = Crypt::encrypt($password); + try { + $server->save(); + $client = Models\Node::guzzleRequest($server->node); $client->request('POST', '/server/password', [ 'headers' => [ @@ -815,10 +821,14 @@ class ServerRepository 'password' => $password, ], ]); + + DB::commit(); return true; } catch (\GuzzleHttp\Exception\TransferException $ex) { + DB::rollBack(); throw new DisplayException('There was an error while attmping to contact the remote service to change the password.', $ex); } catch (\Exception $ex) { + DB::rollBack(); throw $ex; } diff --git a/app/Repositories/SubuserRepository.php b/app/Repositories/SubuserRepository.php index f13c55dbb..38910e00a 100644 --- a/app/Repositories/SubuserRepository.php +++ b/app/Repositories/SubuserRepository.php @@ -93,6 +93,7 @@ class SubuserRepository 'edit-startup' => null, 'view-sftp' => null, 'reset-sftp' => 's:set-password', + 'view-sftp-password' => null, // Databases 'view-databases' => null, diff --git a/database/migrations/2016_09_02_190647_add_sftp_password_storage.php b/database/migrations/2016_09_02_190647_add_sftp_password_storage.php new file mode 100644 index 000000000..b950c631b --- /dev/null +++ b/database/migrations/2016_09_02_190647_add_sftp_password_storage.php @@ -0,0 +1,31 @@ +text('sftp_password')->after('username')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('servers', function (Blueprint $table) { + $table->dropColumn('sftp_password'); + }); + } +} diff --git a/resources/views/server/settings.blade.php b/resources/views/server/settings.blade.php index c3204237d..b5312c763 100644 --- a/resources/views/server/settings.blade.php +++ b/resources/views/server/settings.blade.php @@ -51,29 +51,34 @@ - @can('reset-sftp', $server) -
-
-
- -
-
- -
- -

Passwords must meet the following requirements: at least one uppercase character, one lowercase character, one digit, and be at least 8 characters in length. Click here to generate one to use.

-
-
-
- -
- {!! csrf_field() !!} - -
-
+
+
+
- - @endcan +
+ @can('reset-sftp', $server) +
+ +
+ + + {!! csrf_field() !!} + + +
+

Passwords must meet the following requirements: at least one uppercase character, one lowercase character, one digit, and be at least 8 characters in length. Click here to generate one to use.

+
+ @endcan +
+
+ @can('view-sftp-password', $server) + +
+ +
+ @endcan +
+
diff --git a/resources/views/server/users/new.blade.php b/resources/views/server/users/new.blade.php index 25fcfcbfc..c809f7bed 100644 --- a/resources/views/server/users/new.blade.php +++ b/resources/views/server/users/new.blade.php @@ -200,6 +200,12 @@

Allows user to view the server's SFTP information (not the password).

+

+
+
+