2015-12-06 18:58:49 +00:00
|
|
|
<?php
|
2016-01-20 00:10:39 +00:00
|
|
|
/**
|
2016-01-20 21:05:16 +00:00
|
|
|
* Pterodactyl - Panel
|
2017-01-24 22:57:08 +00:00
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
2016-01-20 00:10:39 +00:00
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2016-01-20 00:10:39 +00:00
|
|
|
*/
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2015-12-06 18:58:49 +00:00
|
|
|
namespace Pterodactyl\Http\Controllers\Server;
|
|
|
|
|
|
|
|
use Log;
|
2016-08-16 04:07:10 +00:00
|
|
|
use Pterodactyl\Models;
|
2015-12-06 18:58:49 +00:00
|
|
|
use Illuminate\Http\Request;
|
2016-12-07 22:46:38 +00:00
|
|
|
use Pterodactyl\Repositories;
|
|
|
|
use Pterodactyl\Exceptions\DisplayException;
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2015-12-06 18:58:49 +00:00
|
|
|
|
|
|
|
class AjaxController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $files = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $folders = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $directory;
|
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Resets a database password for a server.
|
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param string $uuid
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
* @deprecated
|
|
|
|
*/
|
2016-08-16 04:07:10 +00:00
|
|
|
public function postResetDatabasePassword(Request $request, $uuid)
|
|
|
|
{
|
2017-02-03 00:41:38 +00:00
|
|
|
$server = Models\Server::byUuid($uuid);
|
2016-08-16 04:07:10 +00:00
|
|
|
$this->authorize('reset-db-password', $server);
|
2017-02-03 00:41:38 +00:00
|
|
|
|
2017-03-05 21:46:44 +00:00
|
|
|
$database = Models\Database::where('server_id', $server->id)->findOrFail($request->input('database'));
|
|
|
|
$repo = new Repositories\DatabaseRepository;
|
|
|
|
|
2016-08-16 04:07:10 +00:00
|
|
|
try {
|
2017-03-05 21:46:44 +00:00
|
|
|
$password = str_random(20);
|
|
|
|
$repo->password($database->id, $password);
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2016-08-16 04:07:10 +00:00
|
|
|
return response($password);
|
2017-03-05 21:46:44 +00:00
|
|
|
} catch (DisplayException $ex) {
|
|
|
|
return response()->json(['error' => $ex->getMessage()], 503);
|
2016-12-07 22:46:38 +00:00
|
|
|
} catch (\Exception $ex) {
|
2016-08-16 04:07:10 +00:00
|
|
|
Log::error($ex);
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2016-08-16 04:07:10 +00:00
|
|
|
return response()->json([
|
2016-12-07 22:46:38 +00:00
|
|
|
'error' => 'An unhandled error occured while attempting to modify this database\'s password.',
|
2016-08-16 04:07:10 +00:00
|
|
|
], 503);
|
|
|
|
}
|
|
|
|
}
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|