Add support for viewing SFTP password in panel

requested in #74
closes #74
This commit is contained in:
Dane Everitt 2016-09-02 19:26:48 -04:00
parent 8c40f647d3
commit 1ca07e665e
7 changed files with 97 additions and 22 deletions

View file

@ -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.
*

View file

@ -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;
}

View file

@ -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,