]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - html/cgi-bin/tor.cgi
ids.cgi: Rework "Enable IPS" section
[ipfire-2.x.git] / html / cgi-bin / tor.cgi
old mode 100755 (executable)
new mode 100644 (file)
index b920724..0d235c9
 ###############################################################################
 
 use strict;
-use Locale::Country;
+use Locale::Codes::Country;
 
 # enable only the following on debugging purpose
 use warnings;
 use CGI::Carp 'fatalsToBrowser';
 
 require '/var/ipfire/general-functions.pl';
+require "${General::swroot}/geoip-functions.pl";
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
 
@@ -105,9 +106,10 @@ if (&Header::blue_used()) {
 }
 
 $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;
 $settings{'TOR_RELAY_NICKNAME'} = '';
 $settings{'TOR_RELAY_CONTACT_INFO'} = '';
 $settings{'TOR_RELAY_BANDWIDTH_RATE'} = 0;
@@ -143,6 +145,11 @@ if ($settings{'ACTION'} eq $Lang::tr{'save'}) {
        if (!&General::validport($settings{'TOR_RELAY_PORT'})) {
                $errormessage = "$Lang::tr{'tor errmsg invalid relay port'}: $settings{'TOR_RELAY_PORT'}";
        }
+       if ($settings{'TOR_RELAY_DIRPORT'} ne '0') {
+               if (!&General::validport($settings{'TOR_RELAY_DIRPORT'})) {
+                       $errormessage = "$Lang::tr{'tor errmsg invalid directory port'}: $settings{'TOR_RELAY_DIRPORT'}";
+               }
+       }
 
        if ($settings{'TOR_RELAY_ADDRESS'} ne '') {
                if ((!&General::validfqdn($settings{'TOR_RELAY_ADDRESS'})) && (!&General::validip($settings{'TOR_RELAY_ADDRESS'}))) {
@@ -229,8 +236,8 @@ sub showMainBox() {
 
 
 if ( ($memory != 0) && (@pid[0] ne "///") ){
-               print "<table width='95%' cellspacing='0'>";
-               print "<tr><td bgcolor='$color{'color20'}' colspan='3' align='left'><strong>$Lang::tr{'tor service'}</strong></td></tr>";
+               print "<table width='95%' cellspacing='0' class='tbl'>";
+               print "<tr><th bgcolor='$color{'color20'}' colspan='3' align='left'><strong>$Lang::tr{'tor service'}</strong></th></tr>";
                print "<tr><td class='base'>$Lang::tr{'tor daemon'}</td>";
                print "<td align='center' colspan='2' width='75%' bgcolor='${Header::colourgreen}'><font color='white'><strong>$Lang::tr{'running'}</strong></font></td></tr>";
                print "<tr><td class='base'></td>";
@@ -241,8 +248,8 @@ if ( ($memory != 0) && (@pid[0] ne "///") ){
                print "<td bgcolor='$color{'color22'}' align='center'>$memory KB</td></tr>";
                print "</table>";
        } else {
-               print "<table width='95%' cellspacing='0'>";
-               print "<tr><td bgcolor='$color{'color20'}' colspan='3' align='left'><strong>$Lang::tr{'tor service'}</strong></td></tr>";
+               print "<table width='95%' cellspacing='0' class='tbl'>";
+               print "<tr><th bgcolor='$color{'color20'}' colspan='3' align='left'><strong>$Lang::tr{'tor service'}</strong></th></tr>";
                print "<tr><td class='base'>$Lang::tr{'tor daemon'}</td>";
                print "<td align='center' width='75%' bgcolor='${Header::colourred}'><font color='white'><strong>$Lang::tr{'stopped'}</strong></font></td></tr>";
                print "</table>";
@@ -260,7 +267,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>
@@ -317,9 +324,9 @@ END
                                                <option value=''>- $Lang::tr{'tor exit country any'} -</option>
 END
 
-               my @country_names = Locale::Country::all_country_names();
+               my @country_names = Locale::Codes::Country::all_country_names();
                foreach my $country_name (sort @country_names) {
-                       my $country_code = Locale::Country::country2code($country_name);
+                       my $country_code = Locale::Codes::Country::country2code($country_name);
                        $country_code = uc($country_code);
                        print "<option value='$country_code'";
 
@@ -380,23 +387,31 @@ 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'}' />
+                                       <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>
                        </tr>
                        <tr>
-                               <td width='25%' class='base'>$Lang::tr{'tor contact info'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
+                               <td width='25%'>&nbsp;</td>
+                               <td width='30%'>&nbsp;</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'}:</td>
                                <td width='75%' colspan='3'>
                                        <input type='text' name='TOR_RELAY_CONTACT_INFO' value='$settings{'TOR_RELAY_CONTACT_INFO'}' style='width: 98%;' />
                                </td>
@@ -417,9 +432,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";
                }
        }
 
@@ -427,7 +442,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>
@@ -440,9 +455,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;
@@ -470,9 +485,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>
@@ -607,10 +620,14 @@ END
 END
 
                                if (exists($node->{'country_code'})) {
-                                       if ($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 = &GeoIP::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'/>";
                                        }
                                }
 
@@ -683,6 +700,10 @@ sub BuildConfiguration() {
 
                print FILE "ORPort $settings{'TOR_RELAY_PORT'}\n";
 
+               if ($settings{'TOR_RELAY_DIRPORT'} ne '0') {
+                       print FILE "DirPort $settings{'TOR_RELAY_DIRPORT'}\n";
+               }
+
                if ($settings{'TOR_RELAY_ADDRESS'} ne '') {
                        print FILE "Address $settings{'TOR_RELAY_ADDRESS'}\n";
                }
@@ -957,7 +978,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)) {