]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - html/cgi-bin/tor.cgi
Hardcode theme to ipfire
[ipfire-2.x.git] / html / cgi-bin / tor.cgi
index 228b5d48c2ca14598a22cc3431b02adf85dfb766..f39c0d8da0677110f2de3ab974e63974d911051a 100644 (file)
@@ -2,7 +2,7 @@
 ###############################################################################
 #                                                                             #
 # IPFire.org - A linux based firewall                                         #
-# Copyright (C) 2013  IPFire Team  <info@ipfire.org>                          #
+# Copyright (C) 2007-2020  IPFire Team  <info@ipfire.org>                     #
 #                                                                             #
 # This program is free software: you can redistribute it and/or modify        #
 # it under the terms of the GNU General Public License as published by        #
 ###############################################################################
 
 use strict;
-use Locale::Country;
 
 # enable only the following on debugging purpose
-use warnings;
-use CGI::Carp 'fatalsToBrowser';
+#use warnings;
+#use CGI::Carp 'fatalsToBrowser';
 
 require '/var/ipfire/general-functions.pl';
+require "${General::swroot}/location-functions.pl";
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
 
@@ -35,10 +35,10 @@ my @dummy = ( ${Header::colouryellow} );
 undef (@dummy);
 
 my @bandwidth_limits = (
-       1000 * 1024, # 1G
+       1000 * 1024, # 1 GBit/s
         500 * 1024,
         200 * 1024,
-        100 * 1024, # 100M
+        100 * 1024, # 100 MBit/s
          64 * 1024,
          50 * 1024,
          25 * 1024,
@@ -48,10 +48,7 @@ my @bandwidth_limits = (
           8 * 1024,
           4 * 1024,
           2 * 1024,
-              1024, # 1M
-               512,
-               256,
-               160
+              1024  # 1 MBit/s
 );
 my @accounting_periods = ('daily', 'weekly', 'monthly');
 
@@ -91,7 +88,7 @@ our %netsettings = ();
 our %color = ();
 our %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);
 
 our %settings = ();
 
@@ -99,13 +96,15 @@ $settings{'TOR_ENABLED'} = 'off';
 $settings{'TOR_SOCKS_PORT'} = 9050;
 $settings{'TOR_EXIT_COUNTRY'} = '';
 $settings{'TOR_USE_EXIT_NODES'} = '';
+$settings{'TOR_GUARD_COUNTRY'} = '';
+$settings{'TOR_USE_GUARD_NODES'} = '';
 $settings{'TOR_ALLOWED_SUBNETS'} = "$netsettings{'GREEN_NETADDRESS'}\/$netsettings{'GREEN_NETMASK'}";
 if (&Header::blue_used()) {
        $settings{'TOR_ALLOWED_SUBNETS'} .= ",$netsettings{'BLUE_NETADDRESS'}\/$netsettings{'BLUE_NETMASK'}";
 }
 
 $settings{'TOR_RELAY_ENABLED'} = 'off';
-$settings{'TOR_RELAY_MODE'} = 'exit';
+$settings{'TOR_RELAY_MODE'} = 'relay';
 $settings{'TOR_RELAY_ADDRESS'} = '';
 $settings{'TOR_RELAY_PORT'} = 9001;
 $settings{'TOR_RELAY_DIRPORT'} = 0;
@@ -181,6 +180,15 @@ if ($settings{'ACTION'} eq $Lang::tr{'save'}) {
                }
        }
 
