Merge pull request #1735 from sumpfralle/olsr-jsoninfo-parser-handle-empty-result
[oweals/luci.git] / modules / luci-mod-network / htdocs / luci-static / resources / view / network / wireless.js
index efbc1140360101e34e6407655f7e7ade3d724b0f..9e75fe901368d45fd5e2a8780b7d44d3d4768b10 100644 (file)
@@ -87,7 +87,7 @@ function render_network_status(radioNet) {
        var mode = radioNet.getActiveMode(),
            bssid = radioNet.getActiveBSSID(),
            channel = radioNet.getChannel(),
-           disabled = (radioNet.get('disabled') == '1'),
+           disabled = (radioNet.get('disabled') == '1' || uci.get('wireless', radioNet.getWifiDeviceName(), 'disabled') == '1'),
            is_assoc = (bssid && bssid != '00:00:00:00:00:00' && channel && mode != 'Unknown' && !disabled),
            changecount = count_changes(radioNet.getName()),
            status_text = null;
@@ -704,7 +704,8 @@ return L.view.extend({
                                ];
                        }
                        else {
-                               var isDisabled = (inst.get('disabled') == '1');
+                               var isDisabled = (inst.get('disabled') == '1' ||
+                                       uci.get('wireless', inst.getWifiDeviceName(), 'disabled') == '1');
 
                                btns = [
                                        E('button', {
@@ -1045,9 +1046,7 @@ return L.view.extend({
                                };
 
 
-                               encr.value('none', _('No Encryption'));
-                               encr.value('wep-open',   _('WEP Open System'));
-                               encr.value('wep-shared', _('WEP Shared Key'));
+                               var crypto_modes = [];
 
                                if (hwtype == 'mac80211') {
                                        var has_supplicant = L.hasSystemFeature('wpasupplicant'),
@@ -1067,26 +1066,26 @@ return L.view.extend({
 
 
                                        if (has_hostapd || has_supplicant) {
-                                               encr.value('psk', 'WPA-PSK');
-                                               encr.value('psk2', 'WPA2-PSK');
-                                               encr.value('psk-mixed', 'WPA-PSK/WPA2-PSK Mixed Mode');
+                                               crypto_modes.push(['psk2',      'WPA2-PSK',                    33]);
+                                               crypto_modes.push(['psk-mixed', 'WPA-PSK/WPA2-PSK Mixed Mode', 22]);
+                                               crypto_modes.push(['psk',       'WPA-PSK',                     21]);
                                        }
                                        else {
                                                encr.description = _('WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP and ad-hoc mode) to be installed.');
                                        }
 
                                        if (has_ap_sae || has_sta_sae) {
-                                               encr.value('sae', 'WPA3-SAE');
-                                               encr.value('sae-mixed', 'WPA2-PSK/WPA3-SAE Mixed Mode');
+                                               crypto_modes.push(['sae',       'WPA3-SAE',                     31]);
+                                               crypto_modes.push(['sae-mixed', 'WPA2-PSK/WPA3-SAE Mixed Mode', 30]);
                                        }
 
                                        if (has_ap_eap || has_sta_eap) {
-                                               encr.value('wpa', 'WPA-EAP');
-                                               encr.value('wpa2', 'WPA2-EAP');
+                                               crypto_modes.push(['wpa2', 'WPA2-EAP', 32]);
+                                               crypto_modes.push(['wpa',  'WPA-EAP',  20]);
                                        }
 
                                        if (has_ap_owe || has_sta_owe) {
-                                               encr.value('owe', 'OWE');
+                                               crypto_modes.push(['owe', 'OWE', 1]);
                                        }
 
                                        encr.crypto_support = {
@@ -1153,9 +1152,23 @@ return L.view.extend({
                                        };
                                }
                                else if (hwtype == 'broadcom') {
-                                       encr.value('psk', 'WPA-PSK');
-                                       encr.value('psk2', 'WPA2-PSK');
-                                       encr.value('psk+psk2', 'WPA-PSK/WPA2-PSK Mixed Mode');
+                                       crypto_modes.push(['psk2',     'WPA2-PSK',                    33]);
+                                       crypto_modes.push(['psk+psk2', 'WPA-PSK/WPA2-PSK Mixed Mode', 22]);
+                                       crypto_modes.push(['psk',      'WPA-PSK',                     21]);
+                               }
+
+                               crypto_modes.push(['wep-open',   _('WEP Open System'), 11]);
+                               crypto_modes.push(['wep-shared', _('WEP Shared Key'),  10]);
+                               crypto_modes.push(['none',       _('No Encryption'),   0]);
+
+                               crypto_modes.sort(function(a, b) { return b[2] - a[2] });
+
+                               for (var i = 0; i < crypto_modes.length; i++) {
+                                       var security_level = (crypto_modes[i][2] >= 30) ? _('strong security')
+                                               : (crypto_modes[i][2] >= 20) ? _('medium security')
+                                                       : (crypto_modes[i][2] >= 10) ? _('weak security') : _('open network');
+
+                                       encr.value(crypto_modes[i][0], '%s (%s)'.format(crypto_modes[i][1], security_level));
                                }
 
 
@@ -1251,6 +1264,9 @@ return L.view.extend({
                                o.write = function(section_id, value) {
                                        uci.set('wireless', section_id, 'key', value);
                                        uci.unset('wireless', section_id, 'key1');
+                                       uci.unset('wireless', section_id, 'key2');
+                                       uci.unset('wireless', section_id, 'key3');
+                                       uci.unset('wireless', section_id, 'key4');
                                };
 
 
@@ -1264,7 +1280,7 @@ return L.view.extend({
 
                                o.cfgvalue = function(section_id) {
                                        var slot = +uci.get('wireless', section_id, 'key');
-                                       return (slot >= 1 && slot <= 4) ? slot : 1;
+                                       return (slot >= 1 && slot <= 4) ? String(slot) : '';
                                };
 
                                o.write = function(section_id, value) {
@@ -1543,7 +1559,7 @@ return L.view.extend({
                                                        o.depends({ mode: 'sta-wds', encryption: 'sae-mixed' });
                                                        o.depends({ mode: 'sta-wds', encryption: 'owe' });
                                                        o.defaults = {
-                                                               '2': [{ encryption: 'sae' }],
+                                                               '2': [{ encryption: 'sae' }, { encryption: 'owe' }],
                                                                '1': [{ encryption: 'sae-mixed'}],
                                                                '':  []
                                                        };