mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
Refactor loadChannelSelect(), disambiguate ajax handler names
This commit is contained in:
parent
1b155dbf58
commit
648465f6c6
@ -1,43 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require '../../includes/csrf.php';
|
require '../../includes/csrf.php';
|
||||||
require_once '../../includes/config.php';
|
require '../../src/RaspAP/Parsers/IwParser.php';
|
||||||
require_once '../../includes/locale.php';
|
|
||||||
|
|
||||||
if (isset($_POST['interface'])) {
|
if (isset($_POST['interface'])) {
|
||||||
|
|
||||||
define( 'NL80211_BAND_24GHZ', 0x1 );
|
|
||||||
define( 'NL80211_BAND_5GHZ', 0x2 );
|
|
||||||
$iface = escapeshellcmd($_POST['interface']);
|
$iface = escapeshellcmd($_POST['interface']);
|
||||||
$flags = 0;
|
$parser = new \RaspAP\Parsers\IwParser($iface);
|
||||||
|
|
||||||
// get physical device for selected interface
|
$supportedFrequencies = $parser->parseIwList($iface);
|
||||||
exec("iw dev | awk -v iface=".$iface." '/^phy#/ { phy = $0 } $1 == \"Interface\" { interface = $2 } interface == iface { print phy }'", $return);
|
|
||||||
$phy = $return[0];
|
|
||||||
|
|
||||||
// get frequencies supported by device
|
# debug
|
||||||
exec('iw '.$phy.' info | sed -rn "s/^.*\*\s([0-9]{4})\sMHz.*/\1/p"', $frequencies);
|
#foreach ($supportedFrequencies as $frequency) {
|
||||||
|
# echo "<br>Frequency: {$frequency['MHz']} MHz, Channel: {$frequency['Channel']}, dBm: {$frequency['dBm']}\n";
|
||||||
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) {
|
echo json_encode($supportedFrequencies);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
43
ajax/networking/get_nl80211_band.php
Normal file
43
ajax/networking/get_nl80211_band.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?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']);
|
||||||
|
$flags = 0;
|
||||||
|
|
||||||
|
// get physical device for selected interface
|
||||||
|
exec("iw dev | awk -v iface=".$iface." '/^phy#/ { phy = $0 } $1 == \"Interface\" { interface = $2 } interface == iface { print phy }'", $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);
|
||||||
|
}
|
||||||
|
|
122
app/js/custom.js
122
app/js/custom.js
@ -185,7 +185,7 @@ function contentLoaded() {
|
|||||||
setupBtns();
|
setupBtns();
|
||||||
break;
|
break;
|
||||||
case "hostapd_conf":
|
case "hostapd_conf":
|
||||||
loadChannel();
|
getChannel();
|
||||||
setHardwareModeTooltip();
|
setHardwareModeTooltip();
|
||||||
break;
|
break;
|
||||||
case "dhcpd_conf":
|
case "dhcpd_conf":
|
||||||
@ -264,13 +264,6 @@ function setDHCPToggles(state) {
|
|||||||
$('#dhcp-iface').prop('disabled', !state);
|
$('#dhcp-iface').prop('disabled', !state);
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadChannel() {
|
|
||||||
$.get('ajax/networking/get_channel.php',function(data){
|
|
||||||
jsonData = JSON.parse(data);
|
|
||||||
loadChannelSelect(jsonData);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#debugModal').on('shown.bs.modal', function (e) {
|
$('#debugModal').on('shown.bs.modal', function (e) {
|
||||||
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
||||||
$.post('ajax/system/sys_debug.php',{'csrf_token': csrfToken},function(data){
|
$.post('ajax/system/sys_debug.php',{'csrf_token': csrfToken},function(data){
|
||||||
@ -391,53 +384,76 @@ $(".custom-file-input").on("change", function() {
|
|||||||
$(this).siblings(".custom-file-label").addClass("selected").html(fileName);
|
$(this).siblings(".custom-file-label").addClass("selected").html(fileName);
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
// Retrieves the 'channel' value specified in hostapd.conf
|
||||||
Sets the wirelss channel select options based on hw_mode and country_code.
|
function getChannel() {
|
||||||
|
$.get('ajax/networking/get_channel.php',function(data){
|
||||||
Methodology: In North America up to channel 11 is the maximum allowed WiFi 2.4Ghz channel,
|
jsonData = JSON.parse(data);
|
||||||
except for the US that allows channel 12 & 13 in low power mode with additional restrictions.
|
loadChannelSelect(jsonData);
|
||||||
Canada allows channel 12 in low power mode. Because it's unsure if low powered mode can be
|
|
||||||
supported the channels are not selectable for those countries. Also Uzbekistan and Colombia
|
|
||||||
allow up to channel 11 as maximum channel on the 2.4Ghz WiFi band.
|
|
||||||
Source: https://en.wikipedia.org/wiki/List_of_WLAN_channels
|
|
||||||
Additional: https://git.kernel.org/pub/scm/linux/kernel/git/sforshee/wireless-regdb.git
|
|
||||||
*/
|
|
||||||
function loadChannelSelect(selected) {
|
|
||||||
// Fetch wireless regulatory data
|
|
||||||
$.getJSON("config/wireless.json", function(json) {
|
|
||||||
var hw_mode = $('#cbxhwmode').val();
|
|
||||||
var country_code = $('#cbxcountries').val();
|
|
||||||
var channel_select = $('#cbxchannel');
|
|
||||||
var data = json["wireless_regdb"];
|
|
||||||
var selectablechannels = Array.range(1,14);
|
|
||||||
|
|
||||||
// Assign array of countries to valid frequencies (channels)
|
|
||||||
var countries_2_4Ghz_max11ch = data["2_4GHz_max11ch"].countries;
|
|
||||||
var countries_2_4Ghz_max14ch = data["2_4GHz_max14ch"].countries;
|
|
||||||
var countries_5Ghz_max48ch = data["5Ghz_max48ch"].countries;
|
|
||||||
|
|
||||||
// Map selected hw_mode and country to determine channel list
|
|
||||||
if (hw_mode === 'a') {
|
|
||||||
selectablechannels = data["5Ghz_max48ch"].channels;
|
|
||||||
} else if (($.inArray(country_code, countries_2_4Ghz_max11ch) !== -1) && (hw_mode !== 'ac') ) {
|
|
||||||
selectablechannels = data["2_4GHz_max11ch"].channels;
|
|
||||||
} else if (($.inArray(country_code, countries_2_4Ghz_max14ch) !== -1) && (hw_mode === 'b')) {
|
|
||||||
selectablechannels = data["2_4GHz_max14ch"].channels;
|
|
||||||
} else if (($.inArray(country_code, countries_5Ghz_max48ch) !== -1) && (hw_mode === 'ac')) {
|
|
||||||
selectablechannels = data["5Ghz_max48ch"].channels;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set channel select with available values
|
|
||||||
selected = (typeof selected === 'undefined') ? selectablechannels[0] : selected;
|
|
||||||
channel_select.empty();
|
|
||||||
$.each(selectablechannels, function(key,value) {
|
|
||||||
channel_select.append($("<option></option>").attr("value", value).text(value));
|
|
||||||
});
|
|
||||||
channel_select.val(selected);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sets hardware mode tooltip text for selected interface.
|
/*
|
||||||
|
Sets the wirelss channel select options based on frequencies reported by iw.
|
||||||
|
|
||||||
|
See: https://git.kernel.org/pub/scm/linux/kernel/git/sforshee/wireless-regdb.git
|
||||||
|
Also: https://en.wikipedia.org/wiki/List_of_WLAN_channels
|
||||||
|
*/
|
||||||
|
function loadChannelSelect(selected) {
|
||||||
|
var iface = $('#cbxinterface').val();
|
||||||
|
var hwmodeText = '';
|
||||||
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
||||||
|
|
||||||
|
// update hardware mode tooltip
|
||||||
|
setHardwareModeTooltip();
|
||||||
|
|
||||||
|
$.post('ajax/networking/get_frequencies.php',{'interface': iface, 'csrf_token': csrfToken, 'selected': selected},function(response){
|
||||||
|
var hw_mode = $('#cbxhwmode').val();
|
||||||
|
var country_code = $('#cbxcountries').val();
|
||||||
|
var channel_select = $('#cbxchannel');
|
||||||
|
var btn_save = $('#btnSaveHostapd');
|
||||||
|
var data = JSON.parse(response);
|
||||||
|
var selectableChannels = [];
|
||||||
|
|
||||||
|
// Map selected hw_mode to available channels
|
||||||
|
if (hw_mode === 'a') {
|
||||||
|
selectableChannels = data.filter(item => item.MHz.toString().startsWith('5'));
|
||||||
|
} else if (hw_mode !== 'ac') {
|
||||||
|
selectableChannels = data.filter(item => item.MHz.toString().startsWith('24'));
|
||||||
|
} else if (hw_mode === 'b') {
|
||||||
|
selectableChannels = data.filter(item => item.MHz.toString().startsWith('24'));
|
||||||
|
} else if (hw_mode === 'ac') {
|
||||||
|
selectableChannels = data.filter(item => item.MHz.toString().startsWith('5'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// If selected channel doeesn't exist in allowed channels, set default or null (unsupported)
|
||||||
|
if (!selectableChannels.find(item => item.Channel === selected)) {
|
||||||
|
if (selectableChannels.length === 0) {
|
||||||
|
selectableChannels[0] = { Channel: null };
|
||||||
|
} else {
|
||||||
|
defaultChannel = selectableChannels[0].Channel;
|
||||||
|
selected = defaultChannel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set channel select with available values
|
||||||
|
channel_select.empty();
|
||||||
|
if (selectableChannels[0].Channel === null) {
|
||||||
|
channel_select.append($("<option></option>").attr("value", "").text("---"));
|
||||||
|
channel_select.prop("disabled", true);
|
||||||
|
btn_save.prop("disabled", true);
|
||||||
|
} else {
|
||||||
|
channel_select.prop("disabled", false);
|
||||||
|
btn_save.prop("disabled", false);
|
||||||
|
$.each(selectableChannels, function(key,value) {
|
||||||
|
channel_select.append($("<option></option>").attr("value", value.Channel).text(value.Channel));
|
||||||
|
});
|
||||||
|
channel_select.val(selected);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Sets hardware mode tooltip text for selected interface
|
||||||
|
* and calls loadChannelSelect()
|
||||||
*/
|
*/
|
||||||
function setHardwareModeTooltip() {
|
function setHardwareModeTooltip() {
|
||||||
var iface = $('#cbxinterface').val();
|
var iface = $('#cbxinterface').val();
|
||||||
@ -447,7 +463,7 @@ function setHardwareModeTooltip() {
|
|||||||
if ($('#cbxhwmode').find('option[value="ac"]').prop('disabled') == true ) {
|
if ($('#cbxhwmode').find('option[value="ac"]').prop('disabled') == true ) {
|
||||||
var hwmodeText = $('#hwmode').attr('data-tooltip');
|
var hwmodeText = $('#hwmode').attr('data-tooltip');
|
||||||
}
|
}
|
||||||
$.post('ajax/networking/get_frequencies.php?',{'interface': iface, 'csrf_token': csrfToken},function(data){
|
$.post('ajax/networking/get_nl80211_band.php?',{'interface': iface, 'csrf_token': csrfToken},function(data){
|
||||||
var responseText = JSON.parse(data);
|
var responseText = JSON.parse(data);
|
||||||
$('#tiphwmode').attr('data-original-title', responseText + '\n' + hwmodeText );
|
$('#tiphwmode').attr('data-original-title', responseText + '\n' + hwmodeText );
|
||||||
});
|
});
|
||||||
|
@ -28,7 +28,6 @@ class IwParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function parseIwList() {
|
public function parseIwList() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (no IR): the AP won't Initiate Radiation until a DFS scan (or similar) is complete on these bands.
|
* (no IR): the AP won't Initiate Radiation until a DFS scan (or similar) is complete on these bands.
|
||||||
* (radar detection): the specified channels are shared with radar equipment.
|
* (radar detection): the specified channels are shared with radar equipment.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user