mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-09 18:03:44 +02:00
Cleanup node routes, cleanup remote token
This commit is contained in:
@@ -105,27 +105,26 @@ class RemoteController extends Controller
|
||||
return response('', 201);
|
||||
}
|
||||
|
||||
public function getConfiguration(Request $request, $tokenString)
|
||||
public function getConfiguration(Request $request, $token)
|
||||
{
|
||||
// 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);
|
||||
$model = Models\NodeConfigurationToken::with('node')->where('token', $token)->firstOrFail();
|
||||
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
|
||||
return response()->json(['error' => 'token_invalid'], 403);
|
||||
}
|
||||
|
||||
// Check if token is expired
|
||||
if ($token->expires_at->lt(Carbon::now())) {
|
||||
$token->delete();
|
||||
if ($model->created_at->lt(Carbon::now())) {
|
||||
$model->delete();
|
||||
|
||||
return response()->json(['error' => 'token_expired'], 403);
|
||||
}
|
||||
|
||||
// Delete the token, it's one-time use
|
||||
$token->delete();
|
||||
$model->delete();
|
||||
|
||||
// Manually as getConfigurationAsJson() returns it in correct format already
|
||||
return response($node->getConfigurationAsJson())->header('Content-Type', 'text/json');
|
||||
return response($model->node->getConfigurationAsJson())->header('Content-Type', 'text/json');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user