misc_pterodactyl-panel/app/Http/Controllers/Server/AjaxController.php

68 lines
1.7 KiB
PHP
Raw Normal View History

<?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
namespace Pterodactyl\Http\Controllers\Server;
use Log;
use Pterodactyl\Models;
use Illuminate\Http\Request;
2016-12-07 22:46:38 +00:00
use Pterodactyl\Repositories;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Http\Controllers\Controller;
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
*/
public function postResetDatabasePassword(Request $request, $uuid)
{
$server = Models\Server::byUuid($uuid);
$this->authorize('reset-db-password', $server);
2017-03-05 21:46:44 +00:00
$database = Models\Database::where('server_id', $server->id)->findOrFail($request->input('database'));
$repo = new Repositories\DatabaseRepository;
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
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) {
Log::error($ex);
2016-12-07 22:46:38 +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.',
], 503);
}
}
}