Replace interface constant with _SESSION value

This commit is contained in:
billz 2020-06-07 14:25:28 +01:00
parent 677a6c52b0
commit b14175ab0c
5 changed files with 22 additions and 19 deletions

View file

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

View file

@ -1,6 +1,7 @@
<?php
require_once 'config.php';
require_once 'hostapd.php';
/**
* Show dashboard page.
@ -10,7 +11,7 @@ function DisplayDashboard(&$extraFooterScripts)
$status = new StatusMessages();
// 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['client_iface'])) {
$status->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') {

View file

@ -1,6 +1,7 @@
<?php
require_once 'includes/status_messages.php';
require_once 'includes/hostapd.php';
require_once 'config.php';
/**
@ -146,7 +147,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 " .RASPI_WIFI_CLIENT_INTERFACE, $return);
exec("sudo /etc/raspap/openvpn/configauth.sh $tmp_ovpnclient $auth_flag " .$_SESSION['client_iface'], $return);
foreach ($return as $line) {
$status->addMessage($line, 'info');
}

View file

@ -1,6 +1,7 @@
<?php
require_once 'functions.php';
require_once 'hostapd.php';
function knownWifiStations(&$networks)
{
@ -53,10 +54,10 @@ function nearbyWifiStations(&$networks, $cached = true)
$scan_results = cache(
$cacheKey, function () {
exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' scan');
exec('sudo wpa_cli -i ' .$_SESSION['client_iface']. ' scan');
sleep(3);
exec('sudo wpa_cli -i ' . RASPI_WIFI_CLIENT_INTERFACE . ' scan_results', $stdout);
exec('sudo wpa_cli -i ' .$_SESSION['client_iface']. ' scan_results', $stdout);
array_shift($stdout);
return implode("\n", $stdout);

View file

@ -1,9 +1,9 @@
<?php
$arrHostapdConf = parse_ini_file('/etc/raspap/hostapd.ini');
$arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini');
if ($arrHostapdConf['WifiAPEnable'] == 1) {
$client_iface = 'uap0';
} else {
$client_iface = RASPI_WIFI_CLIENT_INTERFACE;
$client_iface = $arrHostapdConf['WifiInterface'];
}
$pars=parse_ini_file(RASPI_HOSTAPD_CONFIG,false,INI_SCANNER_RAW );
$ap_iface = $pars['interface'];