]>
Commit | Line | Data |
---|---|---|
f3bbb213 MT |
1 | #!/usr/bin/perl |
2 | # | |
3 | # Dialup Statistics for IPFire | |
4 | # based on SilverStar's work on | |
5 | # http://goodymuc.go.funpic.de | |
6 | # | |
7 | ||
8 | require '/var/ipfire/general-functions.pl'; | |
9 | require "${General::swroot}/lang.pl"; | |
10 | require "${General::swroot}/header.pl"; | |
11 | ||
12 | ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst)=localtime(); | |
13 | $jahr=$year; | |
14 | $monat=$mon+1; | |
15 | $tag=$mday; | |
16 | $jahr=$year; | |
17 | ||
18 | $jahr=$year +1900; | |
19 | ||
20 | if (length($monat) == 1) | |
21 | { | |
22 | $monat="0$monat"; | |
23 | } | |
24 | if(length($tag) == 1) | |
25 | { | |
26 | $tag="0$tag"; | |
27 | } | |
28 | if(length($hour) == 1) | |
29 | { | |
30 | $hour="0$hour"; | |
31 | } | |
32 | if(length($min) == 1) | |
33 | { | |
34 | $min="0$min"; | |
35 | } | |
36 | if(length($sec) == 1) | |
37 | { | |
38 | $sec="0$sec"; | |
39 | } | |
40 | ||
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"; | |
46 | ||
47 | if ($ARGV[0] eq 'up') { | |
48 | if (! -e "$file_log") { | |
49 | &new; | |
50 | } else { | |
51 | open(CONNECT,">$file_connect"); | |
52 | close(CONNECT); | |
53 | open(COUNTER,"<$file_log"); | |
54 | $line = <COUNTER>; | |
55 | ($start,$update,$up,$down,$rec,$on,$bit) = split(/\|/,$line); | |
56 | close(COUNTER); | |
57 | $up++; | |
58 | $update = $s_date." on ".$s_time; | |
59 | open(COUNTER,">$file_log"); | |
60 | print COUNTER "$start\|$update\|$up\|$down\|$rec\|$on\|$bit"; | |
61 | close(COUNTER); | |
62 | } | |
63 | } | |
64 | ||
65 | if ($ARGV[0] eq 'down') { | |
66 | if (! -e "$file_log") { | |
67 | &new; | |
68 | } else { | |
69 | open(COUNTER,"<$file_log"); | |
70 | $line = <COUNTER>; | |
71 | ($start,$update,$up,$down,$rec,$on,$bit) = split(/\|/,$line); | |
72 | close(COUNTER); | |
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; | |
81 | $sum_s = ($s1 + $s2); | |
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); | |
87 | $m = $totalmins % 60; | |
88 | $s = $sum_1 % 60; | |
89 | $on = "${d}d ${h}h ${m}m ${s}s"; | |
90 | $down++; | |
91 | $update = $s_date." on ".$s_time; | |
92 | open(COUNTER,">$file_log"); | |
93 | print COUNTER "$start\|$update\|$up\|$down\|$rec\|$on\|$bit"; | |
94 | close(COUNTER); | |
95 | } | |
96 | } | |
97 | ||
98 | if ($ARGV[0] eq 'rec') { | |
99 | if (! -e "$file_log") { | |
100 | &new; | |
101 | } else { | |
102 | open(COUNTER,"<$file_log"); | |
103 | $line = <COUNTER>; | |
104 | ($start,$update,$up,$down,$rec,$on,$bit) = split(/\|/,$line); | |
105 | close(COUNTER); | |
106 | $rec++; | |
107 | $update = $s_date." on ".$s_time; | |
108 | open(COUNTER,">$file_log"); | |
109 | print COUNTER "$start\|$update\|$up\|$down\|$rec\|$on\|$bit"; | |
110 | close(COUNTER); | |
111 | } | |
112 | } | |
113 | ||
114 | elsif ($ARGV[0] eq 'show') { | |
115 | if (! -e "$file_log") { | |
116 | &new; | |
117 | } | |
118 | else { | |
119 | open(COUNTER,"<$file_log"); | |
120 | $line = <COUNTER>; | |
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; | |
124 | close(COUNTER); | |
125 | if ( ! -e "${General::swroot}/red/active") { | |
126 | $timecon = "0d 0h 0m 0s"; | |
127 | } else { | |
128 | $timecon = &General::age("$file_connect"); | |
129 | } | |
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; | |
142 | $sum_m2 = $m3 * 60; | |
143 | $sum_s2 = $s3; | |
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; | |
150 | $s = $sum_1 % 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); | |
155 | } | |
156 | elsif ($ontime <= 0.05) { | |
157 | $ontime = sprintf("%.0f", $ontime); | |
158 | } | |
159 | else { | |
160 | $ontime = sprintf("%.1f", $ontime); | |
161 | } | |
162 | ||
163 | print <<END | |
e5a45b46 | 164 | <br />$Lang::tr{'since'} $update |
f3bbb213 | 165 | <tr><td colspan='3' align='center'>$Lang::tr{'connections'}: $up | $Lang::tr{'disconnects'}: $down | $Lang::tr{'attemps'}: $rec |
ab5cc762 | 166 | <tr><td><b>$Lang::tr{'total connection time'}:</b><td align='right'>$current<td align='left'> ~ $ontime% |
f3bbb213 MT |
167 | END |
168 | ; | |
169 | } | |
170 | } | |
171 | ||
172 | elsif ($ARGV[0] eq 'reset') { | |
173 | &new; | |
174 | } | |
175 | ||
176 | elsif ($ARGV[0] eq '') { | |
177 | print "\nDont run on the console...\n\n"; | |
178 | } | |
179 | ||
180 | exit 0; | |
181 | ||
182 | sub new { | |
183 | open(COUNTER,">$file_log"); | |
184 | $start = $s_date." on ".$s_time; | |
185 | $update = "‹no action since clearing›"; | |
186 | $up = "0"; | |
187 | $down = "0"; | |
188 | $rec = "0"; | |
189 | $on = "0d 0h 0m"; | |
190 | $bit = "0"; | |
191 | print COUNTER "$start\|$update\|$up\|$down\|$rec\|$on\|$bit"; | |
192 | close(COUNTER); | |
193 | open(CONNECT,">$file_connect"); | |
194 | print CONNECT "0"; | |
195 | close(CONNECT); | |
196 | open(RESET,">$file_reset"); | |
197 | print RESET "0"; | |
198 | close(RESET); | |
199 | } |