From 95229fd1b7dd1e9ce8c94d2d8c6577707e5ed9a0 Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 16 Nov 2025 21:34:48 +0100 Subject: [PATCH] Add public method getHostapdLogs() --- .../Networking/Hotspot/HotspotService.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/RaspAP/Networking/Hotspot/HotspotService.php b/src/RaspAP/Networking/Hotspot/HotspotService.php index 2f6a3c60..1fff4bde 100644 --- a/src/RaspAP/Networking/Hotspot/HotspotService.php +++ b/src/RaspAP/Networking/Hotspot/HotspotService.php @@ -351,6 +351,36 @@ class HotspotService return array_values($interfaces); } + /** + * Retrieves hostapd service logs from systemd journal + * + * @param int $lines number of log lines to retrieve (default: 100, max: 1000) + * @param bool $follow return command for real-time following (tbd) + * @return array ['success' => bool, 'logs' => array, 'command' => string] + */ + public function getHostapdLogs(int $lines = 100, bool $follow = false): array + { + // sanitize and limit line count + $lines = max(1, min(1000, $lines)); + + if ($follow) { + return [ + 'success' => true, + 'logs' => [], + 'command' => 'journalctl -u hostapd.service -f --no-pager' + ]; + } + + $cmd = sprintf('sudo journalctl -u hostapd.service -n %d --no-pager 2>&1', $lines); + exec($cmd, $output, $status); + + return [ + 'success' => $status === 0, + 'logs' => $output, + 'line_count' => count($output) + ]; + } + /** * Starts services for given interface *