# cpanel - Cpanel/Easy/ModMono2.pm                Copyright(c) 2014 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

package Cpanel::Easy::ModMono2;

use Cpanel::Easy::Utils::ModMono;
our $easyconfig = Cpanel::Easy::Utils::ModMono::get_default_mono_easyconfig();
my $version = $Cpanel::Easy::Utils::ModMono::version;

$easyconfig->{'name'} = qq{Mod Mono $version (.Net 2.x)};
$easyconfig->{'note'} = qq{Not currently compatible with mod_mono .Net 1.x support, one will be dropped};    # maybe tell them which one takes precedence once we know which one we want that to be and set it ?

$easyconfig->{'url'} = 'http://www.mono-project.com/ASP.NET#Supported_Versions';

$easyconfig->{'implies'} = { 'Cpanel::Easy::ModMono' => 0, };

$easyconfig->{'step'}{'10.1'} = {
    'name'    => 'configuring to use partial .NET 2 support instead of default 1.x support',
    'command' => sub {
        my ($self) = @_;

        my @file;
        my $file_name = '/usr/local/apache/conf/mod_mono.conf';

        if ( open my $rfh, '<', $file_name ) {
            @file = <$rfh>;
            close $rfh;
        }
        else {
            return ( 0, q{Could not open '[_1]' for reading: [_2]}, $file_name, $! );
        }

        # move everything after where it needs to be up one
        for my $n ( reverse( 1 .. $#file ) ) { $file[ $n + 1 ] = $file[$n] }

        # then set that spot to the new value
        $file[1] = "    MonoServerPath /opt/mono/bin/mod-mono-server2\n";

        if ( open my $fh, '>', $file_name ) {
            print {$fh} @file;
            close $fh;
        }
        else {
            return ( 0, q{Could not open '[_1]' for writing: [_2]}, $file_name, $! );
        }
        return ( 1, 'ok' );
    },
};

1;
