Skip to content

Commit

Permalink
Merge pull request #1314 from RaspAP/mode-compatibility
Browse files Browse the repository at this point in the history
Wireless mode tooltip
  • Loading branch information
billz authored Mar 21, 2023
2 parents fce63f1 + 7b3a7db commit 8be62bb
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 36 deletions.
42 changes: 42 additions & 0 deletions ajax/networking/get_frequencies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

require '../../includes/csrf.php';
require_once '../../includes/config.php';
require_once '../../includes/locale.php';

if (isset($_POST['interface'])) {

define( 'NL80211_BAND_24GHZ', 0x1 );
define( 'NL80211_BAND_5GHZ', 0x2 );
$iface = escapeshellcmd($_POST['interface']);

// get physical device for selected interface
exec("iw dev | awk '/$iface/ {print line}{line = $0}'", $return);
$phy = $return[0];
// get frequencies supported by device
exec('iw '.$phy.' info | sed -rn "s/^.*\*\s([0-9]{4})\sMHz.*/\1/p"', $frequencies);

if (count(preg_grep('/^24[0-9]{2}/i', $frequencies)) >0) {
$flags += NL80211_BAND_24GHZ;
}
if (count(preg_grep('/^5[0-9]{3}/i', $frequencies)) >0) {
$flags += NL80211_BAND_5GHZ;
}

switch ($flags) {
case NL80211_BAND_24GHZ:
$msg = sprintf(_("The selected interface (%s) has support for the 2.4 GHz wireless band only."), $iface);
break;
case NL80211_BAND_5GHZ:
$msg = sprintf(_("The selected interface (%s) has support for the 5 GHz wireless band only."), $iface);
break;
case NL80211_BAND_24GHZ | NL80211_BAND_5GHZ:
$msg = sprintf(_("The selected interface (%s) has support for both the 2.4 and 5 GHz wireless bands."), $iface);
break;
default:
$msg = sprintf(_("The selected interface (%s) does not support wireless mode operation."), $iface);
}
echo json_encode($msg);
}

2 changes: 1 addition & 1 deletion app/icons/site.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"short_name": "RaspAP",
"icons": [
{
"src": "/dist/icons/android-chrome-192x192.png",
"src": "/app/icons/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
}
Expand Down
16 changes: 16 additions & 0 deletions app/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ function contentLoaded() {
break;
case "hostapd_conf":
loadChannel();
setHardwareModeTooltip();
break;
case "dhcpd_conf":
loadInterfaceDHCPSelect();
Expand Down Expand Up @@ -387,6 +388,21 @@ function loadChannelSelect(selected) {
});
}

/* Sets hardware mode tooltip text for selected interface.
*/
function setHardwareModeTooltip() {
var iface = $('#cbxinterface').val();
var hwmodeText = '';
// Explanatory text if 802.11ac is disabled
if ($('#cbxhwmode').find('option[value="ac"]').prop('disabled') == true ) {
var hwmodeText = $('#hwmode').attr('data-tooltip');
}
$.post('ajax/networking/get_frequencies.php?',{'interface': iface},function(data){
var responseText = JSON.parse(data);
$('#tiphwmode').attr('data-original-title', responseText + '\n' + hwmodeText );
});
}

/* Updates the selected blocklist
* Request is passed to an ajax handler to download the associated list.
* Interface elements are updated to indicate current progress, status.
Expand Down
Empty file modified includes/firewall.php
100644 → 100755
Empty file.
11 changes: 11 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,3 +792,14 @@ function get_public_ip()
return $public_ip[0];
}

/* Returns a standardized tooltip
*
* @return string $tooltip
*/
function getTooltip($msg, $id, $visible = true, $data_html = false)
{
($visible) ? $opt1 = 'visible' : $opt1 = 'invisible';
($data_html) ? $opt2 = 'data-html="true"' : $opt2 = 'data-html="false"';
echo '<i class="fas fa-question-circle text-muted ' .$opt1.'" id="' .$id. '" data-toggle="tooltip" ' .$opt2. ' data-placement="auto" title="' . _($msg). '"></i>';
}

Empty file modified includes/get_clients.php
100644 → 100755
Empty file.
30 changes: 28 additions & 2 deletions includes/hostapd.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function DisplayHostAPDConfig()
'b' => '802.11b - 2.4 GHz',
'g' => '802.11g - 2.4 GHz',
'n' => '802.11n - 2.4 GHz',
'ac' => '802.11.ac - 5 GHz'
'ac' => '802.11ac - 5 GHz'
];
$arrSecurity = array(1 => 'WPA', 2 => 'WPA2', 3 => 'WPA+WPA2', 'none' => _("None"));
$arrEncType = array('TKIP' => 'TKIP', 'CCMP' => 'CCMP', 'TKIP CCMP' => 'TKIP+CCMP');
Expand Down Expand Up @@ -109,6 +109,30 @@ function DisplayHostAPDConfig()
$txpower = $_POST['txpower'];
}

$countries_5Ghz_max48ch = RASPI_5GHZ_ISO_ALPHA2;
$selectedHwMode = $arrConfig['hw_mode'];
if (isset($arrConfig['ieee80211n'])) {
if (strval($arrConfig['ieee80211n']) === '1') {
$selectedHwMode = 'n';
}
}
if (isset($arrConfig['ieee80211ac'])) {
if (strval($arrConfig['ieee80211ac']) === '1') {
$selectedHwMode = 'ac';
}
}
if (isset($arrConfig['ieee80211w'])) {
if (strval($arrConfig['ieee80211w']) === '2') {
$selectedHwMode = 'w';
}
}
if (!in_array($arrConfig['country_code'], $countries_5Ghz_max48ch)) {
$hwModeDisabled = 'ac';
if ($selectedHwMode === $hwModeDisabled) {
unset($selectedHwMode);
}
}

