# -- # HTML::Safe.pm - remove activ html stuff from html strings # Copyright (C) 2001-2006 OTRS GmbH, http://otrs.org/ # -- # $Id: Safe.pm,v 1.4 2006/10/03 14:36:01 mh Exp $ # -- # This software comes with ABSOLUTELY NO WARRANTY. For details, see # the enclosed file COPYING for license information (GPL). If you # did not receive this file, see http://www.gnu.org/licenses/gpl.txt. # -- package HTML::Safe; use strict; use vars qw($VERSION); $VERSION = "1.0"; =head1 NAME HTML::Safe - remove activ html stuff from html strings =head1 SYNOPSIS A module to remove/strip active html tags/addons (javascript, applets, embeds and objects) from html strings. =head1 PUBLIC INTERFACE =over 4 =cut =item new() create a object use HTML::Safe; my $HTMLSafe = HTML::Safe->new(); Or if you want do define own filter params my $HTMLSafe = HTML::Safe->new( NoApplet => 1, NoObject => 1, NoEmbed => 1, NoIntSrcLoad => 0, NoExtSrcLoad => 1, NoJavaScript => 1, ); =cut sub new { my $Type = shift; my %Param = @_; # allocate new hash for object my $Self = {}; bless ($Self, $Type); $Self->{Debug} = $Param{Debug} || 0; foreach (qw(NoApplet NoObject NoEmbed NoExtSrcLoad NoIntSrcLoad NoJavaScript)) { $Self->{$_} = defined($Param{$_}) ? $Param{$_} : 1; } return $Self; } =item Filter() To filter html strings. # get html my $Data = 'Some HTML with active alements!'; # filter active elements $HTMLSafe->Filter(Data => \$Data); # print clean html print $Data; =cut sub Filter { my $Self = shift; my %Param = @_; # check needed stuff foreach (qw(Data)) { if (!$Param{$_}) { print STDERR "Need $_!"; return; } } # remove script tags if ($Self->{NoJavaScript}) { ${$Param{Data}} =~ s{ (.+?) } { # print STDERR "$1 found!"; if ($Self->{Debug} > 0) { print STDERR "Found