diff --git a/includes/hostapd.php b/includes/hostapd.php index 18880515..3e0fe0b5 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -609,64 +609,94 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) } if ($good_input) { - if ($tmp_file = fopen('/tmp/hostapddata', 'w')) { - // Fixed values - fwrite($tmp_file, 'driver=nl80211'.PHP_EOL); - fwrite($tmp_file, 'ctrl_interface='.RASPI_HOSTAPD_CTRL_INTERFACE.PHP_EOL); - fwrite($tmp_file, 'ctrl_interface_group=0'.PHP_EOL); - fwrite($tmp_file, 'auth_algs=1'.PHP_EOL); - fwrite($tmp_file, 'wpa_key_mgmt=WPA-PSK'.PHP_EOL); - fwrite($tmp_file, 'beacon_int=100'.PHP_EOL); - fwrite($tmp_file, 'ssid='.$_POST['ssid'].PHP_EOL); - fwrite($tmp_file, 'channel='.$_POST['channel'].PHP_EOL); - if ($_POST['hw_mode'] === 'n') { - fwrite($tmp_file, 'hw_mode=g'.PHP_EOL); - fwrite($tmp_file, 'ieee80211n=1'.PHP_EOL); - // Enable basic Quality of service - fwrite($tmp_file, 'wme_enabled=1'.PHP_EOL); - } else { - fwrite($tmp_file, 'hw_mode='.$_POST['hw_mode'].PHP_EOL); - fwrite($tmp_file, 'ieee80211n=0'.PHP_EOL); - } - fwrite($tmp_file, 'wpa_passphrase='.$_POST['wpa_passphrase'].PHP_EOL); - if ($wifiAPEnable == 1) { - fwrite($tmp_file, 'interface=uap0'.PHP_EOL); - } else { - fwrite($tmp_file, 'interface='.$_POST['interface'].PHP_EOL); - } - fwrite($tmp_file, 'wpa='.$_POST['wpa'].PHP_EOL); - fwrite($tmp_file, 'wpa_pairwise='.$_POST['wpa_pairwise'].PHP_EOL); - fwrite($tmp_file, 'country_code='.$_POST['country_code'].PHP_EOL); - fwrite($tmp_file, 'ignore_broadcast_ssid='.$ignore_broadcast_ssid.PHP_EOL); - fclose($tmp_file); + // Fixed values + $config = 'driver=nl80211'.PHP_EOL; + $config.= 'ctrl_interface='.RASPI_HOSTAPD_CTRL_INTERFACE.PHP_EOL; + $config.= 'ctrl_interface_group=0'.PHP_EOL; + $config.= 'auth_algs=1'.PHP_EOL; + $config.= 'wpa_key_mgmt=WPA-PSK'.PHP_EOL; + $config.= 'beacon_int=100'.PHP_EOL; + $config.= 'ssid='.$_POST['ssid'].PHP_EOL; + $config.= 'channel='.$_POST['channel'].PHP_EOL; + if ($_POST['hw_mode'] === 'n') { + $config.= 'hw_mode=g'.PHP_EOL; + $config.= 'ieee80211n=1'.PHP_EOL; + // Enable basic Quality of service + $config.= 'wme_enabled=1'.PHP_EOL; + } else { + $config.= 'hw_mode='.$_POST['hw_mode'].PHP_EOL; + $config.= 'ieee80211n=0'.PHP_EOL; + } + $config.= 'wpa_passphrase='.$_POST['wpa_passphrase'].PHP_EOL; + if ($wifiAPEnable == 1) { + $config.= 'interface=uap0'.PHP_EOL; + } else { + $config.= 'interface='.$_POST['interface'].PHP_EOL; + } + $config.= 'wpa='.$_POST['wpa'].PHP_EOL; + $config.= 'wpa_pairwise='.$_POST['wpa_pairwise'].PHP_EOL; + $config.= 'country_code='.$_POST['country_code'].PHP_EOL; + $config.= 'ignore_broadcast_ssid='.$ignore_broadcast_ssid.PHP_EOL; - if ($wifiAPEnable == 1) { - // Enable uap0 configuration in dnsmasq for Wifi client AP mode - $config = 'interface=lo,uap0 # Enable uap0 interface for wireless client AP mode'.PHP_EOL; - $config.= 'bind-interfaces # Bind to the interfaces'.PHP_EOL; - $config.= 'server=8.8.8.8 # Forward DNS requests to Google DNS'.PHP_EOL; - $config.= 'domain-needed # Don\'t forward short names'.PHP_EOL; - $config.= 'bogus-priv # Never forward addresses in the non-routed address spaces'.PHP_EOL; - $config.= 'dhcp-range=192.168.50.50,192.168.50.150,12h'.PHP_EOL; - } else { - // Fallback to default config - $config = 'domain-needed'.PHP_EOL; - $config.= 'interface='.$_POST['interface'].PHP_EOL; - $config.= 'dhcp-range=10.3.141.50,10.3.141.255,255.255.255.0,12h'.PHP_EOL; - } - exec('echo "'.$config.'" > /tmp/dhcpddata', $temp); - system('sudo cp /tmp/dhcpddata '.RASPI_DNSMASQ_CONFIG, $return); + exec('echo "'.$config.'" > /tmp/hostapddata', $temp); + system( "sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $return ); - system( "sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $return ); - if( $return == 0 ) { - $status->addMessage('Wifi Hotspot settings saved', 'success'); - } else { - $status->addMessage('Unable to save wifi hotspot settings', 'danger'); - } + if ($wifiAPEnable == 1) { + // Enable uap0 configuration in dnsmasq for Wifi client AP mode + $config = 'interface=lo,uap0 # Enable uap0 interface for wireless client AP mode'.PHP_EOL; + $config.= 'bind-interfaces # Bind to the interfaces'.PHP_EOL; + $config.= 'server=8.8.8.8 # Forward DNS requests to Google DNS'.PHP_EOL; + $config.= 'domain-needed # Don\'t forward short names'.PHP_EOL; + $config.= 'bogus-priv # Never forward addresses in the non-routed address spaces'.PHP_EOL; + $config.= 'dhcp-range=192.168.50.50,192.168.50.150,12h'.PHP_EOL; + } else { + // Fallback to default config + $config = 'domain-needed'.PHP_EOL; + $config.= 'interface='.$_POST['interface'].PHP_EOL; + $config.= 'dhcp-range=10.3.141.50,10.3.141.255,255.255.255.0,12h'.PHP_EOL; + } + exec('echo "'.$config.'" > /tmp/dhcpddata', $temp); + system('sudo cp /tmp/dhcpddata '.RASPI_DNSMASQ_CONFIG, $return); + + // Fixed dhcpcd values + $config = '# RaspAP defaults'.PHP_EOL; + $config.= 'hostname'.PHP_EOL; + $config.= 'clientid'.PHP_EOL; + $config.= 'persistent'.PHP_EOL; + $config.= 'option rapid_commit'.PHP_EOL; + $config.= 'option domain_name_servers, domain_name, domain_search, host_name'.PHP_EOL; + $config.= 'option classless_static_routes'.PHP_EOL; + $config.= 'option ntp_servers'.PHP_EOL; + $config.= 'require dhcp_server_identifier'.PHP_EOL; + $config.= 'slaac private'.PHP_EOL; + $config.= 'nohook lookup-hostname'.PHP_EOL; + + if ($wifiAPEnable == 1) { + // Enable uap0 configuration in dhcpcd for Wifi client AP mode + $config.= PHP_EOL.'# RaspAP uap0 configuration'.PHP_EOL; + $config.= 'interface=uap0'.PHP_EOL; + $config.= 'static ip_address=192.168.50.1/24'.PHP_EOL; + $config.= 'nohook wpa_supplicant'.PHP_EOL; + } else { + // Default config + $config.= PHP_EOL.'# RaspAP wlan0 configuration'.PHP_EOL; + $config.= 'interface wlan0'.PHP_EOL; + $config.= 'static ip_address=10.3.141.1/24'.PHP_EOL; + $config.= 'static routers=10.3.141.1'.PHP_EOL; + $config.= 'static domain_name_server=1.1.1.1 8.8.8.8'.PHP_EOL; + } + exec('echo "'.$config.'" > /tmp/dhcpddata', $temp); + system('sudo cp /tmp/dhcpddata '.RASPI_DHCPCD_CONFIG, $return); + + + if( $return == 0 ) { + $status->addMessage('Wifi Hotspot settings saved', 'success'); } else { $status->addMessage('Unable to save wifi hotspot settings', 'danger'); - return false; } + } else { + $status->addMessage('Unable to save wifi hotspot settings', 'danger'); + return false; } return true;