X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=html%2Fcgi-bin%2Fshaping.cgi;h=75b9451b4f0e50dc90a46bfb0ef0612c60c82df0;hb=ac1cfefab236b73ed52909e14f43eaffc8d6914e;hp=381bbf12ef697fe19007266ef895706f55364e79;hpb=7ac38dc92777a4a9f3b0d6151befe8f446e2a031;p=ipfire-2.x.git diff --git a/html/cgi-bin/shaping.cgi b/html/cgi-bin/shaping.cgi index 381bbf12ef..75b9451b4f 100644 --- a/html/cgi-bin/shaping.cgi +++ b/html/cgi-bin/shaping.cgi @@ -1,367 +1,367 @@ -#!/usr/bin/perl -# -# Traffic shaping CGI -# -# Copyright 2003-04-06 David Kilpatrick -# -# $Id: shaping.cgi,v 1.3.2.15 2005/02/27 13:42:05 eoberlander Exp $ -# - -use strict; - -# enable only the following on debugging purpose -#use warnings; -#use CGI::Carp 'fatalsToBrowser'; - -require 'CONFIG_ROOT/general-functions.pl'; -require "${General::swroot}/lang.pl"; -require "${General::swroot}/header.pl"; - -#workaround to suppress a warning when a variable is used only once -my @dummy = ( ${Header::table2colour}, ${Header::colouryellow} ); -undef (@dummy); - -my %shapingsettings=(); -my $configfile = "${General::swroot}/shaping/config"; -my $settingsfile = "${General::swroot}/shaping/settings"; -my $errormessage = ''; - -&Header::showhttpheaders(); - -$shapingsettings{'ACTION'} = ''; -$shapingsettings{'ENABLE'} = 'off'; -$shapingsettings{'VALID'} = ''; -$shapingsettings{'UPLINK'} = ''; -$shapingsettings{'DOWNLINK'} = ''; -$shapingsettings{'SERVICE_ENABLED'} = ''; -$shapingsettings{'SERVICE_PROT'} = ''; -$shapingsettings{'SERVICE_PRIO'} = ''; -$shapingsettings{'SERVICE_PORT'} = ''; - -&Header::getcgihash(\%shapingsettings); - -open(FILE, "$configfile") or die 'Unable to open shaping config file.'; -my @current = ; -close(FILE); - -if ($shapingsettings{'ACTION'} eq $Lang::tr{'save'}) -{ - if (!($shapingsettings{'UPLINK'} =~ /^\d+$/) || - ($shapingsettings{'UPLINK'} < 2)) - { - $errormessage = $Lang::tr{'invalid uplink speed'}; - goto ERROR; - } - - if (!($shapingsettings{'DOWNLINK'} =~ /^\d+$/) || - ($shapingsettings{'DOWNLINK'} < 2)) - { - $errormessage = $Lang::tr{'invalid downlink speed'}; - goto ERROR; - } - -ERROR: - if ($errormessage) { - $shapingsettings{'VALID'} = 'no'; } - else { - $shapingsettings{'VALID'} = 'yes'; } - - open(FILE,">$settingsfile") or die 'Unable to open shaping settings file.'; - flock FILE, 2; - print FILE "VALID=$shapingsettings{'VALID'}\n"; - print FILE "ENABLE=$shapingsettings{'ENABLE'}\n"; - print FILE "UPLINK=$shapingsettings{'UPLINK'}\n"; - print FILE "DOWNLINK=$shapingsettings{'DOWNLINK'}\n"; - close FILE; - - if ($shapingsettings{'VALID'} eq 'yes') { - system('/usr/local/bin/restartshaping'); - } -} -if ($shapingsettings{'ACTION'} eq $Lang::tr{'add'}) -{ - unless($shapingsettings{'SERVICE_PROT'} =~ /^(tcp|udp)$/) { $errormessage = $Lang::tr{'invalid input'}; } - unless($shapingsettings{'SERVICE_PRIO'} =~ /^(10|20|30)$/) { $errormessage = $Lang::tr{'invalid input'}; } - unless(&General::validport($shapingsettings{'SERVICE_PORT'})) { $errormessage = $Lang::tr{'invalid port'}; } - - if ( ! $errormessage) - { - if ($shapingsettings{'EDITING'} eq 'no') - { - open(FILE,">>$configfile") or die 'Unable to open shaping config file'; - flock FILE, 2; - print FILE "$shapingsettings{'SERVICE_PROT'},$shapingsettings{'SERVICE_PORT'},$shapingsettings{'SERVICE_PRIO'},$shapingsettings{'SERVICE_ENABLED'}\n"; - } else { - open(FILE,">$configfile") or die 'Unable to open shaping config file'; - flock FILE, 2; - my $id = 0; - foreach my $line (@current) - { - $id++; - chomp($line); - my @temp = split(/\,/,$line); - if ($shapingsettings{'EDITING'} eq $id) { - print FILE "$shapingsettings{'SERVICE_PROT'},$shapingsettings{'SERVICE_PORT'},$shapingsettings{'SERVICE_PRIO'},$shapingsettings{'SERVICE_ENABLED'}\n"; - } else { - print FILE "$line\n"; - } - } - } - close FILE; - undef %shapingsettings; - system ('/usr/local/bin/restartshaping'); - } else { - # stay on edit mode if an error occur - if ($shapingsettings{'EDITING'} ne 'no') - { - $shapingsettings{'ACTION'} = $Lang::tr{'edit'}; - $shapingsettings{'ID'} = $shapingsettings{'EDITING'}; - } - } -} - -if ($shapingsettings{'ACTION'} eq $Lang::tr{'edit'}) -{ - my $id = 0; - foreach my $line (@current) - { - $id++; - if ($shapingsettings{"ID"} eq $id) - { - chomp($line); - my @temp = split(/\,/,$line); - $shapingsettings{'SERVICE_PROT'} = $temp[0]; - $shapingsettings{'SERVICE_PORT'} = $temp[1]; - $shapingsettings{'SERVICE_PRIO'} = $temp[2]; - $shapingsettings{'SERVICE_ENABLED'} = $temp[3]; - } - } -} - -if ($shapingsettings{'ACTION'} eq $Lang::tr{'remove'} || $shapingsettings{'ACTION'} eq $Lang::tr{'toggle enable disable'}) -{ - open(FILE, ">$configfile") or die 'Unable to open config file.'; - flock FILE, 2; - my $id = 0; - foreach my $line (@current) - { - $id++; - unless ($shapingsettings{"ID"} eq $id) { print FILE "$line"; } - elsif ($shapingsettings{'ACTION'} eq $Lang::tr{'toggle enable disable'}) - { - chomp($line); - my @temp = split(/\,/,$line); - if ($temp[3] eq "on") { - print FILE "$temp[0],$temp[1],$temp[2],off\n"; - } else { - print FILE "$temp[0],$temp[1],$temp[2],on\n"; - } - } - } - close(FILE); - system ('/usr/local/bin/restartshaping'); -} - -&General::readhash("${General::swroot}/shaping/settings", \%shapingsettings); - -if ($shapingsettings{'ACTION'} eq '') -{ - $shapingsettings{'SERVICE_ENABLED'} = 'on'; - $shapingsettings{'SERVICE_PROT'} = 'tcp'; - $shapingsettings{'SERVICE_PRIO'} = '20'; - $shapingsettings{'SERVICE_PORT'} = ''; -} - -my %checked=(); -$checked{'ENABLE'}{'off'} = ''; -$checked{'ENABLE'}{'on'} = ''; -$checked{'ENABLE'}{$shapingsettings{'ENABLE'}} = "checked='checked'"; - -my %service_checked=(); -$service_checked{'SERVICE_ENABLED'}{'off'} = ''; -$service_checked{'SERVICE_ENABLED'}{'on'} = ''; -$service_checked{'SERVICE_ENABLED'}{$shapingsettings{'SERVICE_ENABLED'}} = "checked='checked'"; - -my %service_selected=(); -$service_selected{'SERVICE_PROT'}{'udp'} = ''; -$service_selected{'SERVICE_PROT'}{'tcp'} = ''; -$service_selected{'SERVICE_PROT'}{$shapingsettings{'SERVICE_PROT'}} = "selected='selected'"; - -$service_selected{'SERVICE_PRIO'}{'10'} = ''; -$service_selected{'SERVICE_PRIO'}{'20'} = ''; -$service_selected{'SERVICE_PRIO'}{'30'} = ''; -$service_selected{'SERVICE_PRIO'}{$shapingsettings{'SERVICE_PRIO'}} = "selected='selected'"; - -&Header::openpage($Lang::tr{'traffic shaping settings'}, 1, ''); - -&Header::openbigbox('100%', 'left', '', $errormessage); - -if ($errormessage) { - &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); - print "$errormessage \n"; - &Header::closebox(); -} - -print "
\n"; - -&Header::openbox('100%', 'left', "$Lang::tr{'settings'}:"); -print < - - - $Lang::tr{'traffic shaping'} - - -   - $Lang::tr{'downlink speed'}:  - - - -   - $Lang::tr{'uplink speed'}:  - - - - -
- - - - -
 