+       @temp = split(/[\n,]/,$settings{'TOR_USE_GUARD_NODES'});
+       $settings{'TOR_USE_GUARD_NODES'} = "";
+       foreach (@temp) {
+               s/^\s+//g; s/\s+$//g;
+               if ($_) {
+                       $settings{'TOR_USE_GUARD_NODES'} .= $_.",";
+               }
+       }
+
        # Burst bandwidth must be less or equal to bandwidth rate.
        if ($settings{'TOR_RELAY_BANDWIDTH_RATE'} == 0) {
                $settings{'TOR_RELAY_BANDWIDTH_BURST'} = 0;
@@ -266,7 +274,7 @@ if ( ($memory != 0) && (@pid[0] ne "///") ){
                        <tr>
                                <td width='25%' class='base'>$Lang::tr{'tor enabled'}:</td>
                                <td width='30%'><input type='checkbox' name='TOR_ENABLED' $checked{'TOR_ENABLED'}{'on'} /></td>
-                               <td width='25%' class='base'>$Lang::tr{'tor socks port'}:</td>
+                               <td width='25%' class='base'>$Lang::tr{'tor socks port'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
                                <td width='20%'><input type='text' name='TOR_SOCKS_PORT' value='$settings{'TOR_SOCKS_PORT'}' size='5' /></td>
                        </tr>
                        <tr>
@@ -284,6 +292,9 @@ END
        @temp = split(",", $settings{'TOR_USE_EXIT_NODES'});
        $settings{'TOR_USE_EXIT_NODES'} = join("\n", @temp);
 
+       @temp = split(",", $settings{'TOR_USE_GUARD_NODES'});
+       $settings{'TOR_USE_GUARD_NODES'} = join("\n", @temp);
+
        print <<END;
                <br>
                <br>
@@ -306,8 +317,57 @@ END
                        </tr>
                </table>
 
-               <br>
-               <br>
+               <br />
+               <br />
+
+               <table width='95%'>
+                       <tr>
+                               <td colspan='4' class='base' bgcolor='$color{'color20'}'><b>$Lang::tr{'tor guard nodes'}</b></td>
+                       </tr>
+                       <tr>
+                               <td colspan='2' class='base' width='55%'></td>
+                               <td colspan='2' class='base' width='45%'>$Lang::tr{'tor use guard nodes'}:</td>
+                       </tr>
+                       <tr>
+                               <td width='50%' colspan='2'>
+                                       <select name='TOR_GUARD_COUNTRY' multiple='multiple'>
+                                               <option value=''>- $Lang::tr{'tor guard country any'} -</option>
+END
+
+               # Convert Guard country strings into lists to make comparison easier
+               my @guard_countries;
+               if ($settings{'TOR_GUARD_COUNTRY'} ne '') {
+                       @guard_countries = split(/\|/, $settings{'TOR_GUARD_COUNTRY'});
+               }
+
+               my @country_codes = &Location::Functions::get_locations("no_special_locations");
+               foreach my $country_code (@country_codes) {
+                       # Convert country code into upper case format.
+                       $country_code = uc($country_code);
+
+                       # Get country name.
+                       my $country_name = &Location::Functions::get_full_country_name($country_code);
+
+                       print "<option value='$country_code'";
+
+                       if ($settings{'TOR_GUARD_COUNTRY'} ne '') {
+                               print " selected" if grep /$country_code/, @guard_countries;
+                       }
+
+                       print ">$country_name ($country_code)</option>\n";
+               }
+
+       print <<END;
+                                       </select>
+                               </td>
+                               <td width='50%' colspan='2'>
+                                       <textarea name='TOR_USE_GUARD_NODES' cols='32' rows='3' wrap='off'>$settings{'TOR_USE_GUARD_NODES'}</textarea>
+                               </td>
+                       </tr>
+               </table>
+
+               <br />
+               <br />
 
                <table width='95%'>
                        <tr>
@@ -319,18 +379,28 @@ END
                        </tr>
                        <tr>
                                <td width='50%' colspan='2'>
-                                       <select name='TOR_EXIT_COUNTRY'>
+                                       <select name='TOR_EXIT_COUNTRY' multiple='multiple'>
                                                <option value=''>- $Lang::tr{'tor exit country any'} -</option>
 END
+               my @country_codes = &Location::Functions::get_locations("no_special_locations");
+
+               # Convert Exit country strings into lists to make comparison easier
+               my @exit_countries;
+               if ($settings{'TOR_EXIT_COUNTRY'} ne '') {
+                       @exit_countries = split(/\|/, $settings{'TOR_EXIT_COUNTRY'});
+               }
 
-               my @country_names = Locale::Country::all_country_names();
-               foreach my $country_name (sort @country_names) {
-                       my $country_code = Locale::Country::country2code($country_name);
+               foreach my $country_code (@country_codes) {
+                       # Convert country code into upper case format.
                        $country_code = uc($country_code);
+
+                       # Get country name.
+                       my $country_name = &Location::Functions::get_full_country_name($country_code);
+
                        print "<option value='$country_code'";
 
-                       if ($settings{'TOR_EXIT_COUNTRY'} eq $country_code) {
-                               print " selected";
+                       if ($settings{'TOR_EXIT_COUNTRY'} ne '') {
+                               print " selected" if grep /$country_code/, @exit_countries;
                        }
 
                        print ">$country_name ($country_code)</option>\n";
@@ -386,17 +456,17 @@ END
                                                <option value='private-bridge' $selected{'TOR_RELAY_MODE'}{'private-bridge'}>$Lang::tr{'tor relay mode private bridge'}</option>
                                        </select>
                                </td>
-                               <td width='25%' class='base'>$Lang::tr{'tor relay nickname'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
+                               <td width='25%' class='base'>$Lang::tr{'tor relay nickname'}:</td>
                                <td width='20%'>
                                        <input type='text' name='TOR_RELAY_NICKNAME' value='$settings{'TOR_RELAY_NICKNAME'}' maxlength='19' />
                                </td>
                        </tr>
                        <tr>
-                               <td width='25%' class='base'>$Lang::tr{'tor relay address'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
+                               <td width='25%' class='base'>$Lang::tr{'tor relay address'}:</td>
                                <td width='30%'>
                                        <input type='text' name='TOR_RELAY_ADDRESS' value='$settings{'TOR_RELAY_ADDRESS'}' />
                                </td>
-                               <td width='25%' class='base'>$Lang::tr{'tor relay port'}:</td>
+                               <td width='25%' class='base'>$Lang::tr{'tor relay port'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
                                <td width='20%'>
                                        <input type='text' name='TOR_RELAY_PORT' value='$settings{'TOR_RELAY_PORT'}' size='5' />
                                </td>
@@ -404,13 +474,13 @@ END
                        <tr>
                                <td width='25%'>&nbsp;</td>
                                <td width='30%'>&nbsp;</td>
-                               <td width='25%' class='base'>$Lang::tr{'tor directory port'}:</td>
+                               <td width='25%' class='base'>$Lang::tr{'tor directory port'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
                                <td width='20%'>
                                        <input type='text' name='TOR_RELAY_DIRPORT' value='$settings{'TOR_RELAY_DIRPORT'}' size='5' />&nbsp;$Lang::tr{'tor 0 = disabled'}
                                </td>
                        </tr>
                        <tr>
-                               <td width='25%' class='base'>$Lang::tr{'tor contact info'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
+                               <td width='25%' class='base'>$Lang::tr{'tor contact info'}:</td>
                                <td width='75%' colspan='3'>
                                        <input type='text' name='TOR_RELAY_CONTACT_INFO' value='$settings{'TOR_RELAY_CONTACT_INFO'}' style='width: 98%;' />
                                </td>
@@ -431,9 +501,9 @@ END
 
        foreach (@bandwidth_limits) {
                if ($_ >= 1024) {
-                       print "<option value='$_' $selected{'TOR_RELAY_BANDWIDTH_RATE'}{$_}>". $_ / 1024 ." MBit/s</option>\n";
+                       print "<option value='$_' $selected{'TOR_RELAY_BANDWIDTH_RATE'}{$_}>". $_ / 1024 ." Mbit/s</option>\n";
                } else {
-                       print "<option value='$_' $selected{'TOR_RELAY_BANDWIDTH_RATE'}{$_}>$_ kBit/s</option>\n";
+                       print "<option value='$_' $selected{'TOR_RELAY_BANDWIDTH_RATE'}{$_}>$_ kbit/s</option>\n";
                }
        }
 
@@ -441,7 +511,7 @@ END
                                                <option value='0' $selected{'TOR_RELAY_BANDWIDTH_RATE'}{'0'}>$Lang::tr{'tor bandwidth unlimited'}</option>
                                        </select>
                                </td>
-                               <td width='25%' class='base'>$Lang::tr{'tor accounting limit'}:</td>
+                               <td width='25%' class='base'>$Lang::tr{'tor accounting limit'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
                                <td width='20%'>
                                        <input type='text' name='TOR_RELAY_ACCOUNTING_LIMIT' value='$settings{'TOR_RELAY_ACCOUNTING_LIMIT'}' size='12' />
                                </td>
@@ -454,9 +524,9 @@ END
 
        foreach (@bandwidth_limits) {
                if ($_ >= 1024) {
-                       print "<option value='$_' $selected{'TOR_RELAY_BANDWIDTH_BURST'}{$_}>". $_ / 1024 ." MBit/s</option>\n";
+                       print "<option value='$_' $selected{'TOR_RELAY_BANDWIDTH_BURST'}{$_}>". $_ / 1024 ." Mbit/s</option>\n";
                } else {
-                       print "<option value='$_' $selected{'TOR_RELAY_BANDWIDTH_BURST'}{$_}>$_ kBit/s</option>\n";
+                       print "<option value='$_' $selected{'TOR_RELAY_BANDWIDTH_BURST'}{$_}>$_ kbit/s</option>\n";
                }
        }
        print <<END;
@@ -484,9 +554,7 @@ END
        print <<END;
                <table width='95%'>
                        <tr>
-                               <td>
-                                       <img src='/blob.gif' align='top' alt='*' />&nbsp;<font class='base'>$Lang::tr{'this field may be blank'}</font>
-                               </td>
+                               <td><img src='/blob.gif' align='top' alt='*' />&nbsp;<font class='base'>$Lang::tr{'required field'}</font></td>
                                <td align='right'>&nbsp;</td>
                        </tr>
                </table>
@@ -520,7 +588,7 @@ END
                                        <tr>
                                                <td width='40%' class='base'>$Lang::tr{'tor relay fingerprint'}:</td>
                                                <td width='60%'>
-                                                       <a href='https://atlas.torproject.org/#details/$fingerprint' target='_blank'>$fingerprint</a>
+                                                       <a href='https://metrics.torproject.org/rs.html#details/$fingerprint' target='_blank'>$fingerprint</a>
                                                </td>
                                        </tr>
 END
@@ -613,7 +681,7 @@ END
                                print <<END;
                                        <tr>
                                                <td width='40%'>
-                                                       <a href='https://atlas.torproject.org/#details/$node->{'fingerprint'}' target='_blank'>
+                                                       <a href='https://metrics.torproject.org/rs.html#details/$node->{'fingerprint'}' target='_blank'>
                                                                $node->{'name'}
                                                        </a>
                                                </td>
@@ -621,10 +689,14 @@ END
 END
 
                                if (exists($node->{'country_code'})) {
-                                       if (!$node->{'country_code'} or $node->{'country_code'} eq '??') {
-                                               print "<img src='/images/flags/blank.png' border='0' align='absmiddle'/>";
+                                       # Get the flag icon of the country.
+                                       my $flag_icon = &Location::Functions::get_flag_icon($node->{'country_code'});
+
+                                       # Check if a flag for the given country is available.
+                                       if ($flag_icon) {
+                                               print "<a href='country.cgi#$node->{'country_code'}'><img src='$flag_icon' border='0' align='absmiddle' alt='$node->{'country_code'}'></a>";
                                        } else {
-                                               print "<a href='country.cgi#$node->{'country_code'}'><img src='/images/flags/$node->{'country_code'}.png' border='0' align='absmiddle' alt='$node->{'country_code'}'></a>";
+                                               print "<img src='/images/flags/blank.png' border='0' align='absmiddle'/>";
                                        }
                                }
 
@@ -671,10 +743,43 @@ sub BuildConfiguration() {
                }
                print FILE "SocksPolicy reject *\n" if (@subnets);
 
+               if ($settings{'TOR_GUARD_COUNTRY'} ne '') {
+                       $strict_nodes = 1;
+                       my $countrylist;
+
+                       for my $singlecountry (split(/\|/, $settings{'TOR_GUARD_COUNTRY'})) {
+                               if ($countrylist eq '') {
+                                       $countrylist = "{" . lc $singlecountry . "}";
+                               } else {
+                                       $countrylist = $countrylist . "," . "{" . lc $singlecountry . "}";
+                               }
+                       }
+
+                       print FILE "EntryNodes $countrylist\n";
+               }
+
+               if ($settings{'TOR_USE_GUARD_NODES'} ne '') {
+                       $strict_nodes = 1;
+
+                       my @nodes = split(",", $settings{'TOR_USE_GUARD_NODES'});
+                       foreach (@nodes) {
+                               print FILE "EntryNode $_\n";
+                       }
+               }
+
                if ($settings{'TOR_EXIT_COUNTRY'} ne '') {
                        $strict_nodes = 1;
+                       my $countrylist;
+
+                       for my $singlecountry (split(/\|/, $settings{'TOR_EXIT_COUNTRY'})) {
+                               if ($countrylist eq '') {
+                                       $countrylist = "{" . lc $singlecountry . "}";
+                               } else {
+                                       $countrylist = $countrylist . "," . "{" . lc $singlecountry . "}";
+                               }
+                       }
 
-                       print FILE "ExitNodes {$settings{'TOR_EXIT_COUNTRY'}}\n";
+                       print FILE "ExitNodes $countrylist\n";
                }
 
                if ($settings{'TOR_USE_EXIT_NODES'} ne '') {
@@ -907,7 +1012,7 @@ sub TorNodeDescription() {
                        $node->{'address'} = $3;
                        $node->{'port'}    = $4;
 
-                       my $country_code = &TorGetInfo($tor, "ip-to-country/$node->{'address'}");
+                       my $country_code = &Location::Functions::lookup_country_code($node->{'address'});
                        $node->{'country_code'} = $country_code;
 
                # Flags
@@ -975,7 +1080,7 @@ sub FormatBytes() {
 sub FormatBitsPerSecond() {
        my $bits = shift;
 
-       my @units = ("Bit/s", "KBit/s", "MBit/s", "GBit/s", "TBit/s");
+       my @units = ("bit/s", "kbit/s", "Mbit/s", "Gbit/s", "Tbit/s");
        my $units_index = 0;
 
        while (($units_index <= $#units) && ($bits >= 1024)) {