]> git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/qos.cgi
07b63581a2cb03ed83238ba86cd102d90928beb1
[ipfire-2.x.git] / html / cgi-bin / qos.cgi
1 #!/usr/bin/perl
2 #
3 # IPFire CGIs
4 #
5 # This code is distributed under the terms of the GPL
6 #
7 # (c) The IPFire Team
8 #
9
10 use strict;
11 # enable only the following on debugging purpose
12 use warnings;
13 use CGI::Carp 'fatalsToBrowser';
14
15 require '/var/ipfire/general-functions.pl';
16 require "${General::swroot}/lang.pl";
17 require "${General::swroot}/header.pl";
18
19 my %qossettings = ();
20 my %checked = ();
21 my %netsettings = ();
22 my $errormessage = "";
23 my $c = "";
24 my $direntry = "";
25 my @proto = ();
26 my %selected= () ;
27 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
28
29 &Header::showhttpheaders();
30
31 $qossettings{'ENABLED'} = 'off';
32 $qossettings{'OUT_SPD'} = '';
33 $qossettings{'INC_SPD'} = '';
34 $qossettings{'DEFCLASS_INC'} = '';
35 $qossettings{'DEFCLASS_OUT'} = '';
36 $qossettings{'ACK'} = '';
37 $qossettings{'RED_DEV'} = `cat /var/ipfire/red/iface`;
38 $qossettings{'IMQ_DEV'} = 'imq0';
39
40 &General::readhash("${General::swroot}/qos/settings", \%qossettings);
41 &Header::getcgihash(\%qossettings);
42
43 &Header::openpage('QoS', 1, '');
44 &Header::openbigbox('100%', 'left', '', $errormessage);
45
46 if ($qossettings{'ACTION'} eq 'Start')
47 {
48 system("/bin/touch /var/ipfire/qos/enable");
49 $qossettings{'ENABLED'} = 'on';
50 &General::writehash("${General::swroot}/qos/settings", \%qossettings);
51 }
52 elsif ($qossettings{'ACTION'} eq 'Stop')
53 {
54 unlink "/var/ipfire/qos/enable";
55 $qossettings{'ENABLED'} = 'off';
56 &General::writehash("${General::swroot}/qos/settings", \%qossettings);
57 }
58 elsif ($qossettings{'ACTION'} eq $Lang::tr{'save'})
59 {
60 &General::writehash("${General::swroot}/qos/settings", \%qossettings);
61 }
62 elsif ($qossettings{'ACTION'} eq 'Parentklasse hinzufuegen')
63 {
64 &parentclass();
65 &Header::closebigbox();
66 &Header::closepage();
67 exit
68 }
69 elsif ($qossettings{'ACTION'} eq 'Level7-Regel hinzufuegen')
70 {
71 &level7rule();
72 &Header::closebigbox();
73 &Header::closepage();
74 exit
75 }
76 if ($qossettings{'ACTION_BW'} eq 'Andern')
77 {
78 &changebandwidth();
79 &Header::closebigbox();
80 &Header::closepage();
81 exit
82 }
83 if ($qossettings{'ACTION_DEF'} eq 'Andern')
84 {
85 &changedefclasses();
86 &Header::closebigbox();
87 &Header::closepage();
88 exit
89 }
90
91 &General::readhash("${General::swroot}/qos/settings", \%qossettings);
92
93 my $status = $Lang::tr{'stopped'};
94 my $statuscolor = $Header::colourred;
95 if ( $qossettings{'ENABLED'} eq 'on' ) {
96 $status = $Lang::tr{'running'};
97 $statuscolor = $Header::colourgreen;
98 }
99
100 if ( $netsettings{'RED_TYPE'} ne 'PPPOE' ) {
101 $qossettings{'RED_DEV'} = $netsettings{'RED_DEV'};
102 }
103
104 if ($errormessage) {
105 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
106 print "<class name='base'>$errormessage\n";
107 print "&nbsp;</class>\n";
108 &Header::closebox();
109 }
110
111 &Header::openbox('100%', 'center', 'Quality of Service');
112 print <<END
113 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
114 <table width='33%'>
115 <tr><td width='50%' align='left'><b>Quality of Service:</b>
116 <td width='50%' align='center' bgcolor='$statuscolor'><font color='white'>$status</font>
117 <tr><td width='100%' align='center' colspan='2'>
118 <input type='submit' name='ACTION' value='Start' />
119 <input type='submit' name='ACTION' value='Stop' />
120 <input type='submit' name='ACTION' value='$Lang::tr{'restart'}' />
121 END
122 ;
123 if (($qossettings{'OUT_SPD'} ne '') && ($qossettings{'INC_SPD'} ne '')) {
124 print <<END
125 <tr><td colspan='3'>&nbsp;
126 <tr><td width='40%' align='right'>Downloadgeschwindigkeit: <td width='40%' align='left'>$qossettings{'INC_SPD'} kbps
127 <td width='20%' rowspan='2' align='center' valign='middle'><input type='submit' name='ACTION_BW' value='Andern'>
128 <tr><td width='40%' align='right'>Uploadgeschwindigkeit: <td width='40%' align='left'>$qossettings{'OUT_SPD'} kbps
129 END
130 ;
131 }
132 if (($qossettings{'DEFCLASS_OUT'} ne '') && ($qossettings{'DEFCLASS_INC'} ne '')&& ($qossettings{'ACK'} ne '')) {
133 print <<END
134 <tr><td colspan='3'><hr>
135 <tr><td width='40%' align='right'>Downloadstandardklasse: <td width='40%' align='left'>$qossettings{'DEFCLASS_INC'}
136 <td width='20%' rowspan='3' align='center' valign='middle'><input type='submit' name='ACTION_DEF' value='Andern'>
137 <tr><td width='40%' align='right'>Uploadstandardklasse: <td width='40%' align='left'>$qossettings{'DEFCLASS_OUT'}
138 <tr><td width='40%' align='right'>ACKs: <td width='40%' align='left'>$qossettings{'ACK'}
139 <tr><td colspan='3' width='100%'><hr>
140 <tr><td colspan='3' width='100%' align='center'><input type='submit' name='ACTION' value='Parentklasse hinzufuegen'>
141 <tr><td colspan='3' width='100%' align='center'>Nur temporaer >>> <input type='submit' name='ACTION' value='Level7-Regel hinzufuegen'> <<<
142 END
143 ;
144 }
145 print "</table>";
146 &Header::closebox();
147
148 if ( ($qossettings{'OUT_SPD'} eq '') || ($qossettings{'INC_SPD'} eq '') ) {
149 &changebandwidth();
150 &Header::closebox();
151 &Header::closebigbox();
152 &Header::closepage();
153 exit
154 }
155
156 if ( ($qossettings{'DEFCLASS_INC'} eq '') || ($qossettings{'DEFCLASS_OUT'} eq '') || ($qossettings{'ACK'} eq '') ) {
157 &changedefclasses();
158 &Header::closebigbox();
159 &Header::closepage();
160 exit
161 }
162
163
164 # &Header::openbox('100%', 'center', 'Outgoing Interface');
165 # print <<END
166 # <table border='0' width='100%' cellspacing='0'>
167 # <tr><td bgcolor='lightgrey' width='20%'>Interface<td bgcolor='lightgrey' width='20%'>Klasse<td bgcolor='lightgrey' width='20%'>Maximale Geschwindigkeit<td bgcolor='lightgrey' width='40%'>Aktionen
168 # </table>
169 #END
170 #;
171 # &Header::closebox();
172
173 &Header::closebigbox();
174 &Header::closepage();
175
176 # ---------------------------------------------------------------------------------------------------------------------------------
177
178 sub changedefclasses {
179 &Header::openbox('100%', 'center', 'Standardklassen:');
180 print <<END
181 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
182 <table width='66%'>
183 <tr><td width='100%' colspan='3'>Legen sie hier die Standardklassen fest durch die nicht-gefilterte Pakete gehen.
184 <tr><td width='33%' align='right'>Download:<td width='33%' align='left'><select name='DEFCLASS_INC'>
185 END
186 ;
187 for ( $c = 100 ; $c <= 120 ; $c++ )
188 {
189 if ( $qossettings{'DEFCLASS_INC'} ne $c )
190 {
191 print "<option value='$c'>$c</option>\n";
192 }
193 else
194 {
195 print "<option selected value='$c'>$c</option>\n";
196 }
197 }
198 print <<END
199 </select><td width='33%' align='center'>&nbsp;
200 <tr><td width='33%' align='right'>Upload:<td width='33%' align='left'><select name='DEFCLASS_OUT'>
201 END
202 ;
203 for ( $c = 200 ; $c <= 220 ; $c++ )
204 {
205 if ( $qossettings{'DEFCLASS_OUT'} ne $c )
206 {
207 print "<option value='$c'>$c</option>\n";
208 }
209 else
210 {
211 print "<option selected value='$c'>$c</option>\n";
212 }
213 }
214 print <<END
215 </select><td width='33%' align='center'>&nbsp;
216 </table>
217 <hr>
218 <table width='66%'>
219 <tr><td width='100%' colspan='3'>Legen sie hier die ACK-Klasse fest <br> und klicken Sie danach auf <i>Speichern</i>.
220 <tr><td width='33%' align='right'>ACKs:<td width='33%' align='left'><select name='ACK'>
221 END
222 ;
223 for ( $c = 200 ; $c <= 220 ; $c++ )
224 {
225 if ( $qossettings{'ACK'} ne $c )
226 {
227 print "<option value='$c'>$c</option>\n";
228 }
229 else
230 {
231 print "<option selected value='$c'>$c</option>\n";
232 }
233 }
234 print <<END
235 </select><td width='33%' align='center'><input type='submit' name='ACTION' value=$Lang::tr{'save'} />
236 </table>
237 </form>
238 END
239 ;
240 &Header::closebox();
241 }
242
243 sub changebandwidth {
244 &Header::openbox('100%', 'center', 'Bandbreiteneinstellungen');
245 if ($qossettings{'ENABLED'} eq 'on') {
246 print "Sie koennen die Bandbreiteneinstellungen nicht bearbeiten, wenn QoS eingeschaltet ist. Schalten sie es zuerst dazu aus.<p>";
247 print "<a href='/cgi-bin/qos.cgi'>Zurueck</a>";
248 } else {
249 print <<END
250 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
251 <table width='66%'>
252 <tr><td width='100%' colspan='3'>Geben Sie bitte hier ihre Download- bzw. Upload-Geschwindigkeit ein <br> und klicken Sie danach auf <i>Speichern</i>.
253 <tr><td width='33%' align='right'>Download-Geschwindigkeit:
254 <td width='33%' align='left'><input type='text' name='INC_SPD' maxlength='8' value=$qossettings{'INC_SPD'}> &nbsp; kbps
255 <td width='33%' align='center'>&nbsp;
256 <tr><td width='33%' align='right'>Upload-Geschwindigkeit:
257 <td width='33%' align='left'><input type='text' name='OUT_SPD' maxlength='8' value=$qossettings{'OUT_SPD'}> &nbsp; kbps
258 <td width='33%' align='center'><input type='submit' name='ACTION' value=$Lang::tr{'save'} />&nbsp;<input type='reset' name='ACTION' value=$Lang::tr{'reset'} />
259 </table>
260 </form>
261 END
262 ;
263 }
264 &Header::closebox();
265 }
266
267 sub parentclass {
268 &Header::openbox('100%', 'center', 'Parentklasse hinzufuegen');
269 print <<END
270 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
271 <table width='66%'>
272 <tr><td width='100%' colspan='3'>Geben sie die Daten ein <br> und klicken Sie danach auf <i>Speichern</i>.
273 <tr><td width='33%' align='right'>Interface:
274 <td width='33%' align='left'><select name='CLASS'>
275 <option value=$qossettings{'RED_DEV'}>$qossettings{'RED_DEV'}</option>
276 <option value=$qossettings{'IMQ_DEV'}>$qossettings{'IMQ_DEV'}</option></select>
277 <td width='33%' align='center'>&nbsp;
278 <tr><td width='33%' align='right'>Klasse:<td width='33%' align='left'><select name='CLASS'>
279 END
280 ;
281 for ( $c = 100 ; $c <= 120 ; $c++ )
282 {
283 if ( $qossettings{'CLASS'} ne $c )
284 {
285 print "<option value='$c'>$c</option>\n";
286 }
287 else
288 {
289 print "<option selected value='$c'>$c</option>\n";
290 }
291 }
292 for ( $c = 200 ; $c <= 220 ; $c++ )
293 {
294 if ( $qossettings{'CLASS'} ne $c )
295 {
296 print "<option value='$c'>$c</option>\n";
297 }
298 else
299 {
300 print "<option selected value='$c'>$c</option>\n";
301 }
302 }
303 print <<END
304 </select>
305 <td width='33%' align='center'>&nbsp;
306 <tr><td width='33%' align='right'>Prioritaet:<td width='33%' align='left'><select name='PRIO'>
307 END
308 ;
309 for ( $c = 1 ; $c <= 7 ; $c++ )
310 {
311 if ( $qossettings{'PRIO'} ne $c )
312 {
313 print "<option value='$c'>$c</option>\n";
314 }
315 else
316 {
317 print "<option selected value='$c'>$c</option>\n";
318 }
319 }
320 print <<END
321 <td width='33%' align='center'>&nbsp;
322 <tr><td width='33%' align='right'>Garantierte Bandbreite:
323 <td width='33%' align='left'><input type='text' name='MINBDWTH' maxlength='8' value=$qossettings{'MINBWDTH'}>
324 <td width='33%' align='center'>&nbsp;
325 <tr><td width='33%' align='right'>Maximale Bandbreite:
326 <td width='33%' align='left'><input type='text' name='MAXBDWTH' maxlength='8' value=$qossettings{'MAXBWDTH'}>
327 <td width='33%' align='center'>&nbsp;
328 <tr><td width='33%' align='right'>Burst:
329 <td width='33%' align='left'><input type='text' name='BURST' maxlength='8' value=$qossettings{'BURST'}>
330 <td width='33%' align='center'>&nbsp;
331 <tr><td width='33%' align='right'>Ceilburst:
332 <td width='33%' align='left'><input type='text' name='CBURST' maxlength='8' value=$qossettings{'CBURST'}>
333 <td width='33%' align='center'><input type='submit' name='ACTION' value=$Lang::tr{'save'} />
334 </table></form>
335 END
336 ;
337 &Header::closebox();
338 }
339
340 sub level7rule {
341 &Header::openbox('100%', 'center', 'Level7-Regel hinzufuegen');
342 print <<END
343 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
344 <table width='66%'>
345 <tr><td width='100%' colspan='3'>Geben sie die Daten ein <br> und klicken Sie danach auf <i>Speichern</i>.
346 <tr><td width='33%' align='right'>Name:
347 <td width='33%' align='left'><input type='text' name='NAME' maxlength='20' value=$qossettings{'NAME'}>
348 <td width='33%' align='center'>&nbsp;
349 <tr><td width='33%' align='right'>Protokoll:
350 <td width='33%' align='left'><select name='L7PROT'>
351 END
352 ;
353 opendir( DIR, "/etc/l7-protocols/protocols" );
354 foreach $direntry ( sort readdir(DIR) )
355 {
356 next if $direntry eq ".";
357 next if $direntry eq "..";
358 next if -d "/etc/l7-protocols/protocols/$direntry";
359 @proto = split( /\./, $direntry );
360 if ( $proto[0] eq $qossettings{'L7PROT'} ) {
361 print "<option value='$proto[0]' selected>$proto[0]</option>\n";
362 } else {
363 print "<option value='$proto[0]'>$proto[0]</option>\n";
364 }
365 }
366 closedir DIR;
367 print <<END
368 </select><td width='33%' align='center'>&nbsp;
369 <tr><td width='33%' align='right'>Quell-IP-Adresse:
370 <td width='33%' align='left'><input type='text' name='QIP' maxlength='15' value=$qossettings{'QIP'}>
371 <td width='33%' align='center'>&nbsp;
372 <tr><td width='33%' align='right'>Ziel-IP-Adresse:
373 <td width='33%' align='left'><input type='text' name='DIP' maxlength='15' value=$qossettings{'DIP'}>
374 <td width='33%' align='center'><input type='submit' name='ACTION' value=$Lang::tr{'save'} />
375 </table></form>
376 END
377 ;
378 &Header::closebox();
379 }