1
0
mirror of https://github.com/billz/raspap-webgui.git synced 2023-10-10 13:37:24 +02:00

Rename ambiguous variable for clarity

This commit is contained in:
billz 2020-06-09 15:32:49 +01:00
parent e9470aaf7f
commit 2ca9bf5b6f
6 changed files with 26 additions and 26 deletions

View File

@ -17,7 +17,7 @@ function DisplayWPAConfig()
if (isset($_POST['connect'])) { if (isset($_POST['connect'])) {
$result = 0; $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'); $status->addMessage('New network selected', 'success');
} elseif (isset($_POST['client_settings'])) { } elseif (isset($_POST['client_settings'])) {
$tmp_networks = $networks; $tmp_networks = $networks;
@ -77,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 ' . $_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) { 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

@ -11,7 +11,7 @@ function DisplayDashboard(&$extraFooterScripts)
getWifiInterface(); 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]+)$/', $_SESSION['client_iface'])) { if (!preg_match('/^([a-zA-Z0-9]+)$/', $_SESSION['ap_interface'])) {
$status->addMessage(_('Interface name invalid.'), 'danger'); $status->addMessage(_('Interface name invalid.'), 'danger');
$status->showMessages(); $status->showMessages();
return; return;
@ -23,7 +23,7 @@ function DisplayDashboard(&$extraFooterScripts)
return; return;
} }
exec('ip a show '.$_SESSION['client_iface'], $stdoutIp); exec('ip a show '.$_SESSION['ap_interface'], $stdoutIp);
$stdoutIpAllLinesGlued = implode(" ", $stdoutIp); $stdoutIpAllLinesGlued = implode(" ", $stdoutIp);
$stdoutIpWRepeatedSpaces = preg_replace('/\s\s+/', ' ', $stdoutIpAllLinesGlued); $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 // 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/'.$_SESSION['client_iface'].'/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/'.$_SESSION['client_iface'].'/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/'.$_SESSION['client_iface'].'/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/'.$_SESSION['client_iface'].'/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];
@ -91,7 +91,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."
// fetch first wireless interface // fetch first wireless interface
$iface = $_SESSION['client_iface']; $iface = $_SESSION['ap_interface'];
exec("iw dev | awk '$1==\"Interface\" && $2!=\"$iface\" {print $2}'",$iface2); exec("iw dev | awk '$1==\"Interface\" && $2!=\"$iface\" {print $2}'",$iface2);
$host_iface = empty($iface2) ? $iface1 : trim($iface2[0]); $host_iface = empty($iface2) ? $iface1 : trim($iface2[0]);
exec('iw dev ' .$host_iface. ' link ', $stdoutIw); exec('iw dev ' .$host_iface. ' link ', $stdoutIw);
@ -126,7 +126,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 '.$_SESSION['client_iface'].' info ', $stdoutIwInfo); exec('iw dev '.$_SESSION['ap_interface'].' info ', $stdoutIwInfo);
$stdoutIwInfoAllLinesGlued = implode(' ', $stdoutIwInfo); $stdoutIwInfoAllLinesGlued = implode(' ', $stdoutIwInfo);
$stdoutIpInfoWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwInfoAllLinesGlued); $stdoutIpInfoWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwInfoAllLinesGlued);
@ -157,7 +157,7 @@ function DisplayDashboard(&$extraFooterScripts)
// 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 '.$_SESSION['client_iface'].' down'); exec('sudo ip link set '.$_SESSION['ap_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') {
@ -169,8 +169,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 ' .$_SESSION['client_iface']. ' up'); exec('sudo ip link set ' .$_SESSION['ap_interface']. ' up');
exec('sudo ip -s a f label ' . $_SESSION['client_iface']); exec('sudo ip -s a f label ' . $_SESSION['ap_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

@ -171,7 +171,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
$cfg['BridgedEnable'] = $bridgedEnable; $cfg['BridgedEnable'] = $bridgedEnable;
$cfg['WifiManaged'] = $_POST['interface']; $cfg['WifiManaged'] = $_POST['interface'];
write_php_ini($cfg, RASPI_CONFIG.'/hostapd.ini'); write_php_ini($cfg, RASPI_CONFIG.'/hostapd.ini');
$_SESSION['client_iface'] = $_POST['interface']; $_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) {

View File

@ -149,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 " .$_SESSION['client_iface'], $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

@ -53,10 +53,10 @@ function nearbyWifiStations(&$networks, $cached = true)
$scan_results = cache( $scan_results = cache(
$cacheKey, function () { $cacheKey, function () {
exec('sudo wpa_cli -i ' .$_SESSION['client_iface']. ' scan'); exec('sudo wpa_cli -i ' .$_SESSION['ap_interface']. ' scan');
sleep(3); 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); array_shift($stdout);
return implode("\n", $stdout); return implode("\n", $stdout);
@ -107,7 +107,7 @@ function nearbyWifiStations(&$networks, $cached = true)
function connectedWifiStations(&$networks) function connectedWifiStations(&$networks)
{ {
exec('iwconfig ' .$_SESSION['client_iface'], $iwconfig_return); exec('iwconfig ' .$_SESSION['ap_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;
@ -135,15 +135,15 @@ function sortNetworksByRSSI(&$networks)
function getWifiInterface() function getWifiInterface()
{ {
if (empty($_SESSION['client_iface'])) { if (empty($_SESSION['ap_interface'])) {
$arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini'); $arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini');
if (isset($arrHostapdConf['WifiInterface'])) { if (isset($arrHostapdConf['WifiInterface'])) {
$iface = $arrHostapdConf['WifiInterface']; $iface = $arrHostapdConf['WifiInterface'];
// check for 2nd wifi interface // check for 2nd wifi interface
exec("iw dev | awk '$1==\"Interface\" && $2!=\"$iface\" {print $2}'",$iface2); 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 } else { // fallback to default
$_SESSION['client_iface'] = RASPI_WIFI_CLIENT_INTERFACE; $_SESSION['ap_interface'] = RASPI_WIFI_CLIENT_INTERFACE;
} }
} }
} }

View File

@ -1,9 +1,9 @@
<?php <?php
$arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini'); $arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini');
if ($arrHostapdConf['WifiAPEnable'] == 1) { if ($arrHostapdConf['WifiAPEnable'] == 1) {
$client_iface = 'uap0'; $ap_interface = 'uap0';
} else { } else {
$client_iface = $_SESSION['client_iface']; $ap_interface = $_SESSION['ap_interface'];
} }
$pars=parse_ini_file(RASPI_HOSTAPD_CONFIG,false,INI_SCANNER_RAW ); $pars=parse_ini_file(RASPI_HOSTAPD_CONFIG,false,INI_SCANNER_RAW );
$ap_iface = $pars['interface']; $ap_iface = $pars['interface'];
@ -28,7 +28,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_interface) .' '. _($ifaceStatus) ?></span>
</button> </button>
</div> </div>
</div><!-- /.row --> </div><!-- /.row -->
@ -128,9 +128,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").' '.$client_iface ?>" name="ifup_wlan0" /> <input type="submit" class="btn btn-success" value="<?php echo _("Start").' '.$ap_interface ?>" name="ifup_wlan0" />
<?php else : ?> <?php else : ?>
<input type="submit" class="btn btn-warning" value="<?php echo _("Stop").' '.$client_iface ?>" name="ifdown_wlan0" /> <input type="submit" class="btn btn-warning" value="<?php echo _("Stop").' '.$ap_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>