Parcourir la source

wifi_ssid, ip6_net and ip4_nat_prefix uniqueness now checked

Julien VAUBOURG il y a 10 ans
Parent
commit
ae4988d05b
3 fichiers modifiés avec 26 ajouts et 14 suppressions
  1. 0 2
      TODO
  2. 22 1
      sources/controller.php
  3. 4 11
      sources/public/js/custom.js

+ 0 - 2
TODO

@@ -2,7 +2,5 @@
 
 * multissid
 ** WEB: update is_connected_through_hotspot feature
-** WEB: check if ipv6 delgated prefixes and ipv4 nat prefixes are unique
-** WEB: fix the now broken wifiparty button
 ** INIT: differentiate ipv6 and ipv4 in is_dhcpd_running
 ** INIT: use insserv instead of update-rc.d and update service dependencies

+ 22 - 1
sources/controller.php

@@ -151,6 +151,9 @@ dispatch_put('/settings', function() {
 
   $wifi_device_exists = ($retcode == 0);
   $service_enabled = isset($_POST['service_enabled']) ? 1 : 0;
+  $wifi_ssid_uniqueness = array();
+  $ip4_nat_prefix_uniqueness = array();
+  $ip6_net_uniqueness = array();
   $ssids = array();
   $id = 0;
 
@@ -166,7 +169,25 @@ dispatch_put('/settings', function() {
         if(!$ssid['wifi_secure']) {
           $ssid['wifi_passphrase'] = 'none';
         }
+
+        if(in_array($ssid['wifi_ssid'], $wifi_ssid_uniqueness)) {
+          throw new Exception(T_('All Wifi names must be unique'));
+        } else {
+          array_push($wifi_ssid_uniqueness, $ssid['wifi_ssid']);
+        }
     
+        if(in_array($ssid['ip4_nat_prefix'], $ip4_nat_prefix_uniqueness)) {
+          throw new Exception(T_('All IPv4 NAT prefixes must be unique'));
+        } else {
+          array_push($ip4_nat_prefix_uniqueness, $ssid['ip4_nat_prefix']);
+        }
+
+        if($ssid['ip6_net'] != 'none' && in_array($ssid['ip6_net'], $ip6_net_uniqueness)) {
+          throw new Exception(T_('All IPv6 delegated prefixes must be unique'));
+        } else {
+          array_push($ip6_net_uniqueness, $ssid['ip6_net']);
+        }
+
         if(empty($ssid['wifi_ssid']) || empty($ssid['wifi_passphrase'])) {
           throw new Exception(T_('Your Wifi Hotspot needs a name and a password'));
         }
@@ -236,7 +257,7 @@ dispatch_put('/settings', function() {
         array_push($ssids, $ssid);
       }
     } catch(Exception $e) {
-      flash('error', T_('SSID')." $id: ".$e->getMessage().' ('.T_('configuration not updated').').');
+      flash('error', T_('Hotspot')." $id: ".$e->getMessage().' ('.T_('configuration not updated').').');
       goto redirect;
     }
   }

+ 4 - 11
sources/public/js/custom.js

@@ -37,7 +37,7 @@ function tabsClick() {
   return false;
 }
 
-function dropDownClick() {
+function deviceDropDownClick() {
   var menu = $(this).parent();
   var items = menu.children();
   var button = menu.prev();
@@ -50,6 +50,8 @@ function dropDownClick() {
   button.append(' <span class="caret"></span>');
 
   input.val($(this).text());
+
+  updateNbSsidRemaining();
 }
 
 function updateNbSsidRemaining() {
@@ -95,7 +97,7 @@ $(document).ready(function() {
   $('.btn-group').button();
   $('[data-toggle="tooltip"]').tooltip();
 
-  $('.dropdown-menu li').click(dropDownClick);
+  $('.dropdown-menu li').click(deviceDropDownClick);
 
   $('.switch').bootstrapToggle();
 
@@ -177,14 +179,6 @@ $(document).ready(function() {
     var clone = $('#ssids').children().first().clone();
     var id = parseInt($('.ssid').length);
 
-    clone.find('.dropdownmenu').each(function(i) {
-      var initial = $('#ssids').children().first().find('.dropdownmenu');
-      var clone = initial.eq(i).clone(true, true);
-
-      $(this).after(clone);
-      $(this).remove();
-    });
-
     clone.find('[name]').each(function() {
       $(this).attr('name', $(this).attr('name').replace('[0]', '[' + id + ']'));
     });
@@ -221,7 +215,6 @@ $(document).ready(function() {
     clone.find('.switch').bootstrapToggle();
     clone.find('.wifi_secure').change(wifiSecureBtn);
     clone.find('.nav-tabs a').click(tabsClick);
-    clone.find('.dropdown-menu li').click(dropDownClick);
     clone.find('.wifi_passphrase').hide();
 
     clone.find('h3').each(function() {