add ability to generate a token to retrieve the config for a specific node
This commit is contained in:
parent
24bab6de17
commit
e1e159b7de
7 changed files with 147 additions and 0 deletions
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue