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.
This commit is contained in:
Eric 2018-10-26 21:53:14 -07:00 committed by Joe AE6XE
parent 1948ba11e7
commit e8b3520ec7
1 changed files with 29 additions and 9 deletions

View File

@ -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 <font color='red'>Warning!</font> '$host' is already in use!<br>" .
"Please choose another hostname.<br>" .
"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,6 +320,7 @@ foreach $val (@list)
if(validate_hostname($host))
{
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 ){
@ -310,6 +329,7 @@ foreach $val (@list)
}
}
}
}
else
{
if($host) { push @dhcp_err, "$val '$host' is not a valid hostname" }