Add support for viewing SFTP password in panel
requested in #74 closes #74
This commit is contained in:
parent
8c40f647d3
commit
1ca07e665e
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddSftpPasswordStorage extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('servers', function (Blueprint $table) {
|
||||
$table->text('sftp_password')->after('username')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('servers', function (Blueprint $table) {
|
||||
$table->dropColumn('sftp_password');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -51,29 +51,34 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@can('reset-sftp', $server)
|
||||
<form action="{{ route('server.settings.sftp', $server->uuidShort) }}" method="POST">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div id="gen_pass" class=" alert alert-success" style="display:none;margin-bottom: 10px;"></div>
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label class="control-label">New SFTP Password:</label>
|
||||
<div>
|
||||
<input type="password" name="sftp_pass" class="form-control" />
|
||||
<p class="text-muted"><small>Passwords must meet the following requirements: at least one uppercase character, one lowercase character, one digit, and be at least 8 characters in length. <a href="#" data-action="generate-password">Click here</a> to generate one to use.</small></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label class="control-label"> </label>
|
||||
<div>
|
||||
{!! csrf_field() !!}
|
||||
<input type="submit" class="btn btn-sm btn-primary" value="Update Password" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div id="gen_pass" class=" alert alert-success" style="display:none;margin-bottom: 10px;"></div>
|
||||
</div>
|
||||
</form>
|
||||
@endcan
|
||||
<div class="form-group col-md-6">
|
||||
@can('reset-sftp', $server)
|
||||
<form action="{{ route('server.settings.sftp', $server->uuidShort) }}" method="POST">
|
||||
<label class="control-label">New SFTP Password:</label>
|
||||
<div class="input-group">
|
||||
<input type="password" class="form-control" name="sftp_pass" />
|
||||
<span class="input-group-btn">
|
||||
{!! csrf_field() !!}
|
||||
<input type="submit" class="btn btn-primary btn-sm" value="Reset" />
|
||||
</span>
|
||||
</div>
|
||||
<p class="text-muted"><small>Passwords must meet the following requirements: at least one uppercase character, one lowercase character, one digit, and be at least 8 characters in length. <a href="#" data-action="generate-password">Click here</a> to generate one to use.</small></p>
|
||||
</form>
|
||||
@endcan
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
@can('view-sftp-password', $server)
|
||||
<label class="control-label">Current Password:</label>
|
||||
<div>
|
||||
<input type="text" readonly="readonly" class="form-control" value="@if(!is_null($server->sftp_password)){{ Crypt::decrypt($server->sftp_password) }} @endif" />
|
||||
</div>
|
||||
@endcan
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -200,6 +200,12 @@
|
|||
<p class="text-muted"><small>Allows user to view the server's SFTP information (not the password).</small><p>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox highlight">
|
||||
<label class="checkbox-custom highlight" data-initialize="checkbox">
|
||||
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($oldInput['view-sftp-password']))checked="checked"@endif value="view-sftp-password"> <strong>View SFTP Password</strong>
|
||||
<p class="text-muted"><small><span class="label label-danger">Danger</span> Allows user to view the SFTP password for the server.</small><p>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox highlight">
|
||||
<label class="checkbox-custom highlight" data-initialize="checkbox">
|
||||
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($oldInput['reset-sftp']))checked="checked"@endif value="reset-sftp"> <strong>Reset SFTP Password</strong>
|
||||
|
|
|
@ -189,6 +189,12 @@
|
|||
<p class="text-muted"><small>Allows user to view the server's SFTP information (not the password).</small><p>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox highlight">
|
||||
<label class="checkbox-custom highlight" data-initialize="checkbox">
|
||||
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($permissions['view-sftp-password']))checked="checked"@endif @cannot('edit-subuser', $server)disabled="disabled"@endcannot value="view-sftp-password"> <strong>View SFTP Password</strong>
|
||||
<p class="text-muted"><small><span class="label label-danger">Danger</span> Allows user to view the SFTP password for the server.</small><p>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox highlight">
|
||||
<label class="checkbox-custom highlight" data-initialize="checkbox">
|
||||
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($permissions['reset-sftp']))checked="checked"@endif @cannot('edit-subuser', $server)disabled="disabled"@endcannot value="reset-sftp"> <strong>Reset SFTP Password</strong>
|
||||
|
|
Loading…
Reference in New Issue