2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2005-2024 IPFire Team <info@ipfire.org> #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
26 # enable only the following on debugging purpose
28 #use CGI::Carp 'fatalsToBrowser';
30 require '/var/ipfire/general-functions.pl';
31 require "${General::swroot}/location-functions.pl";
32 require "${General::swroot}/ids-functions.pl";
33 require "${General::swroot}/lang.pl";
34 require "${General::swroot}/header.pl";
36 #workaround to suppress a warning when a variable is used only once
37 my @dummy = ( ${Header
::colouryellow
} );
43 my $errormessage = '';
45 # Config file which stores the DNS settings.
46 my $settings_file = "${General::swroot}/dns/settings";
48 # File which stores the configured DNS-Servers.
49 my $servers_file = "${General::swroot}/dns/servers";
51 # Create files if the does not exist.
52 unless (-f
$settings_file) { &General
::system("touch", "$settings_file") };
53 unless (-f
$servers_file) { &General
::system("touch", "$servers_file") };
55 # File which stores the ISP assigned DNS servers.
56 my @ISP_nameserver_files = ( "/var/run/dns1", "/var/run/dns2" );
58 # File which contains the ca-certificates.
59 my $ca_certs_file = "/etc/ssl/certs/ca-bundle.crt";
61 # Server which is used, to determine if the whole DNS system works properly.
62 my $dns_test_server = "ping.ipfire.org";
67 my %mainsettings = ();
68 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
69 &General
::readhash
("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \
%color);
71 &Header
::showhttpheaders
();
72 &Header
::getcgihash
(\
%cgiparams);
75 # Save general settings.
77 if ($cgiparams{'GENERAL'} eq $Lang::tr
{'save'}) {
78 # Prevent form name from been stored in conf file.
79 delete $cgiparams{'GENERAL'};
81 # Add value for non-checked checkbox.
82 if ($cgiparams{'USE_ISP_NAMESERVERS'} ne "on") {
83 $cgiparams{'USE_ISP_NAMESERVERS'} = "off";
86 # Add value for non-checked checkbox.
87 if ($cgiparams{'ENABLE_SAFE_SEARCH'} ne "on") {
88 $cgiparams{'ENABLE_SAFE_SEARCH'} = "off";
91 if ($cgiparams{'ENABLE_SAFE_SEARCH_YOUTUBE'} ne "on") {
92 $cgiparams{'ENABLE_SAFE_SEARCH_YOUTUBE'} = "off";
95 # Check if using ISP nameservers and TLS is enabled at the same time.
96 if (($cgiparams{'USE_ISP_NAMESERVERS'} eq "on") && ($cgiparams{'PROTO'} eq "TLS")) {
97 $errormessage = $Lang::tr
{'dns isp nameservers and tls not allowed'}
100 # Check if there was an error.
101 if ( ! $errormessage) {
103 # Store settings into settings file.
104 &General
::writehash
("$settings_file", \
%cgiparams);
106 # Call function to handle unbound restart, etc.
107 &_handle_unbound_and_more
()
112 # Add / Edit entries.
114 if (($cgiparams{'SERVERS'} eq $Lang::tr
{'save'}) || ($cgiparams{'SERVERS'} eq $Lang::tr
{'update'})) {
115 # Hash to store the generic DNS settings.
118 # Read-in generic settings.
119 &General
::readhash
("$settings_file", \
%settings);
121 # Check if an IP-address has been given.
122 if ($cgiparams{"NAMESERVER"} eq "") {
123 $errormessage = "$Lang::tr{'dns no address given'}";
126 # Check if the given DNS server is valid.
127 elsif(!&General
::validip
($cgiparams{"NAMESERVER"})) {
128 $errormessage = "$Lang::tr{'invalid ip'}: $cgiparams{'NAMESERVER'}";
131 # Check if a TLS is enabled and no TLS_HOSTNAME has benn specified.
132 elsif($settings{'PROTO'} eq "TLS") {
133 unless($cgiparams{"TLS_HOSTNAME"}) {
134 $errormessage = "$Lang::tr{'dns no tls hostname given'}";
136 # Check if the provided domain is valid.
137 unless(&General
::validfqdn
($cgiparams{"TLS_HOSTNAME"})) {
138 $errormessage = "$Lang::tr{'invalid ip or hostname'}: $cgiparams{'TLS_HOSTNAME'}";
143 # Go further if there was no error.
144 if ( ! $errormessage) {
145 # Check if a remark has been entered.
147 # decode the UTF-8 text so that characters with diacritical marks such as
148 # umlauts are treated correctly by the following cleanhtml command
149 $cgiparams{'REMARK'} = decode
("UTF-8", $cgiparams{'REMARK'});
151 # run the REMARK text through cleanhtml to ensure all unsafe html characters
152 # are correctly encoded to their html entities
153 $cgiparams{'REMARK'} = &Header
::cleanhtml
($cgiparams{'REMARK'});
155 # encode the text back to UTF-8 after running the cleanhtml command
156 $cgiparams{'REMARK'} = encode
("UTF-8", $cgiparams{'REMARK'});
158 my %dns_servers = ();
162 # Read-in configfile.
163 &General
::readhasharray
($servers_file, \
%dns_servers);
165 # Check if we should edit an existing entry and got an ID.
166 if (($cgiparams{'SERVERS'} eq $Lang::tr
{'update'}) && ($cgiparams{'ID'})) {
167 # Assin the provided id.
168 $id = $cgiparams{'ID'};
170 # Undef the given ID.
171 undef($cgiparams{'ID'});
173 # Grab the configured status of the corresponding entry.
174 $status = $dns_servers{$id}[2];
176 # Each newly added entry automatically should be enabled.
179 # Generate the ID for the new entry.
181 # Sort the keys by their ID and store them in an array.
182 my @keys = sort { $a <=> $b } keys %dns_servers;
184 # Reverse the key array.
185 my @reversed = reverse(@keys);
187 # Obtain the last used id.
188 my $last_id = @reversed[0];
190 # Increase the last id by one and use it as id for the new entry.
193 # The first allowed id is 3 to keep space for
194 # possible ISP assigned DNS servers.
200 # Add/Modify the entry to/in the dns_servers hash.
201 $dns_servers{$id} = ["$cgiparams{'NAMESERVER'}", "$cgiparams{'TLS_HOSTNAME'}", "$status", "$cgiparams{'REMARK'}"];
203 # Write the changed hash to the config file.
204 &General
::writehasharray
($servers_file, \
%dns_servers);
206 # Call function to handle unbound restart, etc.
207 &_handle_unbound_and_more
();
209 # Switch back to previous mode.
210 $cgiparams{'SERVERS'} = $cgiparams{'MODE'};
213 # Toggle enable / disable.
215 } elsif ($cgiparams{'SERVERS'} eq $Lang::tr
{'toggle enable disable'}) {
216 my %dns_servers = ();
218 # Only go further, if an ID has been passed.
219 if ($cgiparams{'ID'}) {
220 # Assign the given ID.
221 my $id = $cgiparams{'ID'};
223 # Undef the given ID.
224 undef($cgiparams{'ID'});
226 # Read-in configfile.
227 &General
::readhasharray
($servers_file, \
%dns_servers);
229 # Grab the configured status of the corresponding entry.
230 my $status = $dns_servers{$id}[2];
233 if ($status eq "disabled") {
236 $status = "disabled";
239 # Modify the status of the existing entry.
240 $dns_servers{$id} = ["$dns_servers{$id}[0]", "$dns_servers{$id}[1]", "$status", "$dns_servers{$id}[3]"];
242 # Write the changed hash back to the config file.
243 &General
::writehasharray
($servers_file, \
%dns_servers);
245 # Call function to handle unbound restart, etc.
246 &_handle_unbound_and_more
();
249 ## Remove entry from DNS servers list.
251 } elsif ($cgiparams{'SERVERS'} eq $Lang::tr
{'remove'}) {
252 my %dns_servers = ();
254 # Read-in configfile.
255 &General
::readhasharray
($servers_file, \
%dns_servers);
257 # Drop entry from the hash.
258 delete($dns_servers{$cgiparams{'ID'}});
260 # Undef the given ID.
261 undef($cgiparams{'ID'});
263 # Write the changed hash to the config file.
264 &General
::writehasharray
($servers_file, \
%dns_servers);
266 # Call function to handle unbound restart, etc.
267 &_handle_unbound_and_more
();
269 ## Handle request to check the servers.
271 } elsif ($cgiparams{'SERVERS'} eq $Lang::tr
{'dns check servers'}) {
275 # Hash to store the generic DNS settings.
277 $settings{"ENABLE_SAFE_SEARCH_YOUTUBE"} = "on";
279 # Read-in general DNS settings.
280 &General
::readhash
("$settings_file", \
%settings);
282 # Hash which contains the configured DNS servers.
283 my %dns_servers = ();
285 # Read-in config file.
286 &General
::readhasharray
("$servers_file", \
%dns_servers);
288 &Header
::openpage
($Lang::tr
{'dns title'}, 1, '');
290 &Header
::openbigbox
('100%', 'left', '', $errormessage);
293 # Error messages layout.
296 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
297 print "<class name='base'>$errormessage\n";
298 print " </class>\n";
302 # Handle if a nameserver should be added or edited.
303 if (($cgiparams{'SERVERS'} eq "$Lang::tr{'add'}") || ($cgiparams{'SERVERS'} eq "$Lang::tr{'edit'}")) {
304 # Display the sub page.
305 &show_add_edit_nameserver
();
308 &Header
::closebigbox
();
309 &Header
::closepage
();
311 # Finished here for the moment.
315 $cgiparams{'GENERAL'} = '';
316 $cgiparams{'SERVERS'} = '';
317 $cgiparams{'NAMESERVER'} = '';
318 $cgiparams{'TLS_HOSTNAME'} = '';
319 $cgiparams{'REMARK'} ='';
321 $checked{'USE_ISP_NAMESERVERS'}{'off'} = '';
322 $checked{'USE_ISP_NAMESERVERS'}{'on'} = '';
323 $checked{'USE_ISP_NAMESERVERS'}{$settings{'USE_ISP_NAMESERVERS'}} = "checked='checked'";
325 $checked{'ENABLE_SAFE_SEARCH'}{'off'} = '';
326 $checked{'ENABLE_SAFE_SEARCH'}{'on'} = '';
327 $checked{'ENABLE_SAFE_SEARCH'}{$settings{'ENABLE_SAFE_SEARCH'}} = "checked='checked'";
329 $checked{'ENABLE_SAFE_SEARCH_YOUTUBE'}{'off'} = '';
330 $checked{'ENABLE_SAFE_SEARCH_YOUTUBE'}{'on'} = '';
331 $checked{'ENABLE_SAFE_SEARCH_YOUTUBE'}{$settings{'ENABLE_SAFE_SEARCH_YOUTUBE'}} = "checked='checked'";
333 $selected{'PROTO'}{'UDP'} = '';
334 $selected{'PROTO'}{'TLS'} = '';
335 $selected{'PROTO'}{'TCP'} = '';
336 $selected{'PROTO'}{$settings{'PROTO'}} = "selected='selected'";
338 $selected{'QNAME_MIN'}{'standard'} = '';
339 $selected{'QNAME_MIN'}{'strict'} = '';
340 $selected{'QNAME_MIN'}{$settings{'QNAME_MIN'}} = "selected='selected'";
342 # Display nameserver and configuration sections.
344 &show_general_dns_configuration
();
346 &Header
::closebigbox
();
347 &Header
::closepage
();
350 # General DNS-Servers sektion.
352 sub show_general_dns_configuration
() {
353 &Header
::openbox
('100%', 'center', "$Lang::tr{'dns configuration'}");
356 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
360 $Lang::tr{'dns use isp assigned nameservers'}
364 <input type="checkbox" name="USE_ISP_NAMESERVERS" $checked{'USE_ISP_NAMESERVERS'}{'on'}>
376 $Lang::tr{'dns use protocol for dns queries'}
380 <select name="PROTO">
381 <option value="UDP" $selected{'PROTO'}{'UDP'}>UDP</option>
382 <option value="TLS" $selected{'PROTO'}{'TLS'}>TLS</option>
383 <option value="TCP" $selected{'PROTO'}{'TCP'}>TCP</option>
396 $Lang::tr{'dns enable safe-search'}
400 <input type="checkbox" name="ENABLE_SAFE_SEARCH" $checked{'ENABLE_SAFE_SEARCH'}{'on'}>
406 » $Lang::tr{'dns enable safe-search youtube'}
410 <input type="checkbox" name="ENABLE_SAFE_SEARCH_YOUTUBE" $checked{'ENABLE_SAFE_SEARCH_YOUTUBE'}{'on'}>
422 $Lang::tr{'dns mode for qname minimisation'}
426 <select name="QNAME_MIN">
427 <option value="standard" $selected{'QNAME_MIN'}{'standard'}>$Lang::tr{'standard'}</option>
428 <option value="strict" $selected{'QNAME_MIN'}{'strict'}>$Lang::tr{'strict'}</option>
434 <td colspan="2" align="right">
435 <input type="submit" name="GENERAL" value="$Lang::tr{'save'}">
446 # Section to display the configured and used DNS servers.
448 sub show_nameservers
() {
449 &Header
::openbox
('100%', 'center', "$Lang::tr{'dns servers'}");
451 # Determine if we are running in recursor mode
453 my $unbound_forward = qx(unbound
-control forward
);
454 if ($unbound_forward =~ m/^off/) {
458 my $dns_status_string;
463 # Test if the DNS system is working.
465 # Simple send a request to unbound and check if it can resolve the
467 my $dns_status_ret = &check_nameserver
("127.0.0.1", "$dns_test_server", "UDP", undef, "+timeout=5", "+retry=0");
469 if ($dns_status_ret eq "2") {
470 $dns_status_string = "$Lang::tr{'working'}";
471 $dns_status_col = "${Header::colourgreen}";
474 $dns_status_string = "$Lang::tr{'broken'}";
475 $dns_status_col = "${Header::colourred}";
479 $dns_status_string .= " (" . $Lang::tr
{'dns recursor mode'} . ")";
486 <strong>$Lang::tr{'status'}: </strong>
487 <strong><font color='$dns_status_col'>$dns_status_string</font></strong>
493 # Check the usage of ISP assigned nameservers is enabled.
496 # Loop through the array which stores the files.
497 foreach my $file (@ISP_nameserver_files) {
498 # Grab the address of the nameserver.
499 my $address = &General
::grab_address_from_file
($file);
501 # Check if we got an address.
503 # Add the address to the hash of nameservers.
504 $dns_servers{$id} = [ "$address", "none",
505 ($settings{'USE_ISP_NAMESERVERS'} eq "on") ?
"enabled" : "disabled",
506 "$Lang::tr{'dns isp assigned nameserver'}" ];
508 # Increase id by one.
513 # Check some DNS servers have been configured. In this case
514 # the hash contains at least one key.
516 if (keys %dns_servers) {
517 # Sort the keys by their ID and store them in an array.
518 my @keys = sort { $a <=> $b } keys %dns_servers;
523 <table class="tbl" width='100%'>
526 <strong>$Lang::tr{'nameserver'}</strong>
530 <strong>$Lang::tr{'country'}</strong>
534 <strong>$Lang::tr{'rdns'}</strong>
538 <strong>$Lang::tr{'remark'}</strong>
542 # Check if the status should be displayed.
543 if ($check_servers) {
546 <strong>$Lang::tr{'status'}</strong>
553 <td align="center" colspan="3">
554 <strong>$Lang::tr{'action'}</strong>
559 # Loop through all entries of the array/hash.
560 foreach my $id (@keys) {
561 # Inrease server_amount.
564 # Assign data array positions to some nice variable names.
565 my $nameserver = $dns_servers{$id}[0];
566 my $tls_hostname = $dns_servers{$id}[1];
567 my $enabled = $dns_servers{$id}[2];
568 my $remark = $dns_servers{$id}[3];
577 if ($server_amount % 2) {
578 $col="bgcolor='$color{'color22'}'"; }
580 $col="bgcolor='$color{'color20'}'";
583 if ($enabled eq 'enabled') {
584 $gif='on.gif'; $toggle='off'; $gdesc=$Lang::tr
{'click to disable'};
586 $gif='off.gif'; $toggle='on'; $gdesc=$Lang::tr
{'click to enable'};
594 # Only grab the status if the nameserver is enabled.
595 if (($check_servers) && ($enabled eq "enabled")) {
596 $status = &check_nameserver
("$nameserver", "ping.ipfire.org", "$settings{'PROTO'}", "$tls_hostname");
599 if (!defined $status) {
600 $status_short = "$Lang::tr{'disabled'}";
602 # DNSSEC Not supported
603 } elsif ($status eq 0) {
604 $status_short = "$Lang::tr{'broken'}";
605 $status_message = $Lang::tr
{'dnssec not supported'};
606 $status_colour = ${Header
::colourred
};
609 } elsif ($status eq 1) {
610 $status_short = "$Lang::tr{'not validating'}";
611 $status_message = $Lang::tr
{'dnssec aware'};
612 $status_colour = ${Header
::colourblack
};
615 } elsif ($status eq 2) {
616 $status_short = "$Lang::tr{'ok'}";
617 $status_message = $Lang::tr
{'dnssec validating'};
618 $status_colour = ${Header
::colourgreen
};
622 $status_short = "$Lang::tr{'error'}";
623 $status_message = $status;
624 $status_colour = ${Header
::colourred
};
627 # collect more information about name server (rDNS, country code)
628 my $ccode = &Location
::Functions
::lookup_country_code
($nameserver);
629 my $flag_icon = &Location
::Functions
::get_flag_icon
($ccode);
633 # Only do the reverse lookup if the system is online.
635 my $iaddr = inet_aton
($nameserver);
636 $rdns = gethostbyaddr($iaddr, AF_INET
);
639 if (!$rdns) { $rdns = $Lang::tr
{'ptr lookup failed'}; }
641 # Mark ISP name servers as disabled
642 if ($id <= 2 && $enabled eq "disabled") {
643 $nameserver = "<del>$nameserver</del>";
648 <td align="center" $col>
652 <td align="center" $col>
653 <a href='country.cgi#$ccode'><img src="$flag_icon" border="0" alt="$ccode" title="$ccode" /></a>
656 <td align="center" $col>
660 <td align="center" $col>
665 # Display server status if requested.
666 if ($check_servers) {
668 <td align="center" $col>
669 <strong><font color="$status_colour"><abbr title="$status_message">$status_short</abbr></font></strong>
675 # Check if the id is greater than "2".
677 # Nameservers with an ID's of one or two are ISP assigned,
678 # and we cannot perform any actions on them, so hide the tools for
683 <td align='center' width='5%' $col>
684 <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
685 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' title='$gdesc' alt='$gdesc' />
686 <input type='hidden' name='ID' value='$id' />
687 <input type='hidden' name='ENABLE' value='$toggle' />
688 <input type='hidden' name='SERVERS' value='$Lang::tr{'toggle enable disable'}' />
692 <td align='center' width='5%' $col>
693 <form method='post' name='frmb$id' action='$ENV{'SCRIPT_NAME'}'>
694 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' title='$Lang::tr{'edit'}' alt='$Lang::tr{'edit'}' />
695 <input type='hidden' name='ID' value='$id' />
696 <input type='hidden' name='SERVERS' value='$Lang::tr{'edit'}' />
700 <td align='center' width='5%' $col>
701 <form method='post' name='frmc$id' action='$ENV{'SCRIPT_NAME'}'>
702 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}' />
703 <input type='hidden' name='ID' value='$id' />
704 <input type='hidden' name='SERVERS' value='$Lang::tr{'remove'}' />
710 print "<td colspan='3' $col> </td>\n";
720 print"<table width='100%'>\n";
722 # Check if the usage of the ISP nameservers is enabled and there are more than 2 servers.
723 if (($settings{'USE_ISP_NAMESERVERS'} eq "on") && ($server_amount > 2)) {
726 <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td>
727 <td> <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
728 <td class='base'>$Lang::tr{'click to disable'}</td>
729 <td> <img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
730 <td class='base'>$Lang::tr{'click to enable'}</td>
731 <td> <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
732 <td class='base'>$Lang::tr{'edit'}</td>
733 <td> <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
734 <td class='base'>$Lang::tr{'remove'}</td>
741 <form method="post" action="$ENV{'SCRIPT_NAME'}">
742 <td colspan="9" align="right">
743 <input type="submit" name="SERVERS" value="$Lang::tr{'add'}">
744 <input type="submit" name="SERVERS" value="$Lang::tr{'dns check servers'}">
755 <form method="post" action="$ENV{'SCRIPT_NAME'}">
756 <td colspan="6" align="right"><input type="submit" name="SERVERS" value="$Lang::tr{'add'}"></td>
767 # Section to display the add or edit subpage.
769 sub show_add_edit_nameserver
() {
770 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
772 my $buttontext = $Lang::tr
{'save'};
775 if ($cgiparams{'SERVERS'} eq $Lang::tr
{'edit'}) {
776 &Header
::openbox
('100%', 'left', $Lang::tr
{'dnsforward edit an entry'});
778 # Update button text for upate the existing entry.
779 $buttontext = $Lang::tr
{'update'};
781 # Add hidden input for sending ID.
782 print"<input type='hidden' name='ID' value='$cgiparams{'ID'}'>\n";
784 # Check if an ID has been given.
785 if ($cgiparams{'ID'}) {
786 # Assign cgiparams values.
787 $cgiparams{'NAMESERVER'} = $dns_servers{$cgiparams{'ID'}}[0];
788 $cgiparams{'TLS_HOSTNAME'} = $dns_servers{$cgiparams{'ID'}}[1];
789 $cgiparams{'REMARK'} = $dns_servers{$cgiparams{'ID'}}[3];
792 &Header
::openbox
('100%', 'left', $Lang::tr
{'dnsforward add a new entry'});
795 my $tls_required_image;
797 # If the protocol is TLS, dispaly the required image.
798 if ($settings{'PROTO'} eq "TLS") {
799 $tls_required_image = "<img src='/blob.gif' alt='*'>";
802 # Add hidden input to store the mode.
803 print "<input type='hidden' name='MODE' value='$cgiparams{'SERVERS'}'>\n";
808 <td width='20%' class='base'>$Lang::tr{'ip address'}: <img src='/blob.gif' alt='*' /></td>
809 <td><input type='text' name='NAMESERVER' value='$cgiparams{"NAMESERVER"}' size='24' /></td>
814 <td width='20%' class='base'>$Lang::tr{'dns tls hostname'}: $tls_required_image</td>
815 <td><input type='text' name='TLS_HOSTNAME' value='$cgiparams{'TLS_HOSTNAME'}' size='24'></td>
820 <td width ='20%' class='base'>$Lang::tr{'remark'}:</td>
821 <td><input type='text' name='REMARK' value='$cgiparams{'REMARK'}' size='40' maxlength='50' /></td>
830 <td class='base' width='55%'><img src='/blob.gif' alt ='*' align='top' /> $Lang::tr{'required field'}</td>
831 <td width='40%' align='right'>
832 <input type="submit" name="SERVERS" value="$buttontext">
833 <input type="submit" name="SERVERS" value="$Lang::tr{'back'}">
846 # Private function to handle the restart of unbound and more.
847 sub _handle_unbound_and_more
() {
848 # Check if the IDS is running.
849 if(&IDS
::ids_is_running
()) {
850 # Re-generate the file which contains the DNS Server
852 &IDS
::generate_dns_servers_file
();
854 # Call suricatactrl to perform a reload.
855 &IDS
::call_suricatactrl
("restart");
858 &General
::system('/usr/local/bin/unboundctrl', 'reload');
861 # Check if the system is online (RED is connected).
862 sub red_is_active
() {
863 # Check if the "active" file is present.
864 if ( -f
"${General::swroot}/red/active") {
868 # Return nothing - False.
873 # Function to check a given nameserver against propper work.
874 sub check_nameserver
($$$$$) {
875 my ($nameserver, $record, $proto, $tls_hostname, @args) = @_;
877 # Check if the system is online.
878 unless (&red_is_active
()) {
879 return "$Lang::tr{'system is offline'}";
883 my @command = ("kdig", "+dnssec",
884 "+bufsize=1232", @args);
886 # Handle different protols.
887 if ($proto eq "TCP") {
888 # Add TCP switch to the command.
889 push(@command, "+tcp");
891 } elsif($proto eq "TLS") {
892 # Add TLS switch to the command and provide the
893 # path to our file which contains the ca certs.
894 push(@command, "+tls-ca=$ca_certs_file");
896 # Check if a TLS hostname has been provided.
898 # Add TLS hostname to the command.
899 push(@command, "+tls-hostname=$tls_hostname");
901 return "$Lang::tr{'dns no tls hostname given'}";
905 # Add record to the command array.
906 push(@command, "$record");
908 # Add nameserver to the command array.
909 push(@command, "\@$nameserver");
911 # Connect to STDOUT and STDERR.
912 push(@command, "2>&1");
914 my @output = qx(@command);
915 my $output = join("", @output);
919 if ($output =~ m/status: (\w+)/) {
920 $status = ($1 eq "NOERROR");
928 while ($output =~ m/WARNING: (.*)/g) {
929 # Add the current grabbed warning to the warning string.
933 # Return the warning string, if we grabbed at least one.
940 if ($output =~ m/Flags: (.*);/) {
941 @flags = split(/ /, $1);
944 my $aware = ($output =~ m/RRSIG/);
945 my $validating = (grep(/ad;/, @flags));
947 return $aware + $validating;