From b8867fe89a7a51e225f54af380b3e4f4b1815771 Mon Sep 17 00:00:00 2001 From: Jan Paul Tuecking Date: Sun, 18 Aug 2013 12:11:58 +0200 Subject: [PATCH] tor: added daemon stats and little changes on styling --- html/cgi-bin/tor.cgi | 103 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 82 insertions(+), 21 deletions(-) mode change 100644 => 100755 html/cgi-bin/tor.cgi diff --git a/html/cgi-bin/tor.cgi b/html/cgi-bin/tor.cgi old mode 100644 new mode 100755 index 2a31dd4bf..a1d0ae72f --- a/html/cgi-bin/tor.cgi +++ b/html/cgi-bin/tor.cgi @@ -57,9 +57,42 @@ my @accounting_periods = ('daily', 'weekly', 'monthly'); my $TOR_CONTROL_PORT = 9051; +my $string=(); +my $memory=(); +my @memory=(); +my @pid=(); +my @tor=(); +sub daemonstats +{ + $memory = 0; + # for pid and memory + open(FILE, '/usr/local/bin/addonctrl tor status | '); + @tor = ; + close(FILE); + $string = join("", @tor); + $string =~ s/[a-z_]//gi; + $string =~ s/\[[0-1]\;[0-9]+//gi; + $string =~ s/[\(\)\.]//gi; + $string =~ s/ //gi; + $string =~ s///gi; + @pid = split(/\s/,$string); + if (open(FILE, "/proc/$pid[0]/statm")){ + my $temp = ; + @memory = split(/ /,$temp); + close(FILE); + } + $memory+=$memory[0]; +} +daemonstats(); + our %netsettings = (); &General::readhash("${General::swroot}/ethernet/settings", \%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); + our %settings = (); $settings{'TOR_ENABLED'} = 'off'; @@ -192,12 +225,37 @@ sub showMainBox() { print "
\n"; - &Header::openbox('100%', 'left', $Lang::tr{'tor configuration'}); + &Header::openbox('100%', 'center', $Lang::tr{'tor'}); + + +if ( ($memory != 0) && (@pid[0] ne "///") ){ + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print "
$Lang::tr{'tor service'}
$Lang::tr{'tor daemon'}$Lang::tr{'running'}
PID$Lang::tr{'memory'}
@pid[0]$memory KB
"; + } else { + print ""; + print ""; + print ""; + print ""; + print "
$Lang::tr{'tor service'}
$Lang::tr{'tor daemon'}$Lang::tr{'stopped'}
"; + } + + &Header::closebox(); + + &Header::openbox('100%', 'center', $Lang::tr{'tor configuration'}); print < + - + @@ -222,12 +280,11 @@ END print < -

-
$Lang::tr{'tor common settings'}$Lang::tr{'tor common settings'}
$Lang::tr{'tor enabled'}:
+
- +
$Lang::tr{'tor acls'}$Lang::tr{'tor acls'}
@@ -244,12 +301,11 @@ END

-

- +
- + @@ -276,7 +332,6 @@ END
$Lang::tr{'tor exit nodes'}$Lang::tr{'tor exit nodes'}
-

END &Header::closebox(); @@ -305,10 +360,10 @@ END } $selected{'TOR_RELAY_ACCOUNTING_PERIOD'}{$settings{'TOR_RELAY_ACCOUNTING_PERIOD'}} = 'selected'; - &Header::openbox('100%', 'left', $Lang::tr{'tor relay configuration'}); + &Header::openbox('100%', 'center', $Lang::tr{'tor relay configuration'}); print < +
$Lang::tr{'tor relay mode'}: @@ -342,11 +397,11 @@ END
-
+
- +
- + @@ -407,7 +462,7 @@ END &Header::closebox(); print < +
$Lang::tr{'tor bandwidth settings'}$Lang::tr{'tor bandwidth settings'}
$Lang::tr{'tor bandwidth rate'}:
* $Lang::tr{'this field may be blank'} @@ -418,7 +473,7 @@ END
- +
@@ -429,13 +484,13 @@ END # If we have a control connection, show the stats. if ($torctrl) { - &Header::openbox('100%', 'left', $Lang::tr{'tor stats'}); + &Header::openbox('100%', 'center', $Lang::tr{'tor stats'}); my @traffic = &TorTrafficStats($torctrl); if (@traffic) { print < +
 
END if ($settings{'TOR_RELAY_ENABLED'} eq 'on') { @@ -476,7 +531,7 @@ END my $accounting = &TorAccountingStats($torctrl); if ($accounting) { print < +
@@ -527,7 +582,7 @@ END if (@nodes) { my $nodes_length = scalar @nodes; print < +
$Lang::tr{'tor accounting'}
@@ -546,7 +601,11 @@ END END if (exists($node->{'country_code'})) { + if ($node->{'country_code'} eq '??') { + print ""; + } else { print "$node->{"; + } } print </dev/null"); } + # Update pid and memory + daemonstats(); } sub TorConnect() { -- 2.39.2
$Lang::tr{'tor connected relays'} ($nodes_length)