]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/scripts/dialctrl.pl
3 # Dialup Statistics for IPFire
4 # based on SilverStar's work on
5 # http://goodymuc.go.funpic.de
8 require '/var/ipfire/general-functions.pl';
9 require "${General::swroot}/lang.pl";
10 require "${General::swroot}/header.pl";
12 ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst)=localtime();
20 if (length($monat) == 1)
28 if(length($hour) == 1)
41 my $s_date = $tag."/".$monat."/".$jahr;
42 my $s_time = $hour.":".$min.":".$sec;
43 my $file_log = "/var/log/counter/dialup.log";
44 my $file_connect = "/var/log/counter/connect";
45 my $file_reset = "/var/log/counter/reset";
47 if ($ARGV[0] eq 'up') {
48 if (! -e
"$file_log") {
51 open(CONNECT
,">$file_connect");
53 open(COUNTER
,"<$file_log");
55 ($start,$update,$up,$down,$rec,$on,$bit) = split(/\|/,$line);
58 $update = $s_date." on ".$s_time;
59 open(COUNTER
,">$file_log");
60 print COUNTER
"$start\|$update\|$up\|$down\|$rec\|$on\|$bit";
65 if ($ARGV[0] eq 'down') {
66 if (! -e
"$file_log") {
69 open(COUNTER
,"<$file_log");
71 ($start,$update,$up,$down,$rec,$on,$bit) = split(/\|/,$line);
73 $on =~ /(\d+)d\s+(\d+)h\s+(\d+)m\s+(\d+)s/;
74 $d1 = $1; $h1 = $2; $m1 = $3; $s1 = $4;
75 $con = &General
::age
("$file_connect");
76 $con =~ /(\d+)d\s+(\d+)h\s+(\d+)m\s+(\d+)s/;
77 $d2 = $1; $h2 = $2; $m2 = $3; $s2 = $4;
78 $sum_d = ($d1 + $d2) * 86400;
79 $sum_h = ($h1 + $h2) * 3600;
80 $sum_m = ($m1 + $m2) * 60;
82 $sum_1 = $sum_d + $sum_h + $sum_m + $sum_s;
83 $d = int($sum_1 / 86400);
84 $totalhours = int($sum_1 / 3600);
85 $h = $totalhours % 24;
86 $totalmins = int($sum_1 / 60);
89 $on = "${d}d ${h}h ${m}m ${s}s";
91 $update = $s_date." on ".$s_time;
92 open(COUNTER
,">$file_log");
93 print COUNTER
"$start\|$update\|$up\|$down\|$rec\|$on\|$bit";
98 if ($ARGV[0] eq 'rec') {
99 if (! -e
"$file_log") {
102 open(COUNTER
,"<$file_log");
104 ($start,$update,$up,$down,$rec,$on,$bit) = split(/\|/,$line);
107 $update = $s_date." on ".$s_time;
108 open(COUNTER
,">$file_log");
109 print COUNTER
"$start\|$update\|$up\|$down\|$rec\|$on\|$bit";
114 elsif ($ARGV[0] eq 'show') {
115 if (! -e
"$file_log") {
119 open(COUNTER
,"<$file_log");
121 ($start,$update,$up,$down,$rec,$on,$bit) = split(/\|/,$line);
122 $on =~ /(\d+)d\s+(\d+)h\s+(\d+)m\s+(\d+)s/;
123 $d1 = $1; $h1 = $2; $m1 = $3; $s1 = $4;
125 if ( ! -e
"${General::swroot}/red/active") {
126 $timecon = "0d 0h 0m 0s";
128 $timecon = &General
::age
("$file_connect");
130 $timecon =~ /(\d+)d\s+(\d+)h\s+(\d+)m\s+(\d+)s/;
131 $d2 = $1; $h2 = $2; $m2 = $3; $s2 = $4;
132 $timeres = &General
::age
("$file_reset");
133 $timeres =~ /(\d+)d\s+(\d+)h\s+(\d+)m\s+(\d+)s/;
134 $d3 = $1; $h3 = $2; $m3 = $3; $s3 = $4;
135 $sum_d1 = ($d1 + $d2) * 86400;
136 $sum_h1 = ($h1 + $h2) * 3600;
137 $sum_m1 = ($m1 + $m2) * 60;
138 $sum_s1 = ($s1 + $s2);
139 $sum_1 = $sum_d1 + $sum_h1 + $sum_m1 + $sum_s1;
140 $sum_d2 = $d3 * 86400;
141 $sum_h2 = $h3 * 3600;
144 $sum_2 = $sum_d2 + $sum_h2 + $sum_m2 + $sum_s2;
145 $d = int($sum_1 / 86400);
146 $totalhours = int($sum_1 / 3600);
147 $h = $totalhours % 24;
148 $totalmins = int($sum_1 / 60);
149 $m = $totalmins % 60;
151 $current = "${d}d ${h}h ${m}m ${s}s";
152 $ontime = ( $sum_1 * 100 ) / $sum_2;
153 if ($ontime >= 99.95) {
154 $ontime = sprintf("%.0f", $ontime);
156 elsif ($ontime <= 0.05) {
157 $ontime = sprintf("%.0f", $ontime);
160 $ontime = sprintf("%.1f", $ontime);
164 <br />$Lang::tr{'since'} $update
165 <table style='width:60%'>
166 <tr><td>$Lang::tr{'connections'}: $up</td><td>$Lang::tr{'disconnects'}: $down</td><td>$Lang::tr{'attemps'}: $rec</td></tr>
167 <tr><td><b>$Lang::tr{'total connection time'}:</b><td>$current</td><td> ~ $ontime%</td></tr>
174 elsif ($ARGV[0] eq 'reset') {
178 elsif ($ARGV[0] eq '') {
179 print "\nDont run on the console...\n\n";
185 open(COUNTER
,">$file_log");
186 $start = $s_date." on ".$s_time;
187 $update = "‹no action since clearing›";
193 print COUNTER
"$start\|$update\|$up\|$down\|$rec\|$on\|$bit";
195 open(CONNECT
,">$file_connect");
198 open(RESET
,">$file_reset");