]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blobdiff - html/cgi-bin/tor.cgi
tor.cgi: Burst bandwidth may never be less than rate.
[people/teissler/ipfire-2.x.git] / html / cgi-bin / tor.cgi
index 6b4d9cc1b25b370905d5331f30c231dc70acd7c2..0c5477fd60fa7040046b6d0e19df20627ecf37fd 100644 (file)
@@ -51,8 +51,7 @@ my @bandwidth_limits = (
               1024, # 1M
                512,
                256,
               1024, # 1M
                512,
                256,
-               128,
-                64
+               160
 );
 my @accounting_periods = ('daily', 'weekly', 'monthly');
 
 );
 my @accounting_periods = ('daily', 'weekly', 'monthly');
 
@@ -88,9 +87,6 @@ my $warnmessage = '';
 
 &Header::showhttpheaders();
 
 
 &Header::showhttpheaders();
 
-# Load settings from file.
-&General::readhash("${General::swroot}/tor/settings", \%settings);
-
 # Get GUI values.
 &Header::getcgihash(\%settings);
 
 # Get GUI values.
 &Header::getcgihash(\%settings);
 
@@ -120,6 +116,14 @@ if ($settings{'ACTION'} eq $Lang::tr{'save'}) {
                }
        }
 
                }
        }
 
