add ability to generate a token to retrieve the config for a specific node

This commit is contained in:
Jakob Schrettenbrunner 2017-01-07 18:10:11 +01:00
parent 24bab6de17
commit e1e159b7de
7 changed files with 147 additions and 0 deletions

View file

@ -28,6 +28,7 @@ use DB;
use Log;
use Alert;
use Validator;
use Carbon\Carbon;
use Pterodactyl\Models;
use Illuminate\Http\Request;
use Pterodactyl\Exceptions\DisplayException;
@ -276,4 +277,24 @@ class NodesController extends Controller
'tab' => 'tab_delete',
]);
}
public function getConfigurationToken(Request $request, $id) {
// Check if Node exists. Will lead to 404 if not.
Models\Node::findOrFail($id);
// Create a token
$token = new Models\NodeConfigurationToken();
$token->node = $id;
$token->token = str_random(32);
$token->expires_at = Carbon::now()->addMinutes(5); // Expire in 5 Minutes
$token->save();
$token_response = array(
'token' => $token->token,
'expires_at' => $token->expires_at->toDateTimeString()
);
return response(json_encode($token_response), 200)
->header('Content-Type', 'application/json');
}
}