<commit_before>#!/usr/bin/perl -w
##### IMPORTANT #####
# THIS IS NOT A CGI APPLICATION, AND CANNOT BE USED DIRECTLY: SEE USAGE
##### IMPORTANT #####
# USAGE:
# drop this script inside CRIMP_HOME/plugins/perl_plugins, create a subdir
# called CRIMP_HOME/plugins/perl_plugins/Crimp <-- upper case C important!!,
# and finally drop any perl-based crimp plugins inside this new Crimp subdir
#
# perl-php-wrapper.pl - this script acts as a bridge between the older
#   perl-based CRIMP plugins and the new PHP engine.
#
# CRIMP - Content Redirection Internet Management Program
# Copyright (C) 2005-2006 The CRIMP Team
# Authors:       The CRIMP Team
# Project Leads: Martin "Deadpan110" Guppy <<EMAIL>>,
#                <NAME>" Llewellyn <<EMAIL>>
# HomePage:      http://crimp.sf.net/
#
# Revision info: $Id: perl-php-wrapper.pl,v 1.9 2006-12-15 18:04:28 diddledan Exp $
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA

use strict;

## we need to keep the Crimp package, as plugins expect to call functions using
## the $crimp package descriptor which is passed upon plugin initialisation.
my $crimp = new Crimp;
$crimp->execute();





##### Crimp.pm substitute follows: #####

package Crimp;

#constructor
sub new {
  my $class = shift;
  my $self = {
              _DefaultHtml => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"/>
<title></title>
</head>
<body>
</body>
</html>',
              _DefaultLang      => 'en',
              _HttpRequest      => $ENV{'HTTP_REQUEST'},
              _HttpQuery        => $ENV{'QUERY_STRING'} || '',
              _PostQuery        => undef,
              _GetData          => undef,
              _PostData         => undef,
              _receivedCookies  => undef,
              _rawCookies       => $ENV{'COOKIES'},
              _VarDirectory     => $ENV{'VAR_DIR'},
              _ErrorDirectory   => $ENV{'ERROR_DIR'},
              _HtmlDirectory    => $ENV{'DOCUMENT_ROOT'},
              _ContentType      => $ENV{'CONTENT_TYPE'},
              _RemoteHost       => $ENV{'REMOTE_HOST'},
              _ServerName       => $ENV{'SERVER_NAME'},
              _ServerSoftware   => $ENV{'SERVER_SOFTWARE'},
              _ServerProtocol   => $ENV{'PROTOCOL'},
              _UserAgent        => $ENV{'USER_AGENT'},
              _UserConfig       => $ENV{'USERCONFIG'},
             };
  bless $self, $class;

  eval {use Fcntl;use URI::Escape;};
  if ($@) {
    $self->printdebug('Initialisation Failure','fail','Could not load all required modules:',"&nbsp;&nbsp;$@");
    return;
  }

    $self->parsePOSTed();
    $self->parseGETed();
    $self->parseCookies();

  return $self;
}

sub execute {
    my $self = shift;

    ##################
    ## Main Routine ##
    ##################

    $self->executePlugin();
}

###### HELPER ROUTINES ######
sub redirectTo {
    my ($self, $url) = @_;
    return if not defined $url;
    print <<EOF;
header('Location: $url');
EOF
    exit;
}

sub stripHtmlHeaderFooter {
    my $self = shift;
    my $html = shift;

    #parse headers storing the title of the page
    $html =~ m|<title>(.*?)</title>|si;
    my $title = $1;
    #remove everything down to <body>
    $html =~ s|.*?<body.*?>||si;
    #remove everything after </body>
    $html =~ s|</body>.*||si;
    return ($title, $html);
}

sub PageTitle {
    my ($self, $pt, $override) = @_;
    if (defined $pt) {
        if (defined $override) {
            print "\$crimp->setTitle('$pt', true);\n";
        } else {
            print "\$crimp->setTitle('$pt');\n";
        }
    }
}

sub errorPage {
    my $self = shift;
    my $package = shift;
    my $errCode = shift;
    print "\$crimp->errorPage('$package', '$errCode');\n";
    exit;
}

sub HttpRequest {
  my $self = shift;
  return $self->{_HttpRequest};
}

sub ContentType {
    my ($self, $ct) = @_;
    if (defined $ct) {
        $self->{_ContentType} = $ct;
        print "\$crimp->contentType('$ct');\n";
    }
    return $self->{_ContentType};
}

sub ExitCode {
    my ($self, $ec) = @_;
    if (defined $ec) {
        $self->{_ExitCode} = $ec;
        print "\$crimp->exitCode('$ec');\n";
    }
    return $self->{_ExitCode};
}

sub getCookie {
    my ($self, $cookiename) = @_;
    return $self->{_receivedCookies}->{$cookiename};
}

sub userConfig {
  my $self = shift;
  return $self->{_UserConfig};
}
sub VarDirectory {
    my $self = shift;
    return $self->{_VarDirectory};
}
sub HtmlDirectory {
    my $self = shift;
    return $self->{_HtmlDirectory};
}
sub queryParam {
    #return the query parameter requested, favouring POST
    my ($self, $parameter) = @_;

    return $self->{_PostData}->{$parameter} if $self->{_PostData}->{$parameter};
    return $self->{_GetData}->{$parameter} if $self->{_GetData}->{$parameter};
    return undef;
}

