]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - html/cgi-bin/dns.cgi
IPsec: Allow sending DNS server addresses to RW clients
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / dns.cgi
index aac7955ec19d717db2798368153f46298b32da3c..7dc11358223774a6f2cab732c473afd7f95f7080 100755 (executable)
@@ -27,7 +27,7 @@ use IO::Socket;
 #use CGI::Carp 'fatalsToBrowser';
 
 require '/var/ipfire/general-functions.pl';
-require "${General::swroot}/geoip-functions.pl";
+require "${General::swroot}/location-functions.pl";
 require "${General::swroot}/ids-functions.pl";
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
@@ -65,7 +65,7 @@ my $check_servers;
 my %color = ();
 my %mainsettings = ();
 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
-&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
+&General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color);
 
 &Header::showhttpheaders();
 &Header::getcgihash(\%cgiparams);
@@ -87,6 +87,10 @@ if ($cgiparams{'GENERAL'} eq $Lang::tr{'save'}) {
                $cgiparams{'ENABLE_SAFE_SEARCH'} = "off";
        }
 
+       if ($cgiparams{'ENABLE_SAFE_SEARCH_YOUTUBE'} ne "on") {
+               $cgiparams{'ENABLE_SAFE_SEARCH_YOUTUBE'} = "off";
+       }
+
        # Check if using ISP nameservers and TLS is enabled at the same time.
        if (($cgiparams{'USE_ISP_NAMESERVERS'} eq "on") && ($cgiparams{'PROTO'} eq "TLS")) {
                $errormessage = $Lang::tr{'dns isp nameservers and tls not allowed'}
@@ -259,6 +263,7 @@ if (($cgiparams{'SERVERS'} eq $Lang::tr{'save'}) || ($cgiparams{'SERVERS'} eq $L
 
 # Hash to store the generic DNS settings.
 my %settings = ();
+$settings{"ENABLE_SAFE_SEARCH_YOUTUBE"} = "on";
 
 # Read-in general DNS settings.
 &General::readhash("$settings_file", \%settings);
@@ -269,7 +274,7 @@ my %dns_servers = ();
 # Read-in config file.
 &General::readhasharray("$servers_file", \%dns_servers);
 
-&Header::openpage($Lang::tr{'dns'}, 1, '');
+&Header::openpage($Lang::tr{'dns title'}, 1, '');
 
 &Header::openbigbox('100%', 'left', '', $errormessage);
 
@@ -310,6 +315,10 @@ $checked{'ENABLE_SAFE_SEARCH'}{'off'} = '';
 $checked{'ENABLE_SAFE_SEARCH'}{'on'} = '';
 $checked{'ENABLE_SAFE_SEARCH'}{$settings{'ENABLE_SAFE_SEARCH'}} = "checked='checked'";
 
+$checked{'ENABLE_SAFE_SEARCH_YOUTUBE'}{'off'} = '';
+$checked{'ENABLE_SAFE_SEARCH_YOUTUBE'}{'on'} = '';
+$checked{'ENABLE_SAFE_SEARCH_YOUTUBE'}{$settings{'ENABLE_SAFE_SEARCH_YOUTUBE'}} = "checked='checked'";
+
 $selected{'PROTO'}{'UDP'} = '';
 $selected{'PROTO'}{'TLS'} = '';
 $selected{'PROTO'}{'TCP'} = '';
@@ -381,6 +390,16 @@ sub show_general_dns_configuration () {
                                </td>
                        </tr>
 
+                       <tr>
+                               <td width="33%">
+                                       &raquo; $Lang::tr{'dns enable safe-search youtube'}
+                               </td>
+
+                               <td>
+                                       <input type="checkbox" name="ENABLE_SAFE_SEARCH_YOUTUBE" $checked{'ENABLE_SAFE_SEARCH_YOUTUBE'}{'on'}>
+                               </td>
+                       </tr>
+
                        <tr>
                                <td colspan="2">
                                        <br>
@@ -416,7 +435,7 @@ END
 # Section to display the configured and used DNS servers.
 #
 sub show_nameservers () {
-       &Header::openbox('100%', 'center', "$Lang::tr{'dns title'}");
+       &Header::openbox('100%', 'center', "$Lang::tr{'dns servers'}");
 
        # Determine if we are running in recursor mode
        my $recursor = 0;
@@ -434,7 +453,7 @@ sub show_nameservers () {
        #
        # Simple send a request to unbound and check if it can resolve the
        # DNS test server.
-       my $dns_status_ret = &check_nameserver("127.0.0.1", "$dns_test_server", "UDP");
+       my $dns_status_ret = &check_nameserver("127.0.0.1", "$dns_test_server", "UDP", undef, "+timeout=5", "+retry=0");
 
        if ($dns_status_ret eq "2") {
                $dns_status_string = "$Lang::tr{'working'}";
@@ -449,7 +468,7 @@ sub show_nameservers () {
                $dns_status_string .= " (" . $Lang::tr{'dns recursor mode'} . ")";
        }
 
-print <<END;
+       print <<END;
                <table width='100%'>
                        <tr>
                                <td>
@@ -458,7 +477,36 @@ print <<END;
                                </td>
                        </tr>
                </table>
+END
+
+       # Check the usage of ISP assigned nameservers is enabled.
+       my $id = 1;
+
+       # Loop through the array which stores the files.
+       foreach my $file (@ISP_nameserver_files) {
+               # Grab the address of the nameserver.
+               my $address = &General::grab_address_from_file($file);
+
+               # Check if we got an address.
+               if ($address) {
+                       # Add the address to the hash of nameservers.
+                       $dns_servers{$id} = [ "$address", "none",
+                               ($settings{'USE_ISP_NAMESERVERS'} eq "on") ? "enabled" : "disabled",
+                               "$Lang::tr{'dns isp assigned nameserver'}" ];
 
+                       # Increase id by one.
+                       $id++;
+               }
+       }
+
+       # Check some DNS servers have been configured. In this case
+       # the hash contains at least one key.
+       my $server_amount;
+       if (keys %dns_servers) {
+               # Sort the keys by their ID and store them in an array.
+               my @keys = sort { $a <=> $b } keys %dns_servers;
+
+               print <<END;
                <br>
 
                <table class="tbl" width='100%'>
@@ -479,51 +527,23 @@ print <<END;
                                        <strong>$Lang::tr{'remark'}</strong>
                                </td>
 END
-       # Check if the status should be displayed.
-       if ($check_servers) {
-print <<END
+
+               # Check if the status should be displayed.
+               if ($check_servers) {
+                       print <<END;
                                <td align="center">
                                        <strong>$Lang::tr{'status'}</strong>
                                </td>
 END
-;
-       }
+               }
 
-print <<END
+               print <<END;
 
                                <td align="center" colspan="3">
                                        <strong>$Lang::tr{'action'}</strong>
                                </td>
                        </tr>
 END
-;
-
-               # Check the usage of ISP assigned nameservers is enabled.
-               my $id = 1;
-
-               # Loop through the array which stores the files.
-               foreach my $file (@ISP_nameserver_files) {
-                       # Grab the address of the nameserver.
-                       my $address = &General::grab_address_from_file($file);
-
-                       # Check if we got an address.
-                       if ($address) {
-                               # Add the address to the hash of nameservers.
-                               $dns_servers{$id} = [ "$address", "none",
-                                       ($settings{'USE_ISP_NAMESERVERS'} eq "on") ? "enabled" : "disabled",
-                                       "$Lang::tr{'dns isp assigned nameserver'}" ];
-
-                               # Increase id by one.
-                               $id++;
-                       }
-               }
-
-               # Check some DNS servers have been configured. In this case
-               # the hash contains at least one key.
-               my $server_amount;
-               if (keys %dns_servers) {
-                       # Sort the keys by their ID and store them in an array.
-                       my @keys = sort { $a <=> $b } keys %dns_servers;
 
                        # Loop through all entries of the array/hash.
                        foreach my $id (@keys) {
@@ -593,9 +613,9 @@ END
                                        $status_colour = ${Header::colourred};
                                }
 
-                               # collect more information about name server (rDNS, GeoIP country code)
-                               my $ccode = &GeoIP::lookup($nameserver);
-                               my $flag_icon = &GeoIP::get_flag_icon($ccode);
+                               # collect more information about name server (rDNS, country code)
+                               my $ccode = &Location::Functions::lookup_country_code($nameserver);
+                               my $flag_icon = &Location::Functions::get_flag_icon($ccode);
 
                                my $rdns;
 
@@ -605,7 +625,7 @@ END
                                        $rdns = gethostbyaddr($iaddr, AF_INET);
                                }
 
-                               if (!$rdns) { $rdns = $Lang::tr{'lookup failed'}; }
+                               if (!$rdns) { $rdns = $Lang::tr{'ptr lookup failed'}; }
 
                                # Mark ISP name servers as disabled
                                if ($id <= 2 && $enabled eq "disabled") {
@@ -814,9 +834,6 @@ END
 
 # Private function to handle the restart of unbound and more.
 sub _handle_unbound_and_more () {
-       # Restart unbound
-       system('/usr/local/bin/unboundctrl reload >/dev/null');
-
        # Check if the IDS is running.
        if(&IDS::ids_is_running()) {
                # Re-generate the file which contains the DNS Server
@@ -826,6 +843,8 @@ sub _handle_unbound_and_more () {
                # Call suricatactrl to perform a reload.
                &IDS::call_suricatactrl("restart");
        }
+       # Restart unbound
+       system('/usr/local/bin/unboundctrl reload >/dev/null');
 }
 
 # Check if the system is online (RED is connected).
@@ -841,8 +860,8 @@ sub red_is_active () {
 }
 
 # Function to check a given nameserver against propper work.
-sub check_nameserver($$$$) {
-       my ($nameserver, $record, $proto, $tls_hostname) = @_;
+sub check_nameserver($$$$$) {
+       my ($nameserver, $record, $proto, $tls_hostname, @args) = @_;
 
        # Check if the system is online.
        unless (&red_is_active()) {
@@ -851,7 +870,7 @@ sub check_nameserver($$$$) {
 
        # Default values.
        my @command = ("kdig", "+dnssec",
-               "+bufsize=1232");
+               "+bufsize=1232", @args);
 
        # Handle different protols.
        if ($proto eq "TCP") {