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:
122
app/js/custom.js
122
app/js/custom.js
@@ -185,7 +185,7 @@ function contentLoaded() {
|
||||
setupBtns();
|
||||
break;
|
||||
case "hostapd_conf":
|
||||
loadChannel();
|
||||
getChannel();
|
||||
setHardwareModeTooltip();
|
||||
break;
|
||||
case "dhcpd_conf":
|
||||
@@ -264,13 +264,6 @@ function setDHCPToggles(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) {
|
||||
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
||||
$.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);
|
||||
});
|
||||
|
||||
/*
|
||||
Sets the wirelss channel select options based on hw_mode and country_code.
|
||||
|
||||
Methodology: In North America up to channel 11 is the maximum allowed WiFi 2.4Ghz channel,
|
||||
except for the US that allows channel 12 & 13 in low power mode with additional restrictions.
|
||||
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);
|
||||
// Retrieves the 'channel' value specified in hostapd.conf
|
||||
function getChannel() {
|
||||
$.get('ajax/networking/get_channel.php',function(data){
|
||||
jsonData = JSON.parse(data);
|
||||
loadChannelSelect(jsonData);
|
||||
});
|
||||
}
|
||||
|
||||
/* 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() {
|
||||
var iface = $('#cbxinterface').val();
|
||||
@@ -447,7 +463,7 @@ function setHardwareModeTooltip() {
|
||||
if ($('#cbxhwmode').find('option[value="ac"]').prop('disabled') == true ) {
|
||||
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);
|
||||
$('#tiphwmode').attr('data-original-title', responseText + '\n' + hwmodeText );
|
||||
});
|
||||
|
Reference in New Issue
Block a user