From e8b3520ec7bcade69d372226380706c2922ae0cd Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 26 Oct 2018 21:53:14 -0700 Subject: [PATCH] bugfix: Check to prevent duplicate mesh hostnames when reserving DHCP reservations (#226) * bugfix: Check for existing hostnames on the network in DHCP reservations fixes #216 *additional check for existing hostname when creating new DHCP lease. checks hosts_olsr file if entered hostname already exists or not on the connected network(s). outputs info saying such and gives advice to prefix hostname with callsign. * change to use =~ /\s$host\S/i * Reworded warning message * moved the position of the hostname check to only when you click "add" on the DHCP leases page. this stops it checking all the previously entered hostnames. --- files/www/cgi-bin/ports | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/files/www/cgi-bin/ports b/files/www/cgi-bin/ports index 21f45906..3ed1dcca 100755 --- a/files/www/cgi-bin/ports +++ b/files/www/cgi-bin/ports @@ -284,10 +284,28 @@ foreach $val (@list) $host = $parms{"dhcp${val}_host"}; $ip = $parms{"dhcp${val}_ip"}; $mac = $parms{"dhcp${val}_mac"}; - + $foundHost = 0; if($val eq "_add") { - next unless ($host or $ip or $mac) and ($parms{dhcp_add} or $parms{button_save}); + if($host) { + #my $foundHost = 0; + my $olsrFile = 0; + $olsrFile = 1 if -f "/var/run/hosts_olsr"; + if($olsrFile) { + open(my $hostFile, "<", "/var/run/hosts_olsr"); + while(<$hostFile>) { + if($_ =~ /\s$host\s/i) { + $foundHost = 1; + last; + } + } + close($hostFile); + push(@dhcp_err, "$val Warning! '$host' is already in use!
" . + "Please choose another hostname.
" . + "Prefixing the hostname with your callsign will help prevent duplicates on the network.") if $foundHost == 1; + } + } + next unless ($host or $ip or $mac or $foundHost) and ($parms{dhcp_add} or $parms{button_save}); } else { @@ -302,13 +320,15 @@ foreach $val (@list) if(validate_hostname($host)) { - push(@dhcp_err, "$val hostname '$host' is already in use") if (lc $host eq lc $node || lc $host eq lc $tactical); - foreach my $key (keys %hosts) { - if ( lc $key eq lc $host ){ - push(@dhcp_err, "$val hostname '$host' is already in use"); - last; - } - } + if(! $foundHost) { + push(@dhcp_err, "$val hostname '$host' is already in use") if (lc $host eq lc $node || lc $host eq lc $tactical); + foreach my $key (keys %hosts) { + if ( lc $key eq lc $host ){ + push(@dhcp_err, "$val hostname '$host' is already in use"); + last; + } + } + } } else {