diff --git a/net/CHANGELOG b/net/CHANGELOG index 1fa48eebe..fece4ba1c 100644 --- a/net/CHANGELOG +++ b/net/CHANGELOG @@ -77,3 +77,5 @@ Added support for IPv6, DHCP and new ethernet device names on FreeBSD. Added support for configuring intefaces with the "ip" command, as seen on RHEL 7, CentOS 7 and other new Linux distributions. ---- Changes since 1.760 ---- On CentOS, Fedora and Redhat systems, the DNSn lines in ifcfg-* files are now updated in sync with resolv.conf. +---- Changes since 1.910 ---- +Added an option to disable (comment out) hosts file entries. diff --git a/net/edit_host.cgi b/net/edit_host.cgi index 1e2237521..189f78732 100755 --- a/net/edit_host.cgi +++ b/net/edit_host.cgi @@ -7,6 +7,7 @@ $access{'hosts'} == 2 || &error($text{'hosts_ecannot'}); &ReadParse(); if ($in{'new'}) { &ui_print_header(undef, $text{'hosts_create'}, ""); + $h = { 'active' => 1 }; } else { &ui_print_header(undef, $text{'hosts_edit'}, ""); @@ -20,6 +21,10 @@ print &ui_hidden("new", $in{'new'}); print &ui_hidden("idx", $in{'idx'}); print &ui_table_start($text{'hosts_detail'}, undef, 2); +# Active? +print &ui_table_row($text{'hosts_active'}, + &ui_yesno_radio("active", $h->{'active'})); + # IP address print &ui_table_row($text{'hosts_ip'}, &ui_textbox("address", $h->{'address'}, 30)); diff --git a/net/lang/en b/net/lang/en index 1e528cd15..5dba7972e 100644 --- a/net/lang/en +++ b/net/lang/en @@ -221,6 +221,7 @@ dns_hoststoo=Update hostname in host addresses if changed? dns_dhcp=Hostname is set by DHCP server? hosts_title=Host Addresses +hosts_active=Enabled? hosts_ip=IP Address hosts_host=Hostnames hosts_add=Add a new host address. diff --git a/net/list_hosts.cgi b/net/list_hosts.cgi index 3f419da12..d6df40d49 100755 --- a/net/list_hosts.cgi +++ b/net/list_hosts.cgi @@ -16,16 +16,21 @@ if ($access{'hosts'} == 2) { } print &ui_columns_start([ $access{'hosts'} == 2 ? ( "" ) : ( ), $text{'hosts_ip'}, + $text{'hosts_active'}, $text{'hosts_host'} ], undef, 0, \@tds); foreach $h (&list_hosts()) { local @cols; + local $lnk; if ($access{'hosts'} == 2) { - push(@cols, "{'index'}\">". - &html_escape($h->{'address'}).""); + $lnk = &ui_link("edit_host.cgi?idx=$h->{'index'}", + &html_escape($h->{'address'})); } else { - push(@cols, &html_escape($h->{'address'})); + $lnk = &html_escape($h->{'address'}); } + push(@cols, $lnk); + push(@cols, $h->{'active'} ? $text{'yes'} + : "$text{'no'}"); push(@cols, join(" , ", map { &html_escape($_) } @{$h->{'hosts'}})); if ($access{'hosts'} == 2) { diff --git a/net/net-lib.pl b/net/net-lib.pl index 4ede14903..affa1d117 100755 --- a/net/net-lib.pl +++ b/net/net-lib.pl @@ -39,14 +39,19 @@ local $line=""; &open_readfile(HOSTS, $config{'hosts_file'}); while($line=) { + local $comment = 0; $line =~ s/\r|\n//g; + if ($line =~ s/^\s*#+\s*//) { + $comment = 1; + } $line =~ s/#.*$//g; $line =~ s/\s+$//g; - local(@f)=split(/\s+/, $line); - local($ipaddr)=shift(@f); + local @f = split(/\s+/, $line); + local $ipaddr = shift(@f); if (check_ipaddress_any($ipaddr)) { push(@rv, { 'address' => $ipaddr, 'hosts' => [ @f ], + 'active' => !$comment, 'line', $lnum, 'index', scalar(@rv) }); } @@ -56,12 +61,22 @@ close(HOSTS); return @rv; } +# make_host_line(&host) +# Internal function to return a line for the hosts file +sub make_host_line +{ +local ($host) = @_; +return ($host->{'active'} ? "" : "# "). + $host->{'address'}."\t".join(" ",@{$host->{'hosts'}})."\n"; +} + # create_host(&host) # Add a new host to /etc/hosts sub create_host { +local ($host) = @_; &open_tempfile(HOSTS, ">>$config{'hosts_file'}"); -&print_tempfile(HOSTS, $_[0]->{'address'},"\t",join(" ",@{$_[0]->{'hosts'}}),"\n"); +&print_tempfile(HOSTS, &make_host_line($host)); &close_tempfile(HOSTS); } @@ -69,16 +84,17 @@ sub create_host # Update the address and hosts of a line in /etc/hosts sub modify_host { +local ($host) = @_; &replace_file_line($config{'hosts_file'}, - $_[0]->{'line'}, - $_[0]->{'address'}."\t".join(" ",@{$_[0]->{'hosts'}})."\n"); + $_[0]->{'line'}, &make_host_line($host)); } # delete_host(&host) # Delete a host from /etc/hosts sub delete_host { -&replace_file_line($config{'hosts_file'}, $_[0]->{'line'}); +local ($host) = @_; +&replace_file_line($config{'hosts_file'}, $host->{'line'}); } # list_ipnodes() diff --git a/net/save_host.cgi b/net/save_host.cgi index 1bf54745e..ce200602b 100755 --- a/net/save_host.cgi +++ b/net/save_host.cgi @@ -26,7 +26,8 @@ else { if ($in{'new'}) { # saving a host $host = { 'address' => $in{'address'}, - 'hosts' => \@h }; + 'hosts' => \@h, + 'active' => $in{'active'} }; &create_host($host); } else { @@ -34,6 +35,7 @@ else { $host = $hosts[$in{'idx'}]; $host->{'address'} = $in{'address'}; $host->{'hosts'} = \@h; + $host->{'active'} = $in{'active'}; &modify_host($host); } }