package Cpanel::Easy::PHP5::Openssl;

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

use strict;

our $easyconfig = {
    'name'   => 'Openssl',
    'url'    => 'http://www.php.net/manual/en/ref.openssl.php',
    'note'   => 'Requires OpenSSL 0.9.7 or newer',
    'dryrun' => {
        '0' => {
            'name'    => 'Get ssl path for PHP 5',
            'command' => sub {
                my ($self) = @_;
                $self->{'__'}{'OpenSSLPath'} = $self->get_openssl_prefix( { 'skip_mach' => 1 } );
                return ( 1, 'Ok' );
            },
        },
        '1' => {
            'name'    => 'Check OpenSSL version for compatability',
            'command' => sub {
                my $self        = shift;
                my $ssl_version = $self->get_openssl_version_number( $self->{'__'}{'OpenSSLPath'} );
                if ($ssl_version) {
                    if ( $ssl_version < 0x000907000 ) {
                        return ( 0, 'OpenSSL extension required version 0.9.7 or higher' );
                    }
                    else {
                        return ( 1, 'Ok' );
                    }
                }
                else {
                    $self->print_alert_color( 'red', 'Could not determine which version of OpenSSL is in use.' );
                    $self->print_alert_color( 'red', 'If you have build errors please disable the PHP OpenSSL extension!' );
                    return ( 1, 'Ok' );
                }

            },
        },
    },
    'step' => {
        '0' => {
            'name'    => 'to config options',
            'command' => sub {
                my ($self) = @_;

                $self->add_to_configure(
                    {
                        '--with-openssl'     => $self->{'__'}{'OpenSSLPath'},
                        '--with-openssl-dir' => $self->{'__'}{'OpenSSLPath'}
                    }
                );
                return ( 1, 'Ok' );
            },

        },
    },
};

1;