+       # Burst bandwidth must be less or equal to bandwidth rate.
+       if ($settings{'TOR_RELAY_BANDWIDTH_RATE'} == 0) {
+               $settings{'TOR_RELAY_BANDWIDTH_BURST'} = 0;
+
+       } elsif ($settings{'TOR_RELAY_BANDWIDTH_BURST'} < $settings{'TOR_RELAY_BANDWIDTH_RATE'}) {
+               $settings{'TOR_RELAY_BANDWIDTH_BURST'} = $settings{'TOR_RELAY_BANDWIDTH_RATE'};
+       }
+
        if ($errormessage eq '') {
                # Write configuration settings to file.
                &General::writehash("${General::swroot}/tor/settings", \%settings);
        if ($errormessage eq '') {
                # Write configuration settings to file.
                &General::writehash("${General::swroot}/tor/settings", \%settings);
@@ -132,6 +136,9 @@ if ($settings{'ACTION'} eq $Lang::tr{'save'}) {
        $settings{'ACTION'} = '';
 }
 
        $settings{'ACTION'} = '';
 }
 
+# Load settings from file.
+&General::readhash("${General::swroot}/tor/settings", \%settings);
+
 &showMainBox();
 
 # Close Tor control connection.
 &showMainBox();
 
 # Close Tor control connection.
@@ -171,21 +178,19 @@ sub showMainBox() {
                        </tr>
                        <tr>
                                <td width='25%' class='base'>$Lang::tr{'tor enabled'}:</td>
                        </tr>
                        <tr>
                                <td width='25%' class='base'>$Lang::tr{'tor enabled'}:</td>
-                               <td width='20%'><input type='checkbox' name='TOR_ENABLED' $checked{'TOR_ENABLED'}{'on'} /></td>
-                               <td width='25%' class='base'></td>
-                               <td width='30%'></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='20%'><input type='text' name='TOR_SOCKS_PORT' value='$settings{'TOR_SOCKS_PORT'}' size='5' /></td>
                        </tr>
                        <tr>
                                <td width='25%' class='base'>$Lang::tr{'tor relay enabled'}:</td>
                        </tr>
                        <tr>
                                <td width='25%' class='base'>$Lang::tr{'tor relay enabled'}:</td>
-                               <td width='20%'><input type='checkbox' name='TOR_RELAY_ENABLED' $checked{'TOR_RELAY_ENABLED'}{'on'} /></td>
+                               <td width='30%'><input type='checkbox' name='TOR_RELAY_ENABLED' $checked{'TOR_RELAY_ENABLED'}{'on'} /></td>
                                <td width='25%' class='base'></td>
                                <td width='25%' class='base'></td>
-                               <td width='30%'></td>
+                               <td width='20%'></td>
                        </tr>
                </table>
 END
 
                        </tr>
                </table>
 END
 
-       &Header::closebox();
-
        if ($settings{'TOR_ENABLED'} eq 'on') {
                my @temp = split(",", $settings{'TOR_ALLOWED_SUBNETS'});
                $settings{'TOR_ALLOWED_SUBNETS'} = join("\n", @temp);
        if ($settings{'TOR_ENABLED'} eq 'on') {
                my @temp = split(",", $settings{'TOR_ALLOWED_SUBNETS'});
                $settings{'TOR_ALLOWED_SUBNETS'} = join("\n", @temp);
@@ -193,18 +198,10 @@ END
                @temp = split(",", $settings{'TOR_USE_EXIT_NODES'});
                $settings{'TOR_USE_EXIT_NODES'} = join("\n", @temp);
 
                @temp = split(",", $settings{'TOR_USE_EXIT_NODES'});
                $settings{'TOR_USE_EXIT_NODES'} = join("\n", @temp);
 
-               &Header::openbox('100%', 'left', $Lang::tr{'tor configuration'});
-
                print <<END;
                print <<END;
-                       <table width='100%'>
-                               <tr>
-                                       <td width='25%' class='base'>$Lang::tr{'tor socks port'}:</td>
-                                       <td width='30%'><input type='text' name='TOR_SOCKS_PORT' value='$settings{'TOR_SOCKS_PORT'}' size='5' /></td>
-                                       <td width='50%' class='base' colspan='2'></td>
-                               </tr>
-                       </table>
-
+                       <br>
                        <hr size='1'>
                        <hr size='1'>
+                       <br>
 
                        <table width='100%'>
                                <tr>
 
                        <table width='100%'>
                                <tr>
@@ -224,7 +221,9 @@ END
                                </tr>
                        </table>
 
                                </tr>
                        </table>
 
+                       <br>
                        <hr size='1'>
                        <hr size='1'>
+                       <br>
 
                        <table width='100%'>
                                <tr>
 
                        <table width='100%'>
                                <tr>
@@ -250,16 +249,17 @@ END
                print <<END;
                                                </select>
                                        </td>
                print <<END;
                                                </select>
                                        </td>
-                                       <td colspan='2'>
+                                       <td width='50%' colspan='2'>
                                                <textarea name='TOR_USE_EXIT_NODES' cols='32' rows='3' wrap='off'>$settings{'TOR_USE_EXIT_NODES'}</textarea>
                                        </td>
                                </tr>
                        </table>
                                                <textarea name='TOR_USE_EXIT_NODES' cols='32' rows='3' wrap='off'>$settings{'TOR_USE_EXIT_NODES'}</textarea>
                                        </td>
                                </tr>
                        </table>
+                       <br><br>
 END
 END
-
-               &Header::closebox();
        }
 
        }
 
+       &Header::closebox();
+
        if ($settings{'TOR_RELAY_ENABLED'} eq 'on') {
                $checked{'TOR_RELAY_NOADVERTISE'}{'on'} = '';
                $checked{'TOR_RELAY_NOADVERTISE'}{'off'} = '';
        if ($settings{'TOR_RELAY_ENABLED'} eq 'on') {
                $checked{'TOR_RELAY_NOADVERTISE'}{'on'} = '';
                $checked{'TOR_RELAY_NOADVERTISE'}{'off'} = '';
@@ -516,10 +516,12 @@ END
 
                my @nodes = &TorORConnStatus($torctrl);
                if (@nodes) {
 
                my @nodes = &TorORConnStatus($torctrl);
                if (@nodes) {
+                       my $nodes_length = scalar @nodes;
                        print <<END;
                                <table width='100%'>
                                        <tr>
                        print <<END;
                                <table width='100%'>
                                        <tr>
-                                               <td colspan='3' class='base'><b>$Lang::tr{'tor connected relays'}</b></td>
+                                               <td width='40%' class='base'><b>$Lang::tr{'tor connected relays'}</b></td>
+                                               <td width='60%' colspan='2'>($nodes_length)</td>
                                        </tr>
 END
 
                                        </tr>
 END
 
@@ -678,9 +680,9 @@ sub BuildConfiguration() {
 
        # Restart the service.
        if (($settings{'TOR_ENABLED'} eq 'on') || ($settings{'TOR_RELAY_ENABLED'} eq 'on')) {
 
        # Restart the service.
        if (($settings{'TOR_ENABLED'} eq 'on') || ($settings{'TOR_RELAY_ENABLED'} eq 'on')) {
-               system("/usr/local/bin/torctrl restart");
+               system("/usr/local/bin/torctrl restart &>/dev/null");
        } else {
        } else {
-               system("/usr/local/bin/torctrl stop");
+               system("/usr/local/bin/torctrl stop &>/dev/null");
        }
 }
 
        }
 }