]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/qos.cgi
Config: Fix calling b2sum
[ipfire-2.x.git] / html / cgi-bin / qos.cgi
CommitLineData
904a41b9 1#!/usr/bin/perl
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
57d4e488 5# Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
70df8302
MT
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
904a41b9 21
7ccede9b 22use RRDs;
904a41b9
MT
23use strict;
24# enable only the following on debugging purpose
e8babc92 25# use warnings;
33e1f48c 26# use CGI::Carp 'fatalsToBrowser';
904a41b9
MT
27
28require '/var/ipfire/general-functions.pl';
29require "${General::swroot}/lang.pl";
30require "${General::swroot}/header.pl";
0b1641db 31require "${General::swroot}/graphs.pl";
904a41b9 32
2db5d932
MT
33my %qossettings = ();
34my %checked = ();
35my %netsettings = ();
363fb6af 36my $message = '';
904a41b9 37my $errormessage = "";
2db5d932
MT
38my $c = "";
39my $direntry = "";
414e011d 40my $classentry = "";
414e011d 41my $l7ruleentry = "";
84cab473 42my $portruleentry = "";
e8babc92 43my $tosruleentry = "";
414e011d
MT
44my @tmp = ();
45my @classes = ();
414e011d 46my @l7rules = ();
84cab473 47my @portrules = ();
e8babc92 48my @tosrules = ();
414e011d
MT
49my @tmpline = ();
50my @classline = ();
414e011d 51my @l7ruleline = ();
84cab473 52my @portruleline = ();
e8babc92 53my @tosruleline = ();
2db5d932 54my @proto = ();
e8babc92
MT
55my %selected= ();
56my @checked = ();
414e011d 57my $classfile = "/var/ipfire/qos/classes";
414e011d 58my $level7file = "/var/ipfire/qos/level7config";
84cab473 59my $portfile = "/var/ipfire/qos/portconfig";
e8babc92 60my $tosfile = "/var/ipfire/qos/tosconfig";
904a41b9
MT
61&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
62
2db5d932 63$qossettings{'ENABLED'} = 'off';
414e011d 64$qossettings{'EDIT'} = 'no';
904a41b9
MT
65$qossettings{'OUT_SPD'} = '';
66$qossettings{'INC_SPD'} = '';
84cab473
MT
67$qossettings{'DEF_OUT_SPD'} = '';
68$qossettings{'DEF_INC_SPD'} = '';
2db5d932
MT
69$qossettings{'DEFCLASS_INC'} = '';
70$qossettings{'DEFCLASS_OUT'} = '';
4d17a269 71$qossettings{'RED_DEV'} = 'ppp0';
904a41b9 72$qossettings{'IMQ_DEV'} = 'imq0';
414e011d 73$qossettings{'VALID'} = 'yes';
84cab473
MT
74### Values that have to be initialized
75$qossettings{'ACTION'} = '';
76$qossettings{'ACTIONDEF'} = '';
77$qossettings{'ACTIONBW'} = '';
e8babc92
MT
78$qossettings{'RED_DEV_SEL'} = '';
79$qossettings{'IMQ_DEV_SEL'} = '';
84cab473
MT
80$qossettings{'PRIO'} = '';
81$qossettings{'SPD'} = '';
82$qossettings{'CLASS'} = '';
84cab473
MT
83$qossettings{'QPORT'} = '';
84$qossettings{'DPORT'} = '';
85$qossettings{'QIP'} = '';
86$qossettings{'DIP'} = '';
87$qossettings{'PPROT'} = '';
88$qossettings{'L7PROT'} = '';
89$qossettings{'DEVICE'} = '';
90$qossettings{'MINBWDTH'} = '';
91$qossettings{'MAXBWDTH'} = '';
92$qossettings{'BURST'} = '';
93$qossettings{'CBURST'} = '';
94$qossettings{'DOCLASS'} = '';
84cab473
MT
95$qossettings{'DOLEVEL7'} = '';
96$qossettings{'DOPORT'} = '';
7ccede9b
MT
97$qossettings{'CLASS'} = '';
98$qossettings{'CLASSPRFX'} = '';
99$qossettings{'DEV'} = '';
e8babc92 100$qossettings{'TOS'} = '';
ca26f732
MT
101$qossettings{'CAKE_PROFILE'} = 'conservative';
102
103my %CAKE_PROFILES = (
104 "ethernet" => $Lang::tr{'cake profile ethernet 38'},
105 "ethernet ether-vlan" => $Lang::tr{'cake profile ethernet vlan 42'},
106 "raw" => $Lang::tr{'cake profile raw 0'},
107 "conservative" => $Lang::tr{'cake profile conservative 48'},
108 "docsis" => $Lang::tr{'cake profile docsis 18'},
109 "bridged-ptm" => $Lang::tr{'cake profile bridged-ptm 19'},
110 "pppoe-ptm" => $Lang::tr{'cake profile pppoe-ptm 27'},
111 "pppoe-llcsnap" => $Lang::tr{'cake profile pppoe-llcsnap 40'},
112 "pppoe-vcmux" => $Lang::tr{'cake profile pppoe-vcmux 32'},
113 "pppoa-llc" => $Lang::tr{'cake profile pppoa-llc 14'},
114 "pppoa-vcmux" => $Lang::tr{'cake profile pppoa-vcmux 10'},
115 "bridged-llcsnap" => $Lang::tr{'cake profile bridged-llcsnap 32'},
116 "bridged-vcmux" => $Lang::tr{'cake profile bridged-vcmux 24'},
117 "ipoa-llcsnap" => $Lang::tr{'cake profile ipoa-llcsnap 16'},
118 "ipoa-vcmux" => $Lang::tr{'cake profile ipoa-vcmux 8'},
119);
904a41b9
MT
120
121&General::readhash("${General::swroot}/qos/settings", \%qossettings);
122&Header::getcgihash(\%qossettings);
123
12317449 124$qossettings{'RED_DEV'} = &General::get_red_interface();
4d17a269 125
f2fdd0c1
CS
126my %color = ();
127my %mainsettings = ();
128&General::readhash("${General::swroot}/main/settings", \%mainsettings);
8186b372 129&General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color);
f2fdd0c1 130
ca26f732
MT
131$selected{'CAKE_PROFILE'} = ();
132foreach my $key (keys %CAKE_PROFILES) {
133 $selected{'CAKE_PROFILE'}{$key} = '';
134}
135$selected{'CAKE_PROFILE'}{$qossettings{'CAKE_PROFILE'}} = 'selected';
136
4190b2a6 137&Header::showhttpheaders();
bcad0fd0 138
4190b2a6
LAH
139&Header::openpage('QoS', 1, '');
140&Header::openbigbox('100%', 'left', '', $errormessage);
904a41b9 141
84cab473
MT
142############################################################################################################################
143############################################################################################################################
144
145if ($qossettings{'DOCLASS'} eq $Lang::tr{'save'})
414e011d
MT
146{
147 &validclass();
148 &validminbwdth();
149 &validmaxbwdth();
150 if ( $qossettings{'VALID'} eq 'yes' ) {
151 open( FILE, ">> $classfile" ) or die "Unable to write $classfile";
152 print FILE <<END
f013ab2b 153$qossettings{'DEVICE'};$qossettings{'CLASS'};$qossettings{'PRIO'};$qossettings{'MINBWDTH'};$qossettings{'MAXBWDTH'};$qossettings{'BURST'};$qossettings{'CBURST'};$qossettings{'TOS'};$qossettings{'REMARK'};
414e011d
MT
154END
155;
156 close FILE;
157 } else {
65e8619a 158 $qossettings{'ACTION'} = $Lang::tr{'parentclass add'};
414e011d
MT
159 }
160}
65e8619a 161elsif ($qossettings{'DOCLASS'} eq $Lang::tr{'edit'})
414e011d
MT
162{
163 open( FILE, "< $classfile" ) or die "Unable to read $classfile";
164 @classes = <FILE>;
165 close FILE;
166 open( FILE, "> $classfile" ) or die "Unable to write $classfile";
167 foreach $classentry (sort @classes)
168 {
169 @classline = split( /\;/, $classentry );
170 if ( $classline[1] ne $qossettings{'CLASS'} ) {
171 print FILE $classentry;
172 } else {
173 $qossettings{'DEVICE'} = $classline[0];
174 $qossettings{'PRIO'} = $classline[2];
175 $qossettings{'MINBWDTH'} = $classline[3];
176 $qossettings{'MAXBWDTH'} = $classline[4];
177 $qossettings{'BURST'} = $classline[5];
178 $qossettings{'CBURST'} = $classline[6];
f013ab2b
MT
179 $qossettings{'TOS'} = $classline[7];
180 $qossettings{'REMARK'} = $classline[8];
414e011d
MT
181 $qossettings{'EDIT'} = 'yes';
182 }
183 }
184 close FILE;
185 &parentclass();
186 &Header::closebigbox();
187 &Header::closepage();
188 exit
189}
65e8619a 190elsif ($qossettings{'DOCLASS'} eq $Lang::tr{'delete'})
414e011d
MT
191{
192 open( FILE, "< $classfile" ) or die "Unable to read $classfile";
193 @tmp = <FILE>;
194 close FILE;
195 open( FILE, "> $classfile" ) or die "Unable to write $classfile";
196 foreach $classentry (sort @tmp)
197 {
198 @tmpline = split( /\;/, $classentry );
199 if ( $tmpline[1] ne $qossettings{'CLASS'} )
200 {
201 print FILE $classentry;
202 }
203 }
204 close FILE;
0b1641db 205 $message = "$Lang::tr{'Class'} $qossettings{'CLASS'} $Lang::tr{'Class was deleted'}";
414e011d 206}
84cab473
MT
207
208############################################################################################################################
209############################################################################################################################
210
84cab473 211if ($qossettings{'DOLEVEL7'} eq $Lang::tr{'save'})
414e011d
MT
212{
213 if ( $qossettings{'QIP'} ne '' ) {
5a7491ff
MT
214 if ((!&General::validipandmask($qossettings{'QIP'})) && (!&General::validip($qossettings{'QIP'}))) {
215 $qossettings{'VALID'} = 'no';
216 $message = $Lang::tr{'The source IP address is invalid.'};
414e011d
MT
217 }
218 }
219 if ( $qossettings{'DIP'} ne '' ) {
5a7491ff
MT
220 if ((!&General::validipandmask($qossettings{'DIP'})) && (!&General::validip($qossettings{'DIP'}))) {
221 $qossettings{'VALID'} = 'no';
222 $message = $Lang::tr{'The destination IP address is invalid.'};
414e011d
MT
223 }
224 }
225 if ($qossettings{'CLASS'} >= 100 && $qossettings{'CLASS'} < 121) {
226 $qossettings{'DEVICE'} = $qossettings{'RED_DEV'};
227 } elsif ($qossettings{'CLASS'} >= 1000 && $qossettings{'CLASS'} < 1021) {
228 $qossettings{'DEVICE'} = $qossettings{'RED_DEV'};
229 } elsif ($qossettings{'CLASS'} >= 200 && $qossettings{'CLASS'} < 221) {
230 $qossettings{'DEVICE'} = $qossettings{'IMQ_DEV'};
231 } elsif ($qossettings{'CLASS'} >= 2000 && $qossettings{'CLASS'} < 2021) {
232 $qossettings{'DEVICE'} = $qossettings{'IMQ_DEV'};
233 }
234 if ( $qossettings{'VALID'} eq 'yes' ) {
235 open( FILE, ">> $level7file" ) or die "Unable to write $level7file";
236 print FILE <<END
237$qossettings{'CLASS'};$qossettings{'DEVICE'};$qossettings{'L7PROT'};$qossettings{'QIP'};$qossettings{'DIP'};
238END
239;
240 close FILE;
241 } else {
65e8619a 242 $qossettings{'ACTION'} = $Lang::tr{'Add Level7 rule'};
414e011d 243 }
65e8619a 244} elsif ($qossettings{'DOLEVEL7'} eq $Lang::tr{'delete'})
414e011d
MT
245{
246 open( FILE, "< $level7file" ) or die "Unable to read $level7file";
247 @l7rules = <FILE>;
248 close FILE;
5b8ecec9 249 &General::system("rm", "$level7file");
414e011d
MT
250 foreach $l7ruleentry (sort @l7rules)
251 {
252 @l7ruleline = split( /\;/, $l7ruleentry );
399d32cb 253 if ( ($l7ruleline[0] eq $qossettings{'CLASS'}) && ($l7ruleline[2] eq $qossettings{'L7PROT'}))
65e8619a 254 {$message = "$Lang::tr{'Level7 Rule'} ($qossettings{'CLASS'} - $qossettings{'L7PROT'}) $Lang::tr{'was deleted'}.";}
399d32cb
CS
255 else
256 { open( FILE, ">> $level7file" ) or die "Unable to read $level7file";
257 print FILE $l7ruleentry;
258 close FILE;
259 }
260 }
5b8ecec9 261 open( FILE, "< $level7file" ) or &General::system("touch", "$level7file");close FILE;
65e8619a 262 } elsif ($qossettings{'DOLEVEL7'} eq $Lang::tr{'edit'})
399d32cb
CS
263{
264 open( FILE, "< $level7file" ) or die "Unable to read $level7file";
265 @l7rules = <FILE>;
414e011d 266 close FILE;
5b8ecec9 267 &General::system("rm", "$level7file");
399d32cb
CS
268 foreach $l7ruleentry (sort @l7rules)
269 {
270 @l7ruleline = split( /\;/, $l7ruleentry );
271 if ( ($l7ruleline[0] eq $qossettings{'CLASS'}) && ($l7ruleline[2] eq $qossettings{'L7PROT'}))
272 {$qossettings{'QIP'} = $l7ruleline[3];$qossettings{'DIP'} = $l7ruleline[4];}
273 else {
274 open( FILE, ">> $level7file" ) or die "Unable to write $level7file";
275 print FILE $l7ruleentry;
276 close FILE;
277 }
278 }
279 &level7rule;
5b8ecec9 280 open( FILE, "< $level7file" ) or &General::system("touch", "$level7file");close FILE;
399d32cb 281 }
84cab473
MT
282
283############################################################################################################################
284############################################################################################################################
285
286if ($qossettings{'DOPORT'} eq $Lang::tr{'save'})
287{
288 if ( $qossettings{'QIP'} ne '' ) {
5a7491ff 289 if ((!&General::validipandmask($qossettings{'QIP'})) && (!&General::validip($qossettings{'QIP'}))) {
84cab473 290 $qossettings{'VALID'} = 'no';
5a7491ff 291 $message = $Lang::tr{'The source IP address is invalid.'};
84cab473
MT
292 }
293 }
294 if ( $qossettings{'DIP'} ne '' ) {
5a7491ff 295 if ((!&General::validipandmask($qossettings{'DIP'})) && (!&General::validip($qossettings{'DIP'}))) {
84cab473 296 $qossettings{'VALID'} = 'no';
5a7491ff 297 $message = $Lang::tr{'The destination IP address is invalid.'};
84cab473
MT
298 }
299 }
300 if ($qossettings{'CLASS'} >= 100 && $qossettings{'CLASS'} < 121) {
301 $qossettings{'DEVICE'} = $qossettings{'RED_DEV'};
302 } elsif ($qossettings{'CLASS'} >= 1000 && $qossettings{'CLASS'} < 1021) {
303 $qossettings{'DEVICE'} = $qossettings{'RED_DEV'};
304 } elsif ($qossettings{'CLASS'} >= 200 && $qossettings{'CLASS'} < 221) {
305 $qossettings{'DEVICE'} = $qossettings{'IMQ_DEV'};
306 } elsif ($qossettings{'CLASS'} >= 2000 && $qossettings{'CLASS'} < 2021) {
307 $qossettings{'DEVICE'} = $qossettings{'IMQ_DEV'};
308 }
309 if ( $qossettings{'VALID'} eq 'yes' ) {
310 open( FILE, ">> $portfile" ) or die "Unable to write $portfile";
311 print FILE <<END
312$qossettings{'CLASS'};$qossettings{'DEVICE'};$qossettings{'PPROT'};$qossettings{'QIP'};$qossettings{'QPORT'};$qossettings{'DIP'};$qossettings{'DPORT'};
313END
314;
315 close FILE;
316 } else {
65e8619a 317 $qossettings{'ACTION'} = $Lang::tr{'Add Port Rule'};
84cab473 318 }
65e8619a 319} elsif ($qossettings{'DOPORT'} eq $Lang::tr{'delete'})
84cab473
MT
320{
321 open( FILE, "< $portfile" ) or die "Unable to read $portfile";
322 @portrules = <FILE>;
323 close FILE;
324 open( FILE, "> $portfile" ) or die "Unable to read $portfile";
325 foreach $portruleentry (sort @portrules)
326 {
327 @portruleline = split( /\;/, $portruleentry );
328 unless ( ($portruleline[0] eq $qossettings{'CLASS'}) && ($portruleline[2] eq $qossettings{'PPROT'}) && ($portruleline[3] eq $qossettings{'QIP'}) && ($portruleline[4] eq $qossettings{'QPORT'}) && ($portruleline[5] eq $qossettings{'DIP'}) && ($portruleline[6] eq $qossettings{'DPORT'}))
329 {
330 print FILE $portruleentry;
331 }
332 }
333 close FILE;
0b1641db 334 $message = "$Lang::tr{'Port Rule'} ($qossettings{'CLASS'} - $qossettings{'PPROT'}) $Lang::tr{'was deleted'}.";
65e8619a 335} elsif ($qossettings{'DOPORT'} eq $Lang::tr{'edit'})
399d32cb
CS
336{
337 open( FILE, "< $portfile" ) or die "Unable to read $portfile";
338 @portrules = <FILE>;
339 close FILE;
5b8ecec9 340 &General::system("rm", "$portfile");
399d32cb
CS
341 foreach $portruleentry (sort @portrules)
342 {
343 @portruleline = split( /\;/, $portruleentry );
344 if ( ($portruleline[0] eq $qossettings{'CLASS'}) && ($portruleline[2] eq $qossettings{'PPROT'}) && ($portruleline[3] eq $qossettings{'QIP'}) && ($portruleline[4] eq $qossettings{'QPORT'}) && ($portruleline[5] eq $qossettings{'DIP'}) && ($portruleline[6] eq $qossettings{'DPORT'}))
345 {$qossettings{'CLASS'}=$portruleline[0];$qossettings{'PPROT'}=$portruleline[2];$qossettings{'QIP'}=$portruleline[3];$qossettings{'QPORT'}=$portruleline[4];$qossettings{'DIP'}=$portruleline[5];$qossettings{'DPORT'}=$portruleline[6];}
346 else {
347 open( FILE, ">> $portfile" ) or die "Unable to write $portfile";
348 print FILE $portruleentry;
349 close FILE;
350 }
351 }
352 &portrule;
5b8ecec9 353 open( FILE, "< $portfile" ) or &General::system("touch", "$portfile");close FILE;
399d32cb 354 }
84cab473
MT
355
356############################################################################################################################
357############################################################################################################################
358
e8babc92
MT
359if ($qossettings{'DOTOS'} eq $Lang::tr{'save'})
360{
361 if ($qossettings{'CLASS'} >= 100 && $qossettings{'CLASS'} < 121) {
362 $qossettings{'DEVICE'} = $qossettings{'RED_DEV'};
363 } elsif ($qossettings{'CLASS'} >= 1000 && $qossettings{'CLASS'} < 1021) {
364 $qossettings{'DEVICE'} = $qossettings{'RED_DEV'};
365 } elsif ($qossettings{'CLASS'} >= 200 && $qossettings{'CLASS'} < 221) {
366 $qossettings{'DEVICE'} = $qossettings{'IMQ_DEV'};
367 } elsif ($qossettings{'CLASS'} >= 2000 && $qossettings{'CLASS'} < 2021) {
368 $qossettings{'DEVICE'} = $qossettings{'IMQ_DEV'};
369 }
370 open( FILE, ">> $tosfile" ) or die "Unable to write $tosfile";
371 print FILE <<END
372$qossettings{'CLASS'};$qossettings{'DEVICE'};$qossettings{'TOS'};
373END
374;
375 close FILE;
fcd5cb6f 376}
fc81e493 377elsif ($qossettings{'DOTOS'} eq $Lang::tr{'delete'})
e8babc92
MT
378{
379 open( FILE, "< $tosfile" ) or die "Unable to read $tosfile";
380 @tosrules = <FILE>;
381 close FILE;
382 open( FILE, "> $tosfile" ) or die "Unable to read $tosfile";
383 foreach $tosruleentry (sort @tosrules)
384 {
385 @tosruleline = split( /\;/, $tosruleentry );
386 unless ( ($tosruleline[0] eq $qossettings{'CLASS'}) && ($tosruleline[2] eq $qossettings{'TOS'}))
387 {
388 print FILE $tosruleentry;
389 }
390 }
391 close FILE;
0b1641db 392 $message = "$Lang::tr{'TOS Rule'} ($qossettings{'CLASS'} - $qossettings{'TOS'}) $Lang::tr{'was deleted'}.";
65e8619a 393} elsif ($qossettings{'DOTOS'} eq $Lang::tr{'edit'})
e8babc92
MT
394{
395 open( FILE, "< $tosfile" ) or die "Unable to read $tosfile";
396 @tosrules = <FILE>;
397 close FILE;
398 open( FILE, "> $tosfile" ) or die "Unable to write $tosfile";
399 foreach $tosruleentry (sort @tosrules)
400 {
401 @tosruleline = split( /\;/, $tosruleentry );
402 if (( $tosruleline[0] eq $qossettings{'CLASS'} ) && ( $tosruleline[2] eq $qossettings{'TOS'} )) {
403 $qossettings{'DEVICE'} = $tosruleline[1];
404 $qossettings{'CLASS'} = $tosruleline[0];
405 $qossettings{'TOS'} = $tosruleline[2];
406 $qossettings{'EDIT'} = 'yes';
407 } else {
408 print FILE $tosruleentry;
409 }
410 }
411 close FILE;
412 &tosrule();
413 &Header::closebigbox();
414 &Header::closepage();
415 exit
416}
417
418############################################################################################################################
419############################################################################################################################
420
65e8619a 421if ($qossettings{'ACTION'} eq $Lang::tr{'start'})
904a41b9 422{
8b6a7fde
CS
423 $qossettings{'ENABLED'} = 'on';
424 &General::writehash("${General::swroot}/qos/settings", \%qossettings);
5b8ecec9
MT
425 &General::system("/usr/local/bin/qosctrl", "generate");
426 &General::system("/usr/local/bin/qosctrl", "start");
427 &General::system("logger", "-t", "ipfire", "QoS started");
904a41b9 428}
65e8619a 429elsif ($qossettings{'ACTION'} eq $Lang::tr{'stop'})
904a41b9 430{
904a41b9
MT
431 $qossettings{'ENABLED'} = 'off';
432 &General::writehash("${General::swroot}/qos/settings", \%qossettings);
5b8ecec9
MT
433 &General::system("/usr/local/bin/qosctrl", "stop");
434 &General::system("/usr/local/bin/qosctrl", "generate");
435 &General::system("logger", "-t", "ipfire", "QoS stopped");
904a41b9 436}
65e8619a 437elsif ($qossettings{'ACTION'} eq $Lang::tr{'restart'})
84cab473
MT
438{
439 if ($qossettings{'ENABLED'} eq 'on'){
5b8ecec9
MT
440 &General::system("/usr/local/bin/qosctrl", "stop");
441 &General::system("/usr/local/bin/qosctrl", "generate");
442 &General::system("/usr/local/bin/qosctrl", "start");
443 &General::system("logger", "-t", "ipfire", "QoS restarted");
84cab473
MT
444 }
445}
904a41b9
MT
446elsif ($qossettings{'ACTION'} eq $Lang::tr{'save'})
447{
84cab473
MT
448 if ($qossettings{'DEF_INC_SPD'} eq '') {
449 $qossettings{'DEF_INC_SPD'} = int($qossettings{'INC_SPD'} * 0.9);
450 }
451 if ($qossettings{'DEF_OUT_SPD'} eq '') {
452 $qossettings{'DEF_OUT_SPD'} = int($qossettings{'OUT_SPD'} * 0.9);
453 }
904a41b9
MT
454 &General::writehash("${General::swroot}/qos/settings", \%qossettings);
455}
33e1f48c
CS
456elsif ($qossettings{'ACTION'} eq $Lang::tr{'template'} )
457{
40d3e729
MT
458 if (($qossettings{'OUT_SPD'} > 0) && ($qossettings{'INC_SPD'} > 0)) {
459 my @UP;
460 #print "UP<br />";
461 for(my $i = 1; $i <= 10; $i++) {
462 $UP[$i] = int($qossettings{'OUT_SPD'} / $i );
463 #print $i."=".$UP[$i]." ";
464 }
465 my @DOWN;
466 #print "<br /><br />Down<br />";
467 for(my $i = 1; $i <= 20; $i++) {
468 $DOWN[$i] = int($qossettings{'INC_SPD'} / $i);
469 #print $i."=".$DOWN[$i]." ";
470 }
471 open( FILE, "> $classfile" ) or die "Unable to write $classfile";
472 print FILE <<END
20ffa7d1 473imq0;200;1;$DOWN[20];$DOWN[1];;;8;VoIP;
33e1f48c
CS
474imq0;203;4;$DOWN[20];$DOWN[1];;;0;VPN;
475imq0;204;5;$DOWN[20];$DOWN[1];;;8;Webtraffic;
99a6f5f9 476imq0;210;6;1;$DOWN[1];;;0;Default;
20ffa7d1
DW
477$qossettings{'RED_DEV'};101;1;$UP[10];$UP[1];;;8;ACKs;
478$qossettings{'RED_DEV'};102;2;$UP[10];$UP[1];;;8;VoIP;
479$qossettings{'RED_DEV'};103;4;$UP[10];$UP[1];;;2;VPN;
fcd5cb6f 480$qossettings{'RED_DEV'};104;5;$UP[10];$UP[1];;;8;Webtraffic;
99a6f5f9 481$qossettings{'RED_DEV'};110;6;1;$UP[1];;;0;Default;
33e1f48c
CS
482END
483;
40d3e729
MT
484 close FILE;
485 open( FILE, "> $level7file" ) or die "Unable to write $level7file";
486 print FILE <<END
fcd5cb6f 487102;$qossettings{'RED_DEV'};dns;;;
21067331 488102;$qossettings{'RED_DEV'};rtp;;;
fcd5cb6f
MT
489102;$qossettings{'RED_DEV'};skypetoskype;;;
490103;$qossettings{'RED_DEV'};ssh;;;
491103;$qossettings{'RED_DEV'};rdp;;;
492104;$qossettings{'RED_DEV'};http;;;
493104;$qossettings{'RED_DEV'};ssl;;;
494104;$qossettings{'RED_DEV'};pop3;;;
fcd5cb6f
MT
495120;$qossettings{'RED_DEV'};applejuice;;;
496120;$qossettings{'RED_DEV'};bittorrent;;;
21067331 497200;imq0;rtp;;;
33e1f48c
CS
498200;imq0;skypetoskype;;;
499203;imq0;ssh;;;
500203;imq0;rdp;;;
501204;imq0;http;;;
502204;imq0;pop3;;;
503204;imq0;ssl;;;
504220;imq0;applejuice;;;
505220;imq0;bittorrent;;;
33e1f48c
CS
506END
507;
40d3e729
MT
508 close FILE;
509 open( FILE, "> $portfile" ) or die "Unable to write $portfile";
510 print FILE <<END
fcd5cb6f
MT
511101;$qossettings{'RED_DEV'};icmp;;;;;
512102;$qossettings{'RED_DEV'};tcp;;;;53;
513102;$qossettings{'RED_DEV'};udp;;;;53;
514103;$qossettings{'RED_DEV'};esp;;;;;
8de8a508
AF
515103;$qossettings{'RED_DEV'};tcp;;1194;;;
516103;$qossettings{'RED_DEV'};udp;;1194;;;
fcd5cb6f 517103;$qossettings{'RED_DEV'};tcp;;;;1194;
99a6f5f9 518103;$qossettings{'RED_DEV'};udp;;;;1194;
fcd5cb6f
MT
519103;$qossettings{'RED_DEV'};udp;;4500;;4500;
520103;$qossettings{'RED_DEV'};udp;;500;;500;
521104;$qossettings{'RED_DEV'};tcp;;;;80;
33e1f48c
CS
522200;imq0;icmp;;;;;
523203;imq0;esp;;;;;
524203;imq0;tcp;;;;1194;
773362c5 525203;imq0;udp;;;;1194;
8de8a508
AF
526203;imq0;tcp;;1194;;;
527203;imq0;udp;;1194;;;
33e1f48c
CS
528203;imq0;udp;;4500;;4500;
529203;imq0;udp;;500;;500;
8de8a508 530204;imq0;tcp;;80;;;
33e1f48c
CS
531END
532;
40d3e729
MT
533 close FILE;
534 if ($qossettings{'DEF_INC_SPD'} eq '') {
535 $qossettings{'DEF_INC_SPD'} = int($qossettings{'INC_SPD'} * 0.9);
536 }
537 if ($qossettings{'DEF_OUT_SPD'} eq '') {
538 $qossettings{'DEF_OUT_SPD'} = int($qossettings{'OUT_SPD'} * 0.9);
539 }
540 $qossettings{'DEFCLASS_INC'} = "210";
541 $qossettings{'DEFCLASS_OUT'} = "110";
40d3e729
MT
542 $qossettings{'ENABLED'} = 'on';
543 &General::writehash("${General::swroot}/qos/settings", \%qossettings);
5b8ecec9
MT
544 &General::system("/usr/local/bin/qosctrl", "generate");
545 &General::system("/usr/local/bin/qosctrl", "start");
546 &General::system("logger", "-t", "ipfire", "QoS started");
40d3e729
MT
547 } else {
548 $message = $Lang::tr{'qos enter bandwidths'};
33e1f48c 549 }
33e1f48c 550}
65e8619a 551elsif ($qossettings{'ACTION'} eq $Lang::tr{'status'} )
92b5fba4
MT
552{
553 &Header::openbox('100%', 'left', 'QoS Status');
554 if ($qossettings{'ENABLED'} eq 'on'){
555 my $output = "";
12317449 556 my @output = &General::system_output("/usr/local/bin/qosctrl", "status");
c4522a17 557 $output = &Header::cleanhtml(join("", @output), "y");
92b5fba4 558 print "<pre>$output</pre>\n";
0b1641db 559 } else { print "$Lang::tr{'QoS not enabled'}"; }
92b5fba4
MT
560 &Header::closebox();
561 &Header::closebigbox();
562 &Header::closepage();
563 exit
564}
65e8619a 565elsif ($qossettings{'ACTION'} eq $Lang::tr{'parentclass add'} )
2db5d932
MT
566{
567 &parentclass();
568 &Header::closebigbox();
569 &Header::closepage();
570 exit
571}
65e8619a 572elsif ($qossettings{'ACTION'} eq $Lang::tr{'Add Rule'})
2db5d932 573{
0b1641db 574 &Header::openbox('100%', 'center', $Lang::tr{'Add Rule'});
e8babc92
MT
575 print <<END
576 <table>
0b1641db 577 <tr><td align='center'>$Lang::tr{'Choose Rule'}
e8babc92 578 <tr><td align='center'>
65e8619a
JPT
579 <input type="button" onClick="swapVisibility('l7rule')" value='$Lang::tr{'Level7 Rule'}' />
580 <input type="button" onClick="swapVisibility('portrule')" value='$Lang::tr{'Port Rule'}' />
581 <input type="button" onClick="swapVisibility('tosrule')" value='$Lang::tr{'TOS rule'}' />
e8babc92
MT
582 </table>
583END
584;
585 &Header::closebox();
586 print <<END
587 <div id='l7rule' style='display: none'>
588END
589;
590 &level7rule();
591 print <<END
592 </div>
593 <div id='portrule' style='display: none'>
594END
595;
596 &portrule();
597 print <<END
598 </div>
599 <div id='tosrule' style='display: none'>
600END
601;
602 &tosrule();
603 print <<END
604 </div>
605END
606;
414e011d
MT
607 &Header::closebigbox();
608 &Header::closepage();
609 exit
610}
1dd22be2 611if ($qossettings{'ACTIONBW'} eq "$Lang::tr{'modify'}" )
904a41b9 612{
2db5d932
MT
613 &changebandwidth();
614 &Header::closebigbox();
615 &Header::closepage();
616 exit
617}
1dd22be2 618if ($qossettings{'ACTIONDEF'} eq "$Lang::tr{'modify'}" )
2db5d932
MT
619{
620 &changedefclasses();
904a41b9
MT
621 &Header::closebigbox();
622 &Header::closepage();
623 exit
624}
625
626&General::readhash("${General::swroot}/qos/settings", \%qossettings);
627
628my $status = $Lang::tr{'stopped'};
84cab473 629my $statuscolor = '#993333';
904a41b9
MT
630if ( $qossettings{'ENABLED'} eq 'on' ) {
631 $status = $Lang::tr{'running'};
84cab473 632 $statuscolor = '#339933';
904a41b9
MT
633}
634
635if ( $netsettings{'RED_TYPE'} ne 'PPPOE' ) {
636 $qossettings{'RED_DEV'} = $netsettings{'RED_DEV'};
637}
638
639if ($errormessage) {
640 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
641 print "<class name='base'>$errormessage\n";
642 print "&nbsp;</class>\n";
643 &Header::closebox();
644}
645
414e011d
MT
646############################################################################################################################
647############################################################################################################################
648
5ef70cca 649&Header::openbox('100%', 'center', );
f013ab2b 650
904a41b9 651print <<END
f841744c
CS
652 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
653 <table width='66%'>
414e011d
MT
654END
655;
656 if ( $message ne "" ) {
5ef70cca 657 print "<tr><td colspan='2' align='center'><font color='red'>$message</font></tr>";
414e011d
MT
658 }
659 print <<END
5ef70cca
AM
660 <tr><td width='50%' align='left'><b>Quality of Service:</b></td>
661 <td width='50%' align='center' bgcolor='$statuscolor'><font color='white'>$status</font></td></tr>
662 <tr>
663 <td colspan='2'><br></td>
664 </tr>
665 <tr><td width='100%' align='right' colspan='2'>
666 <input type='submit' name='ACTION' value="$Lang::tr{'start'}">
667 <input type='submit' name='ACTION' value="$Lang::tr{'stop'}">
668 <input type='submit' name='ACTION' value="$Lang::tr{'restart'}" ></td></tr></table></form>
904a41b9
MT
669END
670;
671 if (($qossettings{'OUT_SPD'} ne '') && ($qossettings{'INC_SPD'} ne '')) {
672 print <<END
f841744c
CS
673 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
674 <table width='66%'>
904a41b9 675 <tr><td colspan='3'>&nbsp;
1b73b07e 676 <tr><td width='50%' align='right'>$Lang::tr{'downlink speed'}: <td width='30%' align='left'>$qossettings{'INC_SPD'}
1dd22be2 677 <td width='20%' rowspan='2' align='center' valign='middle'><input type='submit' name='ACTIONBW' value='$Lang::tr{'modify'}' />
1b73b07e 678 <tr><td width='50%' align='right'>$Lang::tr{'uplink speed'}: <td width='30%' align='left'>$qossettings{'OUT_SPD'}
f841744c 679 </table></form>
2db5d932
MT
680END
681;
682 }
0bb882c4 683 if (($qossettings{'DEFCLASS_OUT'} ne '') && ($qossettings{'DEFCLASS_INC'} ne '')) {
2db5d932 684 print <<END
f841744c
CS
685 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
686 <table width='66%'>
f013ab2b 687 <tr><td colspan='3'><hr />
fcd5cb6f 688 <tr><td width='50%' align='right'>$Lang::tr{'downlink std class'}: <td width='30%' align='left'>$qossettings{'DEFCLASS_INC'}
1dd22be2 689 <td width='20%' rowspan='3' align='center' valign='middle'><input type='submit' name='ACTIONDEF' value='$Lang::tr{'modify'}' />
1b73b07e 690 <tr><td width='50%' align='right'>$Lang::tr{'uplink std class'}: <td width='30%' align='left'>$qossettings{'DEFCLASS_OUT'}
f013ab2b 691 <tr><td colspan='3' width='100%'><hr />
7ccede9b 692 <tr><td colspan='3' width='100%' align='center'>
f841744c
CS
693 </table>
694 </form>
695 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
48d9bbba
SS
696 <table width='66%' border='0'>
697 <tr><td width='100%' align='center'>
698 <input type='submit' name='ACTION' value='$Lang::tr{'parentclass add'}' />
699 <input type='submit' name='ACTION' value='$Lang::tr{'status'}' />
700 </td></tr></table>
414e011d 701 </form>
904a41b9
MT
702END
703;
704 }
904a41b9
MT
705&Header::closebox();
706
707if ( ($qossettings{'OUT_SPD'} eq '') || ($qossettings{'INC_SPD'} eq '') ) {
2db5d932 708 &changebandwidth();
2db5d932
MT
709 &Header::closebigbox();
710 &Header::closepage();
711 exit
712}
713
0bb882c4 714if ( ($qossettings{'DEFCLASS_INC'} eq '') || ($qossettings{'DEFCLASS_OUT'} eq '') ) {
2db5d932
MT
715 &changedefclasses();
716 &Header::closebigbox();
717 &Header::closepage();
718 exit
719}
720
4190b2a6
LAH
721&Header::openbox('100%', 'center', "$qossettings{'RED_DEV'} $Lang::tr{'graph'}, $Lang::tr{'uplink'}");
722&Graphs::makegraphbox("qos.cgi",$qossettings{'RED_DEV'},"hour");
723&Header::closebox();
724&Header::openbox('100%', 'center', "$qossettings{'IMQ_DEV'} $Lang::tr{'graph'}, $Lang::tr{'downlink'}");
725&Graphs::makegraphbox("qos.cgi",$qossettings{'IMQ_DEV'},"hour");
726&Header::closebox();
f013ab2b
MT
727
728&showclasses($qossettings{'RED_DEV'});
729&showclasses($qossettings{'IMQ_DEV'});
2db5d932 730
904a41b9
MT
731&Header::closebigbox();
732&Header::closepage();
904a41b9 733
414e011d
MT
734############################################################################################################################
735############################################################################################################################
2db5d932
MT
736
737sub changedefclasses {
0b1641db 738 &Header::openbox('100%', 'center', $Lang::tr{'std classes'});
904a41b9 739 print <<END
2db5d932
MT
740 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
741 <table width='66%'>
0b1641db 742 <tr><td width='100%' colspan='3'>$Lang::tr{'no filter pass'}
597005f5 743 <tr><td width='33%' align='right'>$Lang::tr{'download'}:<td width='33%' align='left'><select name='DEFCLASS_INC'>
2db5d932
MT
744END
745;
414e011d 746 for ( $c = 200 ; $c <= 220 ; $c++ )
2db5d932
MT
747 {
748 if ( $qossettings{'DEFCLASS_INC'} ne $c )
fcd5cb6f 749 { print "<option value='$c'>$c</option>\n"; }
414e011d 750 else { print "<option selected value='$c'>$c</option>\n"; }
2db5d932
MT
751 }
752 print <<END
753 </select><td width='33%' align='center'>&nbsp;
597005f5 754 <tr><td width='33%' align='right'>$Lang::tr{'upload'}:<td width='33%' align='left'><select name='DEFCLASS_OUT'>
2db5d932
MT
755END
756;
414e011d 757 for ( $c = 100 ; $c <= 120 ; $c++ )
2db5d932
MT
758 {
759 if ( $qossettings{'DEFCLASS_OUT'} ne $c )
414e011d
MT
760 { print "<option value='$c'>$c</option>\n"; }
761 else { print "<option selected value='$c'>$c</option>\n"; }
2db5d932
MT
762 }
763 print <<END
f013ab2b 764 </select><td width='33%' align='center'><input type='submit' name='ACTION' value="$Lang::tr{'save'}" />
2db5d932
MT
765 </table>
766 </form>
904a41b9
MT
767END
768;
3a70a538 769 &Header::closebox();
2db5d932
MT
770}
771
772sub changebandwidth {
2f6232d5 773 &Header::openbox('100%', 'center', $Lang::tr{'bandwidthsettings'});
2d42f1df 774
2db5d932 775 if ($qossettings{'ENABLED'} eq 'on') {
2f6232d5 776 print "$Lang::tr{'bandwidtherror'}";
57d4e488 777 print "<table width='100%'><tr><td align='center'><a href='/cgi-bin/qos.cgi'><img src='/images/back.png' alt='$Lang::tr{'back'}' title='$Lang::tr{'back'}' /></a></td></tr></table>";
2db5d932 778 } else {
2d42f1df
MT
779 print <<END;
780 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
781 <input type='hidden' name='DEF_OUT_SPD' value='' /><input type='hidden' name='DEF_INC_SPD' value='' />
782 <table width='66%'>
783 <tr>
ca26f732 784 <td width='100%' colspan='2'>$Lang::tr{'down and up speed'}</td>
2d42f1df
MT
785 </tr>
786 <tr>
787 <td width='50%' align='right'>$Lang::tr{'downlink speed'}:</td>
ca26f732 788 <td width='50%' align='left'>
2d42f1df
MT
789 <input type='text' name='INC_SPD' maxlength='8' value="$qossettings{'INC_SPD'}" />
790 </td>
2d42f1df
MT
791 </tr>
792 <tr>
793 <td width='50%' align='right'>$Lang::tr{'uplink speed'}:</td>
ca26f732 794 <td width='50%' align='left'>
2d42f1df
MT
795 <input type='text' name='OUT_SPD' maxlength='8' value="$qossettings{'OUT_SPD'}" />
796 </td>
797 </tr>
ca26f732
MT
798
799 <tr>
800 <td colspan="2">&nbsp;</td>
801 </tr>
802
803 <tr>
804 <td width='50%' align='right'>$Lang::tr{'link-layer encapsulation'}:</td>
805 <td width='50%' align='left'>
806 <select name="CAKE_PROFILE">
807END
808
809 foreach my $key (sort { $CAKE_PROFILES{$a} cmp $CAKE_PROFILES{$b} } keys %CAKE_PROFILES) {
810 print <<END;
811 <option value="$key" $selected{'CAKE_PROFILE'}{$key}>$CAKE_PROFILES{$key}</option>
812END
813 }
814
815 print <<END;
816 </select>
817 </td>
818 </tr>
819
820 <tr>
821 <td colspan="2">&nbsp;</td>
822 </tr>
823
824 <tr>
825 <td width='100%' align='center' colspan="2">
826 <input type='submit' name='ACTION' value="$Lang::tr{'template'}" />
827 <input type='submit' name='ACTION' value="$Lang::tr{'save'}" />
828 <input type='reset' name='ACTION' value="$Lang::tr{'reset'}" />
829 </td>
830 </tr>
2d42f1df
MT
831 </table>
832 </form>
833 <font color='red'>$Lang::tr{'template warning'}</font>
2db5d932 834END
2db5d932 835 }
2d42f1df 836
904a41b9 837 &Header::closebox();
904a41b9
MT
838}
839
2db5d932 840sub parentclass {
0b1641db 841 &Header::openbox('100%', 'center', $Lang::tr{'parentclass'});
2db5d932
MT
842 print <<END
843 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
844 <table width='66%'>
414e011d
MT
845END
846;
847 if ( $message ne "" ) {
848 print "<tr><td colspan='3' align='center'>$message";
849 }
fcd5cb6f 850 if ( $qossettings{'EDIT'} eq 'yes' ) {
18322edf
CS
851 print "<input type='hidden' name='CLASS' value='$qossettings{'CLASS'}' />";
852 print "<input type='hidden' name='DEVICE' value='$qossettings{'DEVICE'}' />";
414e011d
MT
853 }
854 print <<END
0b1641db
CS
855 <tr><td width='100%' colspan='3'>$Lang::tr{'enter data'}
856 <tr><td width='33%' align='right'>$Lang::tr{'interface'}:
414e011d
MT
857 <td width='33%' align='left'>
858END
859;
fcd5cb6f 860 if ( $qossettings{'EDIT'} eq 'yes' ) {
414e011d
MT
861 print "<select name='DEVICE' disabled>";
862 } else {
863 print "<select name='DEVICE'>";
864 }
865 if ( $qossettings{'DEVICE'} eq $qossettings{'RED_DEV'} ) {
866 $qossettings{'RED_DEV_SEL'} = 'selected';
867 } elsif ( $qossettings{'DEVICE'} eq $qossettings{'IMQ_DEV'} ) {
868 $qossettings{'IMQ_DEV_SEL'} = 'selected';
869 }
870 print <<END
18322edf
CS
871 <option value='$qossettings{'RED_DEV'}' $qossettings{'RED_DEV_SEL'}>$qossettings{'RED_DEV'}</option>
872 <option value='$qossettings{'IMQ_DEV'}' $qossettings{'IMQ_DEV_SEL'}>$qossettings{'IMQ_DEV'}</option></select>
2db5d932 873 <td width='33%' align='center'>&nbsp;
0b1641db 874 <tr><td width='33%' align='right'>$Lang::tr{'Class'}:<td width='33%' align='left'>
2db5d932
MT
875END
876;
fcd5cb6f 877 if ( $qossettings{'EDIT'} eq 'yes' ) {
414e011d
MT
878 print "<select name='CLASS' disabled>";
879 } else {
880 print "<select name='CLASS'>";
881 }
2db5d932
MT
882 for ( $c = 100 ; $c <= 120 ; $c++ )
883 {
884 if ( $qossettings{'CLASS'} ne $c )
414e011d
MT
885 { print "<option value='$c'>$c</option>\n"; }
886 else { print "<option selected value='$c'>$c</option>\n"; }
2db5d932
MT
887 }
888 for ( $c = 200 ; $c <= 220 ; $c++ )
889 {
890 if ( $qossettings{'CLASS'} ne $c )
414e011d
MT
891 { print "<option value='$c'>$c</option>\n"; }
892 else { print "<option selected value='$c'>$c</option>\n"; }
2db5d932
MT
893 }
894 print <<END
895 </select>
896 <td width='33%' align='center'>&nbsp;
0b1641db 897 <tr><td width='33%' align='right'>$Lang::tr{'priority'}:<td width='33%' align='left'><select name='PRIO'>
2db5d932
MT
898END
899;
900 for ( $c = 1 ; $c <= 7 ; $c++ )
901 {
902 if ( $qossettings{'PRIO'} ne $c )
414e011d
MT
903 { print "<option value='$c'>$c</option>\n"; }
904 else { print "<option selected value='$c'>$c</option>\n"; }
2db5d932 905 }
f013ab2b 906 if ($qossettings{'MINBWDTH'} eq "") { $qossettings{'MINBWDTH'} = "1"; }
2db5d932 907 print <<END
f013ab2b 908 </select>
2db5d932 909 <td width='33%' align='center'>&nbsp;
2f6232d5 910 <tr><td width='33%' align='right'>$Lang::tr{'guaranteed bandwidth'}:
f013ab2b 911 <td width='33%' align='left'><input type='text' size='20' name='MINBWDTH' maxlength='8' required='1' value="$qossettings{'MINBWDTH'}" />
2db5d932 912 <td width='33%' align='center'>&nbsp;
2f6232d5 913 <tr><td width='33%' align='right'>$Lang::tr{'max bandwidth'}&nbsp;<img src='/blob.gif' alt='*' />:
f013ab2b 914 <td width='33%' align='left'><input type='text' size='20' name='MAXBWDTH' maxlength='8' required='1' value="$qossettings{'MAXBWDTH'}" />
2db5d932
MT
915 <td width='33%' align='center'>&nbsp;
916 <tr><td width='33%' align='right'>Burst:
f013ab2b 917 <td width='33%' align='left'><input type='text' size='20' name='BURST' maxlength='8' value="$qossettings{'BURST'}" />
2db5d932
MT
918 <td width='33%' align='center'>&nbsp;
919 <tr><td width='33%' align='right'>Ceilburst:
f013ab2b 920 <td width='33%' align='left'><input type='text' size='20' name='CBURST' maxlength='8' value="$qossettings{'CBURST'}" />
e8babc92 921 <td width='33%' align='center'>&nbsp;
f013ab2b 922 <tr><td width='33%' align='right'>$Lang::tr{'remark'}:
e3edceeb
LS
923 <td width='66%' colspan='2' align='left'><input type='text' name='REMARK' size='40' maxlength='40' value="$qossettings{'REMARK'}" />
924 <tr><td width='33%' align='right'><img src='/blob.gif' alt='*' />&nbsp;$Lang::tr{'required field'}
f013ab2b 925 <td width='33%' align='left'>&nbsp;
18322edf 926 <td width='33%' align='center'><input type='submit' name='DOCLASS' value='$Lang::tr{'save'}' />&nbsp;<input type='reset' value='$Lang::tr{'reset'}' />
2db5d932
MT
927 </table></form>
928END
929;
930 &Header::closebox();
931}
904a41b9 932
414e011d 933sub level7rule {
0b1641db 934 &Header::openbox('100%', 'center', $Lang::tr{'Level7 Rule'});
414e011d
MT
935 print <<END
936 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
937 <table width='66%'>
938END
939;
940 if ( $message ne "" ) {
941 print "<tr><td colspan='3' align='center'><font color='red'>$message</font>";
942 }
943 print <<END
0b1641db
CS
944 <tr><td colspan='3' width='100%'>$Lang::tr{'current class'}: $qossettings{'CLASS'}
945 <tr><td width='100%' colspan='3'>$Lang::tr{'enter data'}
946 <tr><td width='33%' align='right'>$Lang::tr{'protocol'}:
2db5d932
MT
947 <td width='33%' align='left'><select name='L7PROT'>
948END
949;
950 opendir( DIR, "/etc/l7-protocols/protocols" );
951 foreach $direntry ( sort readdir(DIR) )
952 {
953 next if $direntry eq ".";
954 next if $direntry eq "..";
955 next if -d "/etc/l7-protocols/protocols/$direntry";
956 @proto = split( /\./, $direntry );
957 if ( $proto[0] eq $qossettings{'L7PROT'} ) {
fcd5cb6f 958 print "<option value='$proto[0]' selected>$proto[0]</option>\n";
2db5d932
MT
959 } else {
960 print "<option value='$proto[0]'>$proto[0]</option>\n";
961 }
962 }
963 closedir DIR;
964 print <<END
965 </select><td width='33%' align='center'>&nbsp;
0b1641db 966 <tr><td width='33%' align='right'>$Lang::tr{'source ip'}:
5eee5a60 967 <td width='33%' align='left'><input type='text' name='QIP' maxlength='31' value='$qossettings{'QIP'}' />
2db5d932 968 <td width='33%' align='center'>&nbsp;
0b1641db 969 <tr><td width='33%' align='right'>$Lang::tr{'destination ip'}:
5eee5a60 970 <td width='33%' align='left'><input type='text' name='DIP' maxlength='31' value='$qossettings{'DIP'}' />
18322edf 971 <td width='33%' align='center'><input type='hidden' name='CLASS' value='$qossettings{'CLASS'}' /><input type='submit' name='DOLEVEL7' value='$Lang::tr{'save'}' />
11bccc3f 972 <tr><td colspan="3" align='center'><font color="red"><em>$Lang::tr{'qos warning'}</em></font>
2db5d932
MT
973 </table></form>
974END
975;
976 &Header::closebox();
414e011d
MT
977}
978
979sub portrule {
0b1641db 980 &Header::openbox('100%', 'center', $Lang::tr{'Add Port Rule'});
414e011d
MT
981 print <<END
982 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
983 <table width='66%'>
0b1641db
CS
984 <tr><td width='100%' colspan='3'>$Lang::tr{'enter data'}
985 <tr><td width='33%' align='right'>$Lang::tr{'protocol'}:
414e011d
MT
986 <td width='33%' align='left'><select name='PPROT'>
987END
988;
989 open( FILE, "< /etc/protocols" );
990 @proto = <FILE>;
991 close FILE;
992 foreach $direntry (sort @proto)
993 {
994 @tmpline = split( /\ /, $direntry );
995 next if $tmpline[0] =~ "#";
996 if ( $tmpline[0] eq $qossettings{'PPROT'} ) {
fcd5cb6f 997 print "<option value='$tmpline[0]' selected>$tmpline[0]</option>\n";
414e011d
MT
998 } else {
999 print "<option value='$tmpline[0]'>$tmpline[0]</option>\n";
1000 }
1001 }
1002 print <<END
1003 </select><td width='33%' align='center'>&nbsp;
0b1641db 1004 <tr><td width='33%' align='right'>$Lang::tr{'source port'}:
ec3573fc 1005 <td width='33%' align='left'><input type='text' name='QPORT' maxlength='11' value='$qossettings{'QPORT'}' />
414e011d 1006 <td width='33%' align='center'>&nbsp;
0b1641db 1007 <tr><td width='33%' align='right'>$Lang::tr{'destination port'}:
ec3573fc 1008 <td width='33%' align='left'><input type='text' name='DPORT' maxlength='11' value='$qossettings{'DPORT'}' />
414e011d 1009 <td width='33%' align='center'>&nbsp;
0b1641db 1010 <tr><td width='33%' align='right'>$Lang::tr{'source ip'}:
5eee5a60 1011 <td width='33%' align='left'><input type='text' name='QIP' maxlength='31' value='$qossettings{'QIP'}' />
414e011d 1012 <td width='33%' align='center'>&nbsp;
0b1641db 1013 <tr><td width='33%' align='right'>$Lang::tr{'destination ip'}:
5eee5a60 1014 <td width='33%' align='left'><input type='text' name='DIP' maxlength='31' value='$qossettings{'DIP'}' />
18322edf 1015 <td width='33%' align='center'><input type='hidden' name='CLASS' value='$qossettings{'CLASS'}' /><input type='submit' name='DOPORT' value='$Lang::tr{'save'}' />
414e011d
MT
1016 </table></form>
1017END
1018;
1019 &Header::closebox();
1020}
1021
e8babc92 1022sub tosrule {
0b1641db 1023 &Header::openbox('100%', 'center', $Lang::tr{'TOS Rule'});
e8babc92 1024 if ($qossettings{'TOS'}) {
0b1641db 1025 $checked{$qossettings{'TOS'}} = "checked";
e8babc92
MT
1026 }
1027 print <<END
1028 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1029 <table width='66%'>
1030END
1031;
1032 if ( $message ne "" ) {
1033 print "<tr><td colspan='3' align='center'><font color='red'>$message</font>";
1034 }
1035 print <<END
0b1641db
CS
1036 <tr><td colspan='2' width='100%'>$Lang::tr{'current class'}: $qossettings{'CLASS'}
1037 <tr><td width='100%' colspan='2'>$Lang::tr{'Enter TOS'}
1038 <tr><td width='50%' align='left'>$Lang::tr{'min delay'} (8) <td width='50%'><input type="radio" name="TOS" value="8" $checked[8] />
1039 <tr><td width='50%' align='left'>$Lang::tr{'max throughput'} (4) <td width='50%'><input type="radio" name="TOS" value="4" $checked[4] />
1040 <tr><td width='50%' align='left'>$Lang::tr{'max reliability'} (2) <td width='50%'><input type="radio" name="TOS" value="2" $checked[2] />
da7e2665 1041 <tr><td width='50%' align='left'>$Lang::tr{'min costs'} (1) <td width='50%'><input type="radio" name="TOS" value="1" $checked[1] />
18322edf 1042 <tr><td width='100%' align='right' colspan='2'><input type='hidden' name='CLASS' value='$qossettings{'CLASS'}' /><input type='submit' name='DOTOS' value='$Lang::tr{'save'}' />
e8babc92
MT
1043 </table></form>
1044END
1045;
1046 &Header::closebox();
1047}
1048
414e011d 1049sub showclasses {
f013ab2b 1050 $qossettings{'DEV'} = shift;
414e011d
MT
1051 open( FILE, "< $classfile" ) or die "Unable to read $classfile";
1052 @classes = <FILE>;
1053 close FILE;
1054 if (@classes) {
f013ab2b
MT
1055 open( FILE, "< $level7file" ) or die "Unable to read $level7file";
1056 @l7rules = <FILE>;
1057 close FILE;
1058 open( FILE, "< $tosfile" ) or die "Unable to read $tosfile";
1059 @tosrules = <FILE>;
1060 close FILE;
1061 open( FILE, "< $portfile" ) or die "Unable to read $portfile";
1062 @portrules = <FILE>;
1063 close FILE;
414e011d
MT
1064 foreach $classentry (sort @classes)
1065 {
1066 @classline = split( /\;/, $classentry );
f013ab2b 1067 if ( $classline[0] eq $qossettings{'DEV'} )
414e011d 1068 {
be7534e3 1069 &Header::openbox('100%', 'center', "$Lang::tr{'Class'}: $classline[1] $classline[8]");
414e011d 1070 print <<END
f013ab2b 1071 <table border='0' width='100%' cellspacing='0'>
f2fdd0c1 1072 <tr><td bgcolor='$color{'color20'}' width='10%' align='center'><b>$Lang::tr{'interface'}</b>
0b1641db
CS
1073 <td bgcolor='$color{'color20'}' width='10%' align='center'><b>$Lang::tr{'Class'}</b>
1074 <td bgcolor='$color{'color20'}' width='10%' align='center'>$Lang::tr{'priority'}
2f6232d5
MF
1075 <td bgcolor='$color{'color20'}' width='10%' align='center'>$Lang::tr{'guaranteed bandwidth'}
1076 <td bgcolor='$color{'color20'}' width='10%' align='center'>$Lang::tr{'max bandwidth'}
f2fdd0c1
CS
1077 <td bgcolor='$color{'color20'}' width='10%' align='center'>Burst
1078 <td bgcolor='$color{'color20'}' width='10%' align='center'>Ceil Burst
1079 <td bgcolor='$color{'color20'}' width='10%' align='center'>TOS
0b1641db 1080 <td bgcolor='$color{'color20'}' width='20%' align='center'>$Lang::tr{'action'}
f2fdd0c1
CS
1081 <tr><td align='center' bgcolor='$color{'color22'}'>$classline[0]</td>
1082 <td align='center' bgcolor='$color{'color22'}'>$classline[1]</td>
1083 <td align='center' bgcolor='$color{'color22'}'>$classline[2]</td>
1084 <td align='center' bgcolor='$color{'color22'}'>$classline[3]</td>
1085 <td align='center' bgcolor='$color{'color22'}'>$classline[4]</td>
1086 <td align='center' bgcolor='$color{'color22'}'>$classline[5]</td>
1087 <td align='center' bgcolor='$color{'color22'}'>$classline[6]</td>
1088 <td align='center' bgcolor='$color{'color22'}'>$classline[7]</td>
1089 <td align='right' bgcolor='$color{'color22'}'>
649fd295 1090 <table border='0'><tr>
649fd295 1091 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
f841744c 1092 <input type='hidden' name='CLASS' value='$classline[1]' />
65e8619a 1093 <input type='hidden' name='ACTION' value='$Lang::tr{'Add Rule'}' />
f8aa0679 1094 <input type='image' alt='$Lang::tr{'Add Rule'}' title='$Lang::tr{'Add Rule'}' src='/images/addgreen.gif' />
649fd295
MT
1095 </form>
1096 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
f841744c 1097 <input type='hidden' name='CLASS' value='$classline[1]' />
65e8619a 1098 <input type='hidden' name='DOCLASS' value='$Lang::tr{'edit'}' />
f8aa0679 1099 <input type='image' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' src='/images/edit.gif' />
649fd295
MT
1100 </form>
1101 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
f841744c 1102 <input type='hidden' name='CLASS' value='$classline[1]' />
65e8619a 1103 <input type='hidden' name='DOCLASS' value='$Lang::tr{'delete'}' />
f8aa0679 1104 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/delete.gif' />
649fd295
MT
1105 </form>
1106 </table>
f013ab2b
MT
1107 </td>
1108 <tr><td align='right' colspan='2'><b>$Lang::tr{'remark'}:</b>
1109 <td align='center' colspan='6'> $classline[8]
1110 <td align='right'><b>Queueing:</b> $classline[9]
414e011d
MT
1111END
1112;
f013ab2b
MT
1113
1114 if (@l7rules) {
1115 foreach $l7ruleentry (sort @l7rules)
1116 {
1117 @l7ruleline = split( /\;/, $l7ruleentry );
1118 if ( $l7ruleline[0] eq $classline[1] )
1119 {
1120 print <<END
0b1641db 1121 <tr><td align='right' colspan='2'><b>$Lang::tr{'Level7 Protocol'}:</b>
f013ab2b
MT
1122 <td align='center' colspan='6'>$l7ruleline[2]
1123 <td align='right' >
649fd295 1124 <table border='0'><tr>
649fd295 1125 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
f013ab2b
MT
1126 <input type='hidden' name='CLASS' value='$l7ruleline[0]' />
1127 <input type='hidden' name='L7PROT' value='$l7ruleline[2]' />
65e8619a 1128 <input type='hidden' name='DOLEVEL7' value='$Lang::tr{'edit'}' />
f8aa0679 1129 <input type='image' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' src='/images/edit.gif' />
649fd295
MT
1130 </form>
1131 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
f013ab2b
MT
1132 <input type='hidden' name='CLASS' value='$l7ruleline[0]' />
1133 <input type='hidden' name='L7PROT' value='$l7ruleline[2]' />
65e8619a 1134 <input type='hidden' name='DOLEVEL7' value='$Lang::tr{'delete'}' />
f8aa0679 1135 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/delete.gif' />
649fd295
MT
1136 </form>
1137 </table>
414e011d
MT
1138END
1139;
f013ab2b
MT
1140 if (($l7ruleline[3] ne "") || ($l7ruleline[4] ne "")){
1141 print <<END
1142 <tr><td align='center'>&nbsp;
0b1641db
CS
1143 <td align='right' colspan='3'><b>$Lang::tr{'source ip'}:</b> $l7ruleline[3]
1144 <td align='right' colspan='3'><b>$Lang::tr{'destination ip'}:</b> $l7ruleline[4]
84cab473
MT
1145END
1146;
f013ab2b
MT
1147 }
1148
414e011d 1149
84cab473
MT
1150END
1151;
f013ab2b
MT
1152 }
1153 }
1154 }
1155
1156
1157 if (@portrules) {
1158 foreach $portruleentry (sort @portrules)
1159 {
1160 @portruleline = split( /\;/, $portruleentry );
1161 if ( $portruleline[0] eq $classline[1] )
1162 {
1163 print <<END
0b1641db 1164 <tr><td align='right' colspan='2'><b>$Lang::tr{'Port Rule'}:</b>
f013ab2b
MT
1165 <td align='center'>($portruleline[2])
1166 <td align='center' colspan='2'>
84cab473
MT
1167END
1168;
f013ab2b
MT
1169 if ($portruleline[4]) {
1170 print <<END
99a6f5f9 1171 <i>$Lang::tr{'source port'}:</i> $portruleline[4]
84cab473
MT
1172END
1173;
f013ab2b
MT
1174 }
1175 print "<td align='center' colspan='2'>";
1176 if ($portruleline[6]) {
1177 print <<END
99a6f5f9 1178 <i>$Lang::tr{'destination port'}:</i> $portruleline[6]
84cab473
MT
1179END
1180;
f013ab2b
MT
1181 }
1182 print <<END
1183 <td>&nbsp;
1184 <td align='right'>
8b0883b8
MT
1185 <table border='0'><tr>
1186 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
f841744c
CS
1187 <input type='hidden' name='CLASS' value='$portruleline[0]' />
1188 <input type='hidden' name='PPROT' value='$portruleline[2]' />
1189 <input type='hidden' name='QIP' value='$portruleline[3]' />
1190 <input type='hidden' name='QPORT' value='$portruleline[4]' />
1191 <input type='hidden' name='DIP' value='$portruleline[5]' />
1192 <input type='hidden' name='DPORT' value='$portruleline[6]' />
65e8619a 1193 <input type='hidden' name='DOPORT' value='$Lang::tr{'edit'}' />
f8aa0679 1194 <input type='image' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' src='/images/edit.gif' />
8b0883b8
MT
1195 </form>
1196 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
f841744c
CS
1197 <input type='hidden' name='CLASS' value='$portruleline[0]' />
1198 <input type='hidden' name='PPROT' value='$portruleline[2]' />
1199 <input type='hidden' name='QIP' value='$portruleline[3]' />
1200 <input type='hidden' name='QPORT' value='$portruleline[4]' />
1201 <input type='hidden' name='DIP' value='$portruleline[5]' />
1202 <input type='hidden' name='DPORT' value='$portruleline[6]' />
65e8619a 1203 <input type='hidden' name='DOPORT' value='$Lang::tr{'delete'}' />
f8aa0679 1204 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/delete.gif' />
8b0883b8
MT
1205 </form>
1206 </table>
414e011d
MT
1207END
1208;
f013ab2b
MT
1209 if (($portruleline[3] ne "") || ($portruleline[5] ne "")){
1210 print <<END
1211 <tr><td align='center'>&nbsp;
0b1641db
CS
1212 <td align='right' colspan='3'><b>$Lang::tr{'source ip'}:</b> $portruleline[3]
1213 <td align='right' colspan='3'><b>$Lang::tr{'destination ip'}:</b> $portruleline[5]
84cab473
MT
1214END
1215;
f013ab2b
MT
1216 }
1217 }
1218 }
1219 }
414e011d 1220
f013ab2b
MT
1221 if (@tosrules) {
1222 foreach $tosruleentry (sort @tosrules)
1223 {
1224 @tosruleline = split( /\;/, $tosruleentry );
1225 if ( $tosruleline[0] eq $classline[1] )
1226 {
1227 print <<END
1228 <tr><td align='right' colspan='2'>
1229 <b>TOS Bit matches:</b>
1230 <td colspan='6' align='center'>
e8babc92
MT
1231END
1232;
f013ab2b 1233 if ( $tosruleline[2] eq "8") {
0b1641db 1234 print "$Lang::tr{'min delay'}\n";
f013ab2b 1235 } elsif ( $tosruleline[2] eq "4") {
0b1641db 1236 print "$Lang::tr{'max throughput'}\n";
f013ab2b 1237 } elsif ( $tosruleline[2] eq "2") {
0b1641db 1238 print "$Lang::tr{'max reliability'}\n";
f013ab2b 1239 } elsif ( $tosruleline[2] eq "1") {
0b1641db 1240 print "$Lang::tr{'min costs'}\n";
f013ab2b
MT
1241 } else { print "&nbsp;\n"; }
1242
1243 print <<END
1244 ($tosruleline[2])
1245 <td align='right'>
1246 <table border='0'><tr>
1247 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
f841744c
CS
1248 <input type='hidden' name='CLASS' value='$tosruleline[0]' />
1249 <input type='hidden' name='DEV' value='$tosruleline[1]' />
1250 <input type='hidden' name='TOS' value='$tosruleline[2]' />
65e8619a 1251 <input type='hidden' name='DOTOS' value='$Lang::tr{'edit'}' />
f8aa0679 1252 <input type='image' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' src='/images/edit.gif' />
f013ab2b
MT
1253 </form>
1254 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
f841744c
CS
1255 <input type='hidden' name='CLASS' value='$tosruleline[0]' />
1256 <input type='hidden' name='DEV' value='$tosruleline[1]' />
1257 <input type='hidden' name='TOS' value='$tosruleline[2]' />
65e8619a 1258 <input type='hidden' name='DOTOS' value='$Lang::tr{'delete'}' />
f8aa0679 1259 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/delete.gif' />
f013ab2b
MT
1260 </form>
1261 </table>
e8babc92
MT
1262END
1263;
f013ab2b
MT
1264 }
1265 }
1266 }
e8babc92
MT
1267END
1268;
f013ab2b
MT
1269 print <<END
1270 </table>
e8babc92
MT
1271END
1272;
18322edf 1273 &Header::closebox();
e8babc92 1274 }
18322edf
CS
1275 }
1276 }
e8babc92 1277 }
414e011d
MT
1278sub validminbwdth {
1279 if ( $qossettings{'VALID'} eq 'yes' ) {
1280 if ( $qossettings{'DEVICE'} eq $qossettings{'RED_DEV'} ) {
1281 $qossettings{'SPD'} = $qossettings{'OUT_SPD'};
1282 } elsif ( $qossettings{'DEVICE'} eq $qossettings{'IMQ_DEV'} ) {
1283 $qossettings{'SPD'} = $qossettings{'INC_SPD'};
1284 }
363fb6af 1285 unless ( ( $qossettings{'MINBWDTH'} >= 1 ) && ( $qossettings{'MINBWDTH'} <= $qossettings{'SPD'} ) ) {
414e011d 1286 $qossettings{'VALID'} = 'no';
2f6232d5 1287 $message = "$Lang::tr{'false min bandwidth'}";
414e011d
MT
1288 }
1289 $qossettings{'SPD'} = '';
1290 }
1291}
84cab473 1292
414e011d
MT
1293sub validmaxbwdth {
1294 if ( $qossettings{'VALID'} eq 'yes' ) {
1295 if ( $qossettings{'DEVICE'} eq $qossettings{'RED_DEV'} ) {
1296 $qossettings{'SPD'} = $qossettings{'OUT_SPD'};
1297 } elsif ( $qossettings{'DEVICE'} eq $qossettings{'IMQ_DEV'} ) {
1298 $qossettings{'SPD'} = $qossettings{'INC_SPD'};
1299 }
1300 unless ( ( $qossettings{'MAXBDWTH'} >= 0 ) && ($qossettings{'MAXBDWTH'} >= $qossettings{'MINBDWTH'}) &&( $qossettings{'MAXBDWTH'} <= $qossettings{'SPD'} ) ) {
1301 $qossettings{'VALID'} = 'no';
2f6232d5 1302 $message = "$Lang::tr{'false max bandwidth'}";
414e011d
MT
1303 }
1304 $qossettings{'SPD'} = '';
1305 }
1306}
1307
1308sub validclass {
1309 if ( $qossettings{'VALID'} eq 'yes' ) {
1310 if ( $qossettings{'DEVICE'} eq $qossettings{'RED_DEV'} ) {
1311 if ($qossettings{'CLASS'} lt 100 || $qossettings{'CLASS'} ge 121) {
1312 $qossettings{'VALID'} = 'no';
0b1641db 1313 $message = "$Lang::tr{'false classnumber'}";
414e011d
MT
1314 }
1315 } elsif ( $qossettings{'DEVICE'} eq $qossettings{'IMQ_DEV'} ) {
1316 if ($qossettings{'CLASS'} lt 200 || $qossettings{'CLASS'} ge 221) {
1317 $qossettings{'VALID'} = 'no';
65e8619a 1318 $message = "$Lang::tr{'The class number does not match the specified interface.'}";
414e011d
MT
1319 }
1320 }
1321 open( FILE, "< $classfile" ) or die "Unable to read $classfile";
1322 @tmp = <FILE>;
1323 close FILE;
1324 foreach $classentry (sort @tmp)
1325 {
1326 @tmpline = split( /\;/, $classentry );
1327 if ( $tmpline[1] eq $qossettings{'CLASS'} )
1328 {
1329 $qossettings{'VALID'} = 'no';
0b1641db 1330 $message = "$Lang::tr{'false classnumber'}";
414e011d
MT
1331 last
1332 }
1333 }
1334 }
1335}