Commit b939109f4096811b6b18e64512ffc434e1d1de2b
1 parent
0efc7c84
fix: add debug log viewer and proxy logging
Showing
1 changed file
with
21 additions
and
2 deletions
| ... | ... | @@ -164,10 +164,10 @@ $ws_worker->onMessage = function ($connection, $data) use (&$clients, &$devices, |
| 164 | 164 | // Check if it's a NEW device (not in DB) |
| 165 | 165 | // We need a way to check existence without secret verification failure masking it |
| 166 | 166 | // Let's rely on registerDevice's internal check or check explicitly |
| 167 | - | |
| 167 | + | |
| 168 | 168 | // Ideally verifyDevice returns false if ID not found OR secret wrong. |
| 169 | 169 | // We can try to register it. If it succeeds, it was new. If it fails (ID exists), then it was a wrong secret. |
| 170 | - | |
| 170 | + | |
| 171 | 171 | $regResult = $deviceService->registerDevice($deviceId, $secret, "New Device " . substr($deviceId, -4)); |
| 172 | 172 | if ($regResult['ok']) { |
| 173 | 173 | echo "✨ Auto-Registered New Device: $deviceId\n"; |
| ... | ... | @@ -263,6 +263,9 @@ $ws_worker->onMessage = function ($connection, $data) use (&$clients, &$devices, |
| 263 | 263 | |
| 264 | 264 | // Device -> Client |
| 265 | 265 | if ($msg['type'] === 'proxy_response' && $connection->role === 'device') { |
| 266 | + // Debug: Log the raw response from device to see structure | |
| 267 | + echo "Received proxy_response from device: " . json_encode($msg) . "\n"; | |
| 268 | + | |
| 266 | 269 | $targetClientId = $msg['targetClientId'] ?? null; |
| 267 | 270 | if ($targetClientId && isset($clients[$targetClientId])) { |
| 268 | 271 | $payload = $msg['payload']; |
| ... | ... | @@ -723,6 +726,22 @@ $http_worker->onMessage = function ($connection, $request) use ($config, $authSe |
| 723 | 726 | } |
| 724 | 727 | } |
| 725 | 728 | |
| 729 | + // 5. Debug Log Viewer | |
| 730 | + if ($path === '/api/debug/logs') { | |
| 731 | + $logFile = __DIR__ . '/debug.log'; | |
| 732 | + if (file_exists($logFile)) { | |
| 733 | + // Read last 100 lines for efficiency | |
| 734 | + $lines = file($logFile); | |
| 735 | + $count = count($lines); | |
| 736 | + $last = $count > 100 ? array_slice($lines, -100) : $lines; | |
| 737 | + $content = implode("", $last); | |
| 738 | + $connection->send(new \Workerman\Protocols\Http\Response(200, ['Content-Type' => 'text/plain'], $content)); | |
| 739 | + } else { | |
| 740 | + $connection->send(new \Workerman\Protocols\Http\Response(404, [], 'Log not found')); | |
| 741 | + } | |
| 742 | + return; | |
| 743 | + } | |
| 744 | + | |
| 726 | 745 | $connection->send("Moltbot Relay HTTP Server"); |
| 727 | 746 | }; |
| 728 | 747 | ... | ... |
Please
register
or
login
to post a comment