#!/usr/bin/perl
# cpanel - disable_attracta                       Copyright(c) 2012 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

BEGIN {
    unshift @INC, '/usr/local/cpanel';
}

use strict;

use Cpanel::Config               ();
use Cpanel::FileUtils::TouchFile ();
use Cpanel::SafeDir::MK          ();
use Cpanel::Version              ();

if (   ( Cpanel::Version::compare( Cpanel::Version::getversionnumber(), '<=', '11.32.3' ) )
    && ( Cpanel::Version::compare( Cpanel::Version::getversionnumber(), '>=', '11.30' ) ) ) {

    my $attracta_config_dir = '/var/cpanel/attracta';
    if ( !Cpanel::SafeDir::MK::safemkdir( $attracta_config_dir, '0700' ) ) {
        print STDERR "Attracta configuration directory could not be created!\n";
        exit(1);
    }

    # create touchfile related to mod_fastinclude
    if ( !Cpanel::FileUtils::TouchFile::touchfile('/var/cpanel/attracta/fastincludeoff') ) {
        print STDERR "mod_fastinclude configuration file could not be set!\n";
        exit(1);
    }

    # add attracta=0 to local cpanel.config
    my $cpconf = Cpanel::Config::loadcpconf();
    if ( !$cpconf || ref $cpconf ne ref {} ) {
        print STDERR "Unable to access server configuration file!\n";
        exit(1);
    }

    $cpconf->{'attracta'} = 0;
    if ( !Cpanel::Config::savecpconf($cpconf) ) {
        print STDERR "Unable to save server configuration file!\n";
        exit(1);
    }
    print STDOUT "Attracta has been disabled.\n";
}
else {
    print STDOUT "This script is only compatible with cPanel & WHM versions 11.30 through 11.32.2";
}

exit;
