mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-10 02:55:55 +02:00
Revert "ddos.cgi remove duplicate code"
This reverts commit 8ca6049b32.
This commit is contained in:
@@ -41,15 +41,16 @@ my %dnsddossettings=();
|
||||
my %checked=();
|
||||
my $errormessage='';
|
||||
my $counter = 0;
|
||||
my %tcp_ports=();
|
||||
my %udp_ports=();
|
||||
my $tcp_portfile = "${General::swroot}/ddos/tcp_ports";
|
||||
my $udp_portfile = "${General::swroot}/ddos/udp_ports";
|
||||
my $ddossettingfile = "${General::swroot}/ddos/settings";
|
||||
my $udpddossettingfile = "${General::swroot}/ddos/udp-ddos-settings";
|
||||
my $dnsddossettingfile = "${General::swroot}/ddos/dns-ddos-settings";
|
||||
|
||||
# Get TCP and UDP ports
|
||||
my %tcp_ports = get_ports($tcp_portfile, 'tcp');
|
||||
my %udp_ports = get_ports($udp_portfile, 'udp');
|
||||
&get_tcp_ports();
|
||||
&get_udp_ports();
|
||||
|
||||
# Read configuration file.
|
||||
|
||||
@@ -63,7 +64,7 @@ $udpddossettings{'ENABLE_UDP_DDOS'} = 'off';
|
||||
$dnsddossettings{'ENABLE_DNS_DDOS'} = 'off';
|
||||
$ddossettings{'ACTION'} = '';
|
||||
$udpddossettings{'UDP_ACTION'} = '';
|
||||
$dnsddossettings{'DNS_ACTION'} = '';
|
||||
$udpddossettings{'DNS_ACTION'} = '';
|
||||
|
||||
&Header::getcgihash(\%ddossettings);
|
||||
|
||||
@@ -84,9 +85,13 @@ if ($ddossettings{'ACTION'} eq $Lang::tr{'save'})
|
||||
&General::writehash("$ddossettingfile", \%ddossettings);
|
||||
|
||||
if ($ddossettings{'ENABLE_DDOS'} eq 'on') {
|
||||
&enable_ddos;
|
||||
&General::log($Lang::tr{'ddos is enabled'});
|
||||
&General::system('/usr/bin/touch', "${General::swroot}/ddos/enableddos");
|
||||
&General::system('/usr/local/bin/ddosctrl', 'start');
|
||||
} else {
|
||||
&disable_ddos;
|
||||
&General::log($Lang::tr{'ddos is disabled'});
|
||||
&General::system('/usr/local/bin/ddosctrl', 'stop');
|
||||
unlink "${General::swroot}/ddos/enableddos";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -110,24 +115,32 @@ if ($udpddossettings{'UDP_ACTION'} eq $Lang::tr{'save'})
|
||||
&General::writehash("$udpddossettingfile", \%udpddossettings);
|
||||
|
||||
if ($udpddossettings{'ENABLE_UDP_DDOS'} eq 'on') {
|
||||
&enable_ddos;
|
||||
&General::log($Lang::tr{'ddos is enabled'});
|
||||
&General::system('/usr/bin/touch', "${General::swroot}/ddos/enableddos");
|
||||
&General::system('/usr/local/bin/ddosctrl', 'start');
|
||||
} else {
|
||||
&disable_ddos;
|
||||
&General::log($Lang::tr{'ddos is disabled'});
|
||||
&General::system('/usr/local/bin/ddosctrl', 'stop');
|
||||
unlink "${General::swroot}/ddos/enableddos";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
&Header::getcgihash(\%dnsddossettings);
|
||||
|
||||
if ($dnsddossettings{'DNS_ACTION'} eq $Lang::tr{'save'})
|
||||
if ($udpddossettings{'DNS_ACTION'} eq $Lang::tr{'save'})
|
||||
{
|
||||
|
||||
&General::writehash("$dnsddossettingfile", \%dnsddossettings);
|
||||
|
||||
if ($dnsddossettings{'ENABLE_DNS_DDOS'} eq 'on') {
|
||||
&enable_ddos;
|
||||
&General::log($Lang::tr{'ddos is enabled'});
|
||||
&General::system('/usr/bin/touch', "${General::swroot}/ddos/enableddos");
|
||||
&General::system('/usr/local/bin/ddosctrl', 'start');
|
||||
} else {
|
||||
&disable_ddos;
|
||||
&General::log($Lang::tr{'ddos is disabled'});
|
||||
&General::system('/usr/local/bin/ddosctrl', 'stop');
|
||||
unlink "${General::swroot}/ddos/enableddos";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -143,7 +156,7 @@ if ($errormessage) {
|
||||
}
|
||||
|
||||
# Read configuration file.
|
||||
read_config_file("$ddossettingfile", \%ddossettings);
|
||||
&General::readhash("$ddossettingfile", \%ddossettings);
|
||||
|
||||
# Checkbox pre-selection.
|
||||
my $checked;
|
||||
@@ -169,166 +182,45 @@ END
|
||||
&Header::closebox();
|
||||
|
||||
&Header::openbox('100%', 'center', $Lang::tr{'xdp tcp port'});
|
||||
|
||||
&print_port_head;
|
||||
|
||||
&print_port_status(%tcp_ports);
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
print "</form>\n";
|
||||
#
|
||||
# Read configuration file.
|
||||
read_config_file("$dnsddossettingfile", \%dnsddossettings);
|
||||
|
||||
# Checkbox pre-selection.
|
||||
my $dns_checked;
|
||||
if ($dnsddossettings{'ENABLE_DNS_DDOS'} eq "on") {
|
||||
$dns_checked = "checked='checked'";
|
||||
}
|
||||
|
||||
# Print box to enable/disable locationblock.
|
||||
print"<form method='POST' action='$ENV{'SCRIPT_NAME'}'>\n";
|
||||
|
||||
&Header::openbox('100%', 'center', $Lang::tr{'xdp dns'});
|
||||
print <<END;
|
||||
<table width='95%'>
|
||||
<tr>
|
||||
<td width='50%' class='base'>$Lang::tr{'xdp enable'}
|
||||
<td><input type='checkbox' name='ENABLE_DNS_DDOS' $dns_checked></td>
|
||||
<td align='center'><input type='submit' name='DNS_ACTION' value='$Lang::tr{'save'}'></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
END
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
print "</form>\n";
|
||||
|
||||
# Read configuration file.
|
||||
read_config_file("$udpddossettingfile", \%udpddossettings);
|
||||
|
||||
# Checkbox pre-selection.
|
||||
my $udp_checked;
|
||||
if ($udpddossettings{'ENABLE_UDP_DDOS'} eq "on") {
|
||||
$udp_checked = "checked='checked'";
|
||||
}
|
||||
|
||||
# Print box to enable/disable locationblock.
|
||||
print"<form method='POST' action='$ENV{'SCRIPT_NAME'}'>\n";
|
||||
|
||||
&Header::openbox('100%', 'center', $Lang::tr{'xdp udp'});
|
||||
print <<END;
|
||||
<table width='95%'>
|
||||
<tr>
|
||||
<td width='50%' class='base'>$Lang::tr{'xdp enable'}
|
||||
<td><input type='checkbox' name='ENABLE_UDP_DDOS' $udp_checked></td>
|
||||
<td align='center'><input type='submit' name='UDP_ACTION' value='$Lang::tr{'save'}'></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
END
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
&Header::openbox('100%', 'center', $Lang::tr{'xdp udp port'});
|
||||
|
||||
&print_port_head;
|
||||
|
||||
&print_port_status(%udp_ports);
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
print "</form>\n";
|
||||
|
||||
&Header::openbox('100%', 'center', $Lang::tr{'xdp status'});
|
||||
|
||||
&print_xdp_status_head;
|
||||
|
||||
&print_xdp_status;
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
&Header::closebigbox();
|
||||
|
||||
&Header::closepage();
|
||||
|
||||
# Subroutine to get ports from file
|
||||
sub get_ports {
|
||||
my ($file, $protocol) = @_;
|
||||
my %ports;
|
||||
|
||||
open(my $fh, '<', $file) or die "Unable to open file $file: $!";
|
||||
while (my $line = <$fh>) {
|
||||
chomp $line;
|
||||
next if $line =~ /^\s*#/; # Skip comments
|
||||
my ($service, $port) = $line =~ /^(\w+)\s+(\d+)\/$protocol/;
|
||||
$ports{$service} = $port if $service && $port;
|
||||
}
|
||||
close($fh);
|
||||
return %ports;
|
||||
}
|
||||
|
||||
# Subroutine to read configuration file
|
||||
sub read_config_file {
|
||||
my ($file, $config) = @_;
|
||||
&General::readhash($file, $config);
|
||||
}
|
||||
|
||||
sub enable_ddos() {
|
||||
&General::log($Lang::tr{'ddos is enabled'});
|
||||
&General::system('/usr/bin/touch', "${General::swroot}/ddos/enableddos");
|
||||
&General::system('/usr/local/bin/ddosctrl', 'start');
|
||||
}
|
||||
|
||||
sub disable_ddos() {
|
||||
&General::log($Lang::tr{'ddos is disabled'});
|
||||
&General::system('/usr/local/bin/ddosctrl', 'stop');
|
||||
unlink "${General::swroot}/ddos/enableddos";
|
||||
}
|
||||
|
||||
sub print_port_head() {
|
||||
print <<END;
|
||||
|
||||
<table width='95%' class='tbl' id="countries">
|
||||
<tr>
|
||||
<td width='5%' align='center' bgcolor='$color{'color20'}'></td>
|
||||
<td width='5%' align='center' bgcolor='$color{'color20'}'>
|
||||
<b>$Lang::tr{'port'}</b>
|
||||
</td>
|
||||
<td with='35%' align='left' bgcolor='$color{'color20'}'>
|
||||
<b>$Lang::tr{'service'}</b>
|
||||
</td>
|
||||
<table width='95%' class='tbl' id="countries">
|
||||
<tr>
|
||||
<td width='5%' align='center' bgcolor='$color{'color20'}'></td>
|
||||
<td width='5%' align='center' bgcolor='$color{'color20'}'>
|
||||
<b>$Lang::tr{'port'}</b>
|
||||
</td>
|
||||
<td with='35%' align='left' bgcolor='$color{'color20'}'>
|
||||
<b>$Lang::tr{'service'}</b>
|
||||
</td>
|
||||
|
||||
<td width='5%' bgcolor='$color{'color20'}'> </td>
|
||||
<td width='5%' align='center' bgcolor='$color{'color20'}'></td>
|
||||
<td width='5%' align='center' bgcolor='$color{'color20'}'>
|
||||
<b>$Lang::tr{'port'}</b>
|
||||
</td>
|
||||
<td with='35%' align='left' bgcolor='$color{'color20'}'>
|
||||
<b>$Lang::tr{'service'}</b>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<td width='5%' align='center' bgcolor='$color{'color20'}'></td>
|
||||
<td width='5%' align='center' bgcolor='$color{'color20'}'>
|
||||
<b>$Lang::tr{'port'}</b>
|
||||
</td>
|
||||
<td with='35%' align='left' bgcolor='$color{'color20'}'>
|
||||
<b>$Lang::tr{'service'}</b>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
END
|
||||
}
|
||||
|
||||
sub print_port_status() {
|
||||
my $lines;
|
||||
my $lines2;
|
||||
my $col;
|
||||
my $lines;
|
||||
my $lines2;
|
||||
my $col;
|
||||
|
||||
my %ports = @_;
|
||||
|
||||
# Sort output based on hash value port number
|
||||
for my $service ( sort { $ports{$a} cmp $ports{$b} }
|
||||
keys %ports )
|
||||
# Sort output based on hash value port number
|
||||
for my $service ( sort { $tcp_ports{$a} cmp $tcp_ports{$b} }
|
||||
keys %tcp_ports )
|
||||
{
|
||||
my $port = $ports{$service};
|
||||
my $port = $tcp_ports{$service};
|
||||
|
||||
# Checkbox pre-selection.
|
||||
my $checked;
|
||||
if ($udpddossettings{$port} eq "on") {
|
||||
if ($ddossettings{$port} eq "on") {
|
||||
$checked = "checked='checked'";
|
||||
}
|
||||
|
||||
@@ -360,50 +252,232 @@ for my $service ( sort { $ports{$a} cmp $ports{$b} }
|
||||
}
|
||||
|
||||
print "$line_start<td align='center' $col><input type='checkbox' name='$port' $checked></td>\n";
|
||||
print "<td align='center' $col>$port</td>\n";
|
||||
print "<td align='center' $col>$port</td>\n";
|
||||
print "<td align='left' $col>$service</td>$line_end\n";
|
||||
|
||||
$lines2++;
|
||||
}
|
||||
|
||||
print <<END;
|
||||
</table>
|
||||
|
||||
END
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
print "</form>\n";
|
||||
#
|
||||
# Read configuration file.
|
||||
&General::readhash("$dnsddossettingfile", \%dnsddossettings);
|
||||
|
||||
# Checkbox pre-selection.
|
||||
my $dns_checked;
|
||||
if ($dnsddossettings{'ENABLE_DNS_DDOS'} eq "on") {
|
||||
$dns_checked = "checked='checked'";
|
||||
}
|
||||
|
||||
# Print box to enable/disable locationblock.
|
||||
print"<form method='POST' action='$ENV{'SCRIPT_NAME'}'>\n";
|
||||
|
||||
&Header::openbox('100%', 'center', $Lang::tr{'xdp dns'});
|
||||
print <<END;
|
||||
<table width='95%'>
|
||||
<tr>
|
||||
<td width='50%' class='base'>$Lang::tr{'xdp enable'}
|
||||
<td><input type='checkbox' name='ENABLE_DNS_DDOS' $dns_checked></td>
|
||||
<td align='center'><input type='submit' name='DNS_ACTION' value='$Lang::tr{'save'}'></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
END
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
print "</form>\n";
|
||||
|
||||
# Read configuration file.
|
||||
&General::readhash("$udpddossettingfile", \%udpddossettings);
|
||||
|
||||
# Checkbox pre-selection.
|
||||
my $udp_checked;
|
||||
if ($udpddossettings{'ENABLE_UDP_DDOS'} eq "on") {
|
||||
$udp_checked = "checked='checked'";
|
||||
}
|
||||
|
||||
# Print box to enable/disable locationblock.
|
||||
print"<form method='POST' action='$ENV{'SCRIPT_NAME'}'>\n";
|
||||
|
||||
&Header::openbox('100%', 'center', $Lang::tr{'xdp udp'});
|
||||
print <<END;
|
||||
<table width='95%'>
|
||||
<tr>
|
||||
<td width='50%' class='base'>$Lang::tr{'xdp enable'}
|
||||
<td><input type='checkbox' name='ENABLE_UDP_DDOS' $udp_checked></td>
|
||||
<td align='center'><input type='submit' name='UDP_ACTION' value='$Lang::tr{'save'}'></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
END
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
&Header::openbox('100%', 'center', $Lang::tr{'xdp udp port'});
|
||||
print <<END;
|
||||
|
||||
<table width='95%' class='tbl' id="countries">
|
||||
<tr>
|
||||
<td width='5%' align='center' bgcolor='$color{'color20'}'></td>
|
||||
<td width='5%' align='center' bgcolor='$color{'color20'}'>
|
||||
<b>$Lang::tr{'port'}</b>
|
||||
</td>
|
||||
<td with='35%' align='left' bgcolor='$color{'color20'}'>
|
||||
<b>$Lang::tr{'service'}</b>
|
||||
</td>
|
||||
|
||||
<td width='5%' bgcolor='$color{'color20'}'> </td>
|
||||
|
||||
<td width='5%' align='center' bgcolor='$color{'color20'}'></td>
|
||||
<td width='5%' align='center' bgcolor='$color{'color20'}'>
|
||||
<b>$Lang::tr{'port'}</b>
|
||||
</td>
|
||||
<td with='35%' align='left' bgcolor='$color{'color20'}'>
|
||||
<b>$Lang::tr{'service'}</b>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
END
|
||||
|
||||
my $udp_lines;
|
||||
my $udp_lines2;
|
||||
my $udp_col;
|
||||
|
||||
# Sort output based on hash value port number
|
||||
for my $service ( sort { $udp_ports{$a} cmp $udp_ports{$b} }
|
||||
keys %udp_ports )
|
||||
{
|
||||
my $port = $udp_ports{$service};
|
||||
|
||||
# Checkbox pre-selection.
|
||||
my $checked;
|
||||
if ($udpddossettings{$port} eq "on") {
|
||||
$checked = "checked='checked'";
|
||||
}
|
||||
|
||||
# Colour lines.
|
||||
if ($udp_lines % 2) {
|
||||
$col="bgcolor='$color{'color20'}'";
|
||||
} else {
|
||||
$col="bgcolor='$color{'color22'}'";
|
||||
}
|
||||
|
||||
# Grouping elements.
|
||||
my $line_start;
|
||||
my $line_end;
|
||||
if ($udp_lines2 % 2) {
|
||||
# Increase lines (background color by once.
|
||||
$lines++;
|
||||
|
||||
# Add empty column in front.
|
||||
$line_start="<td $udp_col> </td>";
|
||||
|
||||
# When the line number can be diveded by "2",
|
||||
# we are going to close the line.
|
||||
$line_end="</tr>";
|
||||
} else {
|
||||
# When the line number is not divideable by "2",
|
||||
# we are starting a new line.
|
||||
$line_start="<tr>";
|
||||
$line_end;
|
||||
}
|
||||
|
||||
print "$line_start<td align='center' $udp_col><input type='checkbox' name='$port' $checked></td>\n";
|
||||
print "<td align='center' $udp_col>$port</td>\n";
|
||||
print "<td align='left' $udp_col>$service</td>$line_end\n";
|
||||
|
||||
$udp_lines2++;
|
||||
}
|
||||
print <<END;
|
||||
</table>
|
||||
|
||||
END
|
||||
}
|
||||
|
||||
sub print_xdp_status_head() {
|
||||
&Header::closebox();
|
||||
|
||||
print "</form>\n";
|
||||
|
||||
&Header::openbox('100%', 'center', $Lang::tr{'xdp status'});
|
||||
|
||||
print <<END;
|
||||
<table class="tbl" width="100%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th align="center">
|
||||
<strong>$Lang::tr{'xdp interface'}</strong>
|
||||
</th>
|
||||
<th align="center">
|
||||
<strong>$Lang::tr{'xdp prio'}</strong>
|
||||
</th>
|
||||
<th align="center">
|
||||
<strong>$Lang::tr{'xdp program'}</strong>
|
||||
</th>
|
||||
<th align="center">
|
||||
<strong>$Lang::tr{'xdp mode'}</strong>
|
||||
</th>
|
||||
<th align="center">
|
||||
<strong>$Lang::tr{'xdp id'}</strong>
|
||||
</th>
|
||||
<th align="center">
|
||||
<strong>$Lang::tr{'xdp tag'}</strong>
|
||||
</th>
|
||||
<th align="center">
|
||||
<strong>$Lang::tr{'xdp action'}</strong>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<table class="tbl" width="100%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th align="center">
|
||||
<strong>$Lang::tr{'xdp interface'}</strong>
|
||||
</th>
|
||||
<th align="center">
|
||||
<strong>$Lang::tr{'xdp prio'}</strong>
|
||||
</th>
|
||||
<th align="center">
|
||||
<strong>$Lang::tr{'xdp program'}</strong>
|
||||
</th>
|
||||
<th align="center">
|
||||
<strong>$Lang::tr{'xdp mode'}</strong>
|
||||
</th>
|
||||
<th align="center">
|
||||
<strong>$Lang::tr{'xdp id'}</strong>
|
||||
</th>
|
||||
<th align="center">
|
||||
<strong>$Lang::tr{'xdp tag'}</strong>
|
||||
</th>
|
||||
<th align="center">
|
||||
<strong>$Lang::tr{'xdp action'}</strong>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
END
|
||||
|
||||
&printxdp();
|
||||
|
||||
print "</tbody>\n</table>\n";
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
&Header::closebigbox();
|
||||
|
||||
&Header::closepage();
|
||||
|
||||
sub get_tcp_ports()
|
||||
{
|
||||
my $fh;
|
||||
open($fh, '<', $tcp_portfile) or die "Unable to open file: $!";
|
||||
while (my $line = <$fh>) {
|
||||
chomp $line;
|
||||
next if $line =~ /^\s*#/; # Skip comments
|
||||
my ($service, $port) = $line =~ /^(\w+)\s+(\d+)\/tcp/;
|
||||
if ($service && $port) {
|
||||
$tcp_ports{$service} = $port;
|
||||
}
|
||||
}
|
||||
close($fh);
|
||||
}
|
||||
|
||||
sub print_xdp_status()
|
||||
sub get_udp_ports()
|
||||
{
|
||||
my $fh;
|
||||
open($fh, '<', $udp_portfile) or die "Unable to open file: $!";
|
||||
while (my $line = <$fh>) {
|
||||
chomp $line;
|
||||
next if $line =~ /^\s*#/; # Skip comments
|
||||
my ($service, $port) = $line =~ /^(\w+)\s+(\d+)\/udp/;
|
||||
if ($service && $port) {
|
||||
$udp_ports{$service} = $port;
|
||||
}
|
||||
}
|
||||
close($fh);
|
||||
}
|
||||
|
||||
sub printxdp()
|
||||
{
|
||||
# print active SSH logins (grep outpout of "who -s")
|
||||
my @output = &General::system_output("/usr/local/bin/ddosctrl", "status");
|
||||
@@ -460,5 +534,4 @@ END
|
||||
}
|
||||
|
||||
}
|
||||
print "</tbody>\n</table>\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user