Merge pull request #582 from billz/zbchristian-wlan-switch

Enable switching of AP interface
This commit is contained in:
Bill Zimmerman 2020-06-16 23:15:17 +02:00 committed by GitHub
commit d95113eaaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 100 additions and 60 deletions

View File

@ -6,18 +6,20 @@ require_once '../../includes/config.php';
require_once '../../includes/functions.php'; require_once '../../includes/functions.php';
if (isset($_POST['generate'])) { 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); $cnfNetworking = array_combine($cnfNetworking, $cnfNetworking);
$strConfFile = ""; $strConfFile = file_get_contents(RASPI_CONFIG_NETWORKING.'/defaults')."\n";
foreach ($cnfNetworking as $index => $file) { foreach ($cnfNetworking as $index => $file) {
if ($index != "defaults") { if ($index != "defaults") {
$cnfFile = parse_ini_file(RASPI_CONFIG_NETWORKING.'/'.$file, false, INI_SCANNER_RAW); $cnfFile = parse_ini_file(RASPI_CONFIG_NETWORKING.'/'.$file, false, INI_SCANNER_RAW);
if ($cnfFile['static'] === 'true') { if ($cnfFile['static'] === 'true') {
$strConfFile .= "#Static IP configured for ".$cnfFile['interface']."\n";
$strConfFile .= "interface ".$cnfFile['interface']."\n"; $strConfFile .= "interface ".$cnfFile['interface']."\n";
$strConfFile .= "static ip_address=".$cnfFile['ip_address']."\n"; $strConfFile .= "static ip_address=".$cnfFile['ip_address']."\n";
$strConfFile .= "static routers=".$cnfFile['routers']."\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') { } elseif ($cnfFile['static'] === 'false' && $cnfFile['failover'] === 'true') {
$strConfFile .= "#Failover static IP configured for ".$cnfFile['interface']."\n";
$strConfFile .= "profile static_".$cnfFile['interface']."\n"; $strConfFile .= "profile static_".$cnfFile['interface']."\n";
$strConfFile .= "static ip_address=".$cnfFile['ip_address']."\n"; $strConfFile .= "static ip_address=".$cnfFile['ip_address']."\n";
$strConfFile .= "static routers=".$cnfFile['routers']."\n"; $strConfFile .= "static routers=".$cnfFile['routers']."\n";
@ -27,13 +29,11 @@ if (isset($_POST['generate'])) {
} else { } else {
$strConfFile .= "#DHCP configured for ".$cnfFile['interface']."\n\n"; $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)) { 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']; $output = ['return'=>0,'output'=>'Settings successfully applied'];
} else { } else {
$output = ['return'=>2,'output'=>'Unable to write to apply settings']; $output = ['return'=>2,'output'=>'Unable to write to apply settings'];

View File

@ -4,7 +4,7 @@ define('RASPI_VERSION', '2.4.1');
define('RASPI_CONFIG', '/etc/raspap'); define('RASPI_CONFIG', '/etc/raspap');
define('RASPI_CONFIG_NETWORKING', RASPI_CONFIG.'/networking'); define('RASPI_CONFIG_NETWORKING', RASPI_CONFIG.'/networking');
define('RASPI_ADMIN_DETAILS', RASPI_CONFIG.'/raspap.auth'); 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'); define('RASPI_CACHE_PATH', sys_get_temp_dir() . '/raspap');
// Constants for configuration file paths. // Constants for configuration file paths.

View File

@ -12,11 +12,12 @@ function DisplayWPAConfig()
$status = new StatusMessages(); $status = new StatusMessages();
$networks = []; $networks = [];
getWifiInterface();
knownWifiStations($networks); knownWifiStations($networks);
if (isset($_POST['connect'])) { if (isset($_POST['connect'])) {
$result = 0; $result = 0;
exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_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'); $status->addMessage('New network selected', 'success');
} elseif (isset($_POST['client_settings'])) { } elseif (isset($_POST['client_settings'])) {
$tmp_networks = $networks; $tmp_networks = $networks;
@ -76,7 +77,7 @@ function DisplayWPAConfig()
if ($ok) { if ($ok) {
system('sudo cp /tmp/wifidata ' . RASPI_WPA_SUPPLICANT_CONFIG, $returnval); system('sudo cp /tmp/wifidata ' . RASPI_WPA_SUPPLICANT_CONFIG, $returnval);
if ($returnval == 0) { if ($returnval == 0) {
exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' reconfigure', $reconfigure_out, $reconfigure_return); exec('sudo wpa_cli -i ' . $_SESSION['wifi_client_interface'] . ' reconfigure', $reconfigure_out, $reconfigure_return);
if ($reconfigure_return == 0) { if ($reconfigure_return == 0) {
$status->addMessage('Wifi settings updated successfully', 'success'); $status->addMessage('Wifi settings updated successfully', 'success');
$networks = $tmp_networks; $networks = $tmp_networks;

View File

@ -1,16 +1,17 @@
<?php <?php
require_once 'config.php'; require_once 'includes/config.php';
require_once 'includes/wifi_functions.php';
/** /**
* Show dashboard page. * Show dashboard page.
*/ */
function DisplayDashboard(&$extraFooterScripts) function DisplayDashboard(&$extraFooterScripts)
{ {
getWifiInterface();
$status = new StatusMessages(); $status = new StatusMessages();
// Need this check interface name for proper shell execution. // Need this check interface name for proper shell execution.
if (!preg_match('/^([a-zA-Z0-9]+)$/', RASPI_WIFI_CLIENT_INTERFACE)) { if (!preg_match('/^([a-zA-Z0-9]+)$/', $_SESSION['wifi_client_interface'])) {
$status->addMessage(_('Interface name invalid.'), 'danger'); $status->addMessage(_('Interface name invalid.'), 'danger');
$status->showMessages(); $status->showMessages();
return; return;
@ -21,8 +22,7 @@ function DisplayDashboard(&$extraFooterScripts)
$status->showMessages(); $status->showMessages();
return; return;
} }
exec('ip a show '.$_SESSION['ap_interface'], $stdoutIp);
exec('ip a show '.RASPI_WIFI_CLIENT_INTERFACE, $stdoutIp);
$stdoutIpAllLinesGlued = implode(" ", $stdoutIp); $stdoutIpAllLinesGlued = implode(" ", $stdoutIp);
$stdoutIpWRepeatedSpaces = preg_replace('/\s\s+/', ' ', $stdoutIpAllLinesGlued); $stdoutIpWRepeatedSpaces = preg_replace('/\s\s+/', ' ', $stdoutIpAllLinesGlued);
@ -61,26 +61,26 @@ function DisplayDashboard(&$extraFooterScripts)
// Because of table layout used in the ip output we get the interface statistics directly from // 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. // 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['ap_interface'].'/statistics/rx_packets ', $stdoutCatRxPackets);
$strRxPackets = _('No data'); $strRxPackets = _('No data');
if (ctype_digit($stdoutCatRxPackets[0])) { if (ctype_digit($stdoutCatRxPackets[0])) {
$strRxPackets = $stdoutCatRxPackets[0]; $strRxPackets = $stdoutCatRxPackets[0];
} }
exec('cat /sys/class/net/'.RASPI_WIFI_CLIENT_INTERFACE.'/statistics/tx_packets ', $stdoutCatTxPackets); exec('cat /sys/class/net/'.$_SESSION['ap_interface'].'/statistics/tx_packets ', $stdoutCatTxPackets);
$strTxPackets = _('No data'); $strTxPackets = _('No data');
if (ctype_digit($stdoutCatTxPackets[0])) { if (ctype_digit($stdoutCatTxPackets[0])) {
$strTxPackets = $stdoutCatTxPackets[0]; $strTxPackets = $stdoutCatTxPackets[0];
} }
exec('cat /sys/class/net/'.RASPI_WIFI_CLIENT_INTERFACE.'/statistics/rx_bytes ', $stdoutCatRxBytes); exec('cat /sys/class/net/'.$_SESSION['ap_interface'].'/statistics/rx_bytes ', $stdoutCatRxBytes);
$strRxBytes = _('No data'); $strRxBytes = _('No data');
if (ctype_digit($stdoutCatRxBytes[0])) { if (ctype_digit($stdoutCatRxBytes[0])) {
$strRxBytes = $stdoutCatRxBytes[0]; $strRxBytes = $stdoutCatRxBytes[0];
$strRxBytes .= getHumanReadableDatasize($strRxBytes); $strRxBytes .= getHumanReadableDatasize($strRxBytes);
} }
exec('cat /sys/class/net/'.RASPI_WIFI_CLIENT_INTERFACE.'/statistics/tx_bytes ', $stdoutCatTxBytes); exec('cat /sys/class/net/'.$_SESSION['ap_interface'].'/statistics/tx_bytes ', $stdoutCatTxBytes);
$strTxBytes = _('No data'); $strTxBytes = _('No data');
if (ctype_digit($stdoutCatTxBytes[0])) { if (ctype_digit($stdoutCatTxBytes[0])) {
$strTxBytes = $stdoutCatTxBytes[0]; $strTxBytes = $stdoutCatTxBytes[0];
@ -89,7 +89,7 @@ function DisplayDashboard(&$extraFooterScripts)
define('SSIDMAXLEN', 32); define('SSIDMAXLEN', 32);
// Warning iw comes with: "Do NOT screenscrape this tool, we don't consider its output stable." // 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['wifi_client_interface']. ' link ', $stdoutIw);
$stdoutIwAllLinesGlued = implode(' ', $stdoutIw); $stdoutIwAllLinesGlued = implode(' ', $stdoutIw);
$stdoutIwWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwAllLinesGlued); $stdoutIwWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwAllLinesGlued);
@ -121,7 +121,7 @@ function DisplayDashboard(&$extraFooterScripts)
$bitrate = empty($bitrate) ? "-" : $bitrate; $bitrate = empty($bitrate) ? "-" : $bitrate;
// txpower is now displayed on iw dev(..) info command, not on link command. // 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['wifi_client_interface'].' info ', $stdoutIwInfo);
$stdoutIwInfoAllLinesGlued = implode(' ', $stdoutIwInfo); $stdoutIwInfoAllLinesGlued = implode(' ', $stdoutIwInfo);
$stdoutIpInfoWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwInfoAllLinesGlued); $stdoutIpInfoWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwInfoAllLinesGlued);
@ -147,13 +147,12 @@ function DisplayDashboard(&$extraFooterScripts)
$classMsgDevicestatus = 'success'; $classMsgDevicestatus = 'success';
} }
if (!RASPI_MONITOR_ENABLED) { if (!RASPI_MONITOR_ENABLED) {
if (isset($_POST['ifdown_wlan0'])) { if (isset($_POST['ifdown_wlan0'])) {
// Pressed stop button // Pressed stop button
if ($interfaceState === 'UP') { if ($interfaceState === 'UP') {
$status->addMessage(sprintf(_('Interface is going %s.'), _('down')), 'warning'); $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['wifi_client_interface'].' down');
$wlan0up = false; $wlan0up = false;
$status->addMessage(sprintf(_('Interface is now %s.'), _('down')), 'success'); $status->addMessage(sprintf(_('Interface is now %s.'), _('down')), 'success');
} elseif ($interfaceState === 'unknown') { } elseif ($interfaceState === 'unknown') {
@ -165,8 +164,8 @@ function DisplayDashboard(&$extraFooterScripts)
// Pressed start button // Pressed start button
if ($interfaceState === 'DOWN') { if ($interfaceState === 'DOWN') {
$status->addMessage(sprintf(_('Interface is going %s.'), _('up')), 'warning'); $status->addMessage(sprintf(_('Interface is going %s.'), _('up')), 'warning');
exec('sudo ip link set ' . RASPI_WIFI_CLIENT_INTERFACE . ' up'); exec('sudo ip link set ' .$_SESSION['wifi_client_interface']. ' up');
exec('sudo ip -s a f label ' . RASPI_WIFI_CLIENT_INTERFACE); exec('sudo ip -s a f label ' . $_SESSION['wifi_client_interface']);
$wlan0up = true; $wlan0up = true;
$status->addMessage(sprintf(_('Interface is now %s.'), _('up')), 'success'); $status->addMessage(sprintf(_('Interface is now %s.'), _('up')), 'success');
} elseif ($interfaceState === 'unknown') { } elseif ($interfaceState === 'unknown') {

View File

@ -8,7 +8,7 @@ $defaults = [
'RASPI_VERSION' => '2.4.1', 'RASPI_VERSION' => '2.4.1',
'RASPI_CONFIG_NETWORKING' => RASPI_CONFIG.'/networking', 'RASPI_CONFIG_NETWORKING' => RASPI_CONFIG.'/networking',
'RASPI_ADMIN_DETAILS' => RASPI_CONFIG.'/raspap.auth', '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', 'RASPI_CACHE_PATH' => sys_get_temp_dir() . '/raspap',
// Constants for configuration file paths. // Constants for configuration file paths.

View File

@ -1,8 +1,11 @@
<?php <?php
require_once 'includes/status_messages.php'; require_once 'status_messages.php';
require_once 'app/lib/system.php'; require_once 'app/lib/system.php';
require_once 'config.php'; require_once 'includes/wifi_functions.php';
require_once 'includes/config.php';
getWifiInterface();
/** /**
* *
@ -56,7 +59,7 @@ function DisplayHostAPDConfig()
} }
exec('cat '. RASPI_HOSTAPD_CONFIG, $hostapdconfig); exec('cat '. RASPI_HOSTAPD_CONFIG, $hostapdconfig);
exec('iwgetid '. RASPI_WIFI_CLIENT_INTERFACE. ' -r', $wifiNetworkID); exec('iwgetid '. $_POST['interface']. ' -r', $wifiNetworkID);
if (!empty($wifiNetworkID[0])) { if (!empty($wifiNetworkID[0])) {
$managedModeEnabled = true; $managedModeEnabled = true;
} }
@ -146,27 +149,29 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
if ($arrHostapdConf['LogEnable'] == 0) { if ($arrHostapdConf['LogEnable'] == 0) {
if (isset($_POST['logEnable'])) { if (isset($_POST['logEnable'])) {
$logEnable = 1; $logEnable = 1;
exec('sudo /etc/raspap/hostapd/enablelog.sh'); exec('sudo '.RASPI_CONFIG.'/hostapd/enablelog.sh');
} else { } else {
exec('sudo /etc/raspap/hostapd/disablelog.sh'); exec('sudo '.RASPI_CONFIG.'/hostapd/disablelog.sh');
} }
} else { } else {
if (isset($_POST['logEnable'])) { if (isset($_POST['logEnable'])) {
$logEnable = 1; $logEnable = 1;
exec('sudo /etc/raspap/hostapd/enablelog.sh'); exec('sudo '.RASPI_CONFIG.'/hostapd/enablelog.sh');
} else { } else {
exec('sudo /etc/raspap/hostapd/disablelog.sh'); exec('sudo '.RASPI_CONFIG.'/hostapd/disablelog.sh');
} }
} }
$cfg = []; $cfg = [];
$cfg['WifiInterface'] = $_POST['interface'];
$cfg['LogEnable'] = $logEnable; $cfg['LogEnable'] = $logEnable;
// Save previous Client mode status when Bridged // Save previous Client mode status when Bridged
$cfg['WifiAPEnable'] = ($bridgedEnable == 1 ? $cfg['WifiAPEnable'] = ($bridgedEnable == 1 ?
$arrHostapdConf['WifiAPEnable'] : $wifiAPEnable); $arrHostapdConf['WifiAPEnable'] : $wifiAPEnable);
$cfg['BridgedEnable'] = $bridgedEnable; $cfg['BridgedEnable'] = $bridgedEnable;
$cfg['WifiManaged'] = RASPI_WIFI_CLIENT_INTERFACE; $cfg['WifiManaged'] = $_POST['interface'];
write_php_ini($cfg, '/etc/raspap/hostapd.ini'); write_php_ini($cfg, RASPI_CONFIG.'/hostapd.ini');
$_SESSION['ap_interface'] = $_POST['interface'];
// Verify input // Verify input
if (empty($_POST['ssid']) || strlen($_POST['ssid']) > 32) { if (empty($_POST['ssid']) || strlen($_POST['ssid']) > 32) {
@ -255,7 +260,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
if ($wifiAPEnable == 1) { if ($wifiAPEnable == 1) {
$config.= 'interface=uap0'.PHP_EOL; $config.= 'interface=uap0'.PHP_EOL;
} elseif ($bridgedEnable == 1) { } elseif ($bridgedEnable == 1) {
$config.='interface='.RASPI_WIFI_CLIENT_INTERFACE.PHP_EOL; $config.='interface='.$_POST['interface'].PHP_EOL;
$config.= 'bridge=br0'.PHP_EOL; $config.= 'bridge=br0'.PHP_EOL;
} else { } else {
$config.= 'interface='.$_POST['interface'].PHP_EOL; $config.= 'interface='.$_POST['interface'].PHP_EOL;
@ -303,11 +308,12 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_CONFIG, $return); system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_CONFIG, $return);
// Set dnsmasq values from ini, fallback to default if undefined // 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']; $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']; $routers = ($intConfig['routers'] == '') ? '10.3.141.1' : $intConfig['routers'];
$config = [ '# RaspAP wlan0 configuration' ]; // write options to dhcpcd.conf
$config = [ '# RaspAP '.$_POST['interface'].' configuration' ];
$config[] = 'hostname'; $config[] = 'hostname';
$config[] = 'clientid'; $config[] = 'clientid';
$config[] = 'persistent'; $config[] = 'persistent';
@ -330,12 +336,26 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
$config[] = 'static ip_address='.$ip_address; $config[] = 'static ip_address='.$ip_address;
$config[] = 'nohook wpa_supplicant'; $config[] = 'nohook wpa_supplicant';
} else { } else {
// Default config // Default config
$ip_address = ($intConfig['ip_address'] == '') ? '10.3.141.1/24' : $intConfig['ip_address']; $ip_address = "10.3.141.1/24"; // fallback IP
$config[] = 'interface '.RASPI_WIFI_CLIENT_INTERFACE; // 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'];
$config[] = 'interface '.$_POST['interface'];
$config[] = 'static ip_address='.$ip_address; $config[] = 'static ip_address='.$ip_address;
$config[] = 'static routers='.$routers;
$config[] = 'static domain_name_server='.$domain_name_server; $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'];
$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 = join(PHP_EOL, $config); $config = join(PHP_EOL, $config);

View File

@ -1,7 +1,10 @@
<?php <?php
require_once 'includes/status_messages.php'; require_once 'includes/status_messages.php';
require_once 'config.php'; require_once 'includes/config.php';
require_once 'includes/wifi_functions.php';
getWifiInterface();
/** /**
* Manage OpenVPN configuration * Manage OpenVPN configuration
@ -146,7 +149,7 @@ function SaveOpenVPNConfig($status, $file, $authUser, $authPassword)
} }
// Set iptables rules and, optionally, auth-user-pass // Set iptables rules and, optionally, auth-user-pass
exec("sudo /etc/raspap/openvpn/configauth.sh $tmp_ovpnclient $auth_flag " .RASPI_WIFI_CLIENT_INTERFACE, $return); exec("sudo /etc/raspap/openvpn/configauth.sh $tmp_ovpnclient $auth_flag " .$_SESSION['ap_interface'], $return);
foreach ($return as $line) { foreach ($return as $line) {
$status->addMessage($line, 'info'); $status->addMessage($line, 'info');
} }

View File

@ -52,12 +52,11 @@ function nearbyWifiStations(&$networks, $cached = true)
} }
$scan_results = cache( $scan_results = cache(
$cacheKey, $cacheKey, function () {
function () { exec('sudo wpa_cli -i ' .$_SESSION['wifi_client_interface']. ' scan');
exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' scan');
sleep(3); sleep(3);
exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' scan_results', $stdout); exec('sudo wpa_cli -i ' .$_SESSION['wifi_client_interface']. ' scan_results', $stdout);
array_shift($stdout); array_shift($stdout);
return implode("\n", $stdout); return implode("\n", $stdout);
@ -77,7 +76,7 @@ function nearbyWifiStations(&$networks, $cached = true)
$ssid = trim($arrNetwork[4]); $ssid = trim($arrNetwork[4]);
// filter SSID string: anything invisible in 7bit ASCII or quotes -> ignore network // filter SSID string: anything invisible in 7bit ASCII or quotes -> ignore network
if (preg_match('[\x00-\x1f\x7f-\xff\'\`\´\"]', $ssid)) { if (preg_match('[\x00-\x1f\x7f-\xff\'\`\´\"]', $ssid)) {
continue; continue;
} }
@ -108,7 +107,7 @@ function nearbyWifiStations(&$networks, $cached = true)
function connectedWifiStations(&$networks) function connectedWifiStations(&$networks)
{ {
exec('iwconfig ' . RASPI_WIFI_CLIENT_INTERFACE, $iwconfig_return); exec('iwconfig ' .$_SESSION['wifi_client_interface'], $iwconfig_return);
foreach ($iwconfig_return as $line) { foreach ($iwconfig_return as $line) {
if (preg_match('/ESSID:\"([^"]+)\"/i', $line, $iwconfig_ssid)) { if (preg_match('/ESSID:\"([^"]+)\"/i', $line, $iwconfig_ssid)) {
$networks[$iwconfig_ssid[1]]['connected'] = true; $networks[$iwconfig_ssid[1]]['connected'] = true;
@ -133,3 +132,20 @@ function sortNetworksByRSSI(&$networks)
$networks[$SSID]['RSSI'] = $RSSI; $networks[$SSID]['RSSI'] = $RSSI;
} }
} }
/*
* 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()
{
$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]);
}

View File

@ -1,17 +1,18 @@
<?php <?php
$arrHostapdConf = parse_ini_file('/etc/raspap/hostapd.ini'); $arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini');
if ($arrHostapdConf['WifiAPEnable'] == 1) { if ($arrHostapdConf['WifiAPEnable'] == 1) {
$client_iface = 'uap0'; $client_interface = 'uap0';
} else { } else {
$client_iface = RASPI_WIFI_CLIENT_INTERFACE; $client_interface = $_SESSION['wifi_client_interface'];
} }
$ap_iface = $_SESSION['ap_interface'];
$MACPattern = '"([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}"'; $MACPattern = '"([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}"';
if ($arrHostapdConf['BridgedEnable'] == 1) { if ($arrHostapdConf['BridgedEnable'] == 1) {
$moreLink = "index.php?page=hostapd_conf"; $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 { } else {
$moreLink = "index.php?page=dhcpd_conf"; $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"; $ifaceStatus = $wlan0up ? "up" : "down";
?> ?>
@ -26,7 +27,7 @@ $ifaceStatus = $wlan0up ? "up" : "down";
<div class="col"> <div class="col">
<button class="btn btn-light btn-icon-split btn-sm service-status float-right"> <button class="btn btn-light btn-icon-split btn-sm service-status float-right">
<span class="icon"><i class="fas fa-circle service-status-<?php echo $ifaceStatus ?>"></i></span> <span class="icon"><i class="fas fa-circle service-status-<?php echo $ifaceStatus ?>"></i></span>
<span class="text service-status"><?php echo strtolower($client_iface) .' '. _($ifaceStatus) ?></span> <span class="text service-status"><?php echo strtolower($ap_iface) .' '. _($ifaceStatus) ?></span>
</button> </button>
</div> </div>
</div><!-- /.row --> </div><!-- /.row -->
@ -39,7 +40,7 @@ $ifaceStatus = $wlan0up ? "up" : "down";
<div class="card mb-3"> <div class="card mb-3">
<div class="card-body"> <div class="card-body">
<h4><?php echo _("Hourly traffic amount"); ?></h4> <h4><?php echo _("Hourly traffic amount"); ?></h4>
<div id="divInterface" class="d-none"><?php echo RASPI_WIFI_CLIENT_INTERFACE; ?></div> <div id="divInterface" class="d-none"><?php echo $_SESSION['ap_interface']; ?></div>
<div class="col-md-12"> <div class="col-md-12">
<canvas id="divDBChartBandwidthhourly"></canvas> <canvas id="divDBChartBandwidthhourly"></canvas>
</div> </div>
@ -126,9 +127,9 @@ $ifaceStatus = $wlan0up ? "up" : "down";
<?php echo CSRFTokenFieldTag() ?> <?php echo CSRFTokenFieldTag() ?>
<?php if (!RASPI_MONITOR_ENABLED) : ?> <?php if (!RASPI_MONITOR_ENABLED) : ?>
<?php if (!$wlan0up) : ?> <?php if (!$wlan0up) : ?>
<input type="submit" class="btn btn-success" value="<?php echo _("Start").' '.RASPI_WIFI_CLIENT_INTERFACE ?>" name="ifup_wlan0" /> <input type="submit" class="btn btn-success" value="<?php echo _("Start").' '.$client_interface ?>" name="ifup_wlan0" />
<?php else : ?> <?php else : ?>
<input type="submit" class="btn btn-warning" value="<?php echo _("Stop").' '.RASPI_WIFI_CLIENT_INTERFACE ?>" name="ifdown_wlan0" /> <input type="submit" class="btn btn-warning" value="<?php echo _("Stop").' '.$client_interface ?>" name="ifdown_wlan0" />
<?php endif ?> <?php endif ?>
<?php endif ?> <?php endif ?>
<a href="?page=<?php echo $_GET['page'] ?>" class="btn btn-outline btn-primary"><i class="fas fa-sync-alt"></i> <?php echo _("Refresh") ?></a> <a href="?page=<?php echo $_GET['page'] ?>" class="btn btn-outline btn-primary"><i class="fas fa-sync-alt"></i> <?php echo _("Refresh") ?></a>