#!/usr/bin/perl $temp = "/tmp"; $firestarter = "/etc/firestarter"; $kmyfirewall = "/etc/kmyfirewall"; $regla = "/usr/share/apps/kmyfirewall/rulesets"; $peer = 0; $i = 0; # Descarga de Internet la base de datos del peerguardian, # y la transforma a texto plano. system ("wget -c -t 10 -O $temp/peer.htm http://homepage.ntlworld.com/tim.leonard1/pg_plain.htm"); system ("html2text $temp/peer.htm > $temp/peer.txt"); # Genera el fichero blocked-hosts para el firestarter open FICHERO, "$temp/peer.txt"; open SALIDA, ">$temp/ip_bloqueadas.txt"; while ($linea = ) { chop ($linea); if ($linea =~ /^(.+):(\d+\.\d+\.\d+\.\d+)-(\d+\.\d+\.\d+\.\d+)$/) { $regla = $1; $ip1 = $2; $ip2 = $3; $ip1 =~ s/0*(\d+)\.0*(\d+)\.0*(\d+)\.0*(\d+)/$1\.$2\.$3\.$4/; $ip2 =~ s/0*(\d+)\.0*(\d+)\.0*(\d+)\.0*(\d+)/$1\.$2\.$3\.$4/; print SALIDA "# $regla\n"; print SALIDA "$ip1/$ip2\n"; } elsif ($linea =~ /^(\d+\.\d+\.\d+\.\d+)-(\d+\.\d+\.\d+\.\d+)$/) { $ip1 = $1; $ip2 = $2; $ip1 =~ s/0*(\d+)\.0*(\d+)\.0*(\d+)\.0*(\d+)/$1\.$2\.$3\.$4/; $ip2 =~ s/0*(\d+)\.0*(\d+)\.0*(\d+)\.0*(\d+)/$1\.$2\.$3\.$4/; print SALIDA "# No se sabe\n"; print SALIDA "$ip1/$ip2\n"; } elsif ($linea =~ /^(.+):(\d+\.\d+\.\d+\.\d+)-$/) { $regla = $1; $ip1 = $2; $ip1 =~ s/0*(\d+)\.0*(\d+)\.0*(\d+)\.0*(\d+)/$1\.$2\.$3\.$4/; } elsif ($linea =~ /^(\d+\.\d+\.\d+\.\d+)$/) { $ip2 = $1; $ip2 =~ s/0*(\d+)\.0*(\d+)\.0*(\d+)\.0*(\d+)/$1\.$2\.$3\.$4/; print SALIDA "# $regla\n"; print SALIDA "$ip1/$ip2\n"; } } close FICHERO; close SALIDA; system ("mv $temp/ip_bloqueadas.txt $firestarter/blocked-hosts"); system ("rm $temp/peer.htm"); system ("rm $temp/peer.txt"); # Genera el fichero de regla para kmyfirewall system ("rm /usr/share/apps/kmyfirewall/rulesets/filtro.kmfrs"); open FICHERO, "$firestarter/blocked-hosts"; open REGLAS, "/usr/share/apps/kmyfirewall/rulesets/filtro.tmp"; open SALIDA, ">/usr/share/apps/kmyfirewall/rulesets/filtro.kmfrs"; while ($linea = ) { if ($linea =~ /^ $/) { while ($linea1 = ) { chop ($linea1); if ($linea1 !~ /^\#.+$/) { $i++; print SALIDA "\n"; print SALIDA " \n"; print SALIDA " \n"; print SALIDA " \n"; print SALIDA " \n"; print SALIDA " \n"; print SALIDA " \n"; print SALIDA " \n"; print SALIDA " \n"; print SALIDA " \n"; print SALIDA "\n"; } } } print SALIDA "$linea"; } close FICHERO; close REGLAS; close SALIDA;