From 66bd5d59276748b06eecebbdc5814b1e1527f3ef Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 1 Dec 2020 18:38:57 +0000 Subject: [PATCH 01/20] Added getNetConfig() --- includes/functions.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/includes/functions.php b/includes/functions.php index 9ed854e7..e7508ded 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -234,6 +234,19 @@ function ParseConfig($arrConfig) return $config; } +/** + * Fetches DHCP configuration for an interface, returned as JSON data + * + * @param string $interface + * @return json $jsonData + */ +function getNetConfig($interface) +{ + $URI = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'] .'/ajax/networking/get_netcfg.php?iface='.$interface; + $jsonData = file_get_contents($URI); + return $jsonData; +} + /** * * @param string $freq From b09d61619ac31be9cd126dfbc9136229ab00e8be Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 1 Dec 2020 18:39:23 +0000 Subject: [PATCH 02/20] Bugfix: typo --- ajax/networking/get_netcfg.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ajax/networking/get_netcfg.php b/ajax/networking/get_netcfg.php index cd36a8a3..7ba5dcf6 100644 --- a/ajax/networking/get_netcfg.php +++ b/ajax/networking/get_netcfg.php @@ -43,7 +43,7 @@ if (isset($interface)) { preg_match('/metric\s(\d*)/', $matched[0], $metric); preg_match('/static\sip_address=(.*)/', $matched[0], $static_ip); preg_match('/static\srouters=(.*)/', $matched[0], $static_routers); - preg_match('/static\sdomain_name_servers=(.*)/', $matched[0], $static_dns); + preg_match('/static\sdomain_name_server=(.*)/', $matched[0], $static_dns); preg_match('/fallback\sstatic_'.$interface.'/', $matched[0], $fallback); $dhcpdata['Metric'] = $metric[1]; $dhcpdata['StaticIP'] = substr($static_ip[1], 0, strpos($static_ip[1],'/')); From 160c47defee2dbd2dbb1511424f60bc975f2e123 Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 1 Dec 2020 19:48:59 +0000 Subject: [PATCH 03/20] Create network.json + RASPI_CONFIG_NETWORK --- config/config.php | 2 +- config/network.json | 15 +++++++++++++++ includes/defaults.php | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 config/network.json diff --git a/config/config.php b/config/config.php index 04fb56bc..790338fc 100755 --- a/config/config.php +++ b/config/config.php @@ -2,7 +2,7 @@ define('RASPI_BRAND_TEXT', 'RaspAP'); define('RASPI_CONFIG', '/etc/raspap'); -define('RASPI_CONFIG_NETWORKING', RASPI_CONFIG.'/networking'); +define('RASPI_CONFIG_NETWORK', RASPI_CONFIG.'/networking/network.json'); define('RASPI_ADMIN_DETAILS', RASPI_CONFIG.'/raspap.auth'); define('RASPI_WIFI_AP_INTERFACE', 'wlan0'); define('RASPI_CACHE_PATH', sys_get_temp_dir() . '/raspap'); diff --git a/config/network.json b/config/network.json new file mode 100644 index 00000000..5de32e81 --- /dev/null +++ b/config/network.json @@ -0,0 +1,15 @@ +{ + "wlan0": { + "static ip_address": [ "10.3.141.1/24" ], + "static routers": [ "10.3.141.1" ], + "static domain_name_server": [ "1.1.1.1 8.8.8.8" ], + "dhcp-range": [ "10.3.141.50,10.3.141.255,255.255.255.0,12h" ] + }, + "uap0": { + "static ip_address": [ "192.168.50.1/24" ], + "static routers": [ "192.168.50.1" ], + "static domain_name_server": [ "1.1.1.1 8.8.8.8" ], + "dhcp-range": [ "192.168.50.50,192.168.50.150,12h" ] + } +} + diff --git a/includes/defaults.php b/includes/defaults.php index ce1b4731..022b5347 100755 --- a/includes/defaults.php +++ b/includes/defaults.php @@ -7,7 +7,7 @@ if (!defined('RASPI_CONFIG')) { $defaults = [ 'RASPI_BRAND_TEXT' => 'RaspAP', 'RASPI_VERSION' => '2.5.1', - 'RASPI_CONFIG_NETWORKING' => RASPI_CONFIG.'/networking', + 'RASPI_CONFIG_NETWORK' => RASPI_CONFIG.'/networking/network.json', 'RASPI_ADMIN_DETAILS' => RASPI_CONFIG.'/raspap.auth', 'RASPI_WIFI_AP_INTERFACE' => 'wlan0', 'RASPI_CACHE_PATH' => sys_get_temp_dir() . '/raspap', From 15fb1b714c585180e48d6ec540f9eb8a2a24f0fe Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 1 Dec 2020 22:51:00 +0000 Subject: [PATCH 04/20] Minor: cleanup --- includes/dhcp.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/includes/dhcp.php b/includes/dhcp.php index fb2e4709..071caa1d 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -173,11 +173,6 @@ function UpdateDnsmasqConfig($iface,$status) } $config .= PHP_EOL; } - // enable these settings on the default interface - if ($iface == "wlan0") { - $config .= "log-facility=/tmp/dnsmasq.log".PHP_EOL; - $config .= "conf-dir=/etc/dnsmasq.d".PHP_EOL; - } file_put_contents("/tmp/dnsmasqdata", $config); $msg = file_exists(RASPI_DNSMASQ_PREFIX.$iface.'.conf') ? 'updated' : 'added'; system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_PREFIX.$iface.'.conf', $result); @@ -208,10 +203,6 @@ function UpdateDHCPConfig($iface,$status) $cfg[] = 'fallback static_'.$iface; } $dhcp_cfg = file_get_contents(RASPI_DHCPCD_CONFIG); - if (!preg_match('/^$\s*\z/m', $dhcp_cfg) && !preg_match('/^interface\s'.$iface.'$/m', $dhcp_cfg)) { - echo '===== no ending newline found ====
'; - } - if (!preg_match('/^interface\s'.$iface.'$/m', $dhcp_cfg)) { $cfg[] = PHP_EOL; $cfg = join(PHP_EOL, $cfg); From 8420bbb0da09fc9220c16bcc16e973dd2e3cd18d Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 1 Dec 2020 22:52:15 +0000 Subject: [PATCH 05/20] Read/apply dhcp settings from json --- includes/hostapd.php | 119 +++++++++++++++++++++---------------------- 1 file changed, 59 insertions(+), 60 deletions(-) diff --git a/includes/hostapd.php b/includes/hostapd.php index 30883f48..3327365c 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -284,11 +284,14 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) } if ($wifiAPEnable == 1) { $config.= 'interface=uap0'.PHP_EOL; + $ap_iface = "uap0"; } elseif ($bridgedEnable == 1) { $config.='interface='.$_POST['interface'].PHP_EOL; $config.= 'bridge=br0'.PHP_EOL; + $ap_iface = "br0"; } else { $config.= 'interface='.$_POST['interface'].PHP_EOL; + $ap_iface = $_POST['interface']; } $config.= 'wpa='.$_POST['wpa'].PHP_EOL; $config.= 'wpa_pairwise='.$_POST['wpa_pairwise'].PHP_EOL; @@ -297,94 +300,90 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) if (isset($_POST['max_num_sta'])) { $config.= 'max_num_sta='.$_POST['max_num_sta'].PHP_EOL; } - file_put_contents("/tmp/hostapddata", $config); system("sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $return); // Fetch dhcp-range, lease time from system config - $dhcpConfig = parse_ini_file(RASPI_DNSMASQ_PREFIX.$_SESSION['ap_interface'].'conf', false, INI_SCANNER_RAW); + $syscfg = parse_ini_file(RASPI_DNSMASQ_PREFIX.$ap_iface.'.conf', false, INI_SCANNER_RAW); if ($wifiAPEnable == 1) { - // Enable uap0 configuration in dnsmasq for Wifi client AP mode + // Enable uap0 configuration for AP-STA mode // Set dhcp-range from system config. If undefined, fallback to default - $dhcp_range = ($dhcpConfig['dhcp-range'] =='10.3.141.50,10.3.141.255,255.255.255.0,12h' || - $dhcpConfig['dhcp-range'] =='') ? '192.168.50.50,192.168.50.150,12h' : $dhcpConfig['dhcp-range']; - $config = 'interface=lo,uap0 # Enable uap0 interface for wireless client AP mode'.PHP_EOL; - $config.= 'bind-dynamic # Hybrid between --bind-interfaces and default'.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='.$dhcp_range.PHP_EOL; - if (!empty($dhcpConfig['dhcp-option'])) { - $config.= 'dhcp-option='.$dhcpConfig['dhcp-option'].PHP_EOL; + $dhcp_range = ($syscfg['dhcp-range'] =='10.3.141.50,10.3.141.255,255.255.255.0,12h' || + $dhcpConfig['dhcp-range'] =='') ? '192.168.50.50,192.168.50.150,12h' : $syscfg['dhcp-range']; + $config = [ '# RaspAP uap0 configuration' ]; + $config[] = 'interface=lo,uap0 # Enable uap0 interface for wireless client AP mode'; + $config[] = 'bind-dynamic # Hybrid between --bind-interfaces and default'; + $config[] = 'server=8.8.8.8 # Forward DNS requests to Google DNS'; + $config[] = 'domain-needed # Don\'t forward short names'; + $config[] = 'bogus-priv # Never forward addresses in the non-routed address spaces'; + $config[] = 'dhcp-range='.$dhcp_range; + if (!empty($syscfg['dhcp-option'])) { + $config[] = 'dhcp-option='.$syscfg['dhcp-option']; } } else { // Set dhcp-range from system config. If undefined, fallback to default - $dhcp_range = ($dhcpConfig['dhcp-range'] =='192.168.50.50,192.168.50.150,12h' || - $dhcpConfig['dhcp-range'] =='') ? '10.3.141.50,10.3.141.255,255.255.255.0,12h' : $dhcpConfig['dhcp-range']; - $config = 'domain-needed'.PHP_EOL; - $config.= 'interface='.$_POST['interface'].PHP_EOL; - $config.= 'dhcp-range='.$dhcp_range.PHP_EOL; - if (!empty($dhcpConfig['dhcp-option'])) { - $config.= 'dhcp-option='.$dhcpConfig['dhcp-option'].PHP_EOL; + $dhcp_range = ($syscfg['dhcp-range'] =='192.168.50.50,192.168.50.150,12h' || + $syscfg['dhcp-range'] =='') ? '10.3.141.50,10.3.141.255,255.255.255.0,12h' : $syscfg['dhcp-range']; + $config = [ '# RaspAP '.$_POST['interface'].' configuration' ]; + $config[] = 'interface='.$_POST['interface']; + $config[] = 'domain-needed'; + $config[] = 'dhcp-range='.$dhcp_range; + $ap_iface = $_POST['interface']; + if (!empty($syscfg['dhcp-option'])) { + $config[] = 'dhcp-option='.$syscfg['dhcp-option']; } } + $config[] = PHP_EOL; + $config = join(PHP_EOL, $config); file_put_contents("/tmp/dnsmasqdata", $config); - system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_PREFIX.$_SESSION['ap_interface'].'conf', $return); + system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_PREFIX.$ap_iface.'.conf', $return); - // Set dnsmasq values from ini, fallback to default if undefined - $intConfig = parse_ini_file(RASPI_CONFIG_NETWORKING.'/'.$_POST['interface'].'.ini', false, INI_SCANNER_RAW); - $domain_name_server = ($intConfig['domain_name_server'] =='') ? '1.1.1.1 8.8.8.8' : $intConfig['domain_name_server']; - $routers = ($intConfig['routers'] == '') ? '10.3.141.1' : $intConfig['routers']; - - // write options to dhcpcd.conf - $config = [ '# RaspAP '.$_POST['interface'].' configuration' ]; - $config[] = 'hostname'; - $config[] = 'clientid'; - $config[] = 'persistent'; - $config[] = 'option rapid_commit'; - $config[] = 'option domain_name_servers, domain_name, domain_search, host_name'; - $config[] = 'option classless_static_routes'; - $config[] = 'option ntp_servers'; - $config[] = 'require dhcp_server_identifier'; - $config[] = 'slaac private'; - $config[] = 'nohook lookup-hostname'; + // fetch dhcp settings for selected interface + // todo: replace fallback values with defaults from network.json + $jsonData = json_decode(getNetConfig($ap_iface), true); + $domain_name_server = ($jsonData['StaticDNS'] =='') ? '1.1.1.1 8.8.8.8' : $jsonData['StaticDNS']; + $routers = ($jsonData['StaticRouters'] == '') ? '10.3.141.1' : $jsonData['StaticRouters']; + // Set dhcp values from system config, fallback to default if undefined if ($bridgedEnable == 1) { + $config[] = '# RaspAP br0 configuration'; + $config[] = 'interface '.$ap_iface; $config[] = 'denyinterfaces eth0 wlan0'; - $config[] = 'interface br0'; } elseif ($wifiAPEnable == 1) { - // Enable uap0 configuration in dhcpcd for Wifi client AP mode - $intConfig = parse_ini_file(RASPI_CONFIG_NETWORKING.'/uap0.ini', false, INI_SCANNER_RAW); - $ip_address = ($intConfig['ip_address'] == '') ? '192.168.50.1/24' : $intConfig['ip_address']; - $config[] = 'interface uap0'; + // Enable uap0 configuration for AP-STA + $ip_address = ($jsonData['StaticIP'] == '') ? '192.168.50.1/24' : $jsonData['StaticIP']; + $config = [ '# RaspAP uap0 configuration' ]; + $config[] = 'interface '.$ap_ifacee; $config[] = 'static ip_address='.$ip_address; $config[] = 'nohook wpa_supplicant'; } else { - // Default config - $ip_address = "10.3.141.1/24"; // fallback IP - // default IP of the AP xxx.xxx.xxx.1/24 of the selected dhcp range + // Default wlan0 config + $ip_address = ($jsonData['StaticIP'] == '') ? '10.3.141.1/24' : $jsonData['StaticIP']; $def_ip = array(); if (preg_match("/^([0-9]{1,3}\.){3}/",$dhcp_range,$def_ip) ) $ip_address = $def_ip[0]."1/24"; // use static IP assigned to interface only, if consistent with the selected dhcp range - if (preg_match("/^([0-9]{1,3}\.){3}/",$intConfig['ip_address'],$int_ip) && $def_ip[0] === $int_ip[0]) $ip_address = $intConfig['ip_address']; - $config[] = 'interface '.$_POST['interface']; + if (preg_match("/^([0-9]{1,3}\.){3}/",$jsonData['StaticIP'],$int_ip) && $def_ip[0] === $int_ip[0]) $ip_address = $jsonData['StaticIP']; + $config = [ '# RaspAP wlan0 configuration' ]; + $config[] = 'interface wlan0'; $config[] = 'static ip_address='.$ip_address; + $config[] = 'static routers='.$routers; $config[] = 'static domain_name_server='.$domain_name_server; - - // write the static IP back to the $_POST['interface'].ini file - $intConfig['interface'] = $_POST['interface']; - $intConfig['ip_address'] = $ip_address; - $intConfig['domain_name_server'] = $domain_name_server; - $intConfig['routers'] = $routers; - $intConfig['static'] = "true"; - $intConfig['failover'] = "false"; - write_php_ini($intConfig, RASPI_CONFIG_NETWORKING.'/'.$_POST['interface'].".ini"); + $config[] = 'metric '.$jsonData['Metric']; } - $config = join(PHP_EOL, $config); + $dhcp_cfg = file_get_contents(RASPI_DHCPCD_CONFIG); - $config = preg_replace('/^#\sRaspAP\s.*?(?=\s*^\s*$)/ms', $config, $dhcp_cfg, 1); - file_put_contents("/tmp/dhcpddata", $config); + if (!preg_match('/^interface\s'.$ap_iface.'$/m', $dhcp_cfg)) { + $config[] = PHP_EOL; + $config= join(PHP_EOL, $config); + $dhcp_cfg .= $config; + $status->addMessage('DHCP configuration for '.$ap_iface.' added.', 'success'); + } else { + $config = join(PHP_EOL, $config); + $dhcp_cfg = preg_replace('/^#\sRaspAP\s'.$ap_iface.'\s.*?(?=\s*^\s*$)/ms', $config, $dhcp_cfg, 1); + $status->addMessage('DHCP configuration for '.$ap_iface.' updated.', 'success'); + } + file_put_contents("/tmp/dhcpddata", $dhcp_cfg); system('sudo cp /tmp/dhcpddata '.RASPI_DHCPCD_CONFIG, $return); if ($return == 0) { From 1c6d837a801cefe5a3a0cb30b5108ae17da0106b Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 3 Dec 2020 10:29:11 +0000 Subject: [PATCH 06/20] Bugfix: handle subnetmask null value --- ajax/networking/get_netcfg.php | 2 +- includes/dhcp.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ajax/networking/get_netcfg.php b/ajax/networking/get_netcfg.php index 7ba5dcf6..2dd330bb 100644 --- a/ajax/networking/get_netcfg.php +++ b/ajax/networking/get_netcfg.php @@ -46,7 +46,7 @@ if (isset($interface)) { preg_match('/static\sdomain_name_server=(.*)/', $matched[0], $static_dns); preg_match('/fallback\sstatic_'.$interface.'/', $matched[0], $fallback); $dhcpdata['Metric'] = $metric[1]; - $dhcpdata['StaticIP'] = substr($static_ip[1], 0, strpos($static_ip[1],'/')); + $dhcpdata['StaticIP'] = strpos($static_ip[1],'/') ? substr($static_ip[1], 0, strpos($static_ip[1],'/')) : $static_ip[1]; $dhcpdata['SubnetMask'] = cidr2mask($static_ip[1]); $dhcpdata['StaticRouters'] = $static_routers[1]; $dhcpdata['StaticDNS'] = $static_dns[1]; diff --git a/includes/dhcp.php b/includes/dhcp.php index 071caa1d..e16d4194 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -187,7 +187,8 @@ function UpdateDHCPConfig($iface,$status) $cfg[] = '# RaspAP '.$iface.' configuration'; $cfg[] = 'interface '.$iface; if (isset($_POST['StaticIP'])) { - $cfg[] = 'static ip_address='.$_POST['StaticIP'].'/'.mask2cidr($_POST['SubnetMask']); + $mask = ($_POST['SubnetMask'] !== '' && $_POST['SubnetMask'] !== '0.0.0.0') ? '/'.mask2cidr($_POST['SubnetMask']) : null; + $cfg[] = 'static ip_address='.$_POST['StaticIP'].$mask; } if (isset($_POST['DefaultGateway'])) { $cfg[] = 'static routers='.$_POST['DefaultGateway']; From 6044d3d6ae34bdc0426af6e1b3c595eae7c58963 Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 3 Dec 2020 10:31:50 +0000 Subject: [PATCH 07/20] Replace dnsmasq.conf (deprecated) w/ 090_wlan0.conf --- config/090_wlan0.conf | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 config/090_wlan0.conf diff --git a/config/090_wlan0.conf b/config/090_wlan0.conf new file mode 100644 index 00000000..31f86eb3 --- /dev/null +++ b/config/090_wlan0.conf @@ -0,0 +1,5 @@ +# RaspAP wlan0 configuration for wired (ethernet) AP mode +interface=wlan0 +dhcp-range=10.3.141.50,10.3.141.255,255.255.255.0,12h +dhcp-option=6,1.1.1.1,8.8.8.8 + From f32d7c877827890a26816ab364fde4bb16f0a98f Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 3 Dec 2020 20:26:17 +0000 Subject: [PATCH 08/20] Update installer w/ 090_wlan0.conf --- installers/common.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/installers/common.sh b/installers/common.sh index 960b42d2..ce5ea8f6 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -336,8 +336,8 @@ function _check_for_old_configs() { fi if [ -f $raspap_dnsmasq ]; then - sudo cp $raspap_dnsmasq "$raspap_dir/backups/dnsmasq.conf.`date +%F-%R`" - sudo ln -sf "$raspap_dir/backups/dnsmasq.conf.`date +%F-%R`" "$raspap_dir/backups/dnsmasq.conf" + sudo cp $raspap_dnsmasq "$raspap_dir/backups/090_wlan0.conf.`date +%F-%R`" + sudo ln -sf "$raspap_dir/backups/090_wlan0.conf.`date +%F-%R`" "$raspap_dir/backups/090_wlan0.conf" fi if [ -f /etc/dhcpcd.conf ]; then @@ -376,7 +376,7 @@ function _default_configuration() { fi sudo cp $webroot_dir/config/default_hostapd /etc/default/hostapd || _install_status 1 "Unable to move hostapd defaults file" sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf || _install_status 1 "Unable to move hostapd configuration file" - sudo cp $webroot_dir/config/dnsmasq.conf $raspap_dnsmasq || _install_status 1 "Unable to move dnsmasq configuration file" + sudo cp $webroot_dir/config/090_wlan0.conf $raspap_dnsmasq || _install_status 1 "Unable to move dnsmasq configuration file" sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || _install_status 1 "Unable to move dhcpcd configuration file" echo "Checking for existence of /etc/dnsmasq.d" From de787c424ab0fc3974296ca8229f24f9bf58c89b Mon Sep 17 00:00:00 2001 From: billz Date: Fri, 4 Dec 2020 14:40:54 +0000 Subject: [PATCH 09/20] Create functions from procedural code --- includes/dhcp.php | 32 +++----------- includes/functions.php | 94 +++++++++++++++++++++++++++++++++++++++++- includes/hostapd.php | 42 ++++++++++++------- 3 files changed, 126 insertions(+), 42 deletions(-) diff --git a/includes/dhcp.php b/includes/dhcp.php index e16d4194..362397f8 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -70,8 +70,9 @@ function SaveDHCPConfig($status) // handle disable dhcp option if (!isset($_POST['dhcp-iface']) && file_exists(RASPI_DNSMASQ_PREFIX.$iface.'.conf')) { - // remove dhcp conf for selected interface - $return = RemoveDHCPConfig($iface,$status); + // remove dhcp + dnsmasq configs for selected interface + $return = removeDHCPConfig($iface,$status); + $return = removeDnsmasqConfig($iface,$status); } else { $errors = ValidateDHCPInput(); if (empty($errors)) { @@ -87,7 +88,6 @@ function SaveDHCPConfig($status) if (($_POST['dhcp-iface'] == "1")) { $return = UpdateDnsmasqConfig($iface,$status); } - if ($return == 0) { $status->addMessage('Dnsmasq configuration updated successfully.', 'success'); } else { @@ -140,7 +140,8 @@ function ValidateDHCPInput() function UpdateDnsmasqConfig($iface,$status) { - $config = 'interface='.$iface.PHP_EOL. + $config = '# RaspAP '.$iface.' configuration'.PHP_EOL; + $config .= 'interface='.$iface.PHP_EOL. 'dhcp-range='.$_POST['RangeStart'].','.$_POST['RangeEnd']. ',255.255.255.0,'; if ($_POST['RangeLeaseTimeUnits'] !== 'infinite') { @@ -220,26 +221,3 @@ function UpdateDHCPConfig($iface,$status) return $result; } -function RemoveDHCPConfig($iface,$status) -{ - $dhcp_cfg = file_get_contents(RASPI_DHCPCD_CONFIG); - $dhcp_cfg = preg_replace('/^#\sRaspAP\s'.$iface.'\s.*?(?=\s*^\s*$)([\s]+)/ms', '', $dhcp_cfg, 1); - file_put_contents("/tmp/dhcpddata", $dhcp_cfg); - system('sudo cp /tmp/dhcpddata '.RASPI_DHCPCD_CONFIG, $result); - if ($result == 0) { - $status->addMessage('DHCP configuration for '.$iface.' removed.', 'success'); - } else { - $status->addMessage('Failed to remove DHCP configuration for '.$iface.'.', 'danger'); - return $result; - } - // remove dnsmasq conf - system('sudo rm '.RASPI_DNSMASQ_PREFIX.$iface.'.conf', $result); - if ($result == 0) { - $status->addMessage('Dnsmasq configuration for '.$iface.' removed.', 'success'); - } else { - $status->addMessage('Failed to remove dnsmasq configuration for '.$iface.'.', 'danger'); - } - return $result; -} - - diff --git a/includes/functions.php b/includes/functions.php index e7508ded..78f4720c 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -19,7 +19,7 @@ function mask2cidr($mask) * * @param string $cidr * @return string -*/ + */ function cidr2mask($cidr) { $ta = substr ($cidr, strpos ($cidr, '/') + 1) * 1; @@ -29,6 +29,98 @@ function cidr2mask($cidr) return join ('.', $netmask); } +/** + * Returns a dhcp default config header + * + * @return array $config + */ +function defaultHeader() +{ + $config = [ '# RaspAP default configuration' ]; + $config[] = 'hostname'; + $config[] = 'clientid'; + $config[] = 'persistent'; + $config[] = 'option rapid_commit'; + $config[] = 'option domain_name_servers, domain_name, domain_search, host_name'; + $config[] = 'option classless_static_routes'; + $config[] = 'option ntp_servers'; + $config[] = 'require dhcp_server_identifier'; + $config[] = 'slaac private'; + $config[] = 'nohook lookup-hostname'; + return $config; +} + +/** + * Removes a dhcp configuration block for the specified interface + * + * @param string $iface + * @param object $status + * @return boolean $result + */ +function removeDHCPConfig($iface,$status) +{ + $dhcp_cfg = file_get_contents(RASPI_DHCPCD_CONFIG); + $dhcp_cfg = preg_replace('/^#\sRaspAP\s'.$iface.'\s.*?(?=\s*^\s*$)([\s]+)/ms', '', $dhcp_cfg, 1); + file_put_contents("/tmp/dhcpddata", $dhcp_cfg); + system('sudo cp /tmp/dhcpddata '.RASPI_DHCPCD_CONFIG, $result); + if ($result == 0) { + $status->addMessage('DHCP configuration for '.$iface.' removed.', 'success'); + } else { + $status->addMessage('Failed to remove DHCP configuration for '.$iface.'.', 'danger'); + return $result; + } +} + +/** + * Removes a dhcp configuration block for the specified interface + * + * @param string $dhcp_cfg + * @param string $iface + * @return string $dhcp_cfg + */ +function removeDHCPIface($dhcp_cfg,$iface) +{ + $dhcp_cfg = preg_replace('/^#\sRaspAP\s'.$iface.'\s.*?(?=\s*^\s*$)([\s]+)/ms', '', $dhcp_cfg, 1); + return $dhcp_cfg; +} + +/** + * Removes a dnsmasq configuration block for the specified interface + * + * @param string $iface + * @param object $status + * @return boolean $result + */ +function removeDnsmasqConfig($iface,$status) +{ + system('sudo rm '.RASPI_DNSMASQ_PREFIX.$iface.'.conf', $result); + if ($result == 0) { + $status->addMessage('Dnsmasq configuration for '.$iface.' removed.', 'success'); + } else { + $status->addMessage('Failed to remove dnsmasq configuration for '.$iface.'.', 'danger'); + } + return $result; +} + +/** + * Scans dnsmasq configuration dir for the specified interface + * Non-matching configs are removed, optional adblock.conf is protected + * + * @param string $dir_conf + * @param string $interface + * @param object $status + */ +function scanConfigDir($dir_conf,$interface,$status) +{ + $syscnf = preg_grep('~\.(conf)$~', scandir($dir_conf)); + foreach ($syscnf as $key => $file) { + if ($file !== '090_adblock.conf' && !preg_match('/.*_'.$interface.'.conf/', $file)) { + removeDnsmasqConfig($interface,$status); + } + } + return $status; +} + /* Functions to write ini files */ function write_php_ini($array, $file) diff --git a/includes/hostapd.php b/includes/hostapd.php index 3327365c..901b6f07 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -142,7 +142,6 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $bridgedEnable = 1; } } - // Check for WiFi client AP mode checkbox $wifiAPEnable = 0; if ($bridgedEnable == 0) { // enable client mode actions when not bridged @@ -156,7 +155,6 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) } } } - // Check for Logfile output checkbox $logEnable = 0; if ($arrHostapdConf['LogEnable'] == 0) { @@ -185,6 +183,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $cfg['WifiManaged'] = $_POST['interface']; write_php_ini($cfg, RASPI_CONFIG.'/hostapd.ini'); $_SESSION['ap_interface'] = $_POST['interface']; + $ap_iface = $_POST['interface']; // Verify input if (empty($_POST['ssid']) || strlen($_POST['ssid']) > 32) { @@ -321,7 +320,12 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) if (!empty($syscfg['dhcp-option'])) { $config[] = 'dhcp-option='.$syscfg['dhcp-option']; } - } else { + $config[] = PHP_EOL; + scanConfigDir('/etc/dnsmasq.d/','uap0',$status); + $config = join(PHP_EOL, $config); + file_put_contents("/tmp/dnsmasqdata", $config); + system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_PREFIX.$ap_iface.'.conf', $return); + } elseif ($bridgedEnable !==1) { // Set dhcp-range from system config. If undefined, fallback to default $dhcp_range = ($syscfg['dhcp-range'] =='192.168.50.50,192.168.50.150,12h' || $syscfg['dhcp-range'] =='') ? '10.3.141.50,10.3.141.255,255.255.255.0,12h' : $syscfg['dhcp-range']; @@ -329,15 +333,14 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $config[] = 'interface='.$_POST['interface']; $config[] = 'domain-needed'; $config[] = 'dhcp-range='.$dhcp_range; - $ap_iface = $_POST['interface']; if (!empty($syscfg['dhcp-option'])) { $config[] = 'dhcp-option='.$syscfg['dhcp-option']; } + $config[] = PHP_EOL; + $config = join(PHP_EOL, $config); + file_put_contents("/tmp/dnsmasqdata", $config); + system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_PREFIX.$ap_iface.'.conf', $return); } - $config[] = PHP_EOL; - $config = join(PHP_EOL, $config); - file_put_contents("/tmp/dnsmasqdata", $config); - system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_PREFIX.$ap_iface.'.conf', $return); // fetch dhcp settings for selected interface // todo: replace fallback values with defaults from network.json @@ -347,16 +350,20 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) // Set dhcp values from system config, fallback to default if undefined if ($bridgedEnable == 1) { - $config[] = '# RaspAP br0 configuration'; - $config[] = 'interface '.$ap_iface; + $config = defaultHeader(); + $config[] = PHP_EOL.'# RaspAP br0 configuration'; + $config[] = 'interface br0'; $config[] = 'denyinterfaces eth0 wlan0'; + $config[] = PHP_EOL; } elseif ($wifiAPEnable == 1) { // Enable uap0 configuration for AP-STA $ip_address = ($jsonData['StaticIP'] == '') ? '192.168.50.1/24' : $jsonData['StaticIP']; - $config = [ '# RaspAP uap0 configuration' ]; - $config[] = 'interface '.$ap_ifacee; + $config = defaultHeader(); + $config[] = PHP_EOL.'# RaspAP uap0 configuration'; + $config[] = 'interface uap0'; $config[] = 'static ip_address='.$ip_address; $config[] = 'nohook wpa_supplicant'; + $config[] = PHP_EOL; } else { // Default wlan0 config $ip_address = ($jsonData['StaticIP'] == '') ? '10.3.141.1/24' : $jsonData['StaticIP']; @@ -369,17 +376,24 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $config[] = 'static ip_address='.$ip_address; $config[] = 'static routers='.$routers; $config[] = 'static domain_name_server='.$domain_name_server; - $config[] = 'metric '.$jsonData['Metric']; + if (! is_null($jsonData['Metric'])) { $config[] = 'metric '.$jsonData['Metric']; } } $dhcp_cfg = file_get_contents(RASPI_DHCPCD_CONFIG); - if (!preg_match('/^interface\s'.$ap_iface.'$/m', $dhcp_cfg)) { + if ($bridgedEnable == 1 || $wifiAPEnable == 1) { + $dhcp_cfg = join(PHP_EOL, $config); + $status->addMessage('DHCP configuration for '.$ap_iface.' enabled.', 'success'); + } elseif (!preg_match('/^interface\s'.$ap_iface.'$/m', $dhcp_cfg)) { $config[] = PHP_EOL; $config= join(PHP_EOL, $config); + $dhcp_cfg = removeDHCPIface($dhcp_cfg,'br0'); + $dhcp_cfg = removeDHCPIface($dhcp_cfg,'uap0'); $dhcp_cfg .= $config; $status->addMessage('DHCP configuration for '.$ap_iface.' added.', 'success'); } else { $config = join(PHP_EOL, $config); + $dhcp_cfg = removeDHCPIface($dhcp_cfg,'br0'); + $dhcp_cfg = removeDHCPIface($dhcp_cfg,'uap0'); $dhcp_cfg = preg_replace('/^#\sRaspAP\s'.$ap_iface.'\s.*?(?=\s*^\s*$)/ms', $config, $dhcp_cfg, 1); $status->addMessage('DHCP configuration for '.$ap_iface.' updated.', 'success'); } From bcab63bb30b1573f6cb22dfe9cdd0a171097c681 Mon Sep 17 00:00:00 2001 From: billz Date: Fri, 4 Dec 2020 21:41:10 +0000 Subject: [PATCH 10/20] Bugfix + documentation --- includes/functions.php | 6 +++--- includes/hostapd.php | 22 ++++++++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 78f4720c..ea19b828 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -113,9 +113,9 @@ function removeDnsmasqConfig($iface,$status) function scanConfigDir($dir_conf,$interface,$status) { $syscnf = preg_grep('~\.(conf)$~', scandir($dir_conf)); - foreach ($syscnf as $key => $file) { - if ($file !== '090_adblock.conf' && !preg_match('/.*_'.$interface.'.conf/', $file)) { - removeDnsmasqConfig($interface,$status); + foreach ($syscnf as $cnf) { + if ($cnf !== '090_adblock.conf' && !preg_match('/.*_'.$interface.'.conf/', $cnf)) { + system('sudo rm /etc/dnsmasq.d/'.$cnf, $result); } } return $status; diff --git a/includes/hostapd.php b/includes/hostapd.php index 901b6f07..01b4e1fe 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -8,7 +8,7 @@ require_once 'includes/config.php'; getWifiInterface(); /** - * + * Initialize hostapd values, display interface * */ function DisplayHostAPDConfig() @@ -34,7 +34,6 @@ function DisplayHostAPDConfig() SaveHostAPDConfig($arrSecurity, $arrEncType, $arr80211Standard, $interfaces, $status); } } - $arrHostapdConf = parse_ini_file('/etc/raspap/hostapd.ini'); if (!RASPI_MONITOR_ENABLED) { @@ -71,7 +70,6 @@ function DisplayHostAPDConfig() if (strlen($hostapdconfigline) === 0) { continue; } - if ($hostapdconfigline[0] != "#") { $arrLine = explode("=", $hostapdconfigline); $arrConfig[$arrLine[0]]=$arrLine[1]; @@ -107,6 +105,16 @@ function DisplayHostAPDConfig() ); } +/** + * Validate user input, save configs for hostapd, dnsmasq & dhcp + * + * @param array $wpa_array + * @param array $enc_types + * @param array $modes + * @param string $interface + * @param object $status + * @return boolean + */ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) { // It should not be possible to send bad data for these fields so clearly @@ -125,12 +133,10 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $status->addMessage('Attempting to set channel to invalid number.', 'danger'); $good_input = false; } - if (intval($_POST['channel']) < 1 || intval($_POST['channel']) > RASPI_5GHZ_MAX_CHANNEL) { $status->addMessage('Attempting to set channel outside of permitted range', 'danger'); $good_input = false; } - // Check for Bridged AP mode checkbox $bridgedEnable = 0; if ($arrHostapdConf['BridgedEnable'] == 0) { @@ -173,12 +179,12 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) } } + // persist user-defined options to /etc/raspap $cfg = []; $cfg['WifiInterface'] = $_POST['interface']; $cfg['LogEnable'] = $logEnable; // Save previous Client mode status when Bridged - $cfg['WifiAPEnable'] = ($bridgedEnable == 1 ? - $arrHostapdConf['WifiAPEnable'] : $wifiAPEnable); + $cfg['WifiAPEnable'] = ($bridgedEnable == 1 ? $arrHostapdConf['WifiAPEnable'] : $wifiAPEnable); $cfg['BridgedEnable'] = $bridgedEnable; $cfg['WifiManaged'] = $_POST['interface']; write_php_ini($cfg, RASPI_CONFIG.'/hostapd.ini'); @@ -236,6 +242,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $_POST['max_num_sta'] = $_POST['max_num_sta'] > 2007 ? 2007 : $_POST['max_num_sta']; $_POST['max_num_sta'] = $_POST['max_num_sta'] < 1 ? null : $_POST['max_num_sta']; + // populate hostapd.conf if ($good_input) { // Fixed values $country_code = $_POST['country_code']; @@ -409,6 +416,5 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $status->addMessage('Unable to save wifi hotspot settings', 'danger'); return false; } - return true; } From e3f36158bb32214dba822dbbac4e5de5b4bdad71 Mon Sep 17 00:00:00 2001 From: billz Date: Fri, 4 Dec 2020 22:36:54 +0000 Subject: [PATCH 11/20] Added updateHostapdConfig() --- includes/hostapd.php | 143 +++++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 66 deletions(-) diff --git a/includes/hostapd.php b/includes/hostapd.php index 01b4e1fe..3e5eee42 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -179,7 +179,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) } } - // persist user-defined options to /etc/raspap + // persist user options to /etc/raspap $cfg = []; $cfg['WifiInterface'] = $_POST['interface']; $cfg['LogEnable'] = $logEnable; @@ -242,72 +242,8 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $_POST['max_num_sta'] = $_POST['max_num_sta'] > 2007 ? 2007 : $_POST['max_num_sta']; $_POST['max_num_sta'] = $_POST['max_num_sta'] < 1 ? null : $_POST['max_num_sta']; - // populate hostapd.conf if ($good_input) { - // Fixed values - $country_code = $_POST['country_code']; - $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; - if (isset($_POST['beaconintervalEnable'])) { - $config.= 'beacon_int='.$_POST['beacon_interval'].PHP_EOL; - } - if (isset($_POST['disassoc_low_ackEnable'])) { - $config.= 'disassoc_low_ack=0'.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.= 'wmm_enabled=1'.PHP_EOL; - } elseif ($_POST['hw_mode'] === 'ac') { - $config.= 'hw_mode=a'.PHP_EOL.PHP_EOL; - $config.= '# N'.PHP_EOL; - $config.= 'ieee80211n=1'.PHP_EOL; - $config.= 'require_ht=1'.PHP_EOL; - $config.= 'ht_capab=[MAX-AMSDU-3839][HT40+][SHORT-GI-20][SHORT-GI-40][DSSS_CCK-40]'.PHP_EOL.PHP_EOL; - $config.= '# AC'.PHP_EOL; - $config.= 'ieee80211ac=1'.PHP_EOL; - $config.= 'require_vht=1'.PHP_EOL; - $config.= 'ieee80211d=0'.PHP_EOL; - $config.= 'ieee80211h=0'.PHP_EOL; - $config.= 'vht_capab=[MAX-AMSDU-3839][SHORT-GI-80]'.PHP_EOL; - $config.= 'vht_oper_chwidth=1'.PHP_EOL; - $config.= 'vht_oper_centr_freq_seg0_idx=42'.PHP_EOL.PHP_EOL; - } elseif ($_POST['hw_mode'] === 'w') { - $config.= 'ieee80211w=2'.PHP_EOL; - $config.= 'wpa_key_mgmt=WPA-EAP-SHA256'.PHP_EOL; - } else { - $config.= 'hw_mode='.$_POST['hw_mode'].PHP_EOL; - $config.= 'ieee80211n=0'.PHP_EOL; - } - if ($_POST['wpa'] !== 'none') { - $config.= 'wpa_passphrase='.$_POST['wpa_passphrase'].PHP_EOL; - } - if ($wifiAPEnable == 1) { - $config.= 'interface=uap0'.PHP_EOL; - $ap_iface = "uap0"; - } elseif ($bridgedEnable == 1) { - $config.='interface='.$_POST['interface'].PHP_EOL; - $config.= 'bridge=br0'.PHP_EOL; - $ap_iface = "br0"; - } else { - $config.= 'interface='.$_POST['interface'].PHP_EOL; - $ap_iface = $_POST['interface']; - } - $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 (isset($_POST['max_num_sta'])) { - $config.= 'max_num_sta='.$_POST['max_num_sta'].PHP_EOL; - } - file_put_contents("/tmp/hostapddata", $config); - system("sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $return); + $return = updateHostapdConfig(); // Fetch dhcp-range, lease time from system config $syscfg = parse_ini_file(RASPI_DNSMASQ_PREFIX.$ap_iface.'.conf', false, INI_SCANNER_RAW); @@ -418,3 +354,78 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) } return true; } + +/** + * Updates a hostapd configuration + * + * @return boolean $result + */ +function updateHostapdConfig() +{ + // Fixed values + $country_code = $_POST['country_code']; + $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; + if (isset($_POST['beaconintervalEnable'])) { + $config.= 'beacon_int='.$_POST['beacon_interval'].PHP_EOL; + } + if (isset($_POST['disassoc_low_ackEnable'])) { + $config.= 'disassoc_low_ack=0'.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.= 'wmm_enabled=1'.PHP_EOL; + } elseif ($_POST['hw_mode'] === 'ac') { + $config.= 'hw_mode=a'.PHP_EOL.PHP_EOL; + $config.= '# N'.PHP_EOL; + $config.= 'ieee80211n=1'.PHP_EOL; + $config.= 'require_ht=1'.PHP_EOL; + $config.= 'ht_capab=[MAX-AMSDU-3839][HT40+][SHORT-GI-20][SHORT-GI-40][DSSS_CCK-40]'.PHP_EOL.PHP_EOL; + $config.= '# AC'.PHP_EOL; + $config.= 'ieee80211ac=1'.PHP_EOL; + $config.= 'require_vht=1'.PHP_EOL; + $config.= 'ieee80211d=0'.PHP_EOL; + $config.= 'ieee80211h=0'.PHP_EOL; + $config.= 'vht_capab=[MAX-AMSDU-3839][SHORT-GI-80]'.PHP_EOL; + $config.= 'vht_oper_chwidth=1'.PHP_EOL; + $config.= 'vht_oper_centr_freq_seg0_idx=42'.PHP_EOL.PHP_EOL; + } elseif ($_POST['hw_mode'] === 'w') { + $config.= 'ieee80211w=2'.PHP_EOL; + $config.= 'wpa_key_mgmt=WPA-EAP-SHA256'.PHP_EOL; + } else { + $config.= 'hw_mode='.$_POST['hw_mode'].PHP_EOL; + $config.= 'ieee80211n=0'.PHP_EOL; + } + if ($_POST['wpa'] !== 'none') { + $config.= 'wpa_passphrase='.$_POST['wpa_passphrase'].PHP_EOL; + } + if ($wifiAPEnable == 1) { + $config.= 'interface=uap0'.PHP_EOL; + $ap_iface = "uap0"; + } elseif ($bridgedEnable == 1) { + $config.='interface='.$_POST['interface'].PHP_EOL; + $config.= 'bridge=br0'.PHP_EOL; + $ap_iface = "br0"; + } else { + $config.= 'interface='.$_POST['interface'].PHP_EOL; + $ap_iface = $_POST['interface']; + } + $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 (isset($_POST['max_num_sta'])) { + $config.= 'max_num_sta='.$_POST['max_num_sta'].PHP_EOL; + } + file_put_contents("/tmp/hostapddata", $config); + system("sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $result); + return $result; +} + From e77b0fead1038f4266e48566093426d05333cf1e Mon Sep 17 00:00:00 2001 From: billz Date: Fri, 4 Dec 2020 22:44:27 +0000 Subject: [PATCH 12/20] Minor: camelCase + docblocks --- includes/dhcp.php | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/includes/dhcp.php b/includes/dhcp.php index 362397f8..45ea156f 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -11,7 +11,7 @@ function DisplayDHCPConfig() $status = new StatusMessages(); if (!RASPI_MONITOR_ENABLED) { if (isset($_POST['savedhcpdsettings'])) { - SaveDHCPConfig($status); + saveDHCPConfig($status); } } exec('pidof dnsmasq | wc -l', $dnsmasq); @@ -63,7 +63,12 @@ function DisplayDHCPConfig() ); } -function SaveDHCPConfig($status) +/** + * Saves a DHCP configuration + * + * @return object $status + */ +function saveDHCPConfig($status) { $iface = $_POST['interface']; $return = 1; @@ -74,9 +79,9 @@ function SaveDHCPConfig($status) $return = removeDHCPConfig($iface,$status); $return = removeDnsmasqConfig($iface,$status); } else { - $errors = ValidateDHCPInput(); + $errors = validateDHCPInput(); if (empty($errors)) { - $return = UpdateDHCPConfig($iface,$status); + $return = updateDHCPConfig($iface,$status); } else { $status->addMessage($errors, 'danger'); } @@ -86,7 +91,7 @@ function SaveDHCPConfig($status) } if (($_POST['dhcp-iface'] == "1")) { - $return = UpdateDnsmasqConfig($iface,$status); + $return = updateDnsmasqConfig($iface,$status); } if ($return == 0) { $status->addMessage('Dnsmasq configuration updated successfully.', 'success'); @@ -98,7 +103,12 @@ function SaveDHCPConfig($status) } } -function ValidateDHCPInput() +/** + * Validates DHCP user input from the $_POST object + * + * @return string $errors + */ +function validateDHCPInput() { define('IFNAMSIZ', 16); $iface = $_POST['interface']; @@ -138,7 +148,14 @@ function ValidateDHCPInput() return $errors; } -function UpdateDnsmasqConfig($iface,$status) +/** + * Updates a dnsmasq configuration + * + * @param string $iface + * @param object $status + * @return boolean $result + */ +function updateDnsmasqConfig($iface,$status) { $config = '# RaspAP '.$iface.' configuration'.PHP_EOL; $config .= 'interface='.$iface.PHP_EOL. @@ -183,7 +200,14 @@ function UpdateDnsmasqConfig($iface,$status) return $result; } -function UpdateDHCPConfig($iface,$status) +/** + * Updates a dhcp configuration + * + * @param string $iface + * @param object $status + * @return boolean $result + */ +function updateDHCPConfig($iface,$status) { $cfg[] = '# RaspAP '.$iface.' configuration'; $cfg[] = 'interface '.$iface; From 9f85daaa86c477a93e086a873b7cf0b0dcb7fad8 Mon Sep 17 00:00:00 2001 From: billz Date: Sat, 5 Dec 2020 09:12:47 +0000 Subject: [PATCH 13/20] Added getDefaultNetValue() --- includes/functions.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/includes/functions.php b/includes/functions.php index ea19b828..73f06600 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -121,6 +121,24 @@ function scanConfigDir($dir_conf,$interface,$status) return $status; } +/** + * Returns a default (fallback) value for the selected service, interface & setting + * from /etc/raspap/networking/defaults.json + * + * @param string $svc + * @param string $iface + * @return string $value + */ +function getDefaultNetValue($svc,$iface,$key) +{ + $json = json_decode(file_get_contents(RASPI_CONFIG_NETWORK), true); + if ($json === null) { + return false; + } else { + return $json[$svc][$iface][$key][0]; + } +} + /* Functions to write ini files */ function write_php_ini($array, $file) From d35397f09ef53bbc278107888b2761ab1190262a Mon Sep 17 00:00:00 2001 From: billz Date: Sat, 5 Dec 2020 09:14:07 +0000 Subject: [PATCH 14/20] Remove hardcoded default values, implement defaults.json --- config/config.php | 2 +- config/defaults.json | 22 ++++++++++++++++++++++ config/network.json | 15 --------------- includes/defaults.php | 2 +- includes/hostapd.php | 33 ++++++++++++++------------------- installers/common.sh | 2 ++ 6 files changed, 40 insertions(+), 36 deletions(-) create mode 100644 config/defaults.json delete mode 100644 config/network.json diff --git a/config/config.php b/config/config.php index 790338fc..31bb9376 100755 --- a/config/config.php +++ b/config/config.php @@ -2,7 +2,7 @@ define('RASPI_BRAND_TEXT', 'RaspAP'); define('RASPI_CONFIG', '/etc/raspap'); -define('RASPI_CONFIG_NETWORK', RASPI_CONFIG.'/networking/network.json'); +define('RASPI_CONFIG_NETWORK', RASPI_CONFIG.'/networking/defaults.json'); define('RASPI_ADMIN_DETAILS', RASPI_CONFIG.'/raspap.auth'); define('RASPI_WIFI_AP_INTERFACE', 'wlan0'); define('RASPI_CACHE_PATH', sys_get_temp_dir() . '/raspap'); diff --git a/config/defaults.json b/config/defaults.json new file mode 100644 index 00000000..59f6f4a4 --- /dev/null +++ b/config/defaults.json @@ -0,0 +1,22 @@ +{ + "dhcp": { + "wlan0": { + "static ip_address": [ "10.3.141.1/24" ], + "static routers": [ "10.3.141.1" ], + "static domain_name_server": [ "1.1.1.1 8.8.8.8" ] + }, + "uap0": { + "static ip_address": [ "192.168.50.1/24" ], + "static routers": [ "192.168.50.1" ], + "static domain_name_server": [ "1.1.1.1 8.8.8.8" ] + } + }, + "dnsmasq": { + "wlan0": { + "dhcp-range": [ "10.3.141.50,10.3.141.255,255.255.255.0,12h" ], + "uap0": { + "dhcp-range": [ "192.168.50.50,192.168.50.150,12h" ] + } + } +} + diff --git a/config/network.json b/config/network.json deleted file mode 100644 index 5de32e81..00000000 --- a/config/network.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "wlan0": { - "static ip_address": [ "10.3.141.1/24" ], - "static routers": [ "10.3.141.1" ], - "static domain_name_server": [ "1.1.1.1 8.8.8.8" ], - "dhcp-range": [ "10.3.141.50,10.3.141.255,255.255.255.0,12h" ] - }, - "uap0": { - "static ip_address": [ "192.168.50.1/24" ], - "static routers": [ "192.168.50.1" ], - "static domain_name_server": [ "1.1.1.1 8.8.8.8" ], - "dhcp-range": [ "192.168.50.50,192.168.50.150,12h" ] - } -} - diff --git a/includes/defaults.php b/includes/defaults.php index 022b5347..88b52fe9 100755 --- a/includes/defaults.php +++ b/includes/defaults.php @@ -7,7 +7,7 @@ if (!defined('RASPI_CONFIG')) { $defaults = [ 'RASPI_BRAND_TEXT' => 'RaspAP', 'RASPI_VERSION' => '2.5.1', - 'RASPI_CONFIG_NETWORK' => RASPI_CONFIG.'/networking/network.json', + 'RASPI_CONFIG_NETWORK' => RASPI_CONFIG.'/networking/defaults.json', 'RASPI_ADMIN_DETAILS' => RASPI_CONFIG.'/raspap.auth', 'RASPI_WIFI_AP_INTERFACE' => 'wlan0', 'RASPI_CACHE_PATH' => sys_get_temp_dir() . '/raspap', diff --git a/includes/hostapd.php b/includes/hostapd.php index 3e5eee42..52b2a66b 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -178,6 +178,10 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) exec('sudo '.RASPI_CONFIG.'/hostapd/disablelog.sh'); } } + // set AP interface default, override for ap-sta & bridged options + $ap_iface = $_POST['interface']; + if ($wifiAPEnable) { $ap_iface = 'uap0'; } + if ($bridgedEnable) { $ap_iface = 'br0'; } // persist user options to /etc/raspap $cfg = []; @@ -189,7 +193,6 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $cfg['WifiManaged'] = $_POST['interface']; write_php_ini($cfg, RASPI_CONFIG.'/hostapd.ini'); $_SESSION['ap_interface'] = $_POST['interface']; - $ap_iface = $_POST['interface']; // Verify input if (empty($_POST['ssid']) || strlen($_POST['ssid']) > 32) { @@ -249,10 +252,9 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $syscfg = parse_ini_file(RASPI_DNSMASQ_PREFIX.$ap_iface.'.conf', false, INI_SCANNER_RAW); if ($wifiAPEnable == 1) { - // Enable uap0 configuration for AP-STA mode - // Set dhcp-range from system config. If undefined, fallback to default - $dhcp_range = ($syscfg['dhcp-range'] =='10.3.141.50,10.3.141.255,255.255.255.0,12h' || - $dhcpConfig['dhcp-range'] =='') ? '192.168.50.50,192.168.50.150,12h' : $syscfg['dhcp-range']; + // Enable uap0 configuration for ap-sta mode + // Set dhcp-range from system config, fallback to default if undefined + $dhcp_range = ($syscfg['dhcp-range'] == '') ? getDefaultNetValue('dnsmasq','uap0','dhcp-range') : $syscfg['dhcp-range']; $config = [ '# RaspAP uap0 configuration' ]; $config[] = 'interface=lo,uap0 # Enable uap0 interface for wireless client AP mode'; $config[] = 'bind-dynamic # Hybrid between --bind-interfaces and default'; @@ -269,9 +271,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) file_put_contents("/tmp/dnsmasqdata", $config); system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_PREFIX.$ap_iface.'.conf', $return); } elseif ($bridgedEnable !==1) { - // Set dhcp-range from system config. If undefined, fallback to default - $dhcp_range = ($syscfg['dhcp-range'] =='192.168.50.50,192.168.50.150,12h' || - $syscfg['dhcp-range'] =='') ? '10.3.141.50,10.3.141.255,255.255.255.0,12h' : $syscfg['dhcp-range']; + $dhcp_range = ($syscfg['dhcp-range'] =='') ? getDefaultNetValue('dnsmasq','wlan0','dhcp-range') : $syscfg['dhcp-range']; $config = [ '# RaspAP '.$_POST['interface'].' configuration' ]; $config[] = 'interface='.$_POST['interface']; $config[] = 'domain-needed'; @@ -285,13 +285,10 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_PREFIX.$ap_iface.'.conf', $return); } - // fetch dhcp settings for selected interface - // todo: replace fallback values with defaults from network.json - $jsonData = json_decode(getNetConfig($ap_iface), true); - $domain_name_server = ($jsonData['StaticDNS'] =='') ? '1.1.1.1 8.8.8.8' : $jsonData['StaticDNS']; - $routers = ($jsonData['StaticRouters'] == '') ? '10.3.141.1' : $jsonData['StaticRouters']; - // Set dhcp values from system config, fallback to default if undefined + $jsonData = json_decode(getNetConfig($ap_iface), true); + $domain_name_server = ($jsonData['StaticDNS'] =='') ? getDefaultNetValue('dhcp','wlan0','static domain_name_server') : $jsonData['StaticDNS']; + $routers = ($jsonData['StaticRouters'] == '') ? getDefaultNetValue('dhcp','wlan0','static routers') : $jsonData['StaticRouters']; if ($bridgedEnable == 1) { $config = defaultHeader(); $config[] = PHP_EOL.'# RaspAP br0 configuration'; @@ -299,8 +296,8 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $config[] = 'denyinterfaces eth0 wlan0'; $config[] = PHP_EOL; } elseif ($wifiAPEnable == 1) { - // Enable uap0 configuration for AP-STA - $ip_address = ($jsonData['StaticIP'] == '') ? '192.168.50.1/24' : $jsonData['StaticIP']; + // Enable uap0 configuration for ap-sta + $ip_address = ($jsonData['StaticIP'] == '') ? getDefaultNetValue('dhcp','uap0','static ip_address') : $jsonData['StaticIP']; $config = defaultHeader(); $config[] = PHP_EOL.'# RaspAP uap0 configuration'; $config[] = 'interface uap0'; @@ -309,7 +306,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $config[] = PHP_EOL; } else { // Default wlan0 config - $ip_address = ($jsonData['StaticIP'] == '') ? '10.3.141.1/24' : $jsonData['StaticIP']; + $ip_address = ($jsonData['StaticIP'] == '') ? getDefaultNetValue('dhcp','wlan0','static ip_address') : $jsonData['StaticIP']; $def_ip = array(); if (preg_match("/^([0-9]{1,3}\.){3}/",$dhcp_range,$def_ip) ) $ip_address = $def_ip[0]."1/24"; // use static IP assigned to interface only, if consistent with the selected dhcp range @@ -408,11 +405,9 @@ function updateHostapdConfig() } if ($wifiAPEnable == 1) { $config.= 'interface=uap0'.PHP_EOL; - $ap_iface = "uap0"; } elseif ($bridgedEnable == 1) { $config.='interface='.$_POST['interface'].PHP_EOL; $config.= 'bridge=br0'.PHP_EOL; - $ap_iface = "br0"; } else { $config.= 'interface='.$_POST['interface'].PHP_EOL; $ap_iface = $_POST['interface']; diff --git a/installers/common.sh b/installers/common.sh index ce5ea8f6..4f000a8e 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -21,6 +21,7 @@ readonly raspap_sudoers="/etc/sudoers.d/090_raspap" readonly raspap_dnsmasq="/etc/dnsmasq.d/090_wlan0.conf" readonly raspap_adblock="/etc/dnsmasq.d/090_adblock.conf" readonly raspap_sysctl="/etc/sysctl.d/90_raspap.conf" +readonly raspap_network="$raspap_dir/networking/" readonly rulesv4="/etc/iptables/rules.v4" readonly notracking_url="https://raw.githubusercontent.com/notracking/hosts-blocklists/master/" webroot_dir="/var/www/html" @@ -378,6 +379,7 @@ function _default_configuration() { sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf || _install_status 1 "Unable to move hostapd configuration file" sudo cp $webroot_dir/config/090_wlan0.conf $raspap_dnsmasq || _install_status 1 "Unable to move dnsmasq configuration file" sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || _install_status 1 "Unable to move dhcpcd configuration file" + sudo cp $webroot_dir/config/defaults.json $raspap_network || _install_status 1 "Unable to move defaults.json settings" echo "Checking for existence of /etc/dnsmasq.d" [ -d /etc/dnsmasq.d ] || sudo mkdir /etc/dnsmasq.d From a56a59b7e524b43a621909d21b9dab3e34d7b895 Mon Sep 17 00:00:00 2001 From: billz Date: Sat, 5 Dec 2020 21:49:32 +0000 Subject: [PATCH 15/20] Default config tweaks --- config/090_wlan0.conf | 1 + config/defaults.json | 4 ++-- installers/common.sh | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/config/090_wlan0.conf b/config/090_wlan0.conf index 31f86eb3..56234784 100644 --- a/config/090_wlan0.conf +++ b/config/090_wlan0.conf @@ -1,5 +1,6 @@ # RaspAP wlan0 configuration for wired (ethernet) AP mode interface=wlan0 +domain-needed dhcp-range=10.3.141.50,10.3.141.255,255.255.255.0,12h dhcp-option=6,1.1.1.1,8.8.8.8 diff --git a/config/defaults.json b/config/defaults.json index 59f6f4a4..24f2138e 100644 --- a/config/defaults.json +++ b/config/defaults.json @@ -13,10 +13,10 @@ }, "dnsmasq": { "wlan0": { - "dhcp-range": [ "10.3.141.50,10.3.141.255,255.255.255.0,12h" ], + "dhcp-range": [ "10.3.141.50,10.3.141.255,255.255.255.0,12h" ] + }, "uap0": { "dhcp-range": [ "192.168.50.50,192.168.50.150,12h" ] } } } - diff --git a/installers/common.sh b/installers/common.sh index 4f000a8e..103f9c9b 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -145,9 +145,10 @@ function _create_raspap_directories() { # Create a directory to store networking configs echo "Creating $raspap_dir/networking" sudo mkdir -p "$raspap_dir/networking" - # Copy existing dhcpcd.conf to use as base config - echo "Adding /etc/dhcpcd.conf as base configuration" - cat /etc/dhcpcd.conf | sudo tee -a /etc/raspap/networking/defaults > /dev/null + + # Copy defaults.json to use as fallback config + sudo cp $webroot_dir/config/defaults.json $raspap_network || _install_status 1 "Unable to move defaults.json settings" + echo "Changing file ownership of $raspap_dir" sudo chown -R $raspap_user:$raspap_user "$raspap_dir" || _install_status 1 "Unable to change file ownership for '$raspap_dir'" } @@ -379,7 +380,6 @@ function _default_configuration() { sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf || _install_status 1 "Unable to move hostapd configuration file" sudo cp $webroot_dir/config/090_wlan0.conf $raspap_dnsmasq || _install_status 1 "Unable to move dnsmasq configuration file" sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || _install_status 1 "Unable to move dhcpcd configuration file" - sudo cp $webroot_dir/config/defaults.json $raspap_network || _install_status 1 "Unable to move defaults.json settings" echo "Checking for existence of /etc/dnsmasq.d" [ -d /etc/dnsmasq.d ] || sudo mkdir /etc/dnsmasq.d From 24e4bc87059a0b7b49d172bbf18136eeace4b8c3 Mon Sep 17 00:00:00 2001 From: billz Date: Sat, 5 Dec 2020 22:21:39 +0000 Subject: [PATCH 16/20] Apply defaults.json + set ownership --- installers/common.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/installers/common.sh b/installers/common.sh index 103f9c9b..e012a238 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -146,11 +146,6 @@ function _create_raspap_directories() { echo "Creating $raspap_dir/networking" sudo mkdir -p "$raspap_dir/networking" - # Copy defaults.json to use as fallback config - sudo cp $webroot_dir/config/defaults.json $raspap_network || _install_status 1 "Unable to move defaults.json settings" - - echo "Changing file ownership of $raspap_dir" - sudo chown -R $raspap_user:$raspap_user "$raspap_dir" || _install_status 1 "Unable to change file ownership for '$raspap_dir'" } # Generate hostapd logging and service control scripts @@ -237,7 +232,7 @@ function _install_adblock() { echo "addn-hosts=$raspap_dir/adblock/hostnames.txt" | sudo tee -a "$raspap_adblock" > /dev/null || _install_status 1 "Unable to write to $raspap_adblock" fi - # Remove dhcp-option=6 in dnsmasq.d/090_raspap.conf to force local DNS resolution for DHCP clients + # Remove dhcp-option=6 in dnsmasq.d/090_wlan0.conf to force local DNS resolution for DHCP clients echo "Enabling local DNS name resolution for DHCP clients" sudo sed -i '/dhcp-option=6/d' $raspap_dnsmasq || _install_status 1 "Unable to modify $raspap_dnsmasq" @@ -380,6 +375,10 @@ function _default_configuration() { sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf || _install_status 1 "Unable to move hostapd configuration file" sudo cp $webroot_dir/config/090_wlan0.conf $raspap_dnsmasq || _install_status 1 "Unable to move dnsmasq configuration file" sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || _install_status 1 "Unable to move dhcpcd configuration file" + sudo cp $webroot_dir/config/defaults.json $raspap_network || _install_status 1 "Unable to move defaults.json settings" + + echo "Changing file ownership of $raspap_dir" + sudo chown -R $raspap_user:$raspap_user "$raspap_dir" || _install_status 1 "Unable to change file ownership for '$raspap_dir'" echo "Checking for existence of /etc/dnsmasq.d" [ -d /etc/dnsmasq.d ] || sudo mkdir /etc/dnsmasq.d From 3c4cdefc56d24c36b46a3899a6366038f8d276c5 Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 6 Dec 2020 08:27:18 +0000 Subject: [PATCH 17/20] Minor: wrap msg w/ div --- templates/wifi_stations.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/templates/wifi_stations.php b/templates/wifi_stations.php index bd34246c..176050c4 100755 --- a/templates/wifi_stations.php +++ b/templates/wifi_stations.php @@ -1,6 +1,8 @@ -

-

+
+

+

+
Date: Sun, 6 Dec 2020 09:04:40 +0000 Subject: [PATCH 18/20] Fix: pass required param --- includes/hostapd.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/hostapd.php b/includes/hostapd.php index 52b2a66b..0c335b94 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -246,7 +246,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $_POST['max_num_sta'] = $_POST['max_num_sta'] < 1 ? null : $_POST['max_num_sta']; if ($good_input) { - $return = updateHostapdConfig(); + $return = updateHostapdConfig($ignore_broadcast_ssid); // Fetch dhcp-range, lease time from system config $syscfg = parse_ini_file(RASPI_DNSMASQ_PREFIX.$ap_iface.'.conf', false, INI_SCANNER_RAW); @@ -357,7 +357,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) * * @return boolean $result */ -function updateHostapdConfig() +function updateHostapdConfig($ignore_broadcast_ssid) { // Fixed values $country_code = $_POST['country_code']; From b832954f05a493a97b709b924efe824afd5ee441 Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 6 Dec 2020 09:08:11 +0000 Subject: [PATCH 19/20] Check if 090_wlan0.conf exists --- installers/uninstall.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/installers/uninstall.sh b/installers/uninstall.sh index 77afda6c..b87304ae 100755 --- a/installers/uninstall.sh +++ b/installers/uninstall.sh @@ -172,8 +172,10 @@ function _restore_networking() { fi echo "Done." # Remove dnsmasq and bridge configs - echo "Removing 090_raspap.conf from dnsmasq" - sudo rm "$raspap_dnsmasq" || _install_error "Unable to remove $raspap_dnsmasq" + echo "Removing 090_wlan0.conf from dnsmasq" + if [ -f $raspap_dnsmasq ]; then + sudo rm "$raspap_dnsmasq" || _install_error "Unable to remove $raspap_dnsmasq" + fi echo "Removing raspap bridge configurations" sudo rm "$raspap_network"/raspap* || _install_error "Unable to remove bridge config" if [ -f $raspap_adblock ]; then From e8219c70ec9c5256562eccb1a3cf557c52b524da Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 6 Dec 2020 09:11:43 +0000 Subject: [PATCH 20/20] Check if raspapd.service file exists --- installers/uninstall.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/installers/uninstall.sh b/installers/uninstall.sh index b87304ae..7b33ea25 100755 --- a/installers/uninstall.sh +++ b/installers/uninstall.sh @@ -140,7 +140,9 @@ function _remove_raspap_directories() { # Removes raspapd.service function _remove_raspap_service() { _install_log "Removing raspapd.service" - sudo rm /lib/systemd/system/raspapd.service || _install_error "Unable to remove raspap.service file" + if [ -f /lib/systemd/system/raspapd.service ]; then + sudo rm /lib/systemd/system/raspapd.service || _install_error "Unable to remove raspap.service file" + fi sudo systemctl daemon-reload sudo systemctl disable raspapd.service || _install_error "Failed to disable raspap.service" echo "Done."