echo renderTemplate(
"hostapd", compact(
"status",
Expand All @@ -124,7 +148,9 @@ function DisplayHostAPDConfig()
"arrTxPower",
"txpower",
"arrHostapdConf",
"operatingSystem"
"operatingSystem",
"selectedHwMode",
"hwModeDisabled"
)
);
}
Expand Down
Empty file modified includes/wireguard.php
100644 → 100755
Empty file.
Binary file modified locale/en_US/LC_MESSAGES/messages.mo
Binary file not shown.
15 changes: 15 additions & 0 deletions locale/en_US/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,21 @@ msgstr "Sets the <code>txpower</code> option for the AP interface and the config
msgid "dBm is a unit of level used to indicate that a power ratio is expressed in decibels (dB) with reference to one milliwatt (mW). 30 dBm is equal to 1000 mW, while 0 dBm equals 1.25 mW."
msgstr "dBm is a unit of level used to indicate that a power ratio is expressed in decibels (dB) with reference to one milliwatt (mW). 30 dBm is equal to 1000 mW, while 0 dBm equals 1.25 mW."

msgid "The selected interface (%s) has support for the 2.4 GHz wireless band only."
msgstr "The selected interface (%s) has support for the 2.4 GHz wireless band only."

msgid "The selected interface (%s) has support for the 2.5 GHz wireless band only."
msgstr "The selected interface (%s) has support for the 2.5 GHz wireless band only."

msgid "The selected interface (%s) has support for both the 2.4 and 5 GHz wireless bands."
msgstr "The selected interface (%s) has support for both the 2.4 and 5 GHz wireless bands."

msgid "The selected interface (%s) does not support wireless mode operation."
msgstr "The selected interface (%s) does not support wireless mode operation."

msgid "The 802.11ac 5 GHz option is disabled until a compatible wireless regulatory domain is set."
msgstr "The 802.11ac 5 GHz option is disabled until a compatible wireless regulatory domain is set."

#: includes/networking.php
msgid "Summary"
msgstr "Summary"
Expand Down
6 changes: 2 additions & 4 deletions templates/hostapd/advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@
<div class="row">
<div class="form-group col-md-6">
<label for="cbxtxpower"><?php echo _("Transmit power (dBm)") ?></label>
<i class="fas fa-question-circle text-muted" data-toggle="tooltip" data-placement="auto" title="<?php echo _("dBm is a unit of level used to indicate that a power ratio is expressed in decibels (dB) with reference to one milliwatt (mW). 30 dBm is equal to 1000 mW, while 0 dBm equals 1.25 mW."); ?>"></i>
<?php
SelectorOptions('txpower', $arrTxPower, $txpower, 'cbxtxpower');
?>
<?php getTooltip('dBm is a unit of level used to indicate that a power ratio is expressed in decibels (dB) with reference to one milliwatt (mW). 30 dBm is equal to 1000 mW, while 0 dBm equals 1.25 mW.', 'tiptxpower'); ?>
<?php SelectorOptions('txpower', $arrTxPower, $txpower, 'cbxtxpower'); ?>
<small id="txpower_help" class="text-muted"><?php echo _("Sets the <code>txpower</code> option for the AP interface and the configured country."); ?></small>
</div>
</div>
Expand Down
33 changes: 4 additions & 29 deletions templates/hostapd/basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
<div class="row">
<div class="form-group col-md-6">
<label for="cbxinterface"><?php echo _("Interface") ;?></label>
<?php
SelectorOptions('interface', $interfaces, $arrConfig['interface'], 'cbxinterface');
?>
<?php SelectorOptions('interface', $interfaces, $arrConfig['interface'], 'cbxinterface', 'setHardwareModeTooltip'); ?>
</div>
</div>
<div class="row">
Expand All @@ -17,32 +15,9 @@
<div class="row">
<div class="form-group col-md-6">
<label for="cbxhwmode"><?php echo _("Wireless Mode") ;?></label>
<?php
$countries_5Ghz_max48ch = RASPI_5GHZ_ISO_ALPHA2;
$selectedHwMode = $arrConfig['hw_mode'];
if (isset($arrConfig['ieee80211n'])) {
if (strval($arrConfig['ieee80211n']) === '1') {
$selectedHwMode = 'n';
}
}
if (isset($arrConfig['ieee80211ac'])) {
if (strval($arrConfig['ieee80211ac']) === '1') {
$selectedHwMode = 'ac';
}
}
if (isset($arrConfig['ieee80211w'])) {
if (strval($arrConfig['ieee80211w']) === '2') {
$selectedHwMode = 'w';
}
}

if (!in_array($arrConfig['country_code'], $countries_5Ghz_max48ch)) {
$hwModeDisabled = 'ac';
if ($selectedHwMode === $hwModeDisabled) {
unset($selectedHwMode);
}
}
SelectorOptions('hw_mode', $arr80211Standard, $selectedHwMode, 'cbxhwmode', 'loadChannelSelect', $hwModeDisabled); ?>
<?php getTooltip(null, 'tiphwmode', true); ?>
<?php SelectorOptions('hw_mode', $arr80211Standard, $selectedHwMode, 'cbxhwmode', 'loadChannelSelect', $hwModeDisabled); ?>
<div id="hwmode" data-tooltip="<?php echo _("The 802.11ac 5 GHz option is disabled until a compatible wireless regulatory domain is set."); ?>"></div>
</div>
</div>
<div class="row">
Expand Down

0 comments on commit 8be62bb

Please sign in to comment.