From 15032a3f44dc8e1fcc42c06971410e16da3a8af6 Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 12 May 2020 07:50:28 +0100 Subject: [PATCH 01/27] Apply zbchristian patch --- ajax/networking/gen_int_config.php | 12 +++---- includes/hostapd.php | 53 +++++++++++++++++++----------- templates/dashboard.php | 12 ++++--- 3 files changed, 47 insertions(+), 30 deletions(-) diff --git a/ajax/networking/gen_int_config.php b/ajax/networking/gen_int_config.php index f49d1fa0..8de760e9 100644 --- a/ajax/networking/gen_int_config.php +++ b/ajax/networking/gen_int_config.php @@ -6,18 +6,20 @@ require_once '../../includes/config.php'; require_once '../../includes/functions.php'; if (isset($_POST['generate'])) { - $cnfNetworking = array_diff(scandir(RASPI_CONFIG_NETWORKING, 1), array('..','.','dhcpcd.conf')); + $cnfNetworking = array_diff(scandir(RASPI_CONFIG_NETWORKING, 1), array('..','.','dhcpcd.conf','defaults')); $cnfNetworking = array_combine($cnfNetworking, $cnfNetworking); - $strConfFile = ""; + $strConfFile = file_get_contents(RASPI_CONFIG_NETWORKING.'/defaults')."\n"; foreach ($cnfNetworking as $index => $file) { if ($index != "defaults") { $cnfFile = parse_ini_file(RASPI_CONFIG_NETWORKING.'/'.$file, false, INI_SCANNER_RAW); if ($cnfFile['static'] === 'true') { + $strConfFile .= "#Static IP configured for ".$cnfFile['interface']."\n"; $strConfFile .= "interface ".$cnfFile['interface']."\n"; $strConfFile .= "static ip_address=".$cnfFile['ip_address']."\n"; $strConfFile .= "static routers=".$cnfFile['routers']."\n"; - $strConfFile .= "static domain_name_servers=".$cnfFile['domain_name_server']."\n"; + $strConfFile .= "static domain_name_servers=".$cnfFile['domain_name_server']."\n\n"; } elseif ($cnfFile['static'] === 'false' && $cnfFile['failover'] === 'true') { + $strConfFile .= "#Failover static IP configured for ".$cnfFile['interface']."\n"; $strConfFile .= "profile static_".$cnfFile['interface']."\n"; $strConfFile .= "static ip_address=".$cnfFile['ip_address']."\n"; $strConfFile .= "static routers=".$cnfFile['routers']."\n"; @@ -27,13 +29,11 @@ if (isset($_POST['generate'])) { } else { $strConfFile .= "#DHCP configured for ".$cnfFile['interface']."\n\n"; } - } else { - $strConfFile .= file_get_contents(RASPI_CONFIG_NETWORKING.'/'.$index)."\n\n"; } } if (file_put_contents(RASPI_CONFIG_NETWORKING.'/dhcpcd.conf', $strConfFile)) { - exec('sudo /bin/cp /etc/raspap/networking/dhcpcd.conf /etc/dhcpcd.conf'); + exec('sudo /bin/cp '.RASPI_CONFIG_NETWORKING.'/dhcpcd.conf '.RASPI_DHCPCD_CONFIG); $output = ['return'=>0,'output'=>'Settings successfully applied']; } else { $output = ['return'=>2,'output'=>'Unable to write to apply settings']; diff --git a/includes/hostapd.php b/includes/hostapd.php index ad321dbf..4a1d330d 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -56,7 +56,7 @@ function DisplayHostAPDConfig() } exec('cat '. RASPI_HOSTAPD_CONFIG, $hostapdconfig); - exec('iwgetid '. RASPI_WIFI_CLIENT_INTERFACE. ' -r', $wifiNetworkID); + exec('iwgetid '. $_POST['interface']. ' -r', $wifiNetworkID); if (!empty($wifiNetworkID[0])) { $managedModeEnabled = true; } @@ -165,7 +165,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $cfg['WifiAPEnable'] = ($bridgedEnable == 1 ? $arrHostapdConf['WifiAPEnable'] : $wifiAPEnable); $cfg['BridgedEnable'] = $bridgedEnable; - $cfg['WifiManaged'] = RASPI_WIFI_CLIENT_INTERFACE; + $cfg['WifiManaged'] = $_POST['interface']; write_php_ini($cfg, '/etc/raspap/hostapd.ini'); // Verify input @@ -252,7 +252,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) if ($wifiAPEnable == 1) { $config.= 'interface=uap0'.PHP_EOL; } elseif ($bridgedEnable == 1) { - $config.='interface='.RASPI_WIFI_CLIENT_INTERFACE.PHP_EOL; + $config.='interface='.$_POST['interface'].PHP_EOL; $config.= 'bridge=br0'.PHP_EOL; } else { $config.= 'interface='.$_POST['interface'].PHP_EOL; @@ -300,21 +300,13 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_CONFIG, $return); // Set dnsmasq values from ini, fallback to default if undefined - $intConfig = parse_ini_file(RASPI_CONFIG_NETWORKING.'/'.RASPI_WIFI_CLIENT_INTERFACE.'.ini', false, INI_SCANNER_RAW); + $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']; - $config = [ '# RaspAP wlan0 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'; + // load the defaults for dhcpcd.conf + $config = file_get_contents(RASPI_CONFIG_NETWORKING.'/defaults')."\n\n"; + $config = explode('\n', $config); if ($bridgedEnable == 1) { $config[] = 'denyinterfaces eth0 wlan0'; @@ -327,14 +319,37 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $config[] = 'static ip_address='.$ip_address; $config[] = 'nohook wpa_supplicant'; } else { - // Default config - $ip_address = ($intConfig['ip_address'] == '') ? '10.3.141.1/24' : $intConfig['ip_address']; - $config[] = 'interface '.RASPI_WIFI_CLIENT_INTERFACE; + // 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 + $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']; + + $routers = ""; // NO default route to be set for the hotspot. This screws up the routing! + $config[] = 'interface '.$_POST['interface']; $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[] = 'interface '.$_POST['interface']; + $config[] = 'static ip_address='.$ip_address; + $config[] = 'static routers='.$routers; + $config[] = 'static domain_name_server='.$domain_name_server; + $config[] = PHP_EOL; + } + + $config = join(PHP_EOL, $config); file_put_contents("/tmp/dhcpddata", $config); system('sudo cp /tmp/dhcpddata '.RASPI_DHCPCD_CONFIG, $return); diff --git a/templates/dashboard.php b/templates/dashboard.php index 97c02fbf..e79dbf8d 100755 --- a/templates/dashboard.php +++ b/templates/dashboard.php @@ -5,13 +5,15 @@ if ($arrHostapdConf['WifiAPEnable'] == 1) { } else { $client_iface = RASPI_WIFI_CLIENT_INTERFACE; } +exec('cat '.RASPI_HOSTAPD_CONFIG.' | sed -rn "s/interface=(wlan[0-9])/\1/p" ',$ap_iface); +$ap_iface = $ap_iface[0]; $MACPattern = '"([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}"'; if ($arrHostapdConf['BridgedEnable'] == 1) { $moreLink = "index.php?page=hostapd_conf"; - exec('iw dev '.$client_iface.' station dump | grep -oE '.$MACPattern, $clients); + exec('iw dev '.$ap_iface.' station dump | grep -oE '.$MACPattern, $clients); } else { $moreLink = "index.php?page=dhcpd_conf"; - exec('cat '.RASPI_DNSMASQ_LEASES.'| grep -E $(iw dev '.$client_iface.' station dump | grep -oE '.$MACPattern.' | paste -sd "|")', $clients); + exec('cat '.RASPI_DNSMASQ_LEASES.'| grep -E $(iw dev '.$ap_iface.' station dump | grep -oE '.$MACPattern.' | paste -sd "|")', $clients); } $ifaceStatus = $wlan0up ? "up" : "down"; ?> @@ -39,7 +41,7 @@ $ifaceStatus = $wlan0up ? "up" : "down";

-
+
@@ -126,9 +128,9 @@ $ifaceStatus = $wlan0up ? "up" : "down"; - " name="ifup_wlan0" /> + " name="ifup_wlan0" /> - " name="ifdown_wlan0" /> + " name="ifdown_wlan0" /> From dabec4651127292cd362d0413aa707b22e8a4ddb Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 12 May 2020 08:10:54 +0100 Subject: [PATCH 02/27] Minor: untabify --- includes/hostapd.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/includes/hostapd.php b/includes/hostapd.php index 4a1d330d..f730d602 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -304,7 +304,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $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']; - // load the defaults for dhcpcd.conf + // load the defaults for dhcpcd.conf $config = file_get_contents(RASPI_CONFIG_NETWORKING.'/defaults')."\n\n"; $config = explode('\n', $config); @@ -320,14 +320,14 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $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 - $def_ip = array(); + $ip_address = "10.3.141.1/24"; // fallback IP + // default IP of the AP xxx.xxx.xxx.1/24 of the selected dhcp range + $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 + // 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']; - $routers = ""; // NO default route to be set for the hotspot. This screws up the routing! + $routers = ""; // NO default route to be set for the hotspot. This screws up the routing! $config[] = 'interface '.$_POST['interface']; $config[] = 'static ip_address='.$ip_address; $config[] = 'static routers='.$routers; @@ -346,10 +346,9 @@ 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[] = PHP_EOL; - } + $config[] = PHP_EOL; + } - $config = join(PHP_EOL, $config); file_put_contents("/tmp/dhcpddata", $config); system('sudo cp /tmp/dhcpddata '.RASPI_DHCPCD_CONFIG, $return); From 14508ee7733d5e7e1b9facef97e3392d247fe22f Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 12 May 2020 09:16:04 +0100 Subject: [PATCH 03/27] Remove duplicate $config[] block --- includes/hostapd.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/includes/hostapd.php b/includes/hostapd.php index f730d602..91aa6182 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -332,6 +332,7 @@ 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[] = PHP_EOL; // write the static IP back to the $_POST['interface'].ini file $intConfig['interface'] = $_POST['interface']; @@ -341,12 +342,6 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $intConfig['static'] = "true"; $intConfig['failover'] = "false"; write_php_ini($intConfig, RASPI_CONFIG_NETWORKING.'/'.$_POST['interface'].".ini"); - - $config[] = 'interface '.$_POST['interface']; - $config[] = 'static ip_address='.$ip_address; - $config[] = 'static routers='.$routers; - $config[] = 'static domain_name_server='.$domain_name_server; - $config[] = PHP_EOL; } $config = join(PHP_EOL, $config); From d13c77bd2f5a2d74c47d2d48719e1de58729ce16 Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Wed, 3 Jun 2020 23:32:32 +0200 Subject: [PATCH 04/27] Write required options to dhcpcd.conf --- includes/hostapd.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/includes/hostapd.php b/includes/hostapd.php index 91aa6182..34fbfd59 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -304,9 +304,18 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $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']; - // load the defaults for dhcpcd.conf - $config = file_get_contents(RASPI_CONFIG_NETWORKING.'/defaults')."\n\n"; - $config = explode('\n', $config); + // 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'; if ($bridgedEnable == 1) { $config[] = 'denyinterfaces eth0 wlan0'; From e390c00a2b80e9533fa2223ae444404a0c70e0d0 Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Wed, 3 Jun 2020 23:33:43 +0200 Subject: [PATCH 05/27] Get interface of AP from hostapd config file --- templates/dashboard.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/dashboard.php b/templates/dashboard.php index e79dbf8d..cef8190b 100755 --- a/templates/dashboard.php +++ b/templates/dashboard.php @@ -5,8 +5,8 @@ if ($arrHostapdConf['WifiAPEnable'] == 1) { } else { $client_iface = RASPI_WIFI_CLIENT_INTERFACE; } -exec('cat '.RASPI_HOSTAPD_CONFIG.' | sed -rn "s/interface=(wlan[0-9])/\1/p" ',$ap_iface); -$ap_iface = $ap_iface[0]; +$pars=parse_ini_file(RASPI_HOSTAPD_CONFIG,false,INI_SCANNER_RAW ); +$ap_iface = $pars['interface']; $MACPattern = '"([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}"'; if ($arrHostapdConf['BridgedEnable'] == 1) { $moreLink = "index.php?page=hostapd_conf"; From 677a6c52b0a25da298d08b30abf1dde4c94e59ce Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 7 Jun 2020 14:23:40 +0100 Subject: [PATCH 06/27] Get/set wireless iface from ini, store in _SESSION --- includes/hostapd.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/includes/hostapd.php b/includes/hostapd.php index 34fbfd59..67f93255 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -4,6 +4,15 @@ require_once 'includes/status_messages.php'; require_once 'app/lib/system.php'; require_once 'config.php'; +if (empty($_SESSION['client_iface'])) { + $arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini'); + if (isset($arrHostapdConf['WifiInterface'])) { + $_SESSION['client_iface'] = $arrHostapdConf['WifiInterface']; + } else { // fallback to default + $_SESSSION['client_iface'] = RASPI_WIFI_CLIENT_INTERFACE; + } +} + /** * * @@ -146,27 +155,28 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) if ($arrHostapdConf['LogEnable'] == 0) { if (isset($_POST['logEnable'])) { $logEnable = 1; - exec('sudo /etc/raspap/hostapd/enablelog.sh'); + exec('sudo '.RASPI_CONFIG.'/hostapd/enablelog.sh'); } else { - exec('sudo /etc/raspap/hostapd/disablelog.sh'); + exec('sudo '.RASPI_CONFIG.'/hostapd/disablelog.sh'); } } else { if (isset($_POST['logEnable'])) { $logEnable = 1; - exec('sudo /etc/raspap/hostapd/enablelog.sh'); + exec('sudo '.RASPI_CONFIG.'/hostapd/enablelog.sh'); } else { - exec('sudo /etc/raspap/hostapd/disablelog.sh'); + exec('sudo '.RASPI_CONFIG.'/hostapd/disablelog.sh'); } } $cfg = []; + $cfg['WifiInterface'] = $_POST['interface']; $cfg['LogEnable'] = $logEnable; // Save previous Client mode status when Bridged $cfg['WifiAPEnable'] = ($bridgedEnable == 1 ? $arrHostapdConf['WifiAPEnable'] : $wifiAPEnable); $cfg['BridgedEnable'] = $bridgedEnable; $cfg['WifiManaged'] = $_POST['interface']; - write_php_ini($cfg, '/etc/raspap/hostapd.ini'); + write_php_ini($cfg, RASPI_CONFIG.'/hostapd.ini'); // Verify input if (empty($_POST['ssid']) || strlen($_POST['ssid']) > 32) { @@ -335,11 +345,8 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) 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']; - - $routers = ""; // NO default route to be set for the hotspot. This screws up the routing! $config[] = 'interface '.$_POST['interface']; $config[] = 'static ip_address='.$ip_address; - $config[] = 'static routers='.$routers; $config[] = 'static domain_name_server='.$domain_name_server; $config[] = PHP_EOL; From b14175ab0c901854dfc3d70c32b71f7a41a4979a Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 7 Jun 2020 14:25:28 +0100 Subject: [PATCH 07/27] Replace interface constant with _SESSION value --- includes/configure_client.php | 5 +++-- includes/dashboard.php | 24 ++++++++++++------------ includes/openvpn.php | 3 ++- includes/wifi_functions.php | 5 +++-- templates/dashboard.php | 4 ++-- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/includes/configure_client.php b/includes/configure_client.php index 4e0b001f..9552dae7 100755 --- a/includes/configure_client.php +++ b/includes/configure_client.php @@ -2,6 +2,7 @@ require_once 'includes/status_messages.php'; require_once 'includes/wifi_functions.php'; +require_once 'includes/hostapd.php'; /** * @@ -16,7 +17,7 @@ function DisplayWPAConfig() if (isset($_POST['connect'])) { $result = 0; - exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' select_network '.strval($_POST['connect'])); + exec('sudo wpa_cli -i ' . $_SESSION['client_iface'] . ' select_network '.strval($_POST['connect'])); $status->addMessage('New network selected', 'success'); } elseif (isset($_POST['client_settings'])) { $tmp_networks = $networks; @@ -76,7 +77,7 @@ function DisplayWPAConfig() if ($ok) { system('sudo cp /tmp/wifidata ' . RASPI_WPA_SUPPLICANT_CONFIG, $returnval); if ($returnval == 0) { - exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' reconfigure', $reconfigure_out, $reconfigure_return); + exec('sudo wpa_cli -i ' . $_SESSION['client_iface'] . ' reconfigure', $reconfigure_out, $reconfigure_return); if ($reconfigure_return == 0) { $status->addMessage('Wifi settings updated successfully', 'success'); $networks = $tmp_networks; diff --git a/includes/dashboard.php b/includes/dashboard.php index 1820a4fd..aa31a9eb 100755 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -1,6 +1,7 @@ addMessage(_('Interface name invalid.'), 'danger'); $status->showMessages(); return; @@ -22,7 +23,7 @@ function DisplayDashboard(&$extraFooterScripts) return; } - exec('ip a show '.RASPI_WIFI_CLIENT_INTERFACE, $stdoutIp); + exec('ip a show '.$_SESSION['client_iface'], $stdoutIp); $stdoutIpAllLinesGlued = implode(" ", $stdoutIp); $stdoutIpWRepeatedSpaces = preg_replace('/\s\s+/', ' ', $stdoutIpAllLinesGlued); @@ -61,26 +62,26 @@ function DisplayDashboard(&$extraFooterScripts) // Because of table layout used in the ip output we get the interface statistics directly from // the system. One advantage of this is that it could work when interface is disable. - exec('cat /sys/class/net/'.RASPI_WIFI_CLIENT_INTERFACE.'/statistics/rx_packets ', $stdoutCatRxPackets); + exec('cat /sys/class/net/'.$_SESSION['client_iface'].'/statistics/rx_packets ', $stdoutCatRxPackets); $strRxPackets = _('No data'); if (ctype_digit($stdoutCatRxPackets[0])) { $strRxPackets = $stdoutCatRxPackets[0]; } - exec('cat /sys/class/net/'.RASPI_WIFI_CLIENT_INTERFACE.'/statistics/tx_packets ', $stdoutCatTxPackets); + exec('cat /sys/class/net/'.$_SESSION['client_iface'].'/statistics/tx_packets ', $stdoutCatTxPackets); $strTxPackets = _('No data'); if (ctype_digit($stdoutCatTxPackets[0])) { $strTxPackets = $stdoutCatTxPackets[0]; } - exec('cat /sys/class/net/'.RASPI_WIFI_CLIENT_INTERFACE.'/statistics/rx_bytes ', $stdoutCatRxBytes); + exec('cat /sys/class/net/'.$_SESSION['client_iface'].'/statistics/rx_bytes ', $stdoutCatRxBytes); $strRxBytes = _('No data'); if (ctype_digit($stdoutCatRxBytes[0])) { $strRxBytes = $stdoutCatRxBytes[0]; $strRxBytes .= getHumanReadableDatasize($strRxBytes); } - exec('cat /sys/class/net/'.RASPI_WIFI_CLIENT_INTERFACE.'/statistics/tx_bytes ', $stdoutCatTxBytes); + exec('cat /sys/class/net/'.$_SESSION['client_iface'].'/statistics/tx_bytes ', $stdoutCatTxBytes); $strTxBytes = _('No data'); if (ctype_digit($stdoutCatTxBytes[0])) { $strTxBytes = $stdoutCatTxBytes[0]; @@ -89,7 +90,7 @@ function DisplayDashboard(&$extraFooterScripts) define('SSIDMAXLEN', 32); // Warning iw comes with: "Do NOT screenscrape this tool, we don't consider its output stable." - exec('iw dev '.RASPI_WIFI_CLIENT_INTERFACE.' link ', $stdoutIw); + exec('iw dev '.$_SESSION['client_iface'].' link ', $stdoutIw); $stdoutIwAllLinesGlued = implode(' ', $stdoutIw); $stdoutIwWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwAllLinesGlued); @@ -121,7 +122,7 @@ function DisplayDashboard(&$extraFooterScripts) $bitrate = empty($bitrate) ? "-" : $bitrate; // txpower is now displayed on iw dev(..) info command, not on link command. - exec('iw dev '.RASPI_WIFI_CLIENT_INTERFACE.' info ', $stdoutIwInfo); + exec('iw dev '.$_SESSION['client_iface'].' info ', $stdoutIwInfo); $stdoutIwInfoAllLinesGlued = implode(' ', $stdoutIwInfo); $stdoutIpInfoWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwInfoAllLinesGlued); @@ -147,13 +148,12 @@ function DisplayDashboard(&$extraFooterScripts) $classMsgDevicestatus = 'success'; } - if (!RASPI_MONITOR_ENABLED) { if (isset($_POST['ifdown_wlan0'])) { // Pressed stop button if ($interfaceState === 'UP') { $status->addMessage(sprintf(_('Interface is going %s.'), _('down')), 'warning'); - exec('sudo ip link set '.RASPI_WIFI_CLIENT_INTERFACE.' down'); + exec('sudo ip link set '.$_SESSION['client_iface'].' down'); $wlan0up = false; $status->addMessage(sprintf(_('Interface is now %s.'), _('down')), 'success'); } elseif ($interfaceState === 'unknown') { @@ -165,8 +165,8 @@ function DisplayDashboard(&$extraFooterScripts) // Pressed start button if ($interfaceState === 'DOWN') { $status->addMessage(sprintf(_('Interface is going %s.'), _('up')), 'warning'); - exec('sudo ip link set ' . RASPI_WIFI_CLIENT_INTERFACE . ' up'); - exec('sudo ip -s a f label ' . RASPI_WIFI_CLIENT_INTERFACE); + exec('sudo ip link set ' .$_SESSION['client_iface']. ' up'); + exec('sudo ip -s a f label ' . $_SESSION['client_iface']); $wlan0up = true; $status->addMessage(sprintf(_('Interface is now %s.'), _('up')), 'success'); } elseif ($interfaceState === 'unknown') { diff --git a/includes/openvpn.php b/includes/openvpn.php index 5fc11e63..e5a22b30 100755 --- a/includes/openvpn.php +++ b/includes/openvpn.php @@ -1,6 +1,7 @@ addMessage($line, 'info'); } diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index d8a8ce20..199d6391 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -1,6 +1,7 @@ Date: Sun, 7 Jun 2020 17:13:43 +0100 Subject: [PATCH 08/27] Added getWifiInterface --- includes/wifi_functions.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index 199d6391..1125c0e2 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -92,10 +92,23 @@ function nearbyWifiStations(&$networks, $cached = true) function connectedWifiStations(&$networks) { - exec('iwconfig ' . RASPI_WIFI_CLIENT_INTERFACE, $iwconfig_return); + exec('iwconfig ' .$_SESSION['client_iface'], $iwconfig_return); foreach ($iwconfig_return as $line) { if (preg_match('/ESSID:\"([^"]+)\"/i', $line, $iwconfig_ssid)) { $networks[$iwconfig_ssid[1]]['connected'] = true; } } } + +function getWifiInterface() +{ + if (empty($_SESSION['client_iface'])) { + $arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini'); + if (isset($arrHostapdConf['WifiInterface'])) { + $_SESSION['client_iface'] = $arrHostapdConf['WifiInterface']; + } else { // fallback to default + $_SESSSION['client_iface'] = RASPI_WIFI_CLIENT_INTERFACE; + } + } +} + From a1940ae8f26a3ba471a3df5f359ef3c225222cbb Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 7 Jun 2020 17:15:13 +0100 Subject: [PATCH 09/27] Update w/ session var, fix indents --- templates/dashboard.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/templates/dashboard.php b/templates/dashboard.php index 2e0f2c58..9d18e68d 100755 --- a/templates/dashboard.php +++ b/templates/dashboard.php @@ -1,19 +1,19 @@ From a6a92235f909d10953d37d1b2e58fda8bd43be20 Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 7 Jun 2020 17:17:16 +0100 Subject: [PATCH 10/27] Add include wifi_functions getWifiInterface() --- includes/configure_client.php | 2 +- includes/dashboard.php | 6 +++--- includes/hostapd.php | 11 ++--------- includes/openvpn.php | 6 ++++-- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/includes/configure_client.php b/includes/configure_client.php index 9552dae7..e6892004 100755 --- a/includes/configure_client.php +++ b/includes/configure_client.php @@ -2,7 +2,6 @@ require_once 'includes/status_messages.php'; require_once 'includes/wifi_functions.php'; -require_once 'includes/hostapd.php'; /** * @@ -13,6 +12,7 @@ function DisplayWPAConfig() $status = new StatusMessages(); $networks = []; + getWifiInterface(); knownWifiStations($networks); if (isset($_POST['connect'])) { diff --git a/includes/dashboard.php b/includes/dashboard.php index aa31a9eb..79c3e545 100755 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -1,14 +1,14 @@ Date: Sun, 7 Jun 2020 17:25:11 +0100 Subject: [PATCH 11/27] Add includes/config --- includes/hostapd.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/hostapd.php b/includes/hostapd.php index 8ae41091..2f662e32 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -3,6 +3,7 @@ require_once 'includes/status_messages.php'; require_once 'app/lib/system.php'; require_once 'includes/wifi_functions.php'; +require_once 'includes/config.php'; getWifiInterface(); From 9fb59918cfd6ae4ef0253a4259319441755e3e7c Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 7 Jun 2020 18:46:14 +0100 Subject: [PATCH 12/27] Fix: Update session var when saving cfg --- includes/hostapd.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/hostapd.php b/includes/hostapd.php index 2f662e32..9702c33c 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -171,6 +171,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $cfg['BridgedEnable'] = $bridgedEnable; $cfg['WifiManaged'] = $_POST['interface']; write_php_ini($cfg, RASPI_CONFIG.'/hostapd.ini'); + $_SESSION['client_iface'] = $_POST['interface']; // Verify input if (empty($_POST['ssid']) || strlen($_POST['ssid']) > 32) { From 43819ddfd2f3cf8afcf732358b8fe56c79e92ea5 Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 7 Jun 2020 19:12:00 +0100 Subject: [PATCH 13/27] Fix require path --- includes/hostapd.php | 2 +- includes/wifi_functions.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/hostapd.php b/includes/hostapd.php index 9702c33c..f9e7c9ce 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -1,6 +1,6 @@ Date: Mon, 8 Jun 2020 09:16:10 +0100 Subject: [PATCH 14/27] Bugfix: typo --- includes/wifi_functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index bde2f771..2969c517 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -140,7 +140,7 @@ function getWifiInterface() if (isset($arrHostapdConf['WifiInterface'])) { $_SESSION['client_iface'] = $arrHostapdConf['WifiInterface']; } else { // fallback to default - $_SESSSION['client_iface'] = RASPI_WIFI_CLIENT_INTERFACE; + $_SESSION['client_iface'] = RASPI_WIFI_CLIENT_INTERFACE; } } } From 633f389f4ed967deeabb87deedef6c5416c7f469 Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Tue, 9 Jun 2020 10:15:21 +0200 Subject: [PATCH 15/27] Check for second wifi interface as wifi client --- includes/wifi_functions.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index 2969c517..f907536c 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -138,7 +138,10 @@ function getWifiInterface() if (empty($_SESSION['client_iface'])) { $arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini'); if (isset($arrHostapdConf['WifiInterface'])) { - $_SESSION['client_iface'] = $arrHostapdConf['WifiInterface']; + $iface = $arrHostapdConf['WifiInterface']; + // check for 2nd wifi interface + exec("iw dev | awk '$1==\"Interface\" && $2!=\"$iface\" {print $2}'",$iface2); + $_SESSION['client_iface'] = empty($iface2) ? $iface : trim($iface2[0]); } else { // fallback to default $_SESSION['client_iface'] = RASPI_WIFI_CLIENT_INTERFACE; } From e9470aaf7fc88bd5dc3a6d6e3266d76e17d3fbf9 Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 9 Jun 2020 13:09:58 +0100 Subject: [PATCH 16/27] Get 1st wireless iface, fixes client dashboard widget --- includes/dashboard.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/dashboard.php b/includes/dashboard.php index 79c3e545..1d46b67f 100755 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -90,7 +90,11 @@ function DisplayDashboard(&$extraFooterScripts) define('SSIDMAXLEN', 32); // Warning iw comes with: "Do NOT screenscrape this tool, we don't consider its output stable." - exec('iw dev '.$_SESSION['client_iface'].' link ', $stdoutIw); + // fetch first wireless interface + $iface = $_SESSION['client_iface']; + exec("iw dev | awk '$1==\"Interface\" && $2!=\"$iface\" {print $2}'",$iface2); + $host_iface = empty($iface2) ? $iface1 : trim($iface2[0]); + exec('iw dev ' .$host_iface. ' link ', $stdoutIw); $stdoutIwAllLinesGlued = implode(' ', $stdoutIw); $stdoutIwWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwAllLinesGlued); From 2ca9bf5b6f6ddddf6649cf9074423ddb1f31346f Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 9 Jun 2020 15:32:49 +0100 Subject: [PATCH 17/27] Rename ambiguous variable for clarity --- includes/configure_client.php | 4 ++-- includes/dashboard.php | 22 +++++++++++----------- includes/hostapd.php | 2 +- includes/openvpn.php | 2 +- includes/wifi_functions.php | 12 ++++++------ templates/dashboard.php | 10 +++++----- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/includes/configure_client.php b/includes/configure_client.php index fe45f6e7..22c3febb 100755 --- a/includes/configure_client.php +++ b/includes/configure_client.php @@ -17,7 +17,7 @@ function DisplayWPAConfig() if (isset($_POST['connect'])) { $result = 0; - exec('sudo wpa_cli -i ' . $_SESSION['client_iface'] . ' select_network '.strval($_POST['connect'])); + exec('sudo wpa_cli -i ' . $_SESSION['ap_interface'] . ' select_network '.strval($_POST['connect'])); $status->addMessage('New network selected', 'success'); } elseif (isset($_POST['client_settings'])) { $tmp_networks = $networks; @@ -77,7 +77,7 @@ function DisplayWPAConfig() if ($ok) { system('sudo cp /tmp/wifidata ' . RASPI_WPA_SUPPLICANT_CONFIG, $returnval); if ($returnval == 0) { - exec('sudo wpa_cli -i ' . $_SESSION['client_iface'] . ' reconfigure', $reconfigure_out, $reconfigure_return); + exec('sudo wpa_cli -i ' . $_SESSION['ap_interface'] . ' reconfigure', $reconfigure_out, $reconfigure_return); if ($reconfigure_return == 0) { $status->addMessage('Wifi settings updated successfully', 'success'); $networks = $tmp_networks; diff --git a/includes/dashboard.php b/includes/dashboard.php index 1d46b67f..77b94d5b 100755 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -11,7 +11,7 @@ function DisplayDashboard(&$extraFooterScripts) getWifiInterface(); $status = new StatusMessages(); // Need this check interface name for proper shell execution. - if (!preg_match('/^([a-zA-Z0-9]+)$/', $_SESSION['client_iface'])) { + if (!preg_match('/^([a-zA-Z0-9]+)$/', $_SESSION['ap_interface'])) { $status->addMessage(_('Interface name invalid.'), 'danger'); $status->showMessages(); return; @@ -23,7 +23,7 @@ function DisplayDashboard(&$extraFooterScripts) return; } - exec('ip a show '.$_SESSION['client_iface'], $stdoutIp); + exec('ip a show '.$_SESSION['ap_interface'], $stdoutIp); $stdoutIpAllLinesGlued = implode(" ", $stdoutIp); $stdoutIpWRepeatedSpaces = preg_replace('/\s\s+/', ' ', $stdoutIpAllLinesGlued); @@ -62,26 +62,26 @@ function DisplayDashboard(&$extraFooterScripts) // Because of table layout used in the ip output we get the interface statistics directly from // the system. One advantage of this is that it could work when interface is disable. - exec('cat /sys/class/net/'.$_SESSION['client_iface'].'/statistics/rx_packets ', $stdoutCatRxPackets); + exec('cat /sys/class/net/'.$_SESSION['ap_interface'].'/statistics/rx_packets ', $stdoutCatRxPackets); $strRxPackets = _('No data'); if (ctype_digit($stdoutCatRxPackets[0])) { $strRxPackets = $stdoutCatRxPackets[0]; } - exec('cat /sys/class/net/'.$_SESSION['client_iface'].'/statistics/tx_packets ', $stdoutCatTxPackets); + exec('cat /sys/class/net/'.$_SESSION['ap_interface'].'/statistics/tx_packets ', $stdoutCatTxPackets); $strTxPackets = _('No data'); if (ctype_digit($stdoutCatTxPackets[0])) { $strTxPackets = $stdoutCatTxPackets[0]; } - exec('cat /sys/class/net/'.$_SESSION['client_iface'].'/statistics/rx_bytes ', $stdoutCatRxBytes); + exec('cat /sys/class/net/'.$_SESSION['ap_interface'].'/statistics/rx_bytes ', $stdoutCatRxBytes); $strRxBytes = _('No data'); if (ctype_digit($stdoutCatRxBytes[0])) { $strRxBytes = $stdoutCatRxBytes[0]; $strRxBytes .= getHumanReadableDatasize($strRxBytes); } - exec('cat /sys/class/net/'.$_SESSION['client_iface'].'/statistics/tx_bytes ', $stdoutCatTxBytes); + exec('cat /sys/class/net/'.$_SESSION['ap_interface'].'/statistics/tx_bytes ', $stdoutCatTxBytes); $strTxBytes = _('No data'); if (ctype_digit($stdoutCatTxBytes[0])) { $strTxBytes = $stdoutCatTxBytes[0]; @@ -91,7 +91,7 @@ function DisplayDashboard(&$extraFooterScripts) define('SSIDMAXLEN', 32); // Warning iw comes with: "Do NOT screenscrape this tool, we don't consider its output stable." // fetch first wireless interface - $iface = $_SESSION['client_iface']; + $iface = $_SESSION['ap_interface']; exec("iw dev | awk '$1==\"Interface\" && $2!=\"$iface\" {print $2}'",$iface2); $host_iface = empty($iface2) ? $iface1 : trim($iface2[0]); exec('iw dev ' .$host_iface. ' link ', $stdoutIw); @@ -126,7 +126,7 @@ function DisplayDashboard(&$extraFooterScripts) $bitrate = empty($bitrate) ? "-" : $bitrate; // txpower is now displayed on iw dev(..) info command, not on link command. - exec('iw dev '.$_SESSION['client_iface'].' info ', $stdoutIwInfo); + exec('iw dev '.$_SESSION['ap_interface'].' info ', $stdoutIwInfo); $stdoutIwInfoAllLinesGlued = implode(' ', $stdoutIwInfo); $stdoutIpInfoWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwInfoAllLinesGlued); @@ -157,7 +157,7 @@ function DisplayDashboard(&$extraFooterScripts) // Pressed stop button if ($interfaceState === 'UP') { $status->addMessage(sprintf(_('Interface is going %s.'), _('down')), 'warning'); - exec('sudo ip link set '.$_SESSION['client_iface'].' down'); + exec('sudo ip link set '.$_SESSION['ap_interface'].' down'); $wlan0up = false; $status->addMessage(sprintf(_('Interface is now %s.'), _('down')), 'success'); } elseif ($interfaceState === 'unknown') { @@ -169,8 +169,8 @@ function DisplayDashboard(&$extraFooterScripts) // Pressed start button if ($interfaceState === 'DOWN') { $status->addMessage(sprintf(_('Interface is going %s.'), _('up')), 'warning'); - exec('sudo ip link set ' .$_SESSION['client_iface']. ' up'); - exec('sudo ip -s a f label ' . $_SESSION['client_iface']); + exec('sudo ip link set ' .$_SESSION['ap_interface']. ' up'); + exec('sudo ip -s a f label ' . $_SESSION['ap_interface']); $wlan0up = true; $status->addMessage(sprintf(_('Interface is now %s.'), _('up')), 'success'); } elseif ($interfaceState === 'unknown') { diff --git a/includes/hostapd.php b/includes/hostapd.php index f9e7c9ce..a2350cf9 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -171,7 +171,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $cfg['BridgedEnable'] = $bridgedEnable; $cfg['WifiManaged'] = $_POST['interface']; write_php_ini($cfg, RASPI_CONFIG.'/hostapd.ini'); - $_SESSION['client_iface'] = $_POST['interface']; + $_SESSION['ap_interface'] = $_POST['interface']; // Verify input if (empty($_POST['ssid']) || strlen($_POST['ssid']) > 32) { diff --git a/includes/openvpn.php b/includes/openvpn.php index 6a13b6de..6f9e40b5 100755 --- a/includes/openvpn.php +++ b/includes/openvpn.php @@ -149,7 +149,7 @@ function SaveOpenVPNConfig($status, $file, $authUser, $authPassword) } // Set iptables rules and, optionally, auth-user-pass - exec("sudo /etc/raspap/openvpn/configauth.sh $tmp_ovpnclient $auth_flag " .$_SESSION['client_iface'], $return); + exec("sudo /etc/raspap/openvpn/configauth.sh $tmp_ovpnclient $auth_flag " .$_SESSION['ap_interface'], $return); foreach ($return as $line) { $status->addMessage($line, 'info'); } diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index f907536c..9ad4cc40 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -53,10 +53,10 @@ function nearbyWifiStations(&$networks, $cached = true) $scan_results = cache( $cacheKey, function () { - exec('sudo wpa_cli -i ' .$_SESSION['client_iface']. ' scan'); + exec('sudo wpa_cli -i ' .$_SESSION['ap_interface']. ' scan'); sleep(3); - exec('sudo wpa_cli -i ' .$_SESSION['client_iface']. ' scan_results', $stdout); + exec('sudo wpa_cli -i ' .$_SESSION['ap_interface']. ' scan_results', $stdout); array_shift($stdout); return implode("\n", $stdout); @@ -107,7 +107,7 @@ function nearbyWifiStations(&$networks, $cached = true) function connectedWifiStations(&$networks) { - exec('iwconfig ' .$_SESSION['client_iface'], $iwconfig_return); + exec('iwconfig ' .$_SESSION['ap_interface'], $iwconfig_return); foreach ($iwconfig_return as $line) { if (preg_match('/ESSID:\"([^"]+)\"/i', $line, $iwconfig_ssid)) { $networks[$iwconfig_ssid[1]]['connected'] = true; @@ -135,15 +135,15 @@ function sortNetworksByRSSI(&$networks) function getWifiInterface() { - if (empty($_SESSION['client_iface'])) { + if (empty($_SESSION['ap_interface'])) { $arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini'); if (isset($arrHostapdConf['WifiInterface'])) { $iface = $arrHostapdConf['WifiInterface']; // check for 2nd wifi interface exec("iw dev | awk '$1==\"Interface\" && $2!=\"$iface\" {print $2}'",$iface2); - $_SESSION['client_iface'] = empty($iface2) ? $iface : trim($iface2[0]); + $_SESSION['ap_interface'] = empty($iface2) ? $iface : trim($iface2[0]); } else { // fallback to default - $_SESSION['client_iface'] = RASPI_WIFI_CLIENT_INTERFACE; + $_SESSION['ap_interface'] = RASPI_WIFI_CLIENT_INTERFACE; } } } diff --git a/templates/dashboard.php b/templates/dashboard.php index 9d18e68d..2ad10123 100755 --- a/templates/dashboard.php +++ b/templates/dashboard.php @@ -1,9 +1,9 @@
@@ -128,9 +128,9 @@ $ifaceStatus = $wlan0up ? "up" : "down"; - " name="ifup_wlan0" /> + " name="ifup_wlan0" /> - " name="ifdown_wlan0" /> + " name="ifdown_wlan0" /> From 8ae1e5a8f271ee97bee73eeaea9b132de939c4b6 Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 9 Jun 2020 15:34:19 +0100 Subject: [PATCH 18/27] Rename constant for clarity --- config/config.php | 2 +- includes/defaults.php | 2 +- includes/wifi_functions.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/config.php b/config/config.php index faa08855..2c3c9e8a 100755 --- a/config/config.php +++ b/config/config.php @@ -4,7 +4,7 @@ define('RASPI_VERSION', '2.4.1'); define('RASPI_CONFIG', '/etc/raspap'); define('RASPI_CONFIG_NETWORKING', RASPI_CONFIG.'/networking'); define('RASPI_ADMIN_DETAILS', RASPI_CONFIG.'/raspap.auth'); -define('RASPI_WIFI_CLIENT_INTERFACE', 'wlan0'); +define('RASPI_WIFI_AP_INTERFACE', 'wlan0'); define('RASPI_CACHE_PATH', sys_get_temp_dir() . '/raspap'); // Constants for configuration file paths. diff --git a/includes/defaults.php b/includes/defaults.php index 4fd5b219..524960f5 100755 --- a/includes/defaults.php +++ b/includes/defaults.php @@ -8,7 +8,7 @@ $defaults = [ 'RASPI_VERSION' => '2.4.1', 'RASPI_CONFIG_NETWORKING' => RASPI_CONFIG.'/networking', 'RASPI_ADMIN_DETAILS' => RASPI_CONFIG.'/raspap.auth', - 'RASPI_WIFI_CLIENT_INTERFACE' => 'wlan0', + 'RASPI_WIFI_AP_INTERFACE' => 'wlan0', 'RASPI_CACHE_PATH' => sys_get_temp_dir() . '/raspap', // Constants for configuration file paths. diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index 9ad4cc40..afd81e60 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -143,7 +143,7 @@ function getWifiInterface() exec("iw dev | awk '$1==\"Interface\" && $2!=\"$iface\" {print $2}'",$iface2); $_SESSION['ap_interface'] = empty($iface2) ? $iface : trim($iface2[0]); } else { // fallback to default - $_SESSION['ap_interface'] = RASPI_WIFI_CLIENT_INTERFACE; + $_SESSION['ap_interface'] = RASPI_WIFI_AP_INTERFACE; } } } From 9d1659b97bc66ba2cd3932e06fee1444ff5af66f Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 9 Jun 2020 15:44:21 +0100 Subject: [PATCH 19/27] Document getWifiInterface --- includes/wifi_functions.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index afd81e60..3ab2db93 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -133,6 +133,13 @@ function sortNetworksByRSSI(&$networks) } } +/* + * Determines the configured wireless AP interface + * + * If not saved in /etc/raspap/hostapd.ini, check for a second + * wireless interface with iw dev. Fallback to the constant + * value defined in config.php + */ function getWifiInterface() { if (empty($_SESSION['ap_interface'])) { From 1a85237d15fbcc7100da15bb3618a37ec3bab763 Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 9 Jun 2020 17:01:58 +0100 Subject: [PATCH 20/27] Rename var for clarity --- includes/dashboard.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/includes/dashboard.php b/includes/dashboard.php index 77b94d5b..b3d92e5f 100755 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -22,7 +22,6 @@ function DisplayDashboard(&$extraFooterScripts) $status->showMessages(); return; } - exec('ip a show '.$_SESSION['ap_interface'], $stdoutIp); $stdoutIpAllLinesGlued = implode(" ", $stdoutIp); $stdoutIpWRepeatedSpaces = preg_replace('/\s\s+/', ' ', $stdoutIpAllLinesGlued); @@ -93,8 +92,8 @@ function DisplayDashboard(&$extraFooterScripts) // fetch first wireless interface $iface = $_SESSION['ap_interface']; exec("iw dev | awk '$1==\"Interface\" && $2!=\"$iface\" {print $2}'",$iface2); - $host_iface = empty($iface2) ? $iface1 : trim($iface2[0]); - exec('iw dev ' .$host_iface. ' link ', $stdoutIw); + $wifi_client_interface = empty($iface2) ? $iface1 : trim($iface2[0]); + exec('iw dev ' .$wifi_client_interface. ' link ', $stdoutIw); $stdoutIwAllLinesGlued = implode(' ', $stdoutIw); $stdoutIwWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwAllLinesGlued); From f8a094134bfeb5c805022027ac5dfeb851e813f3 Mon Sep 17 00:00:00 2001 From: christian Zeitnitz Date: Tue, 9 Jun 2020 20:25:19 +0200 Subject: [PATCH 21/27] Add Session variable "wifi_client_interface" --- includes/configure_client.php | 4 ++-- includes/dashboard.php | 17 +++++++---------- includes/wifi_functions.php | 14 +++++++------- templates/dashboard.php | 13 ++++++------- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/includes/configure_client.php b/includes/configure_client.php index 22c3febb..d6f2f554 100755 --- a/includes/configure_client.php +++ b/includes/configure_client.php @@ -17,7 +17,7 @@ function DisplayWPAConfig() if (isset($_POST['connect'])) { $result = 0; - exec('sudo wpa_cli -i ' . $_SESSION['ap_interface'] . ' select_network '.strval($_POST['connect'])); + exec('sudo wpa_cli -i ' . $_SESSION['wifi_client_interface'] . ' select_network '.strval($_POST['connect'])); $status->addMessage('New network selected', 'success'); } elseif (isset($_POST['client_settings'])) { $tmp_networks = $networks; @@ -77,7 +77,7 @@ function DisplayWPAConfig() if ($ok) { system('sudo cp /tmp/wifidata ' . RASPI_WPA_SUPPLICANT_CONFIG, $returnval); if ($returnval == 0) { - exec('sudo wpa_cli -i ' . $_SESSION['ap_interface'] . ' reconfigure', $reconfigure_out, $reconfigure_return); + exec('sudo wpa_cli -i ' . $_SESSION['wifi_client_interface'] . ' reconfigure', $reconfigure_out, $reconfigure_return); if ($reconfigure_return == 0) { $status->addMessage('Wifi settings updated successfully', 'success'); $networks = $tmp_networks; diff --git a/includes/dashboard.php b/includes/dashboard.php index b3d92e5f..0fd1831f 100755 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -11,7 +11,7 @@ function DisplayDashboard(&$extraFooterScripts) getWifiInterface(); $status = new StatusMessages(); // Need this check interface name for proper shell execution. - if (!preg_match('/^([a-zA-Z0-9]+)$/', $_SESSION['ap_interface'])) { + if (!preg_match('/^([a-zA-Z0-9]+)$/', $_SESSION['wifi_client_interface'])) { $status->addMessage(_('Interface name invalid.'), 'danger'); $status->showMessages(); return; @@ -22,7 +22,7 @@ function DisplayDashboard(&$extraFooterScripts) $status->showMessages(); return; } - exec('ip a show '.$_SESSION['ap_interface'], $stdoutIp); + exec('ip a show '.$_SESSION['wifi_client_interface'], $stdoutIp); $stdoutIpAllLinesGlued = implode(" ", $stdoutIp); $stdoutIpWRepeatedSpaces = preg_replace('/\s\s+/', ' ', $stdoutIpAllLinesGlued); @@ -90,10 +90,7 @@ function DisplayDashboard(&$extraFooterScripts) define('SSIDMAXLEN', 32); // Warning iw comes with: "Do NOT screenscrape this tool, we don't consider its output stable." // fetch first wireless interface - $iface = $_SESSION['ap_interface']; - exec("iw dev | awk '$1==\"Interface\" && $2!=\"$iface\" {print $2}'",$iface2); - $wifi_client_interface = empty($iface2) ? $iface1 : trim($iface2[0]); - exec('iw dev ' .$wifi_client_interface. ' link ', $stdoutIw); + exec('iw dev ' .$_SESSION['wifi_client_interface']. ' link ', $stdoutIw); $stdoutIwAllLinesGlued = implode(' ', $stdoutIw); $stdoutIwWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwAllLinesGlued); @@ -125,7 +122,7 @@ function DisplayDashboard(&$extraFooterScripts) $bitrate = empty($bitrate) ? "-" : $bitrate; // txpower is now displayed on iw dev(..) info command, not on link command. - exec('iw dev '.$_SESSION['ap_interface'].' info ', $stdoutIwInfo); + exec('iw dev '.$_SESSION['wifi_client_interface'].' info ', $stdoutIwInfo); $stdoutIwInfoAllLinesGlued = implode(' ', $stdoutIwInfo); $stdoutIpInfoWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwInfoAllLinesGlued); @@ -156,7 +153,7 @@ function DisplayDashboard(&$extraFooterScripts) // Pressed stop button if ($interfaceState === 'UP') { $status->addMessage(sprintf(_('Interface is going %s.'), _('down')), 'warning'); - exec('sudo ip link set '.$_SESSION['ap_interface'].' down'); + exec('sudo ip link set '.$_SESSION['wifi_client_interface'].' down'); $wlan0up = false; $status->addMessage(sprintf(_('Interface is now %s.'), _('down')), 'success'); } elseif ($interfaceState === 'unknown') { @@ -168,8 +165,8 @@ function DisplayDashboard(&$extraFooterScripts) // Pressed start button if ($interfaceState === 'DOWN') { $status->addMessage(sprintf(_('Interface is going %s.'), _('up')), 'warning'); - exec('sudo ip link set ' .$_SESSION['ap_interface']. ' up'); - exec('sudo ip -s a f label ' . $_SESSION['ap_interface']); + exec('sudo ip link set ' .$_SESSION['wifi_client_interface']. ' up'); + exec('sudo ip -s a f label ' . $_SESSION['wifi_client_interface']); $wlan0up = true; $status->addMessage(sprintf(_('Interface is now %s.'), _('up')), 'success'); } elseif ($interfaceState === 'unknown') { diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index 3ab2db93..62d27c3a 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -53,10 +53,10 @@ function nearbyWifiStations(&$networks, $cached = true) $scan_results = cache( $cacheKey, function () { - exec('sudo wpa_cli -i ' .$_SESSION['ap_interface']. ' scan'); + exec('sudo wpa_cli -i ' .$_SESSION['wifi_client_interface']. ' scan'); sleep(3); - exec('sudo wpa_cli -i ' .$_SESSION['ap_interface']. ' scan_results', $stdout); + exec('sudo wpa_cli -i ' .$_SESSION['wifi_client_interface']. ' scan_results', $stdout); array_shift($stdout); return implode("\n", $stdout); @@ -107,7 +107,7 @@ function nearbyWifiStations(&$networks, $cached = true) function connectedWifiStations(&$networks) { - exec('iwconfig ' .$_SESSION['ap_interface'], $iwconfig_return); + exec('iwconfig ' .$_SESSION['wifi_client_interface'], $iwconfig_return); foreach ($iwconfig_return as $line) { if (preg_match('/ESSID:\"([^"]+)\"/i', $line, $iwconfig_ssid)) { $networks[$iwconfig_ssid[1]]['connected'] = true; @@ -145,12 +145,12 @@ function getWifiInterface() if (empty($_SESSION['ap_interface'])) { $arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini'); if (isset($arrHostapdConf['WifiInterface'])) { - $iface = $arrHostapdConf['WifiInterface']; - // check for 2nd wifi interface + $iface = $_SESSION['ap_interface'] = $arrHostapdConf['WifiInterface']; + // check for 2nd wifi interface -> wifi client on different interface exec("iw dev | awk '$1==\"Interface\" && $2!=\"$iface\" {print $2}'",$iface2); - $_SESSION['ap_interface'] = empty($iface2) ? $iface : trim($iface2[0]); + $_SESSION['wifi_client_interface'] = empty($iface2) ? $iface : trim($iface2[0]); } else { // fallback to default - $_SESSION['ap_interface'] = RASPI_WIFI_AP_INTERFACE; + $_SESSION['ap_interface'] = $_SESSION['wifi_client_interface'] = RASPI_WIFI_AP_INTERFACE; } } } diff --git a/templates/dashboard.php b/templates/dashboard.php index 2ad10123..1ce73bea 100755 --- a/templates/dashboard.php +++ b/templates/dashboard.php @@ -1,12 +1,11 @@ @@ -128,9 +127,9 @@ $ifaceStatus = $wlan0up ? "up" : "down"; - " name="ifup_wlan0" /> + " name="ifup_wlan0" /> - " name="ifdown_wlan0" /> + " name="ifdown_wlan0" /> From 656ba9234b551a693fd8f3b0b0b9004fd6e71e22 Mon Sep 17 00:00:00 2001 From: christian Zeitnitz Date: Tue, 9 Jun 2020 20:53:11 +0200 Subject: [PATCH 22/27] Fix intial assignment of $_SESSION['ap_interface'] --- includes/wifi_functions.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index 62d27c3a..e40a628d 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -144,14 +144,10 @@ function getWifiInterface() { if (empty($_SESSION['ap_interface'])) { $arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini'); - if (isset($arrHostapdConf['WifiInterface'])) { - $iface = $_SESSION['ap_interface'] = $arrHostapdConf['WifiInterface']; - // check for 2nd wifi interface -> wifi client on different interface - exec("iw dev | awk '$1==\"Interface\" && $2!=\"$iface\" {print $2}'",$iface2); - $_SESSION['wifi_client_interface'] = empty($iface2) ? $iface : trim($iface2[0]); - } else { // fallback to default - $_SESSION['ap_interface'] = $_SESSION['wifi_client_interface'] = RASPI_WIFI_AP_INTERFACE; - } + $iface = $_SESSION['ap_interface'] = isset($arrHostapdConf['WifiInterface']) ? $arrHostapdConf['WifiInterface'] : RASPI_WIFI_AP_INTERFACE; + // check for 2nd wifi interface -> wifi client on different interface + exec("iw dev | awk '$1==\"Interface\" && $2!=\"$iface\" {print $2}'",$iface2); + $_SESSION['wifi_client_interface'] = empty($iface2) ? $iface : trim($iface2[0]); } } From b9ba2946a546ed9d388347d7b5eb02f9c24c0ceb Mon Sep 17 00:00:00 2001 From: billz Date: Wed, 10 Jun 2020 09:09:10 +0100 Subject: [PATCH 23/27] Fix: display AP interface stats --- includes/dashboard.php | 3 +-- templates/dashboard.php | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/includes/dashboard.php b/includes/dashboard.php index 0fd1831f..ab26c934 100755 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -22,7 +22,7 @@ function DisplayDashboard(&$extraFooterScripts) $status->showMessages(); return; } - exec('ip a show '.$_SESSION['wifi_client_interface'], $stdoutIp); + exec('ip a show '.$_SESSION['ap_interface'], $stdoutIp); $stdoutIpAllLinesGlued = implode(" ", $stdoutIp); $stdoutIpWRepeatedSpaces = preg_replace('/\s\s+/', ' ', $stdoutIpAllLinesGlued); @@ -89,7 +89,6 @@ function DisplayDashboard(&$extraFooterScripts) define('SSIDMAXLEN', 32); // Warning iw comes with: "Do NOT screenscrape this tool, we don't consider its output stable." - // fetch first wireless interface exec('iw dev ' .$_SESSION['wifi_client_interface']. ' link ', $stdoutIw); $stdoutIwAllLinesGlued = implode(' ', $stdoutIw); $stdoutIwWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwAllLinesGlued); diff --git a/templates/dashboard.php b/templates/dashboard.php index 1ce73bea..b7257de6 100755 --- a/templates/dashboard.php +++ b/templates/dashboard.php @@ -3,7 +3,7 @@ $arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini'); if ($arrHostapdConf['WifiAPEnable'] == 1) { $client_interface = 'uap0'; } else { - $client_interface = $_SESSION['wifi_client_interface']; + $client_interface = $_SESSION['ap_interface']; } $ap_iface = $_SESSION['ap_interface']; $MACPattern = '"([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}"'; @@ -40,7 +40,7 @@ $ifaceStatus = $wlan0up ? "up" : "down";

-
+
From 417e9489bb72df8b47a0671c68d38815975e171d Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Sun, 14 Jun 2020 17:40:50 +0200 Subject: [PATCH 24/27] disable check on existing session variable --- includes/wifi_functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index e40a628d..6822ba12 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -142,12 +142,12 @@ function sortNetworksByRSSI(&$networks) */ function getWifiInterface() { - if (empty($_SESSION['ap_interface'])) { +// if (empty($_SESSION['ap_interface'])) { $arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini'); $iface = $_SESSION['ap_interface'] = isset($arrHostapdConf['WifiInterface']) ? $arrHostapdConf['WifiInterface'] : RASPI_WIFI_AP_INTERFACE; // check for 2nd wifi interface -> wifi client on different interface exec("iw dev | awk '$1==\"Interface\" && $2!=\"$iface\" {print $2}'",$iface2); $_SESSION['wifi_client_interface'] = empty($iface2) ? $iface : trim($iface2[0]); - } +// } } From a8238d688e214439fa6dd1eaf53a9aae30befb53 Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Sun, 14 Jun 2020 18:19:34 +0200 Subject: [PATCH 25/27] select correct wifi interface as client --- templates/dashboard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/dashboard.php b/templates/dashboard.php index b7257de6..0b0e7c0d 100755 --- a/templates/dashboard.php +++ b/templates/dashboard.php @@ -3,7 +3,7 @@ $arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini'); if ($arrHostapdConf['WifiAPEnable'] == 1) { $client_interface = 'uap0'; } else { - $client_interface = $_SESSION['ap_interface']; + $client_interface = $_SESSION['wifi_client_interface']; } $ap_iface = $_SESSION['ap_interface']; $MACPattern = '"([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}"'; From e6652c025d1f6b7a55e31d4860a190d16b23e944 Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Sun, 14 Jun 2020 18:22:51 +0200 Subject: [PATCH 26/27] Remove check on existing SESSION variable --- includes/wifi_functions.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index 6822ba12..c4ec7c60 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -142,12 +142,10 @@ function sortNetworksByRSSI(&$networks) */ function getWifiInterface() { -// if (empty($_SESSION['ap_interface'])) { $arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini'); $iface = $_SESSION['ap_interface'] = isset($arrHostapdConf['WifiInterface']) ? $arrHostapdConf['WifiInterface'] : RASPI_WIFI_AP_INTERFACE; // check for 2nd wifi interface -> wifi client on different interface exec("iw dev | awk '$1==\"Interface\" && $2!=\"$iface\" {print $2}'",$iface2); $_SESSION['wifi_client_interface'] = empty($iface2) ? $iface : trim($iface2[0]); -// } } From e1bb73a76dcf4dd44977bcbafa45f31c1ea051a7 Mon Sep 17 00:00:00 2001 From: billz Date: Mon, 15 Jun 2020 09:35:44 +0100 Subject: [PATCH 27/27] Update service-status to indicate AP interface --- templates/dashboard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/dashboard.php b/templates/dashboard.php index 0b0e7c0d..5b606255 100755 --- a/templates/dashboard.php +++ b/templates/dashboard.php @@ -27,7 +27,7 @@ $ifaceStatus = $wlan0up ? "up" : "down";