From ae4988d05b3a697e0c1a1bfd83db13f25296df18 Mon Sep 17 00:00:00 2001 From: Julien VAUBOURG Date: Sat, 2 May 2015 17:20:45 +0200 Subject: [PATCH] wifi_ssid, ip6_net and ip4_nat_prefix uniqueness now checked --- TODO | 2 -- sources/controller.php | 23 ++++++++++++++++++++++- sources/public/js/custom.js | 15 ++++----------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/TODO b/TODO index 139b9d5..ad3169d 100644 --- a/TODO +++ b/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 diff --git a/sources/controller.php b/sources/controller.php index 7b3ee5e..9d17df9 100644 --- a/sources/controller.php +++ b/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; } } diff --git a/sources/public/js/custom.js b/sources/public/js/custom.js index 6d936c4..fb377cb 100644 --- a/sources/public/js/custom.js +++ b/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(' '); 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() {