From a91e44107331cd54975f6d8b4e0dcbb6cac3bb63 Mon Sep 17 00:00:00 2001 From: billz Date: Sat, 19 Jul 2025 00:25:18 -0700 Subject: [PATCH] Implement persistHostapdIni() --- .../Networking/Hotspot/HostapdManager.php | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/RaspAP/Networking/Hotspot/HostapdManager.php b/src/RaspAP/Networking/Hotspot/HostapdManager.php index 1819d5df..0e114108 100644 --- a/src/RaspAP/Networking/Hotspot/HostapdManager.php +++ b/src/RaspAP/Networking/Hotspot/HostapdManager.php @@ -76,6 +76,7 @@ class HostapdManager $selectedHwMode = 'w'; } } + $config['selected_hw_mode'] = $selectedHwMode; $config['ignore_broadcast_ssid'] ??= 0; $config['max_num_sta'] ??= 0; $config['wep_default_key'] ??= 0; @@ -199,8 +200,7 @@ class HostapdManager public function saveConfig(string $config, bool $dualMode, string $iface, bool $restart = false): bool { $configFile = $this->resolveConfigPath($iface, $dualMode); - //$configFile = self::CONF_DEFAULT; - $tempFile = self::CONF_TMP; + $tempFile = SELF::CONF_TMP; if (file_put_contents($tempFile, $config) === false) { @@ -310,6 +310,34 @@ class HostapdManager throw new \RuntimeException("Failed to restart hostapd (tried instance + fallback)."); } + /** + * Persists options to /etc/raspap/ + * + * @param string $apIface + * @param bool $logEnable + * @param bool $bridgedEnable + * @param bool $cfgWifiAPEnable + * @param bool $wifiAPEnable + * @param bool $repeaterEnable + * @param string $cliIface + * @return bool + */ + public function persistHostapdIni($apIface, $logEnable, $bridgedEnable, $cfgWifiAPEnable, $wifiAPEnable, $repeaterEnable, $cliIface): bool + { + $cfg = []; + $cfg['WifiInterface'] = $apIface; + $cfg['LogEnable'] = $logEnable; + $cfg['WifiAPEnable'] = ($bridgedEnable == 1 ? $cfgWifiAPEnable : $wifiAPEnable); + $cfg['BridgedEnable'] = $bridgedEnable; + $cfg['RepeaterEnable'] = $repeaterEnable; + $cfg['WifiManaged'] = $cliIface; + $success = write_php_ini($cfg, RASPI_CONFIG.'/hostapd.ini'); + if (!$success) { + throw new \RuntimeException("Unable to write to hostapd.ini"); + } + return true; + } + }