Browse Source

Add Session variable "wifi_client_interface"

pull/609/head
christian Zeitnitz 3 years ago
parent
commit
f8a094134b
  1. 4
      includes/configure_client.php
  2. 17
      includes/dashboard.php
  3. 14
      includes/wifi_functions.php
  4. 13
      templates/dashboard.php

4
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;

17
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') {

14
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;
}
}
}

13
templates/dashboard.php

@ -1,12 +1,11 @@
<?php
$arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini');
if ($arrHostapdConf['WifiAPEnable'] == 1) {
$ap_interface = 'uap0';
$client_interface = 'uap0';
} else {
$ap_interface = $_SESSION['ap_interface'];
$client_interface = $_SESSION['wifi_client_interface'];
}
$pars=parse_ini_file(RASPI_HOSTAPD_CONFIG,false,INI_SCANNER_RAW );
$ap_iface = $pars['interface'];
$ap_iface = $_SESSION['ap_interface'];
$MACPattern = '"([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}"';
if ($arrHostapdConf['BridgedEnable'] == 1) {
$moreLink = "index.php?page=hostapd_conf";
@ -28,7 +27,7 @@ $ifaceStatus = $wlan0up ? "up" : "down";
<div class="col">
<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="text service-status"><?php echo strtolower($ap_interface) .' '. _($ifaceStatus) ?></span>
<span class="text service-status"><?php echo strtolower($client_interface) .' '. _($ifaceStatus) ?></span>
</button>
</div>
</div><!-- /.row -->
@ -128,9 +127,9 @@ $ifaceStatus = $wlan0up ? "up" : "down";
<?php echo CSRFTokenFieldTag() ?>
<?php if (!RASPI_MONITOR_ENABLED) : ?>
<?php if (!$wlan0up) : ?>
<input type="submit" class="btn btn-success" value="<?php echo _("Start").' '.$ap_interface ?>" name="ifup_wlan0" />
<input type="submit" class="btn btn-success" value="<?php echo _("Start").' '.$client_interface ?>" name="ifup_wlan0" />
<?php else : ?>
<input type="submit" class="btn btn-warning" value="<?php echo _("Stop").' '.$ap_interface ?>" name="ifdown_wlan0" />
<input type="submit" class="btn btn-warning" value="<?php echo _("Stop").' '.$client_interface ?>" name="ifdown_wlan0" />
<?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>

Loading…
Cancel
Save