From 47efb4e803d848a227fcadd9737c579dce85b3fb Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 20 May 2017 09:33:28 +1000 Subject: [PATCH] Use composer for Net_SMTP and Net_Socket and patch for TLS and CiviCRM Custom Error Roll back Net_Socket for php compatabilty --- composer.json | 12 +- composer.lock | 172 +++++++++++++++++- tools/scripts/composer/net-smtp-fix.sh | 20 ++ .../composer/patches/net-smtp-patch.txt | 15 ++ .../composer/patches/net-smtp-tls-patch.txt | 23 +++ tools/scripts/composer/pear-exception-fix.sh | 21 +++ 6 files changed, 258 insertions(+), 5 deletions(-) create mode 100755 tools/scripts/composer/net-smtp-fix.sh create mode 100644 tools/scripts/composer/patches/net-smtp-patch.txt create mode 100644 tools/scripts/composer/patches/net-smtp-tls-patch.txt create mode 100755 tools/scripts/composer/pear-exception-fix.sh diff --git a/composer.json b/composer.json index 597d71a1fb..936a2b4222 100644 --- a/composer.json +++ b/composer.json @@ -16,16 +16,22 @@ "symfony/finder": "2.3.*", "tecnickcom/tcpdf" : "6.2.*", "totten/ca-config": "~13.02", - "civicrm/civicrm-cxn-rpc": "~0.15.12.04" + "civicrm/civicrm-cxn-rpc": "~0.15.12.04", + "pear/Net_SMTP": "1.6.*", + "pear/Net_socket": "1.0.*" }, "scripts": { "post-install-cmd": [ "bash tools/scripts/composer/dompdf-cleanup.sh", - "bash tools/scripts/composer/tcpdf-cleanup.sh" + "bash tools/scripts/composer/tcpdf-cleanup.sh", + "bash tools/scripts/composer/pear-exception-fix.sh", + "bash tools/scripts/composer/net-smtp-fix.sh" ], "post-update-cmd": [ "bash tools/scripts/composer/dompdf-cleanup.sh", - "bash tools/scripts/composer/tcpdf-cleanup.sh" + "bash tools/scripts/composer/tcpdf-cleanup.sh", + "bash tools/scripts/composer/pear-exception-fix.sh", + "bash tools/scripts/composer/net-smtp-fix.sh" ] } } diff --git a/composer.lock b/composer.lock index 5c9a0766e6..651034206a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "fd3f59bfad9a391951d4e773230a4752", - "content-hash": "5ac26ca66347ff4485584db892ed4341", + "hash": "920f618f68514022e41c85825538ee53", + "content-hash": "f9426450ebd69166494ad68f61d53729", "packages": [ { "name": "civicrm/civicrm-cxn-rpc", @@ -108,6 +108,174 @@ "homepage": "https://github.com/dompdf/dompdf", "time": "2016-05-11 00:36:29" }, + { + "name": "pear/net_smtp", + "version": "1.6.3", + "source": { + "type": "git", + "url": "https://github.com/pear/Net_SMTP.git", + "reference": "7b6240761adf6ee245098e238a25d5c35650d82c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/pear/Net_SMTP/zipball/7b6240761adf6ee245098e238a25d5c35650d82c", + "reference": "7b6240761adf6ee245098e238a25d5c35650d82c", + "shasum": "" + }, + "require": { + "pear/net_socket": "*", + "pear/pear_exception": "*", + "php": ">=4.0.5" + }, + "require-dev": { + "phpunit/phpunit": "*" + }, + "suggest": { + "pear/auth_sasl": "Install optionally via your project's composer.json" + }, + "type": "library", + "autoload": { + "psr-0": { + "Net": "./" + } + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "./" + ], + "license": [ + "PHP License" + ], + "authors": [ + { + "name": "Jon Parise", + "email": "jon@php.net", + "homepage": "http://www.indelible.org", + "role": "Lead" + }, + { + "name": "Chuck Hagenbuch", + "email": "chuck@horde.org", + "role": "Lead" + } + ], + "description": "An implementation of the SMTP protocol", + "homepage": "http://pear.github.io/Net_SMTP/", + "keywords": [ + "email", + "mail", + "smtp" + ], + "time": "2015-08-02 17:20:17" + }, + { + "name": "pear/net_socket", + "version": "1.0.14", + "source": { + "type": "git", + "url": "https://github.com/pear/Net_Socket.git", + "reference": "fcd33efd77e4b35ce85489141ab9145343579fe8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/pear/Net_Socket/zipball/fcd33efd77e4b35ce85489141ab9145343579fe8", + "reference": "fcd33efd77e4b35ce85489141ab9145343579fe8", + "shasum": "" + }, + "require": { + "pear/pear_exception": "*" + }, + "require-dev": { + "phpunit/phpunit": "*" + }, + "type": "library", + "autoload": { + "psr-0": { + "Net": "./" + } + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "./" + ], + "license": [ + "PHP License" + ], + "authors": [ + { + "name": "Chuck Hagenbuch", + "email": "chuck@horde.org", + "role": "Lead" + }, + { + "name": "Aleksander Machniak", + "email": "alec@php.net", + "role": "Lead" + }, + { + "name": "Stig Bakken", + "email": "stig@php.net", + "role": "Lead" + } + ], + "description": "More info available on: http://pear.php.net/package/Net_Socket", + "time": "2014-02-20 19:27:06" + }, + { + "name": "pear/pear_exception", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/pear/PEAR_Exception.git", + "reference": "8c18719fdae000b690e3912be401c76e406dd13b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/pear/PEAR_Exception/zipball/8c18719fdae000b690e3912be401c76e406dd13b", + "reference": "8c18719fdae000b690e3912be401c76e406dd13b", + "shasum": "" + }, + "require": { + "php": ">=4.4.0" + }, + "require-dev": { + "phpunit/phpunit": "*" + }, + "type": "class", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "PEAR": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "." + ], + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Helgi Thormar", + "email": "dufuz@php.net" + }, + { + "name": "Greg Beaver", + "email": "cellog@php.net" + } + ], + "description": "The PEAR Exception base class.", + "homepage": "https://github.com/pear/PEAR_Exception", + "keywords": [ + "exception" + ], + "time": "2015-02-10 20:07:52" + }, { "name": "phenx/php-font-lib", "version": "0.4", diff --git a/tools/scripts/composer/net-smtp-fix.sh b/tools/scripts/composer/net-smtp-fix.sh new file mode 100755 index 0000000000..fb573c15b6 --- /dev/null +++ b/tools/scripts/composer/net-smtp-fix.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +## Cleanup the vendor tree. The main issue here is that civi Civi is +## deployed as a module inside a CMS, so all its source-code gets published. +## Some libraries distribute admin tools and sample files which should not +## be published. +## +## This script should be idempotent -- if you rerun it several times, it +## should always produce the same post-condition. + +## Replace a line in a file +## This is a bit like 'sed -i', but dumber and more cross-platform. + +# Add in CiviCRM custom error message for CRM-8744. +if ! grep -q 'CRM-8744' vendor/pear/net_smtp/Net/SMTP.php; then +patch vendor/pear/net_smtp/Net/SMTP.php < tools/scripts/composer/patches/net-smtp-patch.txt +fi +if ! grep -q '@STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT' vendor/pear/net_smtp/Net/SMTP.php; then +patch vendor/pear/net_smtp/Net/SMTP.php < tools/scripts/composer/patches/net-smtp-tls-patch.txt +fi diff --git a/tools/scripts/composer/patches/net-smtp-patch.txt b/tools/scripts/composer/patches/net-smtp-patch.txt new file mode 100644 index 0000000000..6b12048ca5 --- /dev/null +++ b/tools/scripts/composer/patches/net-smtp-patch.txt @@ -0,0 +1,15 @@ +--- SMTP.php 2017-01-15 05:19:55.000000000 +1100 ++++ SMTP.php.new 2017-05-20 09:01:52.832373840 +1000 +@@ -368,8 +368,10 @@ + return true; + } + +- return PEAR::raiseError('Invalid response code received from server', +- $this->_code, PEAR_ERROR_RETURN); ++ // CRM-8744 ++ $errorMessage = 'Invalid response code received from SMTP server while sending email. This is often caused by a misconfiguration in Outbound Email settings. Please verify the settings at Administer CiviCRM >> Global Settings >> Outbound Email (SMTP).'; ++ return PEAR::raiseError($errorMessage, $this->_code, PEAR_ERROR_RETURN); ++ + } + + /** diff --git a/tools/scripts/composer/patches/net-smtp-tls-patch.txt b/tools/scripts/composer/patches/net-smtp-tls-patch.txt new file mode 100644 index 0000000000..94c549fd60 --- /dev/null +++ b/tools/scripts/composer/patches/net-smtp-tls-patch.txt @@ -0,0 +1,23 @@ +diff --git a/Net/SMTP.php b/Net/SMTP.php +index 28eae8c..8f4e92b 100644 +--- a/Net/SMTP.php ++++ b/Net/SMTP.php +@@ -602,7 +602,17 @@ + if (PEAR::isError($result = $this->_parseResponse(220))) { + return $result; + } +- if (PEAR::isError($result = $this->_socket->enableCrypto(true, STREAM_CRYPTO_METHOD_TLS_CLIENT))) { ++ if (isset($this->socket_options['ssl']['crypto_method'])) { ++ $crypto_method = $this->socket_options['ssl']['crypto_method']; ++ } else { ++ /* STREAM_CRYPTO_METHOD_TLS_ANY_CLIENT constant does not exist ++ * and STREAM_CRYPTO_METHOD_SSLv23_CLIENT constant is ++ * inconsistent across PHP versions. */ ++ $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT ++ | @STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT ++ | @STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT; ++ } ++ if (PEAR::isError($result = $this->socket->enableCrypto(true, $crypto_method))) { + return $result; + } elseif ($result !== true) { + return PEAR::raiseError('STARTTLS failed'); diff --git a/tools/scripts/composer/pear-exception-fix.sh b/tools/scripts/composer/pear-exception-fix.sh new file mode 100755 index 0000000000..a733e0357f --- /dev/null +++ b/tools/scripts/composer/pear-exception-fix.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +## Cleanup the vendor tree. The main issue here is that civi Civi is +## deployed as a module inside a CMS, so all its source-code gets published. +## Some libraries distribute admin tools and sample files which should not +## be published. +## +## This script should be idempotent -- if you rerun it several times, it +## should always produce the same post-condition. + +## Replace a line in a file +## This is a bit like 'sed -i', but dumber and more cross-platform. +function simple_replace() { + php -r 'file_put_contents($argv[1], preg_replace($argv[2], $argv[3], file_get_contents($argv[1])));' "$@" +} + + +# add in class_exists test as per CRM-8921. +if ! grep -q 'CRM-8921' vendor/pear/pear_exception/PEAR/Exception.php; then +simple_replace vendor/pear/pear_exception/PEAR/Exception.php '^\<\?php^' '