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

@ -24,10 +24,12 @@
namespace Pterodactyl\Http\Controllers\Remote;
use Carbon\Carbon;
use Pterodactyl\Models;
use Illuminate\Http\Request;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Services\NotificationService;
use Pterodactyl\Models\NodeConfigurationToken;
class RemoteController extends Controller
{
@ -107,4 +109,28 @@ class RemoteController extends Controller
return response('', 201);
}
public function getConfiguration(Request $request, $tokenString) {
// Try to query the token and the node from the database
try {
$token = Models\NodeConfigurationToken::where('token', $tokenString)->firstOrFail();
$node = Models\Node::findOrFail($token->node);
} catch(\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
return response(json_encode(array('error' => 'token_invalid')), 403)
->header('Content-Type', 'application/json');
}
// Check if token is expired
if ($token->expires_at->lt(Carbon::now())) {
$token->delete();
return response(json_encode(array('error' => 'token_expired')), 403)
->header('Content-Type', 'application/json');
}
// Delete the token, it's one-time use
$token->delete();
return response($node->getConfigurationAsJson(), 200)
->header('Content-Type', 'application/json');
}
}