Super early base implementation of notifications from daemon

This commit is contained in:
Dane Everitt 2016-10-14 16:20:24 -04:00
parent c989dd0cc2
commit 63058d8c8e
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 95 additions and 0 deletions

View file

@ -25,6 +25,7 @@ namespace Pterodactyl\Http\Controllers\Remote;
use Pterodactyl\Models;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Services\NotificationService;
use Pterodactyl\Http\Controllers\Controller;
use Illuminate\Http\Request;
@ -82,4 +83,29 @@ class RemoteController extends Controller
], 200);
}
public function event(Request $request)
{
$server = Models\Server::where('uuid', $request->input('server'))->first();
if (!$server) {
return response()->json([
'error' => 'No server by that ID was found on the system.'
], 422);
}
$node = Models\Node::findOrFail($server->node);
$hmac = $request->input('signed');
if (base64_decode($hmac) !== hash_hmac('sha256', $server->uuid, $node->daemonSecret, true)) {
return response()->json([
'error' => 'Signed HMAC was invalid.'
], 403);
}
// Passes Validation, Setup Notifications
$notify = new NotificationService($server);
$notify->pass($request->input('notification'));
return response('', 201);
}
}