]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/qosgraph.cgi
Uploads.cgi entfernt. Die war noch ueber.
[ipfire-2.x.git] / html / cgi-bin / qosgraph.cgi
CommitLineData
268292e7
CS
1#!/usr/bin/perl
2#
3# SmoothWall CGIs
4#
5# This code is distributed under the terms of the GPL
6#
7# (c) The SmoothWall Team
8#
9#
10
11use strict;
12
13# enable only the following on debugging purpose
14use warnings;
15use CGI::Carp 'fatalsToBrowser';
16
17require '/var/ipfire/general-functions.pl';
18require "${General::swroot}/lang.pl";
19require "${General::swroot}/header.pl";
20require "${General::swroot}/graphs.pl";
21
22#workaround to suppress a warning when a variable is used only once
23my @dummy = ( ${Header::colourred} );
24undef (@dummy);
25
26my %qossettings = ();
27my %checked = ();
28my %netsettings = ();
29my $message = '';
30my $errormessage = "";
31my $c = "";
32my $direntry = "";
33my $classentry = "";
34my $subclassentry = "";
35my $l7ruleentry = "";
36my $portruleentry = "";
37my $tosruleentry = "";
38my @tmp = ();
39my @classes = ();
40my @subclasses = ();
41my @l7rules = ();
42my @portrules = ();
43my @tosrules = ();
44my @tmpline = ();
45my @classline = ();
46my @subclassline = ();
47my @l7ruleline = ();
48my @portruleline = ();
49my @tosruleline = ();
50my @proto = ();
51my %selected= ();
52my @checked = ();
53my $classfile = "/var/ipfire/qos/classes";
54my $subclassfile = "/var/ipfire/qos/subclasses";
55my $level7file = "/var/ipfire/qos/level7config";
56my $portfile = "/var/ipfire/qos/portconfig";
57my $tosfile = "/var/ipfire/qos/tosconfig";
58&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
59
60&overviewgraph($qossettings{'RED_DEV'});
61&overviewgraph($qossettings{'IMQ_DEV'});
62
63my %color = ();
64my %mainsettings = ();
65&General::readhash("${General::swroot}/main/settings", \%mainsettings);
66&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
67
68my %cgiparams=();
69# Maps a nice printable name to the changing part of the pid file, which
70# is also the name of the program
71
72
73# Generate Graphs from rrd Data
74&Graphs::updatecpugraph ("day");
75&Graphs::updateloadgraph ("day");
76
77&Header::showhttpheaders();
78&Header::getcgihash(\%cgiparams);
79&Header::openpage($Lang::tr{'status information'}, 1, '');
80&Header::openbigbox('100%', 'left');
81
82 open( FILE, "< $classfile" ) or die "Unable to read $classfile";
83 @classes = <FILE>;
84 close FILE;
85 open( FILE, "< $subclassfile" ) or die "Unable to read $subclassfile";
86 @subclasses = <FILE>;
87 close FILE;
88 &Header::openbox('100%', 'left', 'QoS Graphen');
89 print <<END
90 <table width='100%'> <tr><td align='center'><font color='red'>Diese Seite braucht je nach Geschwindigkeit des Computers laenger zum Laden.</font>
91 <tr><td align='center'><b>Klasse:</b>
92END
93;
94 foreach $classentry (sort @classes)
95 {
96 @classline = split( /\;/, $classentry );
97 $qossettings{'CLASS'}=$classline[1];
98 print <<END
99 <input type="button" onClick="swapVisibility('$qossettings{'CLASS'}')" value='$qossettings{'CLASS'}' />
100END
101;
102 }
103 print <<END
104 </table>
105END
106;
107 &Header::closebox();
108 foreach $classentry (sort @classes)
109 {
110 @classline = split( /\;/, $classentry );
111 $qossettings{'DEV'}=$classline[0];
112 $qossettings{'CLASS'}=$classline[1];
113 &gengraph($qossettings{'DEV'},$qossettings{'CLASS'});
114 print "<div id='$qossettings{'CLASS'}' style='display: none'>";
115 &Header::openbox('100%', 'center', "$qossettings{'CLASS'} ($qossettings{'DEV'})");
116 print <<END
117 <table>
118 <tr><td colspan='2' align='center'><img src='/graphs/class_$qossettings{'CLASSPRFX'}-$qossettings{'CLASS'}_$qossettings{'DEV'}-packets.png' />
119 <tr><td colspan='2' align='center'><img src='/graphs/class_$qossettings{'CLASSPRFX'}-$qossettings{'CLASS'}_$qossettings{'DEV'}-borrowed.png' />
120 <tr><td colspan='2' align='center'><img src='/graphs/class_$qossettings{'CLASSPRFX'}-$qossettings{'CLASS'}_$qossettings{'DEV'}-bytes.png' />
121END
122;
123 foreach $subclassentry (sort @subclasses)
124 {
125 @subclassline = split( /\;/, $subclassentry );
126 if ($subclassline[1] eq $classline[1]) {
127 $qossettings{'DEV'}=$subclassline[0];
128 $qossettings{'SCLASS'}=$subclassline[2];
129 &gengraph($qossettings{'DEV'},$qossettings{'SCLASS'});
130 print <<END
131 <tr><td colspan='2' align='center'><img src='/graphs/class_$qossettings{'CLASSPRFX'}-$qossettings{'SCLASS'}_$qossettings{'DEV'}-packets.png' />
132 <tr><td colspan='2' align='center'><img src='/graphs/class_$qossettings{'CLASSPRFX'}-$qossettings{'SCLASS'}_$qossettings{'DEV'}-borrowed.png' />
133 <tr><td colspan='2' align='center'><img src='/graphs/class_$qossettings{'CLASSPRFX'}-$qossettings{'SCLASS'}_$qossettings{'DEV'}-bytes.png' />
134END
135;
136 }
137 }
138 print "\t\t</table>";
139 &Header::closebox();
140 print "</div>\n";
141 }
142print <<END
143 </table>
144END
145;
146
147if (( -e "/srv/web/ipfire/html/graphs/qos-graph-$qossettings{'RED_DEV'}.png") && ( -e "/srv/web/ipfire/html/graphs/qos-graph-$qossettings{'IMQ_DEV'}.png")) {
148 print <<END
149 <tr><td colspan='9' align='center'><img alt="" src="/graphs/qos-graph-$qossettings{'RED_DEV'}.png" />
150 <tr><td colspan='9' align='center'><img alt="" src="/graphs/qos-graph-$qossettings{'IMQ_DEV'}.png" />
151END
152;}
153
154
155&Header::closebox();
156&Header::closebigbox();
157&Header::closepage();
158
159sub gengraph {
160 $qossettings{'DEV'} = shift;
161 $qossettings{'CLASS'} = shift;
162 my $ERROR="";
163 if ( $qossettings{'DEV'} eq $qossettings{'RED_DEV'} ) {
164 $qossettings{'CLASSPRFX'} = '1';
165 } else {
166 $qossettings{'CLASSPRFX'} = '2';
167 }
168 my $color=random_hex_color(6);
169
170 RRDs::graph ("/srv/web/ipfire/html/graphs/class_$qossettings{'CLASSPRFX'}-$qossettings{'CLASS'}_$qossettings{'DEV'}-packets.png",
171 "--start", "-3240", "-aPNG", "-i", "-z",
172 "--alt-y-grid", "-w 600", "-h 150", "-r",
173 "--color", "SHADEA#EAE9EE",
174 "--color", "SHADEB#EAE9EE",
175 "--color", "BACK#FFFFFF",
176 "-t $qossettings{'CLASS'} ($qossettings{'DEV'})",
177 "DEF:pkts=/var/log/rrd/class_$qossettings{'CLASSPRFX'}-$qossettings{'CLASS'}_$qossettings{'DEV'}.rrd:pkts:AVERAGE",
178 "DEF:dropped=/var/log/rrd/class_$qossettings{'CLASSPRFX'}-$qossettings{'CLASS'}_$qossettings{'DEV'}.rrd:dropped:AVERAGE",
179 "DEF:overlimits=/var/log/rrd/class_$qossettings{'CLASSPRFX'}-$qossettings{'CLASS'}_$qossettings{'DEV'}.rrd:overlimits:AVERAGE",
180 "AREA:pkts$color:packets",
181 "GPRINT:pkts:LAST:total packets\\:%8.3lf %s packets\\j",
182 "LINE3:dropped#FF0000:dropped",
183 "GPRINT:dropped:LAST:dropped packets\\:%8.3lf %s packets\\j",
184 "LINE3:overlimits#0000FF:overlimits",
185 "GPRINT:overlimits:LAST:overlimits\\:%8.3lf %s packets\\j",
186 );
187}
188
189
190sub overviewgraph {
191 $qossettings{'DEV'} = shift;
192 if ( $qossettings{'DEV'} eq $qossettings{'RED_DEV'} ) {
193 $qossettings{'CLASSPRFX'} = '1';
194 } else {
195 $qossettings{'CLASSPRFX'} = '2';
196 }
197 my $ERROR="";
198 my $count="1";
199 my $color="#000000";
200 my @command=("/srv/web/ipfire/html/graphs/qos-graph-$qossettings{'DEV'}.png",
201 "--start", "-3240", "-aPNG", "-i", "-z",
202 "--alt-y-grid", "-w 600", "-h 150", "-r",
203 "--color", "SHADEA#EAE9EE",
204 "--color", "SHADEB#EAE9EE",
205 "--color", "BACK#FFFFFF",
206 "-t Auslastung auf ($qossettings{'DEV'})"
207 );
208 open( FILE, "< $classfile" ) or die "Unable to read $classfile";
209 @classes = <FILE>;
210 close FILE;
211 foreach $classentry (sort @classes)
212 {
213 @classline = split( /\;/, $classentry );
214 if ( $classline[0] eq $qossettings{'DEV'} )
215 {
216 $color=random_hex_color(6);
217 push(@command, "DEF:$classline[1]=/var/log/rrd/class_$qossettings{'CLASSPRFX'}-$classline[1]_$qossettings{'DEV'}.rrd:bits:AVERAGE");
218
219 if ($count eq "1") {
220 push(@command, "AREA:$classline[1]$color:Klasse $classline[1] - $classline[8]\\j");
221 } else {
222 push(@command, "STACK:$classline[1]$color:Klasse $classline[1] - $classline[8]\\j");
223 }
224 $count++;
225 }
226 }
227 RRDs::graph (@command);
228}
229
230sub random_hex_color {
231 my $size = shift;
232 $size = 6 if $size !~ /^3|6$/;
233 my @hex = ( 0 .. 9, 'a' .. 'f' );
234 my @color;
235 push @color, @hex[rand(@hex)] for 1 .. $size;
236 return join('', '#', @color);
237}