diff --git a/config/config.php b/config/config.php index 546441e6..e9a41827 100755 --- a/config/config.php +++ b/config/config.php @@ -23,7 +23,6 @@ define('RASPI_ADBLOCK_CONFIG', RASPI_DNSMASQ_PREFIX.'adblock.conf'); define('RASPI_HOSTAPD_CONFIG', '/etc/hostapd/hostapd.conf'); define('RASPI_DHCPCD_CONFIG', '/etc/dhcpcd.conf'); define('RASPI_DHCPCD_LOG', '/var/log/dnsmasq.log'); -define('RASPI_HOSTAPD_LOG', '/tmp/hostapd.log'); define('RASPI_WPA_SUPPLICANT_CONFIG', '/etc/wpa_supplicant/wpa_supplicant.conf'); define('RASPI_HOSTAPD_CTRL_INTERFACE', '/var/run/hostapd'); define('RASPI_WPA_CTRL_INTERFACE', '/var/run/wpa_supplicant'); diff --git a/includes/defaults.php b/includes/defaults.php index 7a64fa72..fc276727 100755 --- a/includes/defaults.php +++ b/includes/defaults.php @@ -28,7 +28,6 @@ $defaults = [ 'RASPI_HOSTAPD_CONFIG' => '/etc/hostapd/hostapd.conf', 'RASPI_DHCPCD_CONFIG' => '/etc/dhcpcd.conf', 'RASPI_DHCPCD_LOG' => '/var/log/dnsmasq.log', - 'RASPI_HOSTAPD_LOG' => '/tmp/hostapd.log', 'RASPI_WPA_SUPPLICANT_CONFIG' => '/etc/wpa_supplicant/wpa_supplicant.conf', 'RASPI_HOSTAPD_CTRL_INTERFACE' => '/var/run/hostapd', 'RASPI_WPA_CTRL_INTERFACE' => '/var/run/wpa_supplicant', diff --git a/includes/hostapd.php b/includes/hostapd.php index 29c33e35..58b2d9fc 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -45,8 +45,10 @@ function DisplayHostAPDConfig() } else { $interface = $_SESSION['ap_interface']; } + $txpower = $hotspot->getTxPower($interface); $arrHostapdConf = $hotspot->getHostapdIni(); + $logOutput = []; if (!RASPI_MONITOR_ENABLED) { if (isset($_POST['StartHotspot']) || isset($_POST['RestartHotspot'])) { @@ -77,6 +79,10 @@ function DisplayHostAPDConfig() $reg_domain, $status ); + + // reload hostapi.ini + $arrHostapdConf = $hotspot->getHostapdIni(); + } elseif (isset($_POST['StopHotspot'])) { $status->addMessage('Attempting to stop hotspot', 'info'); exec('sudo /bin/systemctl stop hostapd.service', $return); @@ -135,15 +141,21 @@ function DisplayHostAPDConfig() } } + // fetch hostapd logs if enabled + if ((string)$arrHostapdConf['LogEnable'] === "1") { + $logResult = $hotspot->getHostapdLogs(5000); + if ($logResult['success']) { + $joined = implode("\n", $logResult['logs']); + $limited = getLogLimited('', $joined); + $logOutput = explode("\n", $limited); + } + } + // assign disassoc_low_ack boolean if value is set $arrConfig['disassoc_low_ack_bool'] = isset($arrConfig['disassoc_low_ack']) ? 1 : 0; $hostapdstatus = $system->hostapdStatus(); $serviceStatus = $hostapdstatus[0] == 0 ? "down" : "up"; - // ensure log is writeable - exec('sudo /bin/chmod o+r '.RASPI_HOSTAPD_LOG); - $logdata = getLogLimited(RASPI_HOSTAPD_LOG); - echo renderTemplate( "hostapd", compact( "status", @@ -161,7 +173,7 @@ function DisplayHostAPDConfig() "arrHostapdConf", "operatingSystem", "countryCodes", - "logdata" + "logOutput" ) ); } diff --git a/installers/common.sh b/installers/common.sh index 12df56ff..c8e41ff6 100644 --- a/installers/common.sh +++ b/installers/common.sh @@ -325,9 +325,6 @@ function _create_hostapd_scripts() { _install_log "Creating hostapd logging & control scripts" sudo mkdir $raspap_dir/hostapd || _install_status 1 "Unable to create directory '$raspap_dir/hostapd'" - # Copy logging shell scripts - sudo cp "$webroot_dir/installers/"enablelog.sh "$raspap_dir/hostapd" || _install_status 1 "Unable to move logging scripts" - sudo cp "$webroot_dir/installers/"disablelog.sh "$raspap_dir/hostapd" || _install_status 1 "Unable to move logging scripts" # Copy service control shell scripts sudo cp "$webroot_dir/installers/"servicestart.sh "$raspap_dir/hostapd" || _install_status 1 "Unable to move service control scripts" # Change ownership and permissions of hostapd control scripts diff --git a/installers/disablelog.sh b/installers/disablelog.sh deleted file mode 100755 index 4272b88f..00000000 --- a/installers/disablelog.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -/bin/sed -i 's|DAEMON_OPTS=" -f /tmp/hostapd.log"|#DAEMON_OPTS=""|' /etc/default/hostapd - diff --git a/installers/enablelog.sh b/installers/enablelog.sh deleted file mode 100755 index 84a714b8..00000000 --- a/installers/enablelog.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -/bin/sed -i 's|#DAEMON_OPTS=""|DAEMON_OPTS=" -f /tmp/hostapd.log"|' /etc/default/hostapd -touch /tmp/hostapd.log diff --git a/installers/raspap.sudoers b/installers/raspap.sudoers index b7a8a589..63b12506 100644 --- a/installers/raspap.sudoers +++ b/installers/raspap.sudoers @@ -90,3 +90,4 @@ www-data ALL=(ALL) NOPASSWD:/etc/raspap/plugins/plugin_helper.sh www-data ALL=(ALL) NOPASSWD:/bin/systemctl start raspap-network-activity@*.service www-data ALL=(ALL) NOPASSWD:/bin/systemctl stop raspap-network-activity@*.service www-data ALL=(ALL) NOPASSWD:/bin/cp /tmp/wpa_conf_* /etc/wpa_supplicant/wpa_supplicant.conf +www-data ALL=(ALL) NOPASSWD:/usr/bin/journalctl -u hostapd.service * diff --git a/locale/en_US/LC_MESSAGES/messages.mo b/locale/en_US/LC_MESSAGES/messages.mo index 552a4644..58e9c5be 100644 Binary files a/locale/en_US/LC_MESSAGES/messages.mo and b/locale/en_US/LC_MESSAGES/messages.mo differ diff --git a/locale/en_US/LC_MESSAGES/messages.po b/locale/en_US/LC_MESSAGES/messages.po index 55a2c5e7..23e307aa 100644 --- a/locale/en_US/LC_MESSAGES/messages.po +++ b/locale/en_US/LC_MESSAGES/messages.po @@ -744,6 +744,27 @@ msgstr "Enable logging" msgid "Logfile output" msgstr "Logfile output" +msgid "Log level" +msgstr "Log level" + +msgid "Higher levels reduce log verbosity. Informational is recommended." +msgstr "Higher levels reduce log verbosity. Informational is recommended." + +msgid "Verbose debugging" +msgstr "Verbose debugging" + +msgid "Debugging" +msgstr "Debugging" + +msgid "Informational" +msgstr "Informational" + +msgid "Notification" +msgstr "Notification" + +msgid "Warning" +msgstr "Warning" + msgid "WiFi client AP mode" msgstr "WiFi client AP mode" diff --git a/src/RaspAP/Networking/Hotspot/HostapdManager.php b/src/RaspAP/Networking/Hotspot/HostapdManager.php index c9d0a5ef..0caa1523 100644 --- a/src/RaspAP/Networking/Hotspot/HostapdManager.php +++ b/src/RaspAP/Networking/Hotspot/HostapdManager.php @@ -225,6 +225,12 @@ class HostapdManager $config[] = 'max_num_sta=' . (int)$params['max_num_sta']; } + // add logging configuration if enabled + if (!empty($params['log_enable'])) { + $config[] = 'logger_syslog=-1'; + $config[] = 'logger_syslog_level=0'; + } + // optional additional user config $config[] = $this->parseUserHostapdCfg(); @@ -325,17 +331,6 @@ class HostapdManager return [$apIface, $cliIface, $sessionIface]; } - /** - * Enables or disables hostapd logging - * - * @param int $logEnable - */ - private function handleLogState(int $logEnable): void - { - $script = $logEnable === 1 ? 'enablelog.sh' : 'disablelog.sh'; - exec('sudo ' . RASPI_CONFIG . '/hostapd/' . $script); - } - /** * Parses optional /etc/hostapd/hostapd.conf.users file * @@ -415,8 +410,6 @@ class HostapdManager */ public function persistHostapdIni(array $states, string $apIface, string $cliIface, array $previousIni = []): bool { - $this->applyLogState($states['LogEnable']); - // compose new ini payload $cfg = [ 'WifiInterface' => $apIface, @@ -435,17 +428,6 @@ class HostapdManager return write_php_ini($cfg, RASPI_CONFIG . '/hostapd.ini'); } - /** - * Enables or disables hostapd logging - * - * @param int $logEnable 1 = enable, 0 = disable - */ - private function applyLogState(int $logEnable): void - { - $script = $logEnable === 1 ? 'enablelog.sh' : 'disablelog.sh'; - exec('sudo ' . RASPI_CONFIG . '/hostapd/' . $script); - } - /** * Returns a count of hostapd-.conf files * 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 * diff --git a/templates/hostapd/logging.php b/templates/hostapd/logging.php index 3948bc4d..facd8365 100644 --- a/templates/hostapd/logging.php +++ b/templates/hostapd/logging.php @@ -14,7 +14,7 @@
'.htmlspecialchars($logdata, ENT_QUOTES).''; + echo ''; } else { echo ''; }