-END -; -&Header::closebox; - -print "\n"; -print "
\n"; - -my $buttontext = $Lang::tr{'add'}; -if($shapingsettings{'ACTION'} eq $Lang::tr{'edit'}) { - $buttontext = $Lang::tr{'update'}; - &Header::openbox('100%', 'left', $Lang::tr{'edit service'}); -} else { - &Header::openbox('100%', 'left', $Lang::tr{'add service'}); -} - -print < - - $Lang::tr{'priority'}:  - - $Lang::tr{'port'}:  - - $Lang::tr{'protocol'}:  - - $Lang::tr{'enabled'}  - - - - -
- - - - -
 
-END -; -&Header::closebox; - -if ($shapingsettings{'ACTION'} eq $Lang::tr{'edit'}) { - print "\n"; -} else { - print "\n"; -} - -print "\n"; - -&Header::openbox('100%', 'left', $Lang::tr{'shaping list options'}); -print < - - $Lang::tr{'priority'} - $Lang::tr{'port'} - $Lang::tr{'protocol'} - $Lang::tr{'action'} - -END -; - -my $id = 0; -open(SERVICES, "$configfile") or die 'Unable to open shaping config file.'; -while () -{ - my $gif = ''; - my $prio = ''; - my $gdesc = ''; - $id++; - chomp($_); - my @temp = split(/\,/,$_); - if ($temp[3] eq "on") { - $gif = 'on.gif'; $gdesc=$Lang::tr{'click to disable'}; } - else { - $gif = 'off.gif'; $gdesc=$Lang::tr{'click to enable'}; } - if ($shapingsettings{'ACTION'} eq $Lang::tr{'edit'} && $shapingsettings{'ID'} eq $id) { - print "\n"; } - elsif ($id % 2) { - print "\n"; } - else { - print "\n"; } - if ($temp[2] eq "10") { $prio = $Lang::tr{'high'}; } - if ($temp[2] eq "20") { $prio = $Lang::tr{'medium'}; } - if ($temp[2] eq "30") { $prio = $Lang::tr{'low'}; } - -print <$prio -$temp[1] -$temp[0] - - -
- - - -
- - - -
- - - -
- - - -
- - - -
- - - -END -; -} -close(SERVICES); - -print < -END -; -&Header::closebox; - - -&Header::closebigbox(); - -&Header::closepage; +#!/usr/bin/perl +# +# Traffic shaping CGI +# +# Copyright 2003-04-06 David Kilpatrick +# +# $Id: shaping.cgi,v 1.3.2.15 2005/02/27 13:42:05 eoberlander Exp $ +# + +use strict; + +# enable only the following on debugging purpose +#use warnings; +#use CGI::Carp 'fatalsToBrowser'; + +require 'CONFIG_ROOT/general-functions.pl'; +require "${General::swroot}/lang.pl"; +require "${General::swroot}/header.pl"; + +#workaround to suppress a warning when a variable is used only once +my @dummy = ( ${Header::table2colour}, ${Header::colouryellow} ); +undef (@dummy); + +my %shapingsettings=(); +my $configfile = "${General::swroot}/shaping/config"; +my $settingsfile = "${General::swroot}/shaping/settings"; +my $errormessage = ''; + +&Header::showhttpheaders(); + +$shapingsettings{'ACTION'} = ''; +$shapingsettings{'ENABLE'} = 'off'; +$shapingsettings{'VALID'} = ''; +$shapingsettings{'UPLINK'} = ''; +$shapingsettings{'DOWNLINK'} = ''; +$shapingsettings{'SERVICE_ENABLED'} = ''; +$shapingsettings{'SERVICE_PROT'} = ''; +$shapingsettings{'SERVICE_PRIO'} = ''; +$shapingsettings{'SERVICE_PORT'} = ''; + +&Header::getcgihash(\%shapingsettings); + +open(FILE, "$configfile") or die 'Unable to open shaping config file.'; +my @current = ; +close(FILE); + +if ($shapingsettings{'ACTION'} eq $Lang::tr{'save'}) +{ + if (!($shapingsettings{'UPLINK'} =~ /^\d+$/) || + ($shapingsettings{'UPLINK'} < 2)) + { + $errormessage = $Lang::tr{'invalid uplink speed'}; + goto ERROR; + } + + if (!($shapingsettings{'DOWNLINK'} =~ /^\d+$/) || + ($shapingsettings{'DOWNLINK'} < 2)) + { + $errormessage = $Lang::tr{'invalid downlink speed'}; + goto ERROR; + } + +ERROR: + if ($errormessage) { + $shapingsettings{'VALID'} = 'no'; } + else { + $shapingsettings{'VALID'} = 'yes'; } + + open(FILE,">$settingsfile") or die 'Unable to open shaping settings file.'; + flock FILE, 2; + print FILE "VALID=$shapingsettings{'VALID'}\n"; + print FILE "ENABLE=$shapingsettings{'ENABLE'}\n"; + print FILE "UPLINK=$shapingsettings{'UPLINK'}\n"; + print FILE "DOWNLINK=$shapingsettings{'DOWNLINK'}\n"; + close FILE; + + if ($shapingsettings{'VALID'} eq 'yes') { + system('/usr/local/bin/restartshaping'); + } +} +if ($shapingsettings{'ACTION'} eq $Lang::tr{'add'}) +{ + unless($shapingsettings{'SERVICE_PROT'} =~ /^(tcp|udp)$/) { $errormessage = $Lang::tr{'invalid input'}; } + unless($shapingsettings{'SERVICE_PRIO'} =~ /^(10|20|30)$/) { $errormessage = $Lang::tr{'invalid input'}; } + unless(&General::validport($shapingsettings{'SERVICE_PORT'})) { $errormessage = $Lang::tr{'invalid port'}; } + + if ( ! $errormessage) + { + if ($shapingsettings{'EDITING'} eq 'no') + { + open(FILE,">>$configfile") or die 'Unable to open shaping config file'; + flock FILE, 2; + print FILE "$shapingsettings{'SERVICE_PROT'},$shapingsettings{'SERVICE_PORT'},$shapingsettings{'SERVICE_PRIO'},$shapingsettings{'SERVICE_ENABLED'}\n"; + } else { + open(FILE,">$configfile") or die 'Unable to open shaping config file'; + flock FILE, 2; + my $id = 0; + foreach my $line (@current) + { + $id++; + chomp($line); + my @temp = split(/\,/,$line); + if ($shapingsettings{'EDITING'} eq $id) { + print FILE "$shapingsettings{'SERVICE_PROT'},$shapingsettings{'SERVICE_PORT'},$shapingsettings{'SERVICE_PRIO'},$shapingsettings{'SERVICE_ENABLED'}\n"; + } else { + print FILE "$line\n"; + } + } + } + close FILE; + undef %shapingsettings; + system ('/usr/local/bin/restartshaping'); + } else { + # stay on edit mode if an error occur + if ($shapingsettings{'EDITING'} ne 'no') + { + $shapingsettings{'ACTION'} = $Lang::tr{'edit'}; + $shapingsettings{'ID'} = $shapingsettings{'EDITING'}; + } + } +} + +if ($shapingsettings{'ACTION'} eq $Lang::tr{'edit'}) +{ + my $id = 0; + foreach my $line (@current) + { + $id++; + if ($shapingsettings{"ID"} eq $id) + { + chomp($line); + my @temp = split(/\,/,$line); + $shapingsettings{'SERVICE_PROT'} = $temp[0]; + $shapingsettings{'SERVICE_PORT'} = $temp[1]; + $shapingsettings{'SERVICE_PRIO'} = $temp[2]; + $shapingsettings{'SERVICE_ENABLED'} = $temp[3]; + } + } +} + +if ($shapingsettings{'ACTION'} eq $Lang::tr{'remove'} || $shapingsettings{'ACTION'} eq $Lang::tr{'toggle enable disable'}) +{ + open(FILE, ">$configfile") or die 'Unable to open config file.'; + flock FILE, 2; + my $id = 0; + foreach my $line (@current) + { + $id++; + unless ($shapingsettings{"ID"} eq $id) { print FILE "$line"; } + elsif ($shapingsettings{'ACTION'} eq $Lang::tr{'toggle enable disable'}) + { + chomp($line); + my @temp = split(/\,/,$line); + if ($temp[3] eq "on") { + print FILE "$temp[0],$temp[1],$temp[2],off\n"; + } else { + print FILE "$temp[0],$temp[1],$temp[2],on\n"; + } + } + } + close(FILE); + system ('/usr/local/bin/restartshaping'); +} + +&General::readhash("${General::swroot}/shaping/settings", \%shapingsettings); + +if ($shapingsettings{'ACTION'} eq '') +{ + $shapingsettings{'SERVICE_ENABLED'} = 'on'; + $shapingsettings{'SERVICE_PROT'} = 'tcp'; + $shapingsettings{'SERVICE_PRIO'} = '20'; + $shapingsettings{'SERVICE_PORT'} = ''; +} + +my %checked=(); +$checked{'ENABLE'}{'off'} = ''; +$checked{'ENABLE'}{'on'} = ''; +$checked{'ENABLE'}{$shapingsettings{'ENABLE'}} = "checked='checked'"; + +my %service_checked=(); +$service_checked{'SERVICE_ENABLED'}{'off'} = ''; +$service_checked{'SERVICE_ENABLED'}{'on'} = ''; +$service_checked{'SERVICE_ENABLED'}{$shapingsettings{'SERVICE_ENABLED'}} = "checked='checked'"; + +my %service_selected=(); +$service_selected{'SERVICE_PROT'}{'udp'} = ''; +$service_selected{'SERVICE_PROT'}{'tcp'} = ''; +$service_selected{'SERVICE_PROT'}{$shapingsettings{'SERVICE_PROT'}} = "selected='selected'"; + +$service_selected{'SERVICE_PRIO'}{'10'} = ''; +$service_selected{'SERVICE_PRIO'}{'20'} = ''; +$service_selected{'SERVICE_PRIO'}{'30'} = ''; +$service_selected{'SERVICE_PRIO'}{$shapingsettings{'SERVICE_PRIO'}} = "selected='selected'"; + +&Header::openpage($Lang::tr{'traffic shaping settings'}, 1, ''); + +&Header::openbigbox('100%', 'left', '', $errormessage); + +if ($errormessage) { + &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); + print "$errormessage \n"; + &Header::closebox(); +} + +print "
\n"; + +&Header::openbox('100%', 'left', "$Lang::tr{'settings'}:"); +print < + + + $Lang::tr{'traffic shaping'} + + +   + $Lang::tr{'downlink speed'}:  + + + +   + $Lang::tr{'uplink speed'}:  + + + + +
+ + + + +
 
+END +; +&Header::closebox; + +print "\n"; +print "
\n"; + +my $buttontext = $Lang::tr{'add'}; +if($shapingsettings{'ACTION'} eq $Lang::tr{'edit'}) { + $buttontext = $Lang::tr{'update'}; + &Header::openbox('100%', 'left', $Lang::tr{'edit service'}); +} else { + &Header::openbox('100%', 'left', $Lang::tr{'add service'}); +} + +print < + + $Lang::tr{'priority'}:  + + $Lang::tr{'port'}:  + + $Lang::tr{'protocol'}:  + + $Lang::tr{'enabled'}  + + + + +
+ + + + +
 
+END +; +&Header::closebox; + +if ($shapingsettings{'ACTION'} eq $Lang::tr{'edit'}) { + print "\n"; +} else { + print "\n"; +} + +print "\n"; + +&Header::openbox('100%', 'left', $Lang::tr{'shaping list options'}); +print < + + $Lang::tr{'priority'} + $Lang::tr{'port'} + $Lang::tr{'protocol'} + $Lang::tr{'action'} + +END +; + +my $id = 0; +open(SERVICES, "$configfile") or die 'Unable to open shaping config file.'; +while () +{ + my $gif = ''; + my $prio = ''; + my $gdesc = ''; + $id++; + chomp($_); + my @temp = split(/\,/,$_); + if ($temp[3] eq "on") { + $gif = 'on.gif'; $gdesc=$Lang::tr{'click to disable'}; } + else { + $gif = 'off.gif'; $gdesc=$Lang::tr{'click to enable'}; } + if ($shapingsettings{'ACTION'} eq $Lang::tr{'edit'} && $shapingsettings{'ID'} eq $id) { + print "\n"; } + elsif ($id % 2) { + print "\n"; } + else { + print "\n"; } + if ($temp[2] eq "10") { $prio = $Lang::tr{'high'}; } + if ($temp[2] eq "20") { $prio = $Lang::tr{'medium'}; } + if ($temp[2] eq "30") { $prio = $Lang::tr{'low'}; } + +print <$prio +$temp[1] +$temp[0] + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +END +; +} +close(SERVICES); + +print < +END +; +&Header::closebox; + + +&Header::closebigbox(); + +&Header::closepage;