mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-12-26 23:26:47 +01:00
Add public method getHostapdLogs()
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user