sub Config {
	#return the configuration for the specified key from the crimp.ini file
	my ($self, $plugin, $key) = @_;<commit_msg>added a couple of default values to combat uninitialised variable syndrome<commit_after>#!/usr/bin/perl -w
##### IMPORTANT #####
# THIS IS NOT A CGI APPLICATION, AND CANNOT BE USED DIRECTLY: SEE USAGE
##### IMPORTANT #####
# USAGE:
# drop this script inside CRIMP_HOME/plugins/perl_plugins, create a subdir
# called CRIMP_HOME/plugins/perl_plugins/Crimp <-- upper case C important!!,
# and finally drop any perl-based crimp plugins inside this new Crimp subdir
#
# perl-php-wrapper.pl - this script acts as a bridge between the older
#   perl-based CRIMP plugins and the new PHP engine.
#
# CRIMP - Content Redirection Internet Management Program
# Copyright (C) 2005-2006 The CRIMP Team
# Authors:       The CRIMP Team
# Project Leads: Martin "Deadpan110" Guppy <<EMAIL>>,
#                Daniel "Fremen" Llewellyn <<EMAIL>>
# HomePage:      http://crimp.sf.net/
#
# Revision info: $Id: perl-php-wrapper.pl,v 1.10 2006-12-15 20:59:37 diddledan Exp $
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA

use strict;

## we need to keep the Crimp package, as plugins expect to call functions using
## the $crimp package descriptor which is passed upon plugin initialisation.
my $crimp = new Crimp;
$crimp->execute();





##### Crimp.pm substitute follows: #####

package Crimp;

#constructor
sub new {
  my $class = shift;
  my $self = {
              _DefaultHtml => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"/>
<title></title>
</head>
<body>
</body>
</html>',
              _DefaultLang      => 'en',
              _HttpRequest      => $ENV{'HTTP_REQUEST'},
              _HttpQuery        => $ENV{'QUERY_STRING'} || '',
              _PostQuery        => undef,
              _GetData          => undef,
              _PostData         => undef,
              _receivedCookies  => undef,
              _rawCookies       => $ENV{'COOKIES'},
              _VarDirectory     => $ENV{'VAR_DIR'},
              _ErrorDirectory   => $ENV{'ERROR_DIR'},
              _HtmlDirectory    => $ENV{'DOCUMENT_ROOT'},
              _ContentType      => $ENV{'CONTENT_TYPE'},
              _RemoteHost       => $ENV{'REMOTE_HOST'},
              _ServerName       => $ENV{'SERVER_NAME'},
              _ServerSoftware   => $ENV{'SERVER_SOFTWARE'},
              _ServerProtocol   => $ENV{'PROTOCOL'},
              _UserAgent        => $ENV{'USER_AGENT'},
              _UserConfig       => $ENV{'USERCONFIG'},
             };
  bless $self, $class;

  eval {use Fcntl;use URI::Escape;};
  if ($@) {
    $self->printdebug('Initialisation Failure','fail','Could not load all required modules:',"&nbsp;&nbsp;$@");
    return;
  }

    $self->parsePOSTed();
    $self->parseGETed();
    $self->parseCookies();

  return $self;
}

sub execute {
    my $self = shift;

    ##################
    ## Main Routine ##
    ##################

    $self->executePlugin();
}

###### HELPER ROUTINES ######
sub redirectTo {
    my ($self, $url) = @_;
    return if not defined $url;
    print <<EOF;
header('Location: $url');
EOF
    exit;
}

sub stripHtmlHeaderFooter {
    my $self = shift;
    my $html = shift;

    #parse headers storing the title of the page
    $html =~ m|<title>(.*?)</title>|si;
    my $title = $1;
    #remove everything down to <body>
    $html =~ s|.*?<body.*?>||si;
    #remove everything after </body>
    $html =~ s|</body>.*||si;
    return ($title, $html);
}

sub PageTitle {
    my ($self, $pt, $override) = @_;
    if (defined $pt) {
        if (defined $override) {
            print "\$crimp->setTitle('$pt', true);\n";
        } else {
            print "\$crimp->setTitle('$pt');\n";
        }
    }
}

sub errorPage {
    my $self = shift;
    my $package = shift;
    my $errCode = shift;
    print "\$crimp->errorPage('$package', '$errCode');\n";
    exit;
}

sub HttpRequest {
  my $self = shift;
  return $self->{_HttpRequest} || '/';
}

sub ContentType {
    my ($self, $ct) = @_;
    if (defined $ct) {
        $self->{_ContentType} = $ct;
        print "\$crimp->contentType('$ct');\n";
    }
    return $self->{_ContentType};
}

sub ExitCode {
    my ($self, $ec) = @_;
    if (defined $ec) {
        $self->{_ExitCode} = $ec;
        print "\$crimp->exitCode('$ec');\n";
    }
    return $self->{_ExitCode};
}

sub getCookie {
    my ($self, $cookiename) = @_;
    return $self->{_receivedCookies}->{$cookiename} || '';
}

sub userConfig {
  my $self = shift;
  return $self->{_UserConfig} || '/';
}
sub VarDirectory {
    my $self = shift;
    return $self->{_VarDirectory};
}
sub HtmlDirectory {
    my $self = shift;
    return $self->{_HtmlDirectory};
}
sub queryParam {
    #return the query parameter requested, favouring POST
    my ($self, $parameter) = @_;

    return $self->{_PostData}->{$parameter} if $self->{_PostData}->{$parameter};
    return $self->{_GetData}->{$parameter} if $self->{_GetData}->{$parameter};
    return undef;
}

sub Config {
	#return the configuration for the specified key from the crimp.ini file
	my ($self, $plugin, $key) = @_;
{'fraction_non_alphanumeric': 0.15654486189740952, 'fraction_numerical': 0.009864470749699776, 'mean_word_length': 2.770698576972833, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 140, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6718286', 'n_tokens_mistral': 3851, 'n_tokens_neox': 3653, 'n_words': 